/**
 * ============================================================================
 * DEBT MANAGEMENT - STYLES V2
 * ============================================================================
 * Modern UI styles for the Debt Management module
 */

/* =========================================================================
   CSS VARIABLES
   ========================================================================= */

:root {
    --debt-primary: #6366f1;
    --debt-primary-dark: #4f46e5;
    --debt-receivable: #10b981;
    --debt-receivable-bg: rgba(16, 185, 129, 0.1);
    --debt-payable: #ef4444;
    --debt-payable-bg: rgba(239, 68, 68, 0.1);
    --debt-warning: #f59e0b;
    --debt-warning-bg: rgba(245, 158, 11, 0.1);
    --debt-success: #22c55e;
    --debt-danger: #dc2626;
    --debt-gray-50: #f9fafb;
    --debt-gray-100: #f3f4f6;
    --debt-gray-200: #e5e7eb;
    --debt-gray-300: #d1d5db;
    --debt-gray-400: #9ca3af;
    --debt-gray-500: #6b7280;
    --debt-gray-600: #4b5563;
    --debt-gray-700: #374151;
    --debt-gray-800: #1f2937;
    --debt-gray-900: #111827;
    --debt-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --debt-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --debt-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --debt-radius: 8px;
    --debt-radius-lg: 12px;
}

/* =========================================================================
   MODULE CONTAINER
   ========================================================================= */

.debt-module {
    padding: 24px;
    background: var(--debt-gray-50);
    min-height: 100vh;
}

/* =========================================================================
   HEADER
   ========================================================================= */

.debt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--debt-gray-200);
}

.debt-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.debt-header-icon {
    font-size: 2rem;
}

.debt-header-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--debt-gray-900);
    margin: 0;
}

.debt-header-actions {
    display: flex;
    gap: 12px;
}

/* =========================================================================
   TABS
   ========================================================================= */

.debt-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--debt-gray-100);
    border-radius: var(--debt-radius-lg);
    margin-bottom: 24px;
    overflow-x: auto;
}

.debt-tab {
    padding: 10px 20px;
    border: none;
    background: transparent;
    border-radius: var(--debt-radius);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--debt-gray-600);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.debt-tab:hover {
    background: rgba(255, 255, 255, 0.5);
    color: var(--debt-gray-900);
}

.debt-tab.active {
    background: linear-gradient(135deg, var(--debt-primary), var(--debt-primary-dark));
    color: white;
    box-shadow: 0 2px 10px rgba(99, 102, 241, 0.3);
    font-weight: 600;
}

/* =========================================================================
   CONTENT
   ========================================================================= */

.debt-content {
    background: white;
    border-radius: var(--debt-radius-lg);
    padding: 24px;
    box-shadow: var(--debt-shadow-sm);
}

/* =========================================================================
   OVERVIEW GRID (Cards)
   ========================================================================= */

.debt-overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.debt-card {
    padding: 20px;
    border-radius: var(--debt-radius-lg);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px) saturate(150%);
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-left: 4px solid var(--debt-gray-300);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.debt-card:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    transform: translateY(-4px) scale(1.01);
}

.debt-card-icon {
    font-size: 1.6rem;
    margin-bottom: 10px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--debt-gray-100);
    border-radius: 12px;
    transition: transform 0.3s ease;
}

.debt-card:hover .debt-card-icon {
    transform: scale(1.1) rotate(-3deg);
}

.debt-card-label {
    font-size: 0.875rem;
    color: var(--debt-gray-500);
    margin-bottom: 4px;
}

.debt-card-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--debt-gray-900);
    margin-bottom: 8px;
    font-family: var(--font-mono);
    letter-spacing: -0.5px;
}

.debt-card-badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 20px;
    background: var(--debt-gray-100);
    color: var(--debt-gray-600);
}

/* Card variants */
.debt-card-receivable {
    border-left: 4px solid var(--debt-receivable);
}
.debt-card-receivable .debt-card-value {
    color: var(--debt-receivable);
}

.debt-card-payable {
    border-left: 4px solid var(--debt-payable);
}
.debt-card-payable .debt-card-value {
    color: var(--debt-payable);
}

