/* ==========================================================================
   DebtApp - Modern Mobile-First Styles
   ========================================================================== */

/* ── Design System ─────────────────────────────────────────────────────────── */
:root {
    /* Brand */
    --primary:      #6366f1;
    --primary-dark: #4f46e5;
    --primary-soft: #eef2ff;
    --secondary:    #64748b;

    /* Semantic */
    --success: #10b981;
    --warning: #f59e0b;
    --danger:  #ef4444;

    /* Surfaces — 3-level elevation */
    --background: #f8fafc;   /* page bg */
    --surface:    #ffffff;   /* cards, modals, nav */
    --surface-1:  #f1f5f9;   /* table headers, inner bg */
    --surface-2:  #e8eef6;   /* hover rows, active items */

    /* Text */
    --text-primary:   #0f172a;
    --text-secondary: #64748b;
    --text-muted:     #94a3b8;

    /* Border */
    --border:      #e2e8f0;
    --border-soft: rgba(15,23,42,0.05);

    /* Shadows */
    --shadow:    0 1px 3px rgba(15,23,42,0.07), 0 1px 2px rgba(15,23,42,0.04);
    --shadow-md: 0 4px 6px -1px rgba(15,23,42,0.08), 0 2px 4px -2px rgba(15,23,42,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(15,23,42,0.10), 0 4px 6px -4px rgba(15,23,42,0.05);

    /* Chart */
    --chart-grid:       rgba(15,23,42,0.06);
    --chart-label:      #94a3b8;
    --chart-tooltip-bg: #ffffff;

    /* Layout */
    --nav-height:        60px;
    --bottom-nav-height: 64px;
    --radius:            0.625rem;
    --radius-sm:         0.375rem;
    --radius-lg:         0.875rem;
}

/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent horizontal scroll/bounce on iOS */
    overflow-x: hidden;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.main-content {
    flex: 1;
    padding-bottom: var(--bottom-nav-height);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    margin: 0 0 1rem 0;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-primary);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

p {
    margin: 0 0 1rem 0;
}

.text-muted {
    color: var(--text-secondary);
}

/* Navigation - Top */
.top-nav {
    position: sticky;
    top: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 100;
    height: var(--nav-height);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-currency {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0.25rem 0.75rem;
    background: var(--background);
    border-radius: 9999px;
}

.user-avatar {
    font-size: 1.5rem;
    text-decoration: none;
}

/* Navigation - Bottom (mobile only) */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    display: none;
    justify-content: space-around;
    padding: 0.5rem 0 env(safe-area-inset-bottom, 0.5rem);
    z-index: 100;
    height: var(--bottom-nav-height);
}

/* More sheet */
.nav-more-sheet {
    position: fixed;
    inset: 0;
    z-index: 200;
    pointer-events: none;
    visibility: hidden;
    display: none;
}
.nav-more-sheet.open {
    pointer-events: all;
    visibility: visible;
}
.nav-more-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    opacity: 0;
    transition: opacity 0.22s;
}
.nav-more-sheet.open .nav-more-backdrop { opacity: 1; }
.nav-more-panel {
    position: absolute;
    bottom: var(--bottom-nav-height);
    left: 0;
    right: 0;
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-top: 1px solid var(--border);
    padding: 0.5rem 0;
    transform: translateY(100%);
    transition: transform 0.22s ease;
}
.nav-more-sheet.open .nav-more-panel { transform: translateY(0); }
.nav-more-item {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.8rem 1.25rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    background: none;
    border: none;
    width: 100%;
    cursor: pointer;
    transition: background 0.15s;
}
.nav-more-item:hover, .nav-more-item:active { background: var(--surface-1); }
.nav-more-item .nav-icon { font-size: 1.3rem; min-width: 1.5rem; text-align: center; }
.nav-more-divider { height: 1px; background: var(--border); margin: 0.25rem 0; }
.nav-more-btn { background: none; border: none; cursor: pointer; font-family: inherit; }
.nav-more-btn.active { color: var(--primary); }
.dark .nav-more-panel { background: var(--surface); }
.dark .nav-more-item:hover { background: var(--surface-1); }

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    flex: 1;
    min-width: 0;
    transition: color 0.2s;
}

.nav-item:hover, .nav-item.active {
    color: var(--primary);
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    position: relative;
}

.nav-svg {
    width: 22px;
    height: 22px;
    display: block;
    flex-shrink: 0;
}

/* Moon/Sun theme icon swap */
.icon-sun { display: none; }
.dark .icon-moon { display: none; }
.dark .icon-sun  { display: block; }