.debt-card-overdue {
    border-left: 4px solid var(--debt-warning);
}
.debt-card-overdue .debt-card-value {
    color: var(--debt-warning);
}

.debt-card-positive {
    border-left: 4px solid var(--debt-success);
}
.debt-card-positive .debt-card-value {
    color: var(--debt-success);
}

.debt-card-negative {
    border-left: 4px solid var(--debt-danger);
}
.debt-card-negative .debt-card-value {
    color: var(--debt-danger);
}

/* =========================================================================
   OVERVIEW COLUMNS
   ========================================================================= */

.debt-overview-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 24px;
}

/* =========================================================================
   SECTIONS
   ========================================================================= */

.debt-section {
    background: rgba(249, 250, 251, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: var(--debt-radius-lg);
    padding: 20px;
    margin-bottom: 24px;
    border: 1px solid rgba(0, 0, 0, 0.04);
    transition: box-shadow 0.3s ease;
}

.debt-section:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.debt-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.debt-section-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--debt-gray-800);
}

/* =========================================================================
   ENTITY LIST
   ========================================================================= */

.debt-entity-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.debt-entity-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: white;
    border-radius: var(--debt-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.debt-entity-item:hover {
    background: var(--debt-gray-100);
    transform: translateX(4px);
}

.debt-entity-rank {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--debt-primary), var(--debt-primary-dark));
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
    flex-shrink: 0;
}

.debt-entity-info {
    flex: 1;
}

.debt-entity-name {
    font-weight: 500;
    color: var(--debt-gray-900);
}

.debt-entity-meta {
    font-size: 0.75rem;
    color: var(--debt-gray-500);
    margin-top: 2px;
}

.debt-entity-amount {
    font-weight: 600;
    color: var(--debt-gray-900);
}

/* =========================================================================
   WALLET SUMMARY
   ========================================================================= */

.debt-wallet-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.debt-wallet-summary-card {
    padding: 16px;
    background: white;
    border-radius: var(--debt-radius);
    text-align: center;
}

.debt-wallet-summary-icon {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.debt-wallet-summary-label {
    font-size: 0.875rem;
    color: var(--debt-gray-500);
    margin-bottom: 4px;
}

.debt-wallet-summary-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--debt-gray-900);
}

.debt-wallet-summary-count {
    font-size: 0.75rem;
    color: var(--debt-gray-400);
    margin-top: 4px;
}

/* =========================================================================
   FILTER BAR
   ========================================================================= */

.debt-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    padding: 16px;
    background: var(--debt-gray-50);
    border-radius: var(--debt-radius);
    margin-bottom: 16px;
}

.debt-filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.debt-filter-group label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--debt-gray-600);
    white-space: nowrap;
}

.debt-filter-select,
.debt-filter-input {
    padding: 8px 12px;
    border: 1px solid var(--debt-gray-300);
    border-radius: var(--debt-radius);
    font-size: 0.875rem;
    background: white;
    min-width: 120px;
}

.debt-filter-select:focus,
.debt-filter-input:focus {
    outline: none;
    border-color: var(--debt-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.debt-filter-spacer {
    flex: 1;
}

.debt-search-input {
    padding: 8px 12px;
    border: 1px solid var(--debt-gray-300);
    border-radius: var(--debt-radius);
    font-size: 0.875rem;
    min-width: 200px;
}

/* =========================================================================
   LIST STATS
   ========================================================================= */

.debt-list-stats {
    display: flex;
    gap: 24px;
    padding: 12px 0;
    font-size: 0.875rem;
    color: var(--debt-gray-600);
    border-bottom: 1px solid var(--debt-gray-200);
    margin-bottom: 16px;
}

.debt-list-stats strong {
    color: var(--debt-gray-900);
}

/* =========================================================================
   TABLE
   ========================================================================= */

.debt-table-container {
    overflow-x: auto;
}

.debt-table {
    width: 100%;
    border-collapse: collapse;
}

.debt-table thead {
    background: linear-gradient(135deg, var(--debt-gray-100), var(--debt-gray-50));
}

.debt-table th {
    padding: 12px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--debt-gray-600);
    text-align: left;
    border-bottom: 2px solid var(--debt-gray-200);
    white-space: nowrap;
}

.debt-table th.sortable {
    cursor: pointer;
}

.debt-table th.sortable:hover {
    color: var(--debt-primary);
}

.debt-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--debt-gray-100);
    font-size: 0.875rem;
    color: var(--debt-gray-700);
}

.debt-table tbody tr {
    transition: background 0.15s;
}

.debt-table tbody tr:hover {
    background: var(--debt-gray-50);
}

.debt-table tbody tr.overdue {
    background: rgba(239, 68, 68, 0.05);
}

/* =========================================================================
   TABLE CELLS
   ========================================================================= */

.debt-entity-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.debt-entity-avatar {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--debt-primary), var(--debt-primary-dark));
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 50%;
}

/* CÔNG NỢ STANDALONE: đảo thứ tự — NỘI DUNG (chính, to-đậm) hiển thị TRƯỚC, MÃ (phụ, nhỏ-nhạt) dưới */
.debt-desc-cell {
    display: flex;
    flex-direction: column-reverse;
    gap: 2px;
}

.debt-code {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--debt-gray-500);
    font-family: var(--font-mono);
    letter-spacing: 0.02em;
    opacity: 0.85;
}

.debt-desc {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--debt-gray-900);
    line-height: 1.35;
}

.debt-amount {
    text-align: right;
    font-weight: 600;
    font-family: var(--font-mono);
}

.debt-remaining {
    font-weight: 700;
}

.debt-remaining.receivable {
    color: var(--debt-receivable);
}

.debt-remaining.payable {
    color: var(--debt-payable);
}

/* CÔNG NỢ STANDALONE: cột CÒN LẠI — ĐỎ khi còn nợ (>0), xám nhạt khi đã trả hết (=0).
   Đặt SAU .receivable/.payable + !important để thắng màu theo loại. */
.debt-remaining.is-owed,
.debt-amount.is-owed {
    color: #dc2626 !important;
    font-weight: 700;
}

.debt-remaining.is-paid,
.debt-amount.is-paid {
    color: #9ca3af !important;
    font-weight: 600;
}

/* =========================================================================
   PROGRESS BAR
   ========================================================================= */

.debt-progress {
    height: 4px;
    background: var(--debt-gray-200);
    border-radius: 2px;
    margin-top: 4px;
    overflow: hidden;
}

.debt-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--debt-primary), var(--debt-receivable));
    border-radius: 2px;
    transition: width 0.3s;
}

/* =========================================================================
   BADGES
   ========================================================================= */

.debt-type-badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 20px;
}

.debt-type-badge.receivable {
    background: var(--debt-receivable-bg);
    color: var(--debt-receivable);
}

.debt-type-badge.payable {
    background: var(--debt-payable-bg);
    color: var(--debt-payable);
}

.debt-status-badge {
    display: inline-block;
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 20px;
    background: var(--debt-gray-100);
    color: var(--debt-gray-600);
}

.debt-status-badge.open {
    background: #dbeafe;
    color: #1d4ed8;
}

.debt-status-badge.partial {
    background: #fef3c7;
    color: #b45309;
}

.debt-status-badge.paid {
    background: #d1fae5;
    color: #047857;
}

.debt-status-badge.overdue {
    background: #fee2e2;
    color: #b91c1c;
}

/* =========================================================================
   BUTTONS
   ========================================================================= */

.debt-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--debt-radius);
    cursor: pointer;
    transition: all 0.2s;
}

.debt-btn-primary {
    background: linear-gradient(135deg, var(--debt-primary), var(--debt-primary-dark));
    color: white;
}

.debt-btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--debt-shadow);
}

.debt-btn-outline {
    background: white;
    color: var(--debt-gray-700);
    border: 1px solid var(--debt-gray-300);
}

.debt-btn-outline:hover {
    background: var(--debt-gray-50);
    border-color: var(--debt-gray-400);
}

.debt-btn-ghost {
    background: transparent;
    color: var(--debt-gray-600);
}

.debt-btn-ghost:hover {
    background: var(--debt-gray-100);
}

.debt-btn-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--debt-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.debt-btn-link:hover {
    text-decoration: underline;
}