.nav-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-icon-only {
    background: #ff00002e;
    color: var(--danger);
    border: 1px solid #ff000050;
    padding: 0 0.5rem;
}
.btn-icon-only:hover {
    background: #ff000055;
    color: var(--danger);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-control:disabled {
    background: var(--background);
    cursor: not-allowed;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

select.form-control {
    cursor: pointer;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.flex-1 {
    flex: 1;
}

/* Radio Buttons */
.radio-group {
    display: flex;
    gap: 1rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.radio-label input[type="radio"] {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
}

/* Authentication Pages */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    background: var(--surface);
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
}

.auth-title {
    text-align: center;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.auth-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.auth-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.auth-legal {
    margin-top: 0.75rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

.auth-legal a {
    font-weight: 400;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 0.15rem;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.checkbox-label a {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Dashboard */
.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    padding: 1.5rem;
    border-radius: 0.75rem;
    color: white;
}

.summary-card.green {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
}

.summary-card.red {
    background: linear-gradient(135deg, var(--danger) 0%, #DC2626 100%);
}

.summary-label {
    font-size: 0.875rem;
    opacity: 0.9;
    margin-bottom: 0.5rem;
}

.summary-amount {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    overflow-x: auto;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.tab-btn:hover {
    background: var(--background);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Debts Container */
.debts-container {
    display: grid;
    gap: 1rem;
}

.debt-card {
    background: var(--surface);
    border-radius: 0.75rem;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.debt-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.debt-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.75rem;
}

.debt-card-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin: 0;
}

.debt-card-amount {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.debt-card-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.debt-card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Loading Spinner */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    gap: 1rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-state h3 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Page Container */
.page-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1rem;
}

.page-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.back-btn {
    font-size: 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

.back-btn:hover {
    color: var(--primary);
}

/* Debt Form */
.debt-form {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
}

.form-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.payment-item {
    position: relative;
    padding: 1rem;
    background: var(--background);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.btn-remove-payment {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 2rem;
    height: 2rem;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
}

.external-person-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
    position: relative;
}
.external-person-row .form-control { flex: 1; }
.external-person-row .btn-remove-payment {
    position: static;
    width: 2rem;
    height: 2rem;
    flex-shrink: 0;
}

/* Status Badge */
.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
}

.status-badge.active {
    background: #DBEAFE;
    color: #1E40AF;
}

.status-badge.settled {
    background: #D1FAE5;
    color: #065F46;
}

/* Balance Card */
.balance-card {
    padding: 1rem;
    background: var(--background);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.balance-card.positive {
    border-left: 4px solid var(--success);
}

.balance-card.negative {
    border-left: 4px solid var(--danger);
}

/* Settlement Card */
.settlement-card {
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
}

.settlement-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settlement-amount {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--primary);
}

.settlement-btn {
    margin-top: 0.75rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: var(--surface);
    border-radius: 0.75rem;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

/* Balance Details Modal */
.balance-details-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 60vh;
    overflow-y: auto;
}

.balance-person-card {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.balance-person-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.balance-person-header {
    padding: 1rem;
    background: var(--surface);
}

.balance-person-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.balance-person-avatar {
    font-size: 2rem;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    border-radius: 50%;
}

.balance-person-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.balance-person-total {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.balance-person-total strong {
    color: var(--primary);
    font-weight: 700;
}

.balance-debts-list {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border);
}

.balance-debt-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background-color 0.2s;
}

.balance-debt-item:last-child {
    border-bottom: none;
}

.balance-debt-item:hover {
    background: var(--surface);
}

.balance-debt-title {
    color: var(--text-primary);
    font-weight: 500;
}

.balance-debt-amount {
    color: var(--primary);
    font-weight: 600;
}

/* Notification Cards */
.notification-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.25rem;
    margin-bottom: 1rem;
    transition: box-shadow 0.2s;
}

.notification-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.notification-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.notification-icon {
    font-size: 2rem;
    line-height: 1;
}

.notification-info {
    flex: 1;
}

.notification-debt-title {
    font-weight: 600;
    font-size: 1.125rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.notification-action {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.notification-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.notification-details {
    margin-bottom: 1rem;
    padding-left: 3rem;
}

.notification-description {
    font-size: 0.9375rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.notification-comment {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-style: italic;
    padding: 0.75rem;
    background: var(--background);
    border-left: 3px solid var(--primary);
    border-radius: 0.25rem;
}

.notification-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    padding-left: 3rem;
}

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #EF4444;
    color: white;
    font-size: 0.625rem;
    font-weight: 700;
    padding: 0.125rem 0.375rem;
    border-radius: 999px;
    min-width: 18px;
    text-align: center;
    line-height: 1.2;
}

.nav-item {
    position: relative;
}

/* Messages */
.error-message {
    padding: 0.75rem 1rem;
    background: #FEE2E2;
    color: #991B1B;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.success-message {
    padding: 0.75rem 1rem;
    background: #D1FAE5;
    color: #065F46;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 2000;
}

.toast {
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 0.5rem;
    animation: slideIn 0.3s ease;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Badge */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    background: var(--danger);
    color: white;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

/* Summary Box */
.summary-box {
    background: var(--background);
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.summary-row:last-child {
    border-bottom: none;
}

/* Settings Section */
.settings-section {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

/* Responsive Design */
@media (max-width: 767px) {
    .top-nav { display: none; }
    .bottom-nav { display: flex; }
    .nav-more-sheet { display: block; }
    .main-content { padding-bottom: var(--bottom-nav-height); }
}

@media (min-width: 768px) {
    .main-content {
        padding-bottom: 0;
    }

    .debt-form, .settings-section {
        padding: 2rem;
    }
}

@media (max-width: 768px) {
    h1 { font-size: 1.5rem; }
    .auth-card { padding: 1.5rem; }
    .dashboard-header { flex-direction: column; gap: 1rem; align-items: flex-start; }
    .dashboard-header .btn { width: 100%; }
}

/* Friend Cards */
.friend-card, .request-card, .search-result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    transition: box-shadow 0.2s;
}

.friend-card:hover, .request-card:hover, .search-result-card:hover {
    box-shadow: var(--shadow);
}

.friend-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.friend-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--background);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.friend-details {
    flex: 1;
    min-width: 0;
}

.friend-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.friend-email {
    font-size: 0.875rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.request-actions {
    display: flex;
    gap: 0.5rem;
}

.search-result-action {
    flex-shrink: 0;
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Friends List Specific */
#friendsList, #requestsList, #searchResults {
    margin-top: 1rem;
}

/* Search Results Container */
#searchResults {
    max-height: 400px;
    overflow-y: auto;
    margin-top: 1rem;
}

/* Mobile Responsive for Friend Cards */
@media (max-width: 480px) {
    .friend-card, .request-card, .search-result-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .request-actions {
        width: 100%;
    }

    .request-actions .btn {
        flex: 1;
    }

    .search-result-action {
        width: 100%;
    }

    .search-result-action .btn {
        width: 100%;
    }
}

/* Group Cards */
.group-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.group-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.group-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
}

.group-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.group-details {
    flex: 1;
    min-width: 0;
}

.group-name {
    font-weight: 600;
    font-size: 1.125rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.group-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.group-arrow {
    font-size: 1.5rem;
    color: var(--text-secondary);
}

/* Member Cards */
.member-card {
    background: var(--background);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Checkbox Label for Group Members */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.checkbox-label:hover {
    background: var(--background);
}

.checkbox-label input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
}

.checkbox-label span {
    font-weight: 500;
    color: var(--text-primary);
}

/* Groups List */
#groupsList, #groupMembersList {
    margin-top: 1rem;
}

#friendsCheckboxList {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 0.5rem;
}

/* Debt Detail Page */
.debt-detail-header {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.debt-meta {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* Payment Cards */
.payment-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    transition: box-shadow 0.2s;
}

.payment-card:hover {
    box-shadow: var(--shadow);
}

.payment-info {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.payment-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.payment-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--background);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.payment-name {
    font-weight: 600;
    color: var(--text-primary);
}

.payment-details {
    flex: 1;
}

.payment-amount {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.payment-description {
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.payment-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Settlement Card Updates */
.settlement-card {
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.settlement-info {
    flex: 1;
}

.settlement-text {
    font-size: 0.9375rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.settlement-amount {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--primary);
}

.balance-amount {
    font-weight: 600;
    font-size: 1rem;
}

/* Debt Detail Sections */
.detail-section {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.section-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

#paymentsSection, #balancesSection, #settlementsSection {
    margin-top: 0.5rem;
}

/* Mobile Responsive for Payment Cards */
@media (max-width: 480px) {
    .payment-info {
        flex-direction: column;
    }

    .settlement-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .settlement-btn {
        width: 100%;
    }
}

/* Leaderboard Cards */
.leaderboard-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: box-shadow 0.2s, transform 0.2s;
}

.leaderboard-card.highlight {
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.05) 0%, rgba(79, 70, 229, 0.1) 100%);
    border-color: var(--primary);
}

.leaderboard-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.leaderboard-rank {
    font-size: 2rem;
    line-height: 1;
    min-width: 50px;
    text-align: center;
}

.leaderboard-info {
    flex: 1;
    min-width: 0;
}

.leaderboard-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-stats {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.leaderboard-amount {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--primary);
    text-align: right;
}

/* Utility Classes */
.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 1rem;
}

/* Improved Mobile Adaptation */
@media (max-width: 640px) {
    html, body {
        font-size: 14px;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    h3 {
        font-size: 1.125rem;
    }

    .nav-container {
        padding: 0 0.75rem;
    }

    .page-container {
        padding: 0.75rem;
    }

    .debt-card, .friend-card, .group-card {
        padding: 0.875rem;
    }

    .modal-content {
        padding: 1.25rem;
        margin: 0.5rem;
    }

    .form-control {
        padding: 0.625rem 0.875rem;
        font-size: 1rem;
    }

    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.9375rem;
    }

    .btn-sm {
        padding: 0.5rem 0.875rem;
        font-size: 0.875rem;
    }

    .summary-cards {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .leaderboard-card {
        padding: 0.875rem;
    }

    .leaderboard-rank {
        font-size: 1.5rem;
        min-width: 40px;
    }

    .leaderboard-amount {
        font-size: 1rem;
    }

    .payment-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .payment-card .btn {
        width: 100%;
        margin-top: 0.5rem;
    }

    .settlement-card {
        padding: 0.875rem;
    }

    .page-header {
        flex-wrap: wrap;
    }
}

/* ==========================================================================
   Budget Page Styles
   ========================================================================== */

.budget-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1rem 5rem;
}

/* ── Header ── */
.budget-header {
    position: sticky;
    top: var(--nav-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 50;
    padding: 0.75rem 1rem;
    margin: -0.75rem -1rem 1rem;
}

.budget-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.period-selector-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.period-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.period-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    cursor: pointer;
    color: var(--primary);
}

.period-title:hover { text-decoration: underline; }

.period-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    text-transform: uppercase;
}
.badge-active { background: #d1fae5; color: #065f46; }
.badge-archived { background: #e5e7eb; color: #374151; }

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.btn-icon:hover { background: var(--background); color: var(--primary); }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Currency banner ── */
.currency-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1rem;
    margin-bottom: 0.75rem;
    background: #EEF2FF;
    border: 1px solid #C7D2FE;
    border-radius: 0.5rem;
    color: #4338CA;
    font-size: 0.8rem;
    font-weight: 500;
}

/* ── Section ── */
.budget-section {
    background: var(--surface);
    border-radius: 0.75rem;
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.section-header h3 { margin: 0; font-size: 1rem; }

/* ── Summary Cards ── */
.budget-summary-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.budget-summary-card {
    background: var(--background);
    border-radius: 0.625rem;
    padding: 0.875rem 1rem;
    position: relative;
    cursor: help;
    transition: transform 0.15s, box-shadow 0.15s;
    border-left: 4px solid transparent;
}

.budget-summary-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.income-card { border-left-color: #10b981; }
.spent-card { border-left-color: #ef4444; }
.limit-card { border-left-color: #f59e0b; }
.remaining-card { border-left-color: #4f46e5; }
.savings-card { border-left-color: #8b5cf6; }

.bsc-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.bsc-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.bsc-value.positive { color: var(--success); }
.bsc-value.negative { color: var(--danger); }

.bsc-currency {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.bsc-info {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 0.75rem;
    opacity: 0.5;
}

.savings-check {
    font-size: 1.2rem;
    margin-top: 0.25rem;
    font-weight: 700;
}
.savings-check.ok { color: var(--success); }
.savings-check.fail { color: var(--danger); }

/* ── Verification Bar ── */
.verification-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--background);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    flex-wrap: wrap;
}

.color-ok { color: var(--success); font-weight: 600; }
.color-fail { color: var(--danger); font-weight: 600; }

.delta-label { color: var(--text-secondary); margin-left: auto; }
.delta-value { font-weight: 700; cursor: help; }
.delta-value.positive { color: var(--success); }
.delta-value.negative { color: var(--danger); }

/* ── Categories Table ── */
.categories-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

.categories-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.categories-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: var(--surface-1);
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    cursor: help;
}

.categories-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.categories-table .cat-row:hover td { background: var(--surface-2); }
.categories-table .income-row td   { background: rgba(16,185,129,0.06); }
.categories-table .uncat-row td    { background: var(--surface-1); color: var(--text-muted); font-style: italic; }

.num-col { text-align: right; white-space: nowrap; }
.num-light { color: var(--text-secondary); font-size: 0.8rem; }
.status-col { text-align: center; }
.actions-col { text-align: right; white-space: nowrap; }

.cat-name-cell { max-width: 200px; }
.cat-name { font-weight: 500; }
.income-badge {
    font-size: 0.65rem;
    background: rgba(16,185,129,0.12);
    color: #059669;
    padding: 0.1rem 0.35rem;
    border-radius: 999px;
    margin-left: 0.35rem;
    font-weight: 600;
}

.cat-progress-mini {
    height: 3px;
    background: var(--border);
    border-radius: 999px;
    margin-top: 0.25rem;
    overflow: hidden;
}

.cat-progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 999px;
    transition: width 0.4s ease;
}
.cat-progress-fill.near { background: var(--warning); }
.cat-progress-fill.over { background: var(--danger); }

.editable-num {
    cursor: pointer;
    text-decoration: underline dotted;
    color: var(--primary);
}
.editable-num:hover { color: var(--primary-dark); }

.spent-positive { color: var(--danger); }
.negative { color: var(--danger) !important; }
.positive { color: var(--success) !important; }

.status-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.45rem;
    border-radius: 999px;
    white-space: nowrap;
}
.status-ok { background: #d1fae5; color: #065f46; }
.status-norm { background: #dbeafe; color: #1e40af; }
.status-close { background: #fef3c7; color: #92400e; }
.status-over { background: #fee2e2; color: #991b1b; }
.status-neutral { background: var(--background); color: var(--text-secondary); }

.totals-row td {
    background: var(--background) !important;
    font-weight: 600;
    padding-top: 0.875rem;
}
.savings-totals td { background: #f0fdf4 !important; }
.grand-totals td { background: #eff6ff !important; font-weight: 700; }

.th-info { cursor: pointer; opacity: 0.6; font-size: 0.7rem; }

/* ── Category progress bars (visual) ── */
.category-bars {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.cat-bar-card {
    background: var(--background);
    border-radius: 0.5rem;
    padding: 0.75rem;
}

.cat-bar-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.cat-bar-name {
    font-weight: 600;
    font-size: 0.875rem;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cat-bar-amounts {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
.spent-val { font-weight: 700; color: var(--text-primary); }
.cur-label { color: var(--text-secondary); }

.cat-bar-track {
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    cursor: help;
    margin-bottom: 0.35rem;
}

.cat-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.5s ease;
}
.cat-bar-fill.low { background: var(--success); }
.cat-bar-fill.mid { background: #34d399; }
.cat-bar-fill.near { background: var(--warning); }
.cat-bar-fill.over { background: var(--danger); }

.cat-bar-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* ── Transactions ── */
.tx-toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-input {
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    outline: none;
    width: 200px;
    transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--primary); }

.filter-select {
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
    background: var(--surface);
    cursor: pointer;
    max-width: 180px;
}

.transactions-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.transactions-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 600px;
}

.transactions-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: var(--surface-1);
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.transactions-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.tx-row:hover td { background: var(--surface-2); }
.income-tx { }
.expense-tx { }

.date-col { white-space: nowrap; color: var(--text-secondary); font-size: 0.8rem; min-width: 90px; }
.desc-cell { max-width: 260px; }
.desc-main {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.85rem;
}
.import-badge { font-size: 0.75rem; opacity: 0.6; }
.cat-col { min-width: 160px; }
.note-col { max-width: 160px; color: var(--text-secondary); font-size: 0.8rem; }
.note-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.amount-cell { text-align: right; font-weight: 700; white-space: nowrap; }

.cat-inline-select {
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    padding: 0.25rem 0.35rem;
    font-size: 0.8rem;
    background: var(--surface);
    width: 100%;
    cursor: pointer;
}
.cat-inline-select:hover { border-color: var(--primary); }

.tx-footer { padding: 0.75rem 0 0; }
.tx-totals {
    display: flex;
    gap: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}
.tx-count { margin-left: auto; }

/* ── Buttons ── */
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #d97706; }
.btn-warning:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-success { background: #16a34a; color: white; }
.btn-success:hover { background: #15803d; }
.btn-success:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-danger { background: #ef4444; color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-danger:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-icon-only.btn-danger { background: #ff00002e; color: #ef4444; border: 1px solid #ff000050; }
.btn-icon-only.btn-danger:hover { background: #ff000055; }
.editable-num.dimmed { color: var(--text-secondary); font-style: italic; font-size: 0.8rem; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: #eff6ff; }

.btn-icon-sm {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.2rem 0.3rem;
    border-radius: 0.25rem;
    font-size: 0.9rem;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.btn-icon-sm:hover { opacity: 1; background: var(--background); }
.btn-icon-sm.danger:hover { background: #fee2e2; }
.btn-icon-sm:disabled { opacity: 0.2; cursor: not-allowed; }

/* ── Loading / Empty ── */
.loading-row, .empty-row {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem !important;
    font-style: italic;
}

/* ── Modals ── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background: var(--surface);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.modal-content.modal-lg { max-width: 680px; }
.modal-content.modal-xl { max-width: 900px; }

/* ── XML Import Preview ── */
.xml-preview-body { padding: 0; }
.xml-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1.25rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
    flex-wrap: wrap;
}
.xml-select-all-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.875rem;
    cursor: pointer;
    white-space: nowrap;
}
.xml-table-wrap {
    max-height: 420px;
    overflow-y: auto;
}
.xml-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.xml-preview-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
    padding: 0.5rem 0.75rem;
    border-bottom: none;
    box-shadow: 0 2px 0 var(--border);
    text-align: left;
    font-weight: 600;
}
.xml-preview-table td {
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.xml-preview-table .col-check { width: 36px; text-align: center; }
.xml-preview-table .col-date { width: 90px; white-space: nowrap; color: var(--text-secondary); }
.xml-preview-table .col-amt { width: 90px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.xml-preview-table .col-cat { width: 130px; color: var(--text-secondary); font-size: 0.78rem; }
.xml-preview-table .col-desc { word-break: break-word; }
.xml-row-duplicate { opacity: 0.4; }
.xml-row-duplicate .xml-edit-desc { text-decoration: line-through; }

.xml-edit {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 0.2rem 0.35rem;
    font-size: 0.82rem;
    font-family: inherit;
    background: transparent;
    color: inherit;
    box-sizing: border-box;
    transition: border-color 0.15s, background 0.15s;
}
.xml-edit:hover { border-color: var(--border); }
.xml-edit:focus { border-color: var(--primary); background: var(--surface); outline: none; }
.xml-edit-date { width: 120px; }
.xml-edit-amount { width: 90px; text-align: right; }
.xml-edit-desc { min-width: 160px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 1rem; }

.modal-body { padding: 1.25rem; flex: 1; overflow-y: auto; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    padding: 0;
}
.modal-close:hover { color: var(--text-primary); }
.modal-hint { font-size: 0.8rem; color: var(--text-secondary); margin: 0.5rem 0; }
.modal-open { overflow: hidden; }

/* ── XML textarea ── */
.xml-textarea {
    width: 100%;
    min-height: 200px;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.75rem;
    font-family: monospace;
    font-size: 0.8rem;
    resize: vertical;
    outline: none;
    transition: border-color 0.15s;
}
.xml-textarea:focus { border-color: var(--primary); }
.file-input { margin-top: 0.25rem; font-size: 0.8rem; }

/* ── Form elements ── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.375rem; }
.form-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s;
    background: var(--surface);
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.form-input:disabled { background: var(--background); cursor: not-allowed; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.checkbox-group label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.checkbox-group input[type=checkbox] { width: auto; }
.tooltip-hint { cursor: pointer; opacity: 0.6; font-size: 0.75rem; }

/* ── Periods list ── */
.period-list-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
    transition: all 0.15s;
}
.period-list-item:hover { border-color: var(--primary); background: #eff6ff; }
.period-list-item.archived { opacity: 0.7; }
.period-list-main { flex: 1; cursor: pointer; min-width: 0; }
.period-list-actions { display: flex; flex-direction: column; gap: 0.25rem; flex-shrink: 0; }
.period-copy-btn { color: var(--primary); }
.period-copy-btn:hover { background: #eff6ff; }
.period-list-info { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
.period-list-name { font-weight: 600; }
.period-list-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

/* ── Tooltip popup ── */
.tooltip-popup {
    position: absolute;
    z-index: 9999;
    background: #1f2937;
    color: white;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.78rem;
    max-width: 320px;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.tt-text { margin-bottom: 0.25rem; opacity: 0.85; }
.tt-formula {
    font-family: 'Courier New', monospace;
    font-size: 0.72rem;
    color: #93c5fd;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 0.25rem;
    margin-top: 0.25rem;
}

/* ══ Budget — Responsive ══════════════════════════════════════════════════════ */

@media (max-width: 900px) {
    .budget-summary-grid { grid-template-columns: repeat(3, 1fr); }
    .delta-label { display: none; }
}

/* On mobile the top-nav is hidden, so sticky header must stick at 0 not 60px.
   This rule is placed AFTER the base .budget-header to win the cascade. */
@media (max-width: 767px) {
    .budget-header { top: 0; }
}

@media (max-width: 640px) {
    .budget-page { padding: 0.5rem 0.75rem 5.5rem; }

    /* Summary cards: 2-column, larger value numbers */
    .budget-summary-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    .budget-summary-card {
        padding: 0.75rem 0.875rem;
        border-radius: 0.625rem;
    }
    .bsc-label   { font-size: 0.7rem; }
    .bsc-value   { font-size: 1.2rem; }
    .bsc-currency { font-size: 0.7rem; }
    .savings-check { font-size: 1.1rem; }

    /* Header: compact, fix negative margins to match reduced page padding */
    .budget-header { top: 0; margin: -0.5rem -0.75rem 0.75rem; }
    .budget-header-top { gap: 0.4rem; }
    .header-actions {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.35rem;
        padding-bottom: 2px;
        scrollbar-width: none;
        flex-wrap: nowrap;  /* don't wrap — scroll instead */
    }
    .header-actions::-webkit-scrollbar { display: none; }
    .btn-sm { padding: 0.45rem 0.7rem; font-size: 0.78rem; min-height: 2.5rem; flex-shrink: 0; }
    .btn    { min-height: 2.75rem; }
    .modal-footer .btn { flex: 1; justify-content: center; }

    /* Category table: horizontal scroll, hide least-important column */
    .categories-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--radius);
        border: 1px solid var(--border);
    }
    .categories-table { font-size: 0.79rem; min-width: 420px; }
    .categories-table th, .categories-table td { padding: 0.45rem 0.5rem; }
    /* Hide "Still Needed" on small screens */
    .categories-table th:nth-child(6),
    .categories-table td:nth-child(6) { display: none; }

    /* Transactions: horizontal scroll, condensed */
    .transactions-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .transactions-table { font-size: 0.82rem; min-width: 460px; }
    .transactions-table th, .transactions-table td { padding: 0.45rem 0.5rem; }

    /* Toolbar: compact */
    .tx-toolbar     { gap: 0.35rem; flex-wrap: wrap; }
    .search-input   { width: 130px; min-width: 0; }
    .filter-select  { max-width: 120px; }
    .tx-totals      { gap: 0.6rem; font-size: 0.8rem; flex-wrap: wrap; }

    /* Form rows: single column */
    .form-row { grid-template-columns: 1fr; }

    /* Forecast panel: smaller chart */
    .forecast-chart-wrap { height: 180px; }

    /* Section headers */
    .section-header h3 { font-size: 0.95rem; }
    .budget-section { padding: 0.75rem 0; }
}

@media (max-width: 400px) {
    .budget-summary-grid { grid-template-columns: 1fr 1fr; }
    .savings-card { grid-column: 1 / -1; }
    .bsc-value { font-size: 1.1rem; }
}

/* ── Bottom nav: larger touch targets on mobile ─────────────────────────────── */
@media (max-width: 640px) {
    .bottom-nav .nav-svg { width: 24px; height: 24px; }
    .nav-label { font-size: 0.68rem; }
    .bottom-nav { padding: 0.35rem 0 env(safe-area-inset-bottom, 0); }
}

/* ── Modals: full-width + safe area on mobile ───────────────────────────────── */
@media (max-width: 540px) {
    .modal-content {
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        max-height: 92dvh;
        overflow-y: auto;
    }
    .modal {
        align-items: flex-end !important;
    }
    .modal-body { padding: 1rem; }
    .modal-footer { padding: 0.75rem 1rem; padding-bottom: max(0.75rem, env(safe-area-inset-bottom)); }
}

/* ── DebtDetail page mobile ─────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .page-container { padding: 0.75rem; }
    .page-header { gap: 0.5rem; }
    .section h2 { font-size: 1rem; }
    .debt-header h1 { font-size: 1.3rem; }
    .summary-box { font-size: 0.88rem; }
    .settlement-card { padding: 0.75rem; }
}

/* ═══════════════════════════════════════════════════════════════
   Analytics / Charts page
   ═══════════════════════════════════════════════════════════════ */

.analytics-page {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 1rem 4rem;
}

.analytics-header {
    margin-bottom: 1.5rem;
}

.analytics-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.25rem;
}

.analytics-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0;
}

/* Loading state */
.analytics-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.loading-spinner-lg {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Charts grid */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.chart-card.chart-full {
    grid-column: 1 / -1;
}

.chart-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.2rem;
    color: var(--text-primary);
}

.chart-card-header {
    margin-bottom: 1rem;
}

.chart-card-sub {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.chart-wrap {
    position: relative;
    height: 280px;
}

.chart-wrap.chart-tall {
    height: 380px;
}

.chart-wrap.chart-extra-tall {
    height: 420px;
}

/* Empty state inside chart */
.chart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: center;
    padding: 1rem;
    border: 1px dashed var(--border);
    border-radius: 0.5rem;
    background: var(--background);
}

@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .chart-wrap { height: 240px; }
    .chart-wrap.chart-tall { height: 300px; }
    .chart-wrap.chart-extra-tall { height: 320px; }
}

/* ── Consent Gate (full-screen, blocks everything) ── */
.consent-gate {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
}

.consent-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    padding: 2rem 2rem 1.75rem;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 32px 80px rgba(0,0,0,0.4);
    animation: cgSlideUp 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cgSlideUp {
    from { opacity: 0; transform: translateY(24px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* icon wrapper circles */
.cg-icon-wrap {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.1rem;
}

.cg-icon-wrap svg {
    width: 28px;
    height: 28px;
}

.cg-icon-wrap--primary {
    background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.cg-icon-wrap--primary svg {
    stroke: var(--primary);
}

.cg-icon-wrap--danger {
    background: color-mix(in srgb, #ef4444 12%, transparent);
}

.cg-icon-wrap--danger svg {
    stroke: #ef4444;
}

/* declined state */
.cg-declined {
    text-align: center;
}

.cg-declined-title {
    color: #ef4444 !important;
}

.cg-declined-hint {
    margin-top: 0.9rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.cg-declined-hint a {
    color: var(--primary);
}

.consent-btn-full {
    width: 100%;
    justify-content: center;
    margin-top: 0.25rem;
}

/* ghost danger button for Decline */
.btn-ghost-danger {
    background: transparent;
    border: 1px solid transparent;
    color: #ef4444;
    width: 100%;
    justify-content: center;
}

.btn-ghost-danger:hover {
    background: color-mix(in srgb, #ef4444 8%, transparent);
    border-color: color-mix(in srgb, #ef4444 30%, transparent);
}

.consent-gate-title {
    font-size: 1.2rem;
    font-weight: 700;
    text-align: center;
    color: var(--text-primary);
    margin-bottom: 0.45rem;
}

.consent-gate-sub {
    font-size: 0.845rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.6;
    margin-bottom: 1.1rem;
}

.consent-section {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

.consent-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.consent-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}

.consent-tag {
    display: inline-block;
    font-size: 0.73rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.2rem 0.6rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.consent-tag--warn {
    border-color: #f59e0b;
    color: #92400e;
}
.dark .consent-tag--warn {
    color: #fbbf24;
    border-color: #78350f;
    background: rgba(120,53,15,0.15);
}

.consent-note {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0.35rem 0 0;
}

.consent-links {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin: 0.75rem 0 1.25rem;
    font-size: 0.82rem;
}

.consent-links a {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.consent-gate-actions {
    display: flex;
    gap: 0.75rem;
    flex-direction: column;
}

.consent-gate-actions .btn {
    width: 100%;
    justify-content: center;
}

@media (min-width: 420px) {
    .consent-gate-actions { flex-direction: row; }
    .consent-gate-actions .btn { width: auto; flex: 1; }
}

/* ── Consent banner — Privacy / Terms pages (always fully open) ── */
.consent-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 99999;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.14);
}

.consent-banner-body {
    display: none;
    flex-direction: column;
    max-height: 52vh;
}

.consent-banner.is-expanded .consent-banner-body {
    display: flex;
}

/* header row: icon + title */
.cb-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.cb-icon {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    margin: 0;
}

.cb-icon svg {
    width: 22px;
    height: 22px;
}

.cb-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.15rem;
}

.cb-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.4;
}

/* internal scroll — fixed element so no second page scrollbar */
.consent-banner-scroll {
    overflow-y: auto;
    padding: 0.75rem 1.25rem 0.5rem;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.cb-intro {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.cb-section {
    margin-bottom: 0.75rem;
}

.cb-section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.cb-section p,
.cb-section li {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.55;
}

.cb-section ul {
    padding-left: 1.1rem;
    margin: 0.25rem 0 0.4rem;
}

.cb-section li {
    margin-bottom: 0.2rem;
}

.cb-section a {
    color: var(--primary);
}

.cb-section code {
    font-size: 0.75rem;
    background: var(--surface-1);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}

/* sticky footer with Accept / Decline */
.consent-banner-footer {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem 1.25rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface); /* prevent scroll bleed */
}

.consent-banner-footer .btn {
    flex: 1;
    justify-content: center;
}

/* ── Cookie consent (legacy — now unused but kept for compat) ── */
.cookie-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--surface);
    color: var(--text-primary);
    border-top: 2px solid var(--primary);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: center;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.15);
}

.cookie-content {
    max-width: 860px;
    width: 100%;
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.cookie-icon {
    font-size: 1.75rem;
    flex-shrink: 0;
    line-height: 1;
}

.cookie-body {
    flex: 1;
    min-width: 0;
}

.cookie-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
}

.cookie-desc {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin: 0;
}

.cookie-desc a {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cookie-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.6rem;
    margin-top: 0.45rem;
}

.cookie-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.73rem;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.cookie-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
}

.cookie-blocked {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.cookie-blocked-inner {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.cookie-blocked-inner h2 { margin-bottom: 0.75rem; font-size: 1.15rem; }
.cookie-blocked-inner p  { color: var(--text-secondary); margin-bottom: 1rem; font-size: 0.875rem; line-height: 1.55; }

@media (max-width: 600px) {
    .cookie-content { flex-direction: column; gap: 0.75rem; align-items: flex-start; }
    .cookie-actions { flex-direction: row; width: 100%; }
    .cookie-actions .btn { flex: 1; }
    .cookie-icon { display: none; }
}

/* ═══════════════════════════════════════════════════════════════
   Group Budget page
   ═══════════════════════════════════════════════════════════════ */

.gb-matrix-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.gb-matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 480px;
}

.gb-matrix-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    background: var(--surface-1);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

.gb-matrix-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.gb-member-col { min-width: 110px; }

.gb-member-cell { min-width: 110px; }

.gb-cell-limit {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.gb-cell-spent {
    font-weight: 600;
    font-size: 0.875rem;
}

.income-row td { background: #f0fdf4; }

.income-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: #d1fae5;
    color: #065f46;
    margin-left: 0.35rem;
    vertical-align: middle;
}

.member-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: #eff6ff;
    color: var(--primary);
    white-space: nowrap;
}

/* Group budget toggle (in Budget page) */
.group-budget-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
}

.gb-toggle-label {
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-primary);
}

.group-budget-summary-row {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 0.5rem;
}

.gb-summary-header {
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.gb-inline-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.gb-inline-cat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
}

@media (max-width: 640px) {
    .gb-matrix-table { font-size: 0.8rem; }
    .gb-matrix-table th, .gb-matrix-table td { padding: 0.4rem 0.5rem; }
    .gb-member-col, .gb-member-cell { min-width: 90px; }
}


.info-banner {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 0.5rem;
    color: #1d4ed8;
    padding: 0.6rem 1rem;
    margin: 0.5rem 0 0;
    font-size: 0.875rem;
    text-align: center;
}

/* ── Dark Theme ─────────────────────────────────────────────────────────────── */
/* ══════════════════════════════════════════════════════════════════
   DARK THEME — 4-level elevation system (clear visual hierarchy)
   bg(#07101f) → surface(#111827) → surface-1(#1a2438) → surface-2(#1f2d48)
   ══════════════════════════════════════════════════════════════════ */
.dark {
    /* Brand (lighter shades for dark bg) */
    --primary:      #818cf8;
    --primary-dark: #6366f1;
    --primary-soft: #1e1b4b;
    --success:      #34d399;
    --warning:      #fbbf24;
    --danger:       #f87171;

    /* 4-level surface elevation — clear, noticeable differences */
    --background: #07101f;   /* page bg — deepest */
    --surface:    #111827;   /* cards, modals, nav */
    --surface-1:  #1a2438;   /* table headers, secondary panels */
    --surface-2:  #1f2d48;   /* hover rows, active items */

    /* Text */
    --text-primary:   #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted:     #475569;

    /* Border — very subtle glows */
    --border:      rgba(148,163,184,0.14);
    --border-soft: rgba(148,163,184,0.07);

    /* Shadows */
    --shadow:    0 1px 4px rgba(0,0,0,0.5), 0 0 0 1px rgba(148,163,184,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.5), 0 0 0 1px rgba(148,163,184,0.06);
    --shadow-lg: 0 12px 28px rgba(0,0,0,0.6), 0 0 0 1px rgba(148,163,184,0.06);

    /* Chart */
    --chart-grid:       rgba(148,163,184,0.09);
    --chart-label:      #475569;
    --chart-tooltip-bg: #1a2438;

    color-scheme: dark;
}

/* ── Nav ──────────────────────────────────────────────────────────────────── */
.dark .top-nav  { background: var(--surface);   border-color: var(--border); box-shadow: 0 1px 0 var(--border); }
.dark .bottom-nav { background: var(--surface); border-color: var(--border); }
.dark .nav-item { color: var(--text-secondary); }
.dark .nav-item:hover, .dark .nav-item.active { color: var(--primary); }

/* ── Modals ───────────────────────────────────────────────────────────────── */
.dark .modal-content { background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.dark .modal-header  { border-bottom-color: var(--border); }
.dark .modal-footer  { border-top-color:    var(--border); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.dark .form-input, .dark .form-control, .dark select.form-input, .dark select.form-control,
.dark .search-input, .dark .filter-select, .dark .cat-inline-select, .dark .xml-textarea {
    background: var(--surface-1); color: var(--text-primary); border-color: var(--border);
}
.dark .form-input:focus, .dark .form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(129,140,248,0.15); }
.dark .form-group label { color: var(--text-primary); }
.dark option { background: var(--surface-1); color: var(--text-primary); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.dark .btn-outline       { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.dark .btn-outline:hover { background: var(--surface-1); color: var(--text-primary); border-color: var(--text-muted); }
.dark .btn-icon-sm:hover { background: var(--surface-1); }
.dark .btn-icon-sm.danger:hover { background: rgba(248,113,113,0.12); }
.dark .btn-icon-only { background: rgba(248,113,113,0.10); }
.dark .btn-icon-only:hover { background: rgba(248,113,113,0.20); }

/* ── Summary cards ────────────────────────────────────────────────────────── */
.dark .budget-summary-card { background: var(--surface); border-color: var(--border); color: var(--text-primary); box-shadow: var(--shadow); }
.dark .bsc-label { color: var(--text-secondary); }
.dark .bsc-currency { color: var(--text-muted); }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.dark .badge-active   { background: rgba(52,211,153,0.12); color: #34d399; border-color: rgba(52,211,153,0.2); }
.dark .badge-archived { background: var(--surface-1); color: var(--text-muted); }
.dark .income-badge   { background: rgba(52,211,153,0.12); color: #34d399; }

/* ── Currency banner ──────────────────────────────────────────────────────── */
.dark .currency-banner { background: rgba(129,140,248,0.1); border-color: rgba(129,140,248,0.3); color: #a5b4fc; }

/* ── Category table ───────────────────────────────────────────────────────── */
.dark .categories-table thead th         { background: var(--surface-1); color: var(--text-secondary); border-color: var(--border); }
.dark .categories-table td               { border-color: var(--border); }
.dark .categories-table .cat-row:hover td { background: var(--surface-2); }
.dark .categories-table .income-row td   { background: rgba(52,211,153,0.07); }
.dark .categories-table .uncat-row td    { background: var(--surface-1); color: var(--text-muted); }

/* ── Transaction table ────────────────────────────────────────────────────── */
.dark .transactions-table thead th  { background: var(--surface-1); color: var(--text-secondary); border-color: var(--border); }
.dark .transactions-table td        { border-color: var(--border); }
.dark .tx-row:hover td              { background: var(--surface-2); }

/* ── Table totals ─────────────────────────────────────────────────────────── */
.dark .totals-row td    { background: var(--surface-1) !important; }
.dark .savings-totals td { background: rgba(52,211,153,0.08)  !important; }
.dark .grand-totals td  { background: rgba(129,140,248,0.08)  !important; }
.dark .tax-totals td    { background: rgba(251,191,36,0.08)   !important; }

/* ── Status badges ────────────────────────────────────────────────────────── */
.dark .status-ok    { background: rgba(52,211,153,0.12);  color: #34d399;  }
.dark .status-norm  { background: rgba(96,165,250,0.12);  color: #60a5fa;  }
.dark .status-close { background: rgba(251,191,36,0.12);  color: #fbbf24;  }
.dark .status-over  { background: rgba(248,113,113,0.12); color: #f87171;  }

/* ── Tags ─────────────────────────────────────────────────────────────────── */
.dark .tag-chip, .dark .tag-chip-sm { background: rgba(129,140,248,0.15); color: #a5b4fc; }
.dark .tags-input-wrap { background: var(--surface-1); border-color: var(--border); }

/* ── Forecast panel ───────────────────────────────────────────────────────── */
.dark .forecast-bar      { background: rgba(52,211,153,0.07); border-color: rgba(52,211,153,0.2); color: #34d399; }
.dark .forecast-panel    { background: rgba(52,211,153,0.07); border-color: rgba(52,211,153,0.2); }
.dark .forecast-summary  { color: #34d399; }
.dark .forecast-chart-wrap { background: var(--surface); border-color: var(--border); }

/* ── Not-participant banner ───────────────────────────────────────────────── */
.dark .not-participant-banner { background: rgba(251,191,36,0.08); border-color: rgba(251,191,36,0.25); color: #fbbf24; }

/* ── Group budget rows ────────────────────────────────────────────────────── */
.dark .gb-cat-row td         { background: rgba(129,140,248,0.04); }
.dark .gb-tx-row td          { background: rgba(0,0,0,0.0); }
.dark .gb-tx-row:hover td    { background: var(--surface-2); }
.dark .gb-tx-separator td    { background: var(--surface-1); border-color: var(--border); }

/* ── XML preview ──────────────────────────────────────────────────────────── */
.dark .xml-preview-table th          { background: var(--surface-1); color: var(--text-secondary); }
.dark .xml-preview-table td          { border-color: var(--border); color: var(--text-primary); }
.dark .xml-preview-table tr:hover td { background: var(--surface-2); }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.dark .tab-btn        { background: var(--surface-1); border-color: var(--border); color: var(--text-secondary); }
.dark .tab-btn:hover  { background: var(--surface-2); }
.dark .tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Period copy / misc ───────────────────────────────────────────────────── */
.dark .period-copy-btn:hover { background: var(--surface-1); }
.dark .gb-summary-header     { border-color: var(--border); }
.dark .gb-inline-cat         { border-color: var(--border); }
.dark .verification-bar      { background: var(--surface-1); border-color: var(--border); }
.dark .group-budget-toggle   { border-color: var(--border); }

/* ── Charts ───────────────────────────────────────────────────────────────── */
.dark .chart-card  { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow); }
.dark .chart-empty { background: var(--surface-1); border-color: var(--border); }

/* ── Group budget extras ──────────────────────────────────────────────────── */
.dark .gb-cat-badge   { background: rgba(96,165,250,0.12);  color: #60a5fa; }
.dark .gb-merge-badge { background: rgba(129,140,248,0.15); color: #a5b4fc; }
.dark .gb-spent-sub   { color: #a5b4fc; }
.dark .gb-split-sub   { color: #64748b; }
.dark .gb-split-own   { color: #94a3b8; }
.dark .gb-split-grp   { color: #a5b4fc; }
.dark .gb-tx-separator td { background: var(--surface-1); }
.dark .gb-map-tree-header { background: var(--surface-1); }
.dark .gb-map-tree-item:hover { background: var(--surface-2); }

/* Group budget matrix dark mode — income rows and member badge */
.dark .gb-matrix-table .income-row td { background: rgba(52,211,153,0.07); }
.dark .member-badge { background: rgba(99,102,241,0.15); }

/* Dark theme toggle button */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    cursor: pointer;
    padding: 0.35rem 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: color 0.2s;
}
.theme-toggle:hover { color: var(--primary); }

/* ── Tags ───────────────────────────────────────────────────────────────────── */
.tags-input-wrap {
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.4rem 0.6rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    align-items: center;
    min-height: 2.5rem;
    background: var(--surface);
    cursor: text;
}
.tags-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag-chip {
    background: #eef2ff;
    color: #4f46e5;
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.tag-chip button {
    background: none;
    border: none;
    cursor: pointer;
    color: #6366f1;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1;
}
.tags-text-input {
    border: none;
    outline: none;
    flex: 1;
    min-width: 100px;
    font-size: 0.875rem;
    background: transparent;
    color: var(--text-primary);
}
.tag-chip-sm {
    background: #eef2ff;
    color: #4f46e5;
    border-radius: 999px;
    padding: 0.05rem 0.45rem;
    font-size: 0.68rem;
    display: inline-block;
    margin-right: 0.2rem;
}
.tx-tags-row { margin-top: 0.2rem; }

/* ── Forecast bar ───────────────────────────────────────────────────────────── */
.forecast-panel {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 0.75rem;
    margin: 0.5rem 0;
    overflow: hidden;
}
.dark .forecast-panel { background: #052e16; border-color: #166534; }

.forecast-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 1rem;
    font-size: 0.875rem;
    flex-wrap: wrap;
    color: #166534;
}
.dark .forecast-summary { color: #bbf7d0; }

.forecast-chart-wrap {
    height: 210px;
    padding: 0 0.75rem 0.75rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.forecast-icon { font-size: 1rem; }
.forecast-sep { color: var(--text-secondary); }
.forecast-detail { color: var(--text-secondary); font-size: 0.78rem; margin-left: 0.25rem; }
.forecast-pace { font-size: 0.78rem; margin-left: 0.5rem; }

.forecast-mode-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 1rem 0.5rem;
    flex-wrap: wrap;
    border-top: 1px solid #bbf7d0;
    background: #f0fdf4;
}
.dark .forecast-mode-row { border-color: #166534; background: #052e16; }

.forecast-mode-label {
    font-size: 0.78rem;
    color: #166534;
    white-space: nowrap;
}
.dark .forecast-mode-label { color: #86efac; }

.forecast-mode-tabs {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.fmt-tab {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    border: 1px solid #86efac;
    background: transparent;
    color: #166534;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.fmt-tab:hover { background: rgba(34,197,94,0.12); }
.fmt-tab.active { background: #16a34a; color: #fff; border-color: #16a34a; }
.dark .fmt-tab { border-color: #166534; color: #86efac; }
.dark .fmt-tab:hover { background: rgba(52,211,153,0.12); }
.dark .fmt-tab.active { background: #15803d; color: #fff; border-color: #15803d; }

.forecast-day-input {
    width: 4rem;
    padding: 0.18rem 0.4rem;
    font-size: 0.8rem;
    border: 1px solid #86efac;
    border-radius: 0.35rem;
    background: var(--surface);
    color: var(--text);
}
.dark .forecast-day-input { border-color: #166534; }

.forecast-date-input {
    padding: 0.18rem 0.4rem;
    font-size: 0.8rem;
    border: 1px solid #86efac;
    border-radius: 0.35rem;
    background: var(--surface);
    color: var(--text);
}
.dark .forecast-date-input { border-color: #166534; }

/* ── Not-participant banner ─────────────────────────────────────────────────── */
.not-participant-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 0.5rem;
    margin: 0.75rem 1rem;
    font-size: 0.9rem;
    color: #92400e;
}

/* ── Activity log ───────────────────────────────────────────────────────────── */
.activity-log-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 320px;
    overflow-y: auto;
}
.activity-log-item {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    font-size: 0.82rem;
    flex-wrap: wrap;
}
.log-time { color: var(--text-secondary); font-size: 0.75rem; min-width: 120px; }
.log-user { font-weight: 600; }
.log-action { color: var(--primary); }
.log-details { color: var(--text-secondary); }

/* ── Auth divider ───────────────────────────────────────────────────────────── */
.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
}
.auth-divider::before, .auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Input validation states ────────────────────────────────────────────────── */
.input-error {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 2px rgba(239,68,68,0.15) !important;
}
.field-error {
    font-size: 0.78rem;
    color: var(--danger);
    margin-top: 0.25rem;
}
.tx-gross-section {
    border-top: 1px solid var(--border);
    margin-top: 0.5rem;
    padding-top: 0.75rem;
}
.tx-tax-info { font-size: 0.82rem; }

/* ── Gross / tax subline ────────────────────────────────────────────────────── */
.cat-gross-subline {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.tx-gross-sub {
    font-size: 0.7em;
    color: var(--text-muted);
    line-height: 1.3;
    display: block;
}
.tax-amount { color: var(--danger); }

/* ── Group budget tx / cat row styles ───────────────────────────────────────── */
.gb-tx-row td { opacity: 0.88; }
.gb-tx-row:hover td { opacity: 1; }
.gb-tx-ref { font-size: 0.68rem; color: var(--text-secondary); margin-top: 2px; }
.gb-tx-separator td {
    padding: 0.35rem 0.75rem;
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    font-size: 0.72rem;
}
.gb-tx-sep-label { font-weight: 600; color: var(--primary); }

/* ── Transaction deep-link highlight animation ───────────────────────────────── */
@keyframes txHighlightFade {
    0%   { background: rgba(99, 102, 241, 0.28); }
    60%  { background: rgba(99, 102, 241, 0.14); }
    100% { background: transparent; }
}
.tx-highlight td {
    animation: txHighlightFade 2.8s ease-out forwards;
    position: relative;
}
/* Slight outline on the row itself for extra visibility */
.tx-highlight {
    outline: 2px solid rgba(99, 102, 241, 0.45);
    outline-offset: -1px;
    border-radius: 4px;
}
.dark .tx-highlight td {
    animation: txHighlightFadeDark 2.8s ease-out forwards;
}
@keyframes txHighlightFadeDark {
    0%   { background: rgba(165, 180, 252, 0.22); }
    60%  { background: rgba(165, 180, 252, 0.10); }
    100% { background: transparent; }
}

.gb-cat-row td { background: var(--background); opacity: 0.85; }
.gb-cat-row:hover td { opacity: 1; }
.gb-cat-badge {
    font-size: 0.6rem;
    background: rgba(96,165,250,0.15);
    color: #1e40af;
    border-radius: 999px;
    padding: 0.1rem 0.35rem;
    margin-left: 0.3rem;
    font-weight: 600;
    vertical-align: middle;
}
.dark .gb-cat-badge-light { color: #60a5fa; }
.gb-merge-badge {
    font-size: 0.6rem;
    background: rgba(99,102,241,0.12);
    color: #3730a3;
    border-radius: 999px;
    padding: 0.1rem 0.35rem;
    margin-left: 0.3rem;
    font-weight: 600;
    vertical-align: middle;
}
.gb-spent-sub { font-size: 0.7rem; color: var(--primary); margin-top: 2px; }

/* ── Group budget category split breakdown ───────────────────────────────────── */
.gb-split-sub {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 3px;
    white-space: nowrap;
    line-height: 1.3;
}
.gb-split-own { color: var(--text-secondary); }
.gb-split-grp { color: var(--primary); font-weight: 600; }

/* ── Crypto budget widget (on Budget page) ───────────────────────────────────── */
.crypto-budget-widget {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.cbw-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.cbw-icon {
    font-size: 1.6rem;
    line-height: 1;
}
.cbw-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cbw-amounts {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.cbw-amounts strong {
    font-size: 1.15rem;
    color: var(--text-primary);
}
.cbw-cur {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
}
.cbw-pnl {
    font-size: 0.78rem;
    font-weight: 600;
}
.cbw-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.cbw-count {
    font-size: 0.78rem;
    color: var(--text-muted);
}
.cbw-budget-info {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
.dark .crypto-budget-widget {
    background: var(--surface);
    border-color: var(--border);
}

/* ── Group budget category mapping treeview ─────────────────────────────────── */
.gb-map-tree { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-top: 0.5rem; }
.gb-map-tree-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    background: var(--bg-secondary, #f8fafc);
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.gb-map-tree-children { padding: 0.35rem 0; }
.gb-map-tree-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 1rem 0.45rem 2.25rem;
    transition: background 0.1s;
}
.gb-map-tree-item:hover { background: var(--surface); }
.gb-map-tree-cat { display: flex; align-items: center; gap: 0.35rem; flex: 1; min-width: 100px; font-weight: 500; font-size: 0.88rem; }
.gb-map-tree-arrow { color: var(--text-secondary); flex-shrink: 0; font-size: 1rem; }
.gb-map-period-sel { margin-bottom: 1rem; }
.gb-map-period-sel label { font-weight: 600; font-size: 0.875rem; display: block; margin-bottom: 0.35rem; color: var(--text-primary); }
.gb-totals-row {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding-top: 0.4rem;
    border-top: 1px dashed var(--border);
    margin-top: 0.35rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.cat-inline-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    max-width: 160px;
}
/* Group budget status chip (minimal, when GB data is integrated) */
.gb-status-chip {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    padding: 0.4rem 0.75rem;
    background: rgba(99,102,241,0.07);
    border: 1px solid rgba(99,102,241,0.18);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    margin: 0.4rem 0;
}
.gb-status-detail { color: var(--text-secondary); font-size: 0.78rem; }
.dark .gb-status-chip { background: rgba(129,140,248,0.1); border-color: rgba(129,140,248,0.2); }

/* Group budget toggle area */
.group-budget-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin: 0.5rem 0;
}

/* ── Financial Insights Panel ───────────────────────────────────────────────── */
.fin-insights-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0.875rem;
    margin: 0.75rem 0 0.5rem;
}

.fin-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.18s;
}
.fin-card:hover { box-shadow: var(--shadow-md); }

.fin-card-header {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0.75rem;
}
.fin-card-icon { font-size: 1.1rem; }
.fin-card-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
}
.fin-card-tip {
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: help;
}

/* KPI grid inside fin-card */
.fin-kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.65rem;
}
.fin-kpi {
    background: var(--surface-1);
    border-radius: var(--radius-sm);
    padding: 0.45rem 0.6rem;
}
.fin-kpi-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fin-kpi-val {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}
.fin-cur { font-size: 0.72rem; font-weight: 400; color: var(--text-muted); }

/* Status colours */
.fin-ok      { color: #10b981; }
.fin-warn    { color: #f59e0b; }
.fin-danger  { color: #ef4444; }
.fin-primary { color: var(--primary); }

/* Daily pace progress bar */
.fin-pace-bar-wrap { margin-top: 0.4rem; }
.fin-pace-bar {
    height: 6px;
    background: var(--surface-1);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 4px;
}
.fin-pace-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    transition: width 0.5s ease;
}
.fin-pace-fill.over { background: #ef4444; }
.fin-pace-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.68rem;
    color: var(--text-muted);
}

/* 50/30/20 rows */
.r5030-row {
    display: grid;
    grid-template-columns: 10px 1fr 1fr auto auto auto;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0.55rem;
    font-size: 0.8rem;
}
.r5030-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.r5030-needs   { background: #ef4444; }
.r5030-wants   { background: #f59e0b; }
.r5030-savings { background: #10b981; }

.r5030-label { color: var(--text-secondary); font-size: 0.75rem; }

.r5030-bar-wrap {
    position: relative;
    height: 8px;
    background: var(--surface-1);
    border-radius: 999px;
    overflow: visible;
}
.r5030-bar-fill {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
    opacity: 0.85;
}
.r5030-bar-target {
    position: absolute;
    top: -3px;
    width: 2px; height: 14px;
    background: var(--text-muted);
    border-radius: 1px;
    transform: translateX(-50%);
}
.r5030-pct   { font-weight: 700; min-width: 30px; text-align: right; }
.r5030-target-lbl { font-size: 0.68rem; color: var(--text-muted); white-space: nowrap; }
.r5030-badge {
    font-size: 0.72rem;
    font-weight: 700;
    width: 18px; height: 18px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
}
.badge-ok   { background: rgba(16,185,129,0.12); color: #10b981; }
.badge-warn { background: rgba(245,158,11,0.12); color: #f59e0b; }
.r5030-note {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
    padding-top: 0.4rem;
    border-top: 1px solid var(--border-soft);
}

/* Emergency Fund */
.fin-ef-timeline { display: flex; flex-direction: column; gap: 0.4rem; }
.fin-ef-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--surface-1);
    padding: 0.4rem 0.65rem;
    border-radius: var(--radius-sm);
}
.fin-ef-icon { font-size: 1rem; flex-shrink: 0; }

/* FIRE stats row in analytics */
.fire-stats { margin-top: 0.75rem; }
.fire-stat-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
}
.fire-stat { background: var(--surface-1); padding: 0.35rem 0.65rem; border-radius: var(--radius-sm); }
.fire-highlight { background: rgba(99,102,241,0.1); color: var(--primary); font-weight: 600; }

/* Dark mode fin-card overrides */
.dark .fin-card { background: var(--surface-1); border-color: rgba(148,163,184,0.12); }
.dark .fin-kpi  { background: var(--surface-2); }
.dark .fin-ef-item { background: var(--surface-2); }
.dark .fire-stat { background: var(--surface-2); }

@media (max-width: 640px) {
    .fin-insights-panel { grid-template-columns: 1fr; }
    .fin-kpi-row { grid-template-columns: repeat(2, 1fr); }
    .r5030-row { grid-template-columns: 10px 1fr 1fr auto; }
    .r5030-target-lbl, .r5030-badge { display: none; }
}

/* ── What-if Simulations Page ──────────────────────────────────────────────── */
.whatif-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

.whatif-header {
    margin-bottom: 1.5rem;
}
.whatif-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 0.25rem;
}
.whatif-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0;
}

/* Data banner */
.whatif-data-banner {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}
.wdb-item { display: flex; flex-direction: column; gap: 0.2rem; }
.wdb-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.wdb-value { font-size: 1rem; font-weight: 600; color: var(--text-primary); }

/* Grid */
.whatif-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}
.whatif-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.whatif-card-wide {
    grid-column: 1 / -1;
}

.wc-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.wc-icon { font-size: 1.4rem; flex-shrink: 0; line-height: 1; }
.wc-header h3 { font-size: 0.95rem; font-weight: 600; margin: 0 0 0.15rem; color: var(--text-primary); }
.wc-desc { font-size: 0.8rem; color: var(--text-secondary); margin: 0; }

.wc-body { padding: 1rem 1.25rem; }
.wc-controls-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

/* Slider control */
.wc-control { margin-bottom: 0.75rem; }
.wc-control > label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
    font-weight: 500;
}
.slider-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.wc-slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--surface-2);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.wc-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 1px var(--primary);
}
.wc-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid var(--surface);
}
.slider-val {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    min-width: 3.5rem;
    text-align: right;
    white-space: nowrap;
}
.wc-select { width: 100%; margin-bottom: 0.5rem; }

/* Results */
.wc-result-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.wc-result-item {
    background: var(--surface-1);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
}
.wcr-label { display: block; font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.2rem; }
.wcr-value { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.wcr-sub { font-size: 0.75rem; color: var(--text-secondary); }
.wc-insight {
    margin-top: 0.6rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(99,102,241,0.06);
    border-left: 3px solid var(--primary);
    padding: 0.4rem 0.6rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.wc-insight.negative { border-left-color: var(--danger); background: rgba(239,68,68,0.06); color: var(--danger); }
.wc-empty { color: var(--text-muted); font-size: 0.85rem; margin: 0.5rem 0; }
.wc-chart-wrap { position: relative; height: 200px; }

/* Amortisation table */
.wc-amort-table { margin-top: 0.75rem; }
.wc-amort-title { font-size: 0.78rem; color: var(--text-secondary); margin: 0 0 0.35rem; font-weight: 500; }
.wc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.wc-table th, .wc-table td {
    padding: 0.3rem 0.5rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
}
.wc-table th { font-weight: 600; color: var(--text-secondary); background: var(--surface-1); text-align: right; }
.wc-table th:first-child, .wc-table td:first-child { text-align: center; }

/* Dark mode */
.dark .whatif-card { background: var(--surface); border-color: rgba(148,163,184,0.12); }
.dark .whatif-data-banner { background: var(--surface); border-color: rgba(148,163,184,0.12); }
.dark .wc-result-item { background: var(--surface-1); }
.dark .wc-insight { background: rgba(99,102,241,0.1); }

/* Responsive */
@media (max-width: 768px) {
    .whatif-data-banner { grid-template-columns: repeat(2, 1fr); }
    .whatif-grid { grid-template-columns: 1fr; }
    .whatif-card-wide { grid-column: auto; }
    .wc-controls-row { grid-template-columns: 1fr; gap: 0 }
    .wc-result-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
    .whatif-data-banner { grid-template-columns: 1fr 1fr; }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   Crypto Portfolio Page
   ═══════════════════════════════════════════════════════════════════════════════ */

.crypto-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1rem 4rem;
}

/* Header */
.crypto-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.crypto-header h1 { margin: 0 0 0.25rem; font-size: 1.6rem; font-weight: 700; }
.crypto-subtitle { margin: 0; color: var(--text-secondary); font-size: 0.88rem; }
.crypto-header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Summary cards */
.crypto-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.crypto-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
}
.cc-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.3rem;
}
.cc-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 0.2rem;
}
.cc-value.positive { color: var(--success, #22c55e); }
.cc-value.negative { color: var(--danger, #ef4444); }
.cc-currency {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
}
.cc-note { font-size: 0.72rem; color: var(--text-muted); }

/* Holdings section */
.crypto-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}
.crypto-section-header h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.crypto-price-note { font-size: 0.72rem; color: var(--text-muted); }

/* Table */
.crypto-table-wrap { overflow-x: auto; }
.crypto-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.crypto-table th {
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.crypto-table td {
    padding: 0.7rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.crypto-table th.num, .crypto-table td.num { text-align: right; }
.crypto-table tbody tr:hover td { background: var(--surface-1); }
.crypto-table .positive { color: var(--success, #22c55e); font-weight: 600; }
.crypto-table .negative { color: var(--danger, #ef4444); font-weight: 600; }
.crypto-table small { font-size: 0.72em; opacity: 0.8; }

.crypto-coin-cell { display: flex; align-items: center; gap: 0.6rem; min-width: 140px; }
.crypto-coin-badge {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    letter-spacing: -0.02em;
}
.crypto-coin-name { font-weight: 600; font-size: 0.88rem; }
.crypto-coin-id { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; }

/* Action buttons in table */
.btn-icon-sm {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem 0.4rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}
.btn-icon-sm:hover { background: var(--surface-1); color: var(--text-primary); }
.btn-icon-sm.danger:hover { background: rgba(239,68,68,0.1); color: var(--danger, #ef4444); border-color: rgba(239,68,68,0.3); }

/* Allocation chart */
.crypto-allocation-wrap {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.crypto-allocation-wrap h4 { margin: 0 0 1rem; font-size: 0.95rem; font-weight: 600; }
.crypto-chart-row {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}
.crypto-chart-container {
    width: 220px;
    height: 220px;
    flex-shrink: 0;
}
.crypto-alloc-legend { display: flex; flex-direction: column; gap: 0.5rem; flex: 1; min-width: 150px; }
.alloc-leg-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
}
.alloc-leg-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.alloc-leg-name { flex: 1; font-weight: 500; }
.alloc-leg-pct { color: var(--text-secondary); font-size: 0.78rem; }

/* Empty state */
.crypto-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}
.crypto-empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.crypto-empty p { margin: 0.25rem 0; font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.crypto-empty-sub { font-size: 0.85rem !important; font-weight: 400 !important; color: var(--text-secondary) !important; margin-bottom: 1.25rem !important; }

/* Coin search autocomplete */
.crypto-suggestions {
    position: absolute;
    z-index: 200;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    max-height: 240px;
    overflow-y: auto;
    width: 100%;
    margin-top: 2px;
}
.form-group { position: relative; }
.crypto-sugg-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.85rem;
    cursor: pointer;
    transition: background 0.12s;
    font-size: 0.875rem;
}
.crypto-sugg-item:hover { background: var(--surface-1); }
.sugg-sym {
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--primary);
    min-width: 44px;
}
.sugg-name { color: var(--text-secondary); }

/* Dark mode */
.dark .crypto-card { background: var(--surface); border-color: rgba(148,163,184,0.12); }
.dark .crypto-allocation-wrap { background: var(--surface); border-color: rgba(148,163,184,0.12); }
.dark .crypto-suggestions { background: var(--surface); border-color: rgba(148,163,184,0.2); box-shadow: 0 4px 20px rgba(0,0,0,0.4); }

/* Responsive */
@media (max-width: 900px) {
    .crypto-summary-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
    .crypto-summary-grid { grid-template-columns: repeat(2, 1fr); }
    .crypto-chart-container { width: 180px; height: 180px; }
    .crypto-table th, .crypto-table td { padding: 0.5rem 0.4rem; }
}
@media (max-width: 400px) {
    .crypto-summary-grid { grid-template-columns: 1fr 1fr; }
    .crypto-header { flex-direction: column; }
}