.debt-action-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--debt-gray-100);
    border: none;
    border-radius: var(--debt-radius);
    cursor: pointer;
    transition: all 0.15s;
}

.debt-action-btn:hover {
    background: var(--debt-gray-200);
    transform: scale(1.1);
}

.debt-action-btn.primary {
    background: var(--debt-primary);
    color: white;
}

.debt-action-btn.primary:hover {
    background: var(--debt-primary-dark);
}

.debt-actions {
    display: flex;
    gap: 6px;
}

/* =========================================================================
   EMPTY STATE
   ========================================================================= */

.debt-empty {
    padding: 48px 24px;
    text-align: center;
}

.debt-empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.debt-empty-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--debt-gray-700);
    margin-bottom: 8px;
}

.debt-empty-desc {
    font-size: 0.875rem;
    color: var(--debt-gray-500);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Small button variant */
.debt-btn-sm {
    padding: 6px 12px;
    font-size: 0.75rem;
}

/* =========================================================================
   PAYMENT PANEL
   ========================================================================= */

.debt-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.debt-payment-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 100%;
    background: white;
    box-shadow: var(--debt-shadow-lg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.debt-payment-panel.open {
    transform: translateX(0);
}

.debt-payment-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--debt-primary), var(--debt-primary-dark));
    color: white;
}

.debt-payment-panel-header h3 {
    margin: 0;
    font-size: 1.125rem;
}

.debt-payment-panel-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
}

.debt-payment-panel-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.debt-payment-panel-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.debt-payment-panel-footer {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    background: var(--debt-gray-50);
    border-top: 1px solid var(--debt-gray-200);
}

.debt-payment-panel-footer .debt-btn {
    flex: 1;
}

/* Payment Entity */
.debt-payment-entity {
    padding: 16px;
    background: var(--debt-gray-50);
    border-radius: var(--debt-radius);
    margin-bottom: 20px;
}

.debt-payment-entity label {
    font-size: 0.75rem;
    color: var(--debt-gray-500);
    margin-bottom: 4px;
    display: block;
}

.debt-payment-entity-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--debt-gray-900);
}

.debt-payment-entity-total {
    margin-top: 8px;
    font-size: 0.875rem;
    color: var(--debt-gray-600);
}

.debt-payment-entity-total strong {
    color: var(--debt-primary);
}

/* Invoice List */
.debt-payment-invoices {
    margin-top: 20px;
}

.debt-payment-invoices label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--debt-gray-600);
    margin-bottom: 8px;
    display: block;
}

.debt-invoice-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--debt-gray-200);
    border-radius: var(--debt-radius);
}

.debt-invoice-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--debt-gray-100);
}

.debt-invoice-item:last-child {
    border-bottom: none;
}

.debt-invoice-item.highlighted {
    background: var(--debt-receivable-bg);
}

.debt-invoice-info {
    display: flex;
    gap: 12px;
    align-items: center;
}

.debt-invoice-code {
    font-weight: 600;
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

.debt-invoice-date {
    font-size: 0.75rem;
    color: var(--debt-gray-500);
}

.debt-invoice-amount {
    font-weight: 600;
    color: var(--debt-gray-900);
}

/* =========================================================================
   FORM ELEMENTS
   ========================================================================= */

.debt-form-group {
    margin-bottom: 16px;
}

.debt-form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--debt-gray-600);
    margin-bottom: 6px;
}

.debt-form-input,
.debt-form-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--debt-gray-300);
    border-radius: var(--debt-radius);
    font-size: 0.875rem;
    transition: border-color 0.15s;
}

.debt-form-input:focus,
.debt-form-select:focus {
    outline: none;
    border-color: var(--debt-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* =========================================================================
   UTILITY CLASSES
   ========================================================================= */

.text-success { color: var(--debt-success) !important; }
.text-danger { color: var(--debt-danger) !important; }
.text-warning { color: var(--debt-warning) !important; }

/* =========================================================================
   RESPONSIVE
   ========================================================================= */

@media (max-width: 768px) {
    .debt-module {
        padding: 16px;
    }

    .debt-header {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .debt-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .debt-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .debt-overview-grid {
        grid-template-columns: 1fr 1fr;
    }

    .debt-filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .debt-filter-group {
        width: 100%;
    }

    .debt-filter-select,
    .debt-filter-input,
    .debt-search-input {
        width: 100%;
    }

    .debt-payment-panel {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .debt-overview-grid {
        grid-template-columns: 1fr;
    }
}

/* =========================================================================
   ANIMATIONS
   ========================================================================= */

@keyframes debtCardFadeIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.debt-overview-grid .debt-card {
    animation: debtCardFadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.debt-overview-grid .debt-card:nth-child(1) { animation-delay: 0ms; }
.debt-overview-grid .debt-card:nth-child(2) { animation-delay: 80ms; }
.debt-overview-grid .debt-card:nth-child(3) { animation-delay: 160ms; }
.debt-overview-grid .debt-card:nth-child(4) { animation-delay: 240ms; }

.debt-entity-item {
    animation: debtCardFadeIn 0.35s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.debt-entity-item:nth-child(1) { animation-delay: 50ms; }
.debt-entity-item:nth-child(2) { animation-delay: 100ms; }
.debt-entity-item:nth-child(3) { animation-delay: 150ms; }
.debt-entity-item:nth-child(4) { animation-delay: 200ms; }
.debt-entity-item:nth-child(5) { animation-delay: 250ms; }

/* Card icon background per type */
.debt-card-receivable .debt-card-icon {
    background: rgba(16, 185, 129, 0.1);
}

.debt-card-payable .debt-card-icon {
    background: rgba(239, 68, 68, 0.1);
}

.debt-card-overdue .debt-card-icon {
    background: rgba(245, 158, 11, 0.1);
}

.debt-card-positive .debt-card-icon {
    background: rgba(34, 197, 94, 0.1);
}

.debt-card-negative .debt-card-icon {
    background: rgba(220, 38, 38, 0.1);
}

/* =========================================================================
   DARK MODE STYLES (Tokyo Night Inspired)
   ========================================================================= */

[data-theme="dark"] {
    /* Override debt-specific variables for dark mode */
    --debt-gray-50: #1a1b26;
    --debt-gray-100: #24283b;
    --debt-gray-200: #3b4261;
    --debt-gray-300: #414868;
    --debt-gray-400: #565f89;
    --debt-gray-500: #9aa5ce;
    --debt-gray-600: #a9b1d6;
    --debt-gray-700: #c0caf5;
    --debt-gray-800: #cfc9c2;
    --debt-gray-900: #c0caf5;
    --debt-primary: #7aa2f7;
    --debt-primary-dark: #5d7ed8;
    --debt-receivable: #9ece6a;
    --debt-receivable-bg: rgba(158, 206, 106, 0.15);
    --debt-payable: #f7768e;
    --debt-payable-bg: rgba(247, 118, 142, 0.15);
    --debt-warning: #e0af68;
    --debt-warning-bg: rgba(224, 175, 104, 0.15);
    --debt-success: #9ece6a;
    --debt-danger: #f7768e;
    --debt-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --debt-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    --debt-shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .debt-module {
    background: #1a1b26;
}

[data-theme="dark"] .debt-header {
    border-bottom-color: #3b4261;
}

[data-theme="dark"] .debt-header-title {
    color: #c0caf5;
}

[data-theme="dark"] .debt-tabs {
    background: #24283b;
}

[data-theme="dark"] .debt-tab {
    color: #9aa5ce;
}

[data-theme="dark"] .debt-tab:hover {
    background: rgba(122, 162, 247, 0.1);
    color: #c0caf5;
}

[data-theme="dark"] .debt-tab.active {
    background: linear-gradient(135deg, #7aa2f7, #5d7ed8);
    color: #1a1b26;
    box-shadow: 0 2px 10px rgba(122, 162, 247, 0.35);
}

[data-theme="dark"] .debt-content {
    background: #24283b;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Summary Cards - Dark Mode */
[data-theme="dark"] .debt-card {
    background: linear-gradient(135deg, rgba(36, 40, 59, 0.9) 0%, rgba(31, 35, 53, 0.85) 100%);
    backdrop-filter: blur(12px) saturate(150%);
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    border-color: rgba(59, 66, 97, 0.6);
}

[data-theme="dark"] .debt-card:hover {
    border-color: #565f89;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .debt-card-receivable {
    background: linear-gradient(135deg, rgba(158, 206, 106, 0.15) 0%, rgba(36, 40, 59, 0.9) 100%);
    border-left: 4px solid #9ece6a;
}

[data-theme="dark"] .debt-card-receivable .debt-card-value {
    color: #9ece6a;
}

[data-theme="dark"] .debt-card-payable {
    background: linear-gradient(135deg, rgba(247, 118, 142, 0.15) 0%, rgba(36, 40, 59, 0.9) 100%);
    border-left: 4px solid #f7768e;
}

[data-theme="dark"] .debt-card-payable .debt-card-value {
    color: #f7768e;
}

[data-theme="dark"] .debt-card-overdue {
    background: linear-gradient(135deg, rgba(224, 175, 104, 0.15) 0%, rgba(36, 40, 59, 0.9) 100%);
    border-left: 4px solid #e0af68;
}

[data-theme="dark"] .debt-card-overdue .debt-card-value {
    color: #e0af68;
}

[data-theme="dark"] .debt-card-positive {
    background: linear-gradient(135deg, rgba(158, 206, 106, 0.15) 0%, rgba(36, 40, 59, 0.9) 100%);
    border-left: 4px solid #9ece6a;
}

[data-theme="dark"] .debt-card-positive .debt-card-value {
    color: #9ece6a;
}

[data-theme="dark"] .debt-card-negative {
    background: linear-gradient(135deg, rgba(247, 118, 142, 0.15) 0%, rgba(36, 40, 59, 0.9) 100%);
    border-left: 4px solid #f7768e;
}

[data-theme="dark"] .debt-card-negative .debt-card-value {
    color: #f7768e;
}

[data-theme="dark"] .debt-card-warning {
    background: linear-gradient(135deg, rgba(224, 175, 104, 0.12) 0%, rgba(224, 175, 104, 0.05) 100%);
    border-left: 4px solid #e0af68;
}

[data-theme="dark"] .debt-card-neutral {
    background: linear-gradient(135deg, rgba(122, 162, 247, 0.12) 0%, rgba(122, 162, 247, 0.05) 100%);
    border-left: 4px solid #7aa2f7;
}

[data-theme="dark"] .debt-card-receivable .debt-card-icon { background: rgba(158, 206, 106, 0.15); }
[data-theme="dark"] .debt-card-payable .debt-card-icon { background: rgba(247, 118, 142, 0.15); }
[data-theme="dark"] .debt-card-overdue .debt-card-icon { background: rgba(224, 175, 104, 0.15); }
[data-theme="dark"] .debt-card-positive .debt-card-icon { background: rgba(158, 206, 106, 0.15); }
[data-theme="dark"] .debt-card-negative .debt-card-icon { background: rgba(247, 118, 142, 0.15); }

[data-theme="dark"] .debt-card-label {
    color: #9aa5ce;
}

[data-theme="dark"] .debt-card-value {
    color: #c0caf5;
}

[data-theme="dark"] .debt-card-count {
    color: #565f89;
    background: rgba(86, 95, 137, 0.2);
}

/* Sections - Dark Mode */
[data-theme="dark"] .debt-section {
    background: rgba(31, 35, 53, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-color: rgba(59, 66, 97, 0.5);
}

[data-theme="dark"] .debt-section-header h3 {
    color: #c0caf5;
}

/* Entity List - Dark Mode */
[data-theme="dark"] .debt-entity-item {
    background: #24283b;
    border-color: #3b4261;
}

[data-theme="dark"] .debt-entity-item:hover {
    background: #2a2e42;
    border-color: #565f89;
}

[data-theme="dark"] .debt-entity-rank {
    background: #7aa2f7;
    color: #1a1b26;
}

[data-theme="dark"] .debt-entity-name {
    color: #c0caf5;
}

[data-theme="dark"] .debt-entity-meta {
    color: #565f89;
}

[data-theme="dark"] .debt-entity-amount {
    color: #9ece6a;
}

/* Table - Dark Mode */
[data-theme="dark"] .debt-table {
    background: #1f2335;
}

[data-theme="dark"] .debt-table thead {
    background: linear-gradient(135deg, #24283b 0%, #2a2e42 100%);
}

[data-theme="dark"] .debt-table th {
    color: #7aa2f7;
    border-bottom: 2px solid #3b4261;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.5px;
}

[data-theme="dark"] .debt-table td {
    color: #a9b1d6;
    border-bottom-color: #3b4261;
}

[data-theme="dark"] .debt-table tbody tr:hover {
    background: rgba(122, 162, 247, 0.08);
}

[data-theme="dark"] .debt-table tbody tr:hover td {
    color: #c0caf5;
}

/* Buttons - Dark Mode */
[data-theme="dark"] .debt-btn {
    color: #c0caf5;
    border-color: #3b4261;
}

[data-theme="dark"] .debt-btn:hover {
    background: rgba(122, 162, 247, 0.1);
    border-color: #7aa2f7;
}

[data-theme="dark"] .debt-btn-primary {
    background: linear-gradient(135deg, #7aa2f7 0%, #5d7ed8 100%);
    color: #1a1b26;
    border: none;
}

[data-theme="dark"] .debt-btn-primary:hover {
    background: linear-gradient(135deg, #8ab4ff 0%, #7aa2f7 100%);
    box-shadow: 0 4px 12px rgba(122, 162, 247, 0.4);
}

[data-theme="dark"] .debt-btn-outline {
    background: transparent;
    border-color: #565f89;
    color: #a9b1d6;
}

[data-theme="dark"] .debt-btn-outline:hover {
    background: rgba(122, 162, 247, 0.1);
    border-color: #7aa2f7;
    color: #7aa2f7;
}

[data-theme="dark"] .debt-btn-link {
    color: #7aa2f7;
}

[data-theme="dark"] .debt-btn-link:hover {
    color: #8ab4ff;
}

/* Button variants */
.debt-btn-danger {
    color: #dc2626 !important;
    border-color: #dc2626 !important;
}

.debt-btn-danger:hover {
    background: rgba(220, 38, 38, 0.1) !important;
}

.debt-btn-warning {
    color: #f59e0b !important;
    border-color: #f59e0b !important;
}

.debt-btn-warning:hover {
    background: rgba(245, 158, 11, 0.1) !important;
}

[data-theme="dark"] .debt-btn-danger {
    color: #f7768e !important;
    border-color: #f7768e !important;
}

[data-theme="dark"] .debt-btn-danger:hover {
    background: rgba(247, 118, 142, 0.15) !important;
}

[data-theme="dark"] .debt-btn-warning {
    color: #e0af68 !important;
    border-color: #e0af68 !important;
}

[data-theme="dark"] .debt-btn-warning:hover {
    background: rgba(224, 175, 104, 0.15) !important;
}

/* Wallet Summary - Dark Mode */
[data-theme="dark"] .debt-wallet-summary-card {
    background: #24283b;
    border-color: #3b4261;
}

[data-theme="dark"] .debt-wallet-summary-label {
    color: #9aa5ce;
}

[data-theme="dark"] .debt-wallet-summary-value {
    color: #c0caf5;
}

[data-theme="dark"] .debt-wallet-summary-count {
    color: #565f89;
}

/* Filter Bar - Dark Mode */
[data-theme="dark"] .debt-filter-bar {
    background: #24283b;
    border-color: #3b4261;
}

[data-theme="dark"] .debt-filter-select,
[data-theme="dark"] .debt-filter-input,
[data-theme="dark"] .debt-search-input {
    background: #1a1b26;
    border-color: #3b4261;
    color: #c0caf5;
}

[data-theme="dark"] .debt-filter-select:focus,
[data-theme="dark"] .debt-filter-input:focus,
[data-theme="dark"] .debt-search-input:focus {
    border-color: #7aa2f7;
    box-shadow: 0 0 0 3px rgba(122, 162, 247, 0.2);
}

/* Empty State - Dark Mode */
[data-theme="dark"] .debt-empty {
    color: #565f89;
    background: rgba(59, 66, 97, 0.3);
    border-radius: 8px;
    padding: 24px;
    text-align: center;
}

/* Status Badges - Dark Mode */
[data-theme="dark"] .debt-status-pending {
    background: rgba(122, 162, 247, 0.15);
    color: #7aa2f7;
}

[data-theme="dark"] .debt-status-partial {
    background: rgba(224, 175, 104, 0.15);
    color: #e0af68;
}

[data-theme="dark"] .debt-status-paid {
    background: rgba(158, 206, 106, 0.15);
    color: #9ece6a;
}

[data-theme="dark"] .debt-status-overdue {
    background: rgba(247, 118, 142, 0.15);
    color: #f7768e;
}

/* Modal - Dark Mode */
[data-theme="dark"] .debt-modal-content {
    background: #24283b;
    border-color: #3b4261;
}

[data-theme="dark"] .debt-modal-header {
    background: linear-gradient(135deg, #1a1b26 0%, #24283b 100%);
    border-bottom-color: #3b4261;
}

[data-theme="dark"] .debt-modal-title {
    color: #c0caf5;
}

[data-theme="dark"] .debt-form-label {
    color: #9aa5ce;
}

[data-theme="dark"] .debt-form-input,
[data-theme="dark"] .debt-form-select,
[data-theme="dark"] .debt-form-textarea {
    background: #1a1b26;
    border-color: #3b4261;
    color: #c0caf5;
}

/* Payment Panel - Dark Mode */
[data-theme="dark"] .debt-payment-panel {
    background: #24283b;
    border-left-color: #3b4261;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .debt-payment-header {
    background: linear-gradient(135deg, #1a1b26 0%, #24283b 100%);
    border-bottom-color: #3b4261;
}

/* Overlay - Dark Mode */
[data-theme="dark"] .debt-overlay {
    background: rgba(0, 0, 0, 0.7);
}

/* Scrollbar - Dark Mode */
[data-theme="dark"] .debt-module ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

[data-theme="dark"] .debt-module ::-webkit-scrollbar-track {
    background: #1a1b26;
}

[data-theme="dark"] .debt-module ::-webkit-scrollbar-thumb {
    background: #3b4261;
    border-radius: 4px;
}

[data-theme="dark"] .debt-module ::-webkit-scrollbar-thumb:hover {
    background: #565f89;
}

/* Month Navigator - Dark Mode specific */
[data-theme="dark"] #debtMonthNavigator {
    background: #24283b;
    border-radius: 10px;
}

[data-theme="dark"] #debtFilterLabel {
    background: linear-gradient(135deg, rgba(224, 175, 104, 0.15), rgba(224, 175, 104, 0.08));
    border-left-color: #e0af68;
    color: #e0af68;
}

/* =========================================================================
   CÔNG NỢ STANDALONE: MODAL (Thêm công nợ / Thanh toán...) — bản gốc thiếu CSS
   cho .debt-modal-overlay / .debt-modal nên form trôi xuống cuối trang, lệch.
   ========================================================================= */
.debt-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    animation: debtModalFade 0.15s ease;
}

@keyframes debtModalFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.debt-modal {
    background: var(--bg-primary, #ffffff);
    color: var(--text-primary, #111827);
    border-radius: 14px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.debt-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}

.debt-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.debt-modal-close {
    background: none;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted, #6b7280);
    padding: 0 4px;
}

.debt-modal-close:hover {
    color: var(--debt-payable, #dc2626);
}

.debt-modal-body {
    padding: 20px;
    overflow-y: auto;
}

.debt-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border, #e5e7eb);
}

/* form bên trong modal dùng .form-group (đã có global) — bổ sung khoảng cách & input full-width */
.debt-modal .debt-form .form-group { margin-bottom: 14px; }
.debt-modal .debt-form label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
.debt-modal .debt-form .required { color: var(--debt-payable, #dc2626); }
.debt-modal .debt-form input,
.debt-modal .debt-form select,
.debt-modal .debt-form textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border, #d1d5db);
    border-radius: 8px;
    font-size: 0.95rem;
    box-sizing: border-box;
    background: var(--bg-primary, #fff);
    color: var(--text-primary, #111827);
}

[data-theme="dark"] .debt-modal {
    background: #1e293b;
    color: #e2e8f0;
}
