:root {
    /* Ocean Theme (Blue-Green) - Dein gewünschtes Design */
    --primary: #06b6d4; /* Cyan 500 */
    --primary-dark: #0e7490; /* Cyan 700 */
    --secondary: #10b981; /* Emerald 500 */

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #06b6d4 0%, #10b981 100%);
    --gradient-hover: linear-gradient(135deg, #22d3ee 0%, #34d399 100%);

    /* Backgrounds */
    --bg: #e6f2fa; /* Slightly darker than #f0f9ff (Sky 50) */
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border-light: #e2e8f0;

    /* Text & Borders */
    --text: #0f172a; /* Slate 900 */
    --text-secondary: #64748b; /* Slate 500 */
    --border: #cbd5e1;

    /* Status Colors */
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;

    /* UI Utils */
    --radius: 20px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    /* Removed glow effect from shadow-lg */
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --desktop-header-offset: 108px;
    --desktop-header-bg: #ffffff;
    --desktop-header-border: #e5e7eb;
    --desktop-nav-text: #475569;
    --desktop-nav-active: #0f172a;
    --desktop-nav-underline: #06b6d4;
    --desktop-profile-border: #d1d5db;
    --desktop-profile-text: #0f172a;
    --mobile-bottom-nav-height: 55px;
    --mobile-bottom-nav-extra-padding: 8px;
    --mobile-bottom-nav-offset: calc(var(--mobile-bottom-nav-height) + var(--mobile-bottom-nav-extra-padding) + env(safe-area-inset-bottom));
    --mobile-ai-chat-input-height: 92px;
}

[data-theme="dark"] {
    --primary: #22d3ee;
    --primary-dark: #06b6d4;
    --bg: #0f172a; /* Darker background */
    --surface: #1e293b; /* Darker surface */
    --surface-alt: #334155; /* Lighter alt for contrast */
    --text: #f3f4f6;
    --text-secondary: #9ca3af;
    --border: #475569;
    --border-light: #334155; /* Better separation */
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);

    /* Dark mode overrides for desktop header */
    --desktop-header-bg: var(--surface);
    --desktop-header-border: var(--border);
    --desktop-nav-text: var(--text-secondary);
    --desktop-nav-active: var(--text);
    --desktop-nav-underline: var(--primary);
    --desktop-profile-border: var(--border);
    --desktop-profile-text: var(--text);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; -webkit-tap-highlight-color: transparent; scrollbar-width: none; }
::-webkit-scrollbar { display: none; }
html { overscroll-behavior: none; }
body { background-color: var(--bg); color: var(--text); height: 100dvh; overflow: hidden; overscroll-behavior: none; transition: background-color 0.3s ease; }

.container { max-width: none; margin: 0; padding: 20px calc(max(20px, (100% - 800px) / 2)); padding-bottom: 100px; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; scroll-behavior: smooth; }

.app-layout {
    position: relative;
}

.header {
    display: flex;
    align-items: center; justify-content: space-between;
    padding: 20px 0 30px;
    position: relative;
    z-index: 50;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.header-left img { height: 32px; width: auto; }
.header-left h1 {
    font-size: 2rem; font-weight: 800;
    background: var(--gradient-primary); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.header-right {
    display: flex;
    align-items: center;
}

/* Profile Menu */
.profile-menu-container {
    position: relative;
}
.profile-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
}
.profile-btn:active {
    transform: scale(0.95);
}

.profile-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 100;
}
.profile-dropdown::before {
    content: "";
    position: absolute;
    top: -6px;
    right: 16px;
    width: 10px;
    height: 10px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    border-top: 1px solid var(--border);
    transform: rotate(45deg);
    border-radius: 2px;
}
.profile-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
    width: 100%;
}
.dropdown-item:active {
    background: var(--bg);
}
.dropdown-item.text-danger {
    color: var(--danger);
}

/* --- Hero & Stats --- */
.hero-card {
    background: linear-gradient(135deg, #06b6d4 0%, #10b981 100%);
    color: white;
    padding: 20px 24px;
    border-radius: 28px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
    margin-bottom: 10px;
    cursor: pointer;
    transition: transform 0.2s;
    will-change: transform;
}
.hero-card:active { transform: scale(0.98); }
.hero-card:focus { outline: none; }
.hero-card::before { content: ''; position: absolute; top: -50px; left: -50px; width: 150px; height: 150px; background: rgba(255,255,255,0.1); border-radius: 50%; }
.hero-card::after { content: ''; position: absolute; bottom: -20px; right: -20px; width: 100px; height: 100px; background: rgba(255,255,255,0.15); border-radius: 50%; }

.hero-label {
    display: inline-block; background: rgba(0,0,0,0.15);
    padding: 6px 14px; border-radius: 20px; font-size: 0.75rem; font-weight: 700;
    letter-spacing: 0.5px; margin-bottom: 12px; text-transform: uppercase;
}
.hero-amount { font-size: 2.8rem; font-weight: 800; margin-bottom: 6px; line-height: 1.1; color: white; }
.hero-subtitle { font-size: 0.95rem; opacity: 0.9; font-weight: 500; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 30px; min-width: 0; }
.stat-box {
    background: var(--surface); padding: 12px; border-radius: 20px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); border: none;
}
.stat-box > div:not(.stat-icon) {
    display: flex; flex-direction: column; align-items: center; width: 100%; min-width: 0;
}
.stat-icon { display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; }
.stat-icon.success { background-color: #F0FDF4; color: var(--success); }
.stat-icon.danger { background-color: #FEF2F2; color: var(--danger); }
.stat-icon.info { background-color: #F0F9FF; color: #0EA5E9; }
.stat-icon.warning { background-color: #FFFBEB; color: #D97706; }
.stat-label { font-size: 0.7rem; color: var(--text-secondary); font-weight: 700; text-transform: uppercase; margin-bottom: 2px; }
.stat-value { font-size: 1.1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-info { color: #0EA5E9; }
.text-warning { color: #D97706; }

/* --- Dashboard Layout --- */
.dashboard-top-section {
    display: block; /* Stack on mobile */
}

.dashboard-right {
    display: none; /* Hidden on mobile */
}

.chart-card {
    background: var(--surface);
    border-radius: 28px; /* Match hero-card radius or similar */
    padding: 10px;
    box-shadow: var(--shadow-lg);
    border: none;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chart-header {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 15px;
    letter-spacing: 0.5px;
}

.chart-container {
    position: relative;
    width: 100%;
    flex-grow: 1;
    min-height: 140px;
}

#balanceChart {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* --- Tabs (Content only) --- */
.tab-content { display: none; }
.tab-content.active { display: block; }

.tab-content.slide-in-right { animation: slideInRight 0.4s cubic-bezier(0.25, 1, 0.5, 1); }
.tab-content.slide-in-left { animation: slideInLeft 0.4s cubic-bezier(0.25, 1, 0.5, 1); }

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

/* --- Cards & Settings --- */
.card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); border: 1px solid var(--border);
    margin-bottom: 20px; overflow: hidden; transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}
.card-settings { padding: 0; }
.card-header {
    padding: 20px 20px 5px; /* Increased top padding, reduced bottom */
    background: transparent;
    border-bottom: none;
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--text);
}
.card-body { padding: 10px 20px 20px; } /* Reduced top padding */

/* --- Person List UX Improvements --- */
.list-section-title {
    font-size: 0.9rem; font-weight: 700; color: var(--text-secondary);
    margin: 10px 0 10px 5px; text-transform: uppercase; letter-spacing: 0.5px;
    display: flex; align-items: center; gap: 8px;
}
.list-section-title::after { content: ''; flex: 1; height: 1px; background: var(--border); opacity: 0.6; }

/* Wrapper for the whole card item */
.person-wrapper {
    margin-bottom: 12px;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    /* ⚡ Bolt: Optimizes rendering performance for long lists */
}

.person-wrapper.active {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* The Main Clickable Card */
.person-item {
    background: var(--surface);
    border-radius: 16px;
    padding: 16px;
    border: none;
    box-shadow: var(--shadow);
    cursor: pointer;
    position: relative;
    z-index: 2;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Active state for the main card */
.person-item.active {
    background: var(--surface);
    /* When active inside wrapper, remove shadow and bottom radius to merge */
    box-shadow: none;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: 1px solid var(--border-light);
}

.person-item:active { transform: scale(0.97); }
.person-item:focus { outline: none; }

.person-pill { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.person-left { display: flex; flex-direction: column; gap: 4px; }
.person-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.person-name { font-weight: 700; font-size: 1rem; color: var(--text); display: flex; align-items: center; gap: 8px;}
.person-status { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; color: var(--text-secondary); opacity: 0.8; }

.payment-pill {
    font-weight: 700; font-size: 0.8rem; padding: 4px 12px;
    border-radius: 99px; color: white; display: inline-block;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.status-ok { background: var(--success); }
.status-warn { background: var(--warning); }
.status-err { background: linear-gradient(90deg, #ef4444 0%, #b91c1c 100%); }
.time-remaining { font-size: 0.75rem; color: var(--text-secondary); font-weight: 500; }

/* Chevron Icon */
.chevron {
    font-size: 1.2rem;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
    margin-left: 8px;
    display: inline-block;
    will-change: transform;
}
.person-item.active .chevron {
    transform: rotate(90deg);
    color: var(--primary);
}

/* The Dropdown Details */
.person-details {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    background: transparent;
    border: none;
    margin: 0;
    padding: 0;

    /* Animation Physics */
    transition: max-height 0.4s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.3s ease;
    position: relative;
    z-index: 1;
}

.person-details.active {
    opacity: 1;
}

/* Timeline Component */
.timeline {
    position: relative;
    padding-left: 24px;
    border-left: 2px solid var(--border-light);
    margin-left: 8px;
    margin-top: 15px;
    margin-bottom: 15px;
}
.timeline-item {
    position: relative;
    margin-bottom: 24px;
}
.timeline-item:last-child { margin-bottom: 0; }

.timeline-dot {
    position: absolute;
    left: -31px; /* 24px padding + 2px border + 5px center align */
    top: 6px;
    width: 12px;
    height: 12px;
    background: var(--primary);
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 4px #fff; /* Mask line */
}

.details-content { padding: 20px; }

/* --- New Details UI --- */
.details-status-card {
    background: var(--surface-alt);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}
.details-status-card.danger { background: rgba(239, 68, 68, 0.05); border-color: rgba(239, 68, 68, 0.2); }
.details-status-card.success { background: rgba(16, 185, 129, 0.05); border-color: rgba(16, 185, 129, 0.2); }

.details-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 0.95rem; }
.details-row:last-child { margin-bottom: 0; }
.details-label { color: var(--text-secondary); font-weight: 500; }
.details-value { font-weight: 700; color: var(--text); }

.details-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 25px; }
.details-actions .btn { font-size: 0.9rem; padding: 10px; width: 100%; justify-content: center; }
.details-actions .btn-primary { box-shadow: none; }
.details-actions .secondary-actions { display: flex; gap: 10px; width: 100%; }
.details-actions .secondary-actions .btn { flex: 1; margin: 0; }

.history-header {
    font-size: 0.8rem; text-transform: uppercase; color: var(--text-secondary);
    margin: 25px 0 10px; letter-spacing: 0.5px; font-weight: 700; display: flex; align-items: center; gap: 8px;
}
.history-header::after { content: ''; flex: 1; height: 1px; background: var(--border); opacity: 0.5; }

/* --- Forms --- */
.form-group { margin-bottom: 15px; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-input, .form-select {
    width: 100%; padding: 12px; border-radius: 12px;
    border: 2px solid var(--border); background: var(--surface-alt);
    color: var(--text); font-size: 1rem; transition: 0.2s;
}
.form-input:focus, .form-select:focus {
    outline: none; border-color: var(--primary); background: var(--surface);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}

/* --- Buttons --- */
.btn {
    padding: 12px 20px; border-radius: 12px; border: none; font-weight: 600;
    cursor: pointer; transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1); font-size: 0.95rem; width: auto;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:active { transform: scale(0.95); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: linear-gradient(90deg, #06b6d4 0%, #10b981 100%); color: white; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1px solid var(--border); }
.btn-secondary.active { background: rgba(6, 182, 212, 0.1); color: var(--primary); border-color: var(--primary); }
.btn-danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.settings-flex-row {
    display: flex; gap: 10px; width: 100%; flex-wrap: wrap;
}
.settings-flex-row > * {
    flex: 1; min-width: 100px; display: flex; justify-content: center;
}
.btn-small { padding: 8px 16px; font-size: 0.85rem; width: auto; }

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

@media (max-width: 600px) {
    .action-buttons {
        grid-template-columns: 1fr;
    }
}

.desktop-fab {
    display: none;
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    border: none;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    z-index: 1002;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}
.desktop-fab:active { transform: scale(0.95); }
.desktop-fab.active svg { transform: rotate(45deg); }
.desktop-fab svg {
    width: 32px;
    height: 32px;
    stroke: white;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

/* --- Bottom Navigation --- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; width: 100%;
    background-color: var(--surface);
    border-top: 1px solid var(--border-light);
    display: flex; justify-content: space-around; align-items: center;
    padding: 2px 0 calc(var(--mobile-bottom-nav-extra-padding) + env(safe-area-inset-bottom));
    min-height: var(--mobile-bottom-nav-height);
    box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.08);
    z-index: 1000;
}

[data-theme="dark"] .bottom-nav {
    border-top-color: transparent;
    box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.5);
}

.nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: none; border: none; cursor: pointer;
    color: var(--text-secondary); font-size: 0.7rem; font-weight: 600;
    gap: 2px; padding: 4px;
}
.nav-item svg { width: 24px; height: 24px; opacity: 0.7; transition: 0.2s; }
.nav-item.active { color: var(--secondary); }
.nav-item.active svg { opacity: 1; stroke: var(--secondary); }

.nav-action-bg {
    width: 44px; height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}
.mobile-fab:active .nav-action-bg {
    transform: scale(0.95);
}
.mobile-fab.active svg {
    transform: rotate(45deg);
    stroke: white !important;
}
.nav-action-bg svg {
    opacity: 1 !important;
    width: 24px; height: 24px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.nav-center {
    position: absolute; width: 64px; height: 64px;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex; align-items: center; justify-content: center;
}

.nav-fab {
    width: 64px; height: 64px; border-radius: 50%;
    background: linear-gradient(135deg, #06b6d4 0%, #10b981 100%);
    border: none;
    display: flex; align-items: center; justify-content: center;
    box-shadow: none;
    cursor: pointer; transition: 0.3s;
    position: relative; z-index: 1001;
    will-change: transform;
}
.nav-fab:active { transform: scale(0.95); }
.nav-fab.active { transform: rotate(45deg); }
.nav-fab svg { width: 32px; height: 32px; }

/* FAB Menu */
.fab-menu {
    position: fixed; bottom: 85px; left: 50%; right: auto;
    width: max-content; max-width: 90%;
    background: var(--surface); border-radius: 20px;
    padding: 16px; box-shadow: 0 15px 30px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 16px;
    z-index: 1002; pointer-events: none;
    transform: translateX(-50%) translateY(20px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s cubic-bezier(0.25, 1, 0.5, 1), transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), visibility 0s 0.3s;
}
.fab-menu.show {
    pointer-events: all;
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    transition: opacity 0.3s cubic-bezier(0.25, 1, 0.5, 1), transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), visibility 0s;
}
.fab-menu-item {
    display: flex; align-items: center; text-align: left;
    background: none; border: none; padding: 0;
    cursor: pointer; width: 100%; outline: none;
    opacity: 0;
    transform: translateY(15px) scale(0.95);
    transition: opacity 0.3s cubic-bezier(0.25, 1, 0.5, 1), transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    will-change: transform, opacity;
}
.fab-menu.show .fab-menu-item {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.fab-menu.show .fab-menu-item:nth-child(1) { transition-delay: 0.1s; }
.fab-menu.show .fab-menu-item:nth-child(2) { transition-delay: 0.05s; }
.fab-menu.show .fab-menu-item:nth-child(3) { transition-delay: 0s; }

.fab-menu-icon {
    width: 40px; height: 40px;
    border-radius: 12px; background: var(--surface-alt);
    color: var(--primary); display: flex;
    align-items: center; justify-content: center;
    flex-shrink: 0; transition: background-color 0.2s, color 0.2s;
}
.fab-menu-icon svg {
    width: 20px; height: 20px;
}
.fab-menu-item:hover .fab-menu-icon {
    background: var(--gradient-primary); color: #ffffff;
}
.fab-menu-text {
    margin-left: 12px; display: flex;
    flex-direction: column;
}
.fab-menu-title {
    font-size: 16px; font-weight: 700;
    color: var(--text); line-height: 1.2;
}
.fab-menu-subtitle {
    font-size: 12px; font-weight: 400;
    color: var(--text-secondary); margin-top: 2px;
}

/* Modals */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000; opacity: 0; pointer-events: none; transition: opacity 0.3s cubic-bezier(0.25, 1, 0.5, 1), backdrop-filter 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    will-change: opacity, backdrop-filter;
}
.modal.show { opacity: 1; pointer-events: all; backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.modal-content {
    background: var(--surface); width: 90%; max-width: 440px;
    border-radius: 24px; padding: 0 24px 24px 24px;
    transform: translateY(20px) scale(0.95); transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 85vh; overflow-y: auto; -webkit-overflow-scrolling: touch; border: none;
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.18), 0 4px 16px rgba(0, 0, 0, 0.08);
    will-change: transform, opacity;
}
[data-theme="dark"] .modal-content {
    border: 1px solid var(--border);
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.65), 0 4px 16px rgba(0, 0, 0, 0.4);
}
.modal.show .modal-content { transform: translateY(0) scale(1); }

/* Login Modal Specific Backdrop */
#login-modal {
    background: var(--bg);
    background-image:
        radial-gradient(at 0% 0%, rgba(6, 182, 212, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.15) 0px, transparent 50%);
    backdrop-filter: none;
}

.modal-header {
    font-size: 1.2rem;
    font-weight: 800;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    color: var(--text);
    position: sticky;
    top: 0;
    background: var(--surface);
    padding-top: 24px;
    z-index: 10;
}

/* Enhanced Modal Styling (Non-Glassy, Segmented, Responsive & Tactile) */
.modal-content-enhanced {
    padding: 0 !important;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 40px);
}

.modal-header-enhanced {
    flex-shrink: 0;
    padding: 16px 20px 14px 20px;
    margin-bottom: 0;
    position: relative;
    background: var(--surface);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
[data-theme="dark"] .modal-header-enhanced {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

.modal-header-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.modal-icon-badge {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}
.badge-person { background: #eef2ff; color: #4f46e5; }
.badge-donation { background: #ecfdf5; color: #059669; }
.badge-expense { background: #fff1f2; color: #e11d48; }

[data-theme="dark"] .badge-person { background: rgba(79, 70, 229, 0.25); color: #818cf8; }
[data-theme="dark"] .badge-donation { background: rgba(16, 185, 129, 0.25); color: #34d399; }
[data-theme="dark"] .badge-expense { background: rgba(244, 63, 94, 0.25); color: #fb7185; }

.modal-title-main {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.modal-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 2px;
    font-weight: 400;
}

.modal-body-enhanced {
    padding: 16px 20px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    flex: 1;
}

.modal-section-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.modal-section-card:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.modal-section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.hero-amount-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}
.hero-amount-prefix {
    position: absolute;
    left: 14px;
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary);
    pointer-events: none;
}
.hero-amount-input {
    padding-left: 32px !important;
    font-size: 1.25rem !important;
    font-weight: 700 !important;
    letter-spacing: -0.02em;
    color: var(--text) !important;
    height: 44px !important;
    background: var(--surface) !important;
}

.file-upload-dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    text-align: center;
    background: var(--surface);
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
}
.file-upload-dropzone:hover {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.03);
}
.file-upload-dropzone input[type="file"] {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0;
    cursor: pointer;
}
.file-upload-icon {
    font-size: 1.2rem;
    margin-bottom: 2px;
    color: var(--text-secondary);
}
.file-upload-text {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
}
.file-upload-subtext {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 2px;
}


/* Trans List */
.trans-item {
    background: var(--surface);
    border-radius: 16px;
    padding: 16px;
    border: none;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.95rem;
    position: relative;
    z-index: 2;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
@media (hover: hover) {
    .trans-item:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 15px rgba(0,0,0,0.05);
    }
}
.trans-item:active {
    transform: scale(0.97);
}
.trans-left { display: flex; flex-direction: column; min-width: 0; }
.trans-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; display: flex; align-items: center; min-width: 0; }
.trans-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.trans-amount { font-weight: 700; }

.trans-icon-wrapper {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 16px;
    flex-shrink: 0;
}

.trans-icon-wrapper.pay {
    background: rgba(16, 185, 129, 0.15); /* Green 15% */
    color: var(--success);
}

.trans-icon-wrapper.don {
    background: rgba(139, 92, 246, 0.15); /* Purple 15% */
    color: #8b5cf6;
}

.trans-icon-wrapper.exp {
    background: rgba(239, 68, 68, 0.15); /* Red 15% */
    color: var(--danger);
}

/* Switch */
.switch { position: relative; display: inline-block; width: 50px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background: var(--gradient-primary); }
input:checked + .slider:before { transform: translateX(22px); }

/* NEU: Loading Overlay */
#loading-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #ffffff;
    z-index: 9999; display: none; align-items: center; justify-content: center; flex-direction: column;
    transition: opacity 0.3s;
}
[data-theme="dark"] #loading-overlay { background: var(--bg); }

.loading-footer {
    position: absolute;
    bottom: 20px;
    font-size: 0.7rem;
    color: #94a3b8 !important;
    font-weight: 500;
}

/* Dynamic Spinner */
.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(6, 182, 212, 0.1);
    border-left-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: relative;
    margin-bottom: 15px;
}

.spinner::before {
    content: '';
    position: absolute;
    top: -4px; left: -4px; right: -4px; bottom: -4px;
    border: 4px solid transparent;
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: spin 2s linear infinite reverse;
}

.spinner::after {
    content: '';
    position: absolute;
    top: 6px; left: 6px; right: 6px; bottom: 6px;
    border: 4px solid transparent;
    border-right-color: var(--primary-dark);
    border-radius: 50%;
    animation: spin 1.5s linear infinite;
}

/* Skeleton Loader */
.skeleton {
    background: linear-gradient(90deg, var(--surface-alt) 25%, rgba(6, 182, 212, 0.05) 50%, var(--surface-alt) 75%);
    background-size: 400% 100%;
    animation: skeleton-loading 2s ease-in-out infinite;
    border-radius: 4px;
}
@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Desktop Nav (hidden by default) */
.desktop-nav {
    display: none;
    align-items: center;
    gap: 6px;
}

.nav-btn {
    background: none;
    border: none;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 14px 12px 12px;
    border-bottom: 4px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.nav-btn.active {
    color: var(--primary-dark);
    border-bottom-color: var(--primary-dark);
}

.nav-btn svg {
    flex-shrink: 0;
}

.people-grid-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

@media (min-width: 769px) {
    .container {
        max-width: none;
        display: block; /* Reset grid */
        padding-top: var(--desktop-header-offset);
        padding-left: calc(max(20px, (100% - 1200px) / 2));
        padding-right: calc(max(20px, (100% - 1200px) / 2));
    }

    .header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        justify-content: space-between;
        padding: 16px 28px 0;
        background: var(--desktop-header-bg);
        border-bottom: 1px solid var(--desktop-header-border);
        box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
        z-index: 1100;
    }

    .header-left {
        flex: 1;
        gap: 20px;
        overflow: hidden;
    }

    .header-right {
        margin-left: 20px;
        flex-shrink: 0;
    }

    .desktop-nav {
        display: flex;
        overflow-x: auto;
        max-width: 100%;
    }

    .desktop-nav .nav-btn {
        color: var(--desktop-nav-text);
    }

    .desktop-nav .nav-btn.active {
        color: var(--desktop-nav-active);
        border-bottom-color: var(--desktop-nav-underline);
    }

    .profile-btn {
        background: var(--desktop-header-bg);
        border-color: var(--desktop-profile-border);
        color: var(--desktop-profile-text);
    }

    .bottom-nav {
        display: none !important;
    }

    /* Grid for People List: Left Overdue, Right Valid */
    .people-grid-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 30px;
        align-items: start;
    }

    /* User View: Solid Desktop Version */
    #user-view {
        max-width: 600px;
        margin: 0 auto;
    }

    /* Admin View: Centered content for tabs */
    #overview {
        max-width: 100%;
    }

    #settings {
        max-width: 800px;
        margin: 0 auto;
    }

    #user-settings {
        width: 100%;
    }

    /* Ensure Hero and Stats are not too wide on full width */
    #overview .hero-card,
    #overview .stats-grid {
        max-width: none;
        width: 100%;
        margin-bottom: 25px;
    }

    #card-design, #card-rates, #card-report, #card-invite, #card-security {
         max-width: 800px;
    }

    /* Dashboard Grid Layout */
    .dashboard-top-section {
        display: grid;
        grid-template-columns: 400px 1fr;
        gap: 50px;
        align-items: stretch;
        margin-bottom: 40px;
    }

    .dashboard-left {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        gap: 10px;
        height: 100%;
    }

    .dashboard-left .hero-card {
        margin-bottom: 0;
    }

    .stats-grid {
        margin-bottom: 0;
    }

    .dashboard-right {
        display: block;
    }

    .desktop-fab { display: flex; }

    .fab-menu {
        left: auto;
        right: 30px;
        bottom: 100px;
        transform: translateY(20px);
        width: max-content;
        max-width: 360px;
        border-radius: 28px;
        padding: 24px;
        gap: 22px;
    }
    .fab-menu.show {
        transform: translateY(0);
    }
    .fab-menu .fab-menu-icon {
        width: 48px; height: 48px;
        border-radius: 16px;
    }
    .fab-menu .fab-menu-icon svg {
        width: 24px; height: 24px;
    }
    .fab-menu .fab-menu-text {
        margin-left: 16px;
    }
    .fab-menu .fab-menu-title {
        font-size: 18px;
    }
    .fab-menu .fab-menu-subtitle {
        font-size: 14px;
    }

    /* Keep stats grid internal layout */
    .stats-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
}

/* --- Accessibility Improvements --- */
.close-btn {
    background: transparent;
    border: none;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 4px;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.close-btn:focus {
    color: var(--danger);
    outline: none;
}
.close-btn:focus-visible {
    outline: 2px solid var(--danger);
    border-radius: 4px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* --- Validation Feedback --- */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}
.input-error {
    border-color: var(--danger) !important;
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
    background-color: rgba(239, 68, 68, 0.05) !important;
}

/* --- Super Admin Zone --- */
.super-admin-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}
.super-admin-group:last-child {
    margin-bottom: 0;
}

.super-admin-group-title {
    font-weight: 800;
    font-size: 1.05rem;
    color: var(--text);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.super-admin-group-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 15px;
    line-height: 1.4;
}

.super-admin-input {
    border-color: rgba(239, 68, 68, 0.3);
}
.super-admin-input:focus {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.super-admin-btn {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
    font-weight: 700;
}

/* --- User View UI Improvements --- */
.user-hero-status {
    background: var(--surface);
    border-radius: 20px;
    padding: 25px 20px;
    text-align: center;
    margin-bottom: 20px;
    border: 2px solid transparent;
    box-shadow: var(--shadow);
}

.user-info-boxes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}
.user-info-box {
    background: var(--surface);
    border-radius: 16px;
    padding: 15px;
    text-align: center;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100px;
}
.user-info-box-label {
    font-size: clamp(0.7rem, 3vw, 0.85rem);
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    word-wrap: break-word;
}
.user-info-box-value {
    font-size: clamp(0.9rem, 4vw, 1.2rem);
    font-weight: 800;
    color: var(--text);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}
.user-status-overdue {
    background: rgba(239, 68, 68, 0.05);
    border-color: rgba(239, 68, 68, 0.2);
}
.user-status-soon {
    background: rgba(245, 158, 11, 0.05);
    border-color: rgba(245, 158, 11, 0.2);
}
.user-status-ok {
    background: rgba(16, 185, 129, 0.05);
    border-color: rgba(16, 185, 129, 0.2);
}

.user-quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.user-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 18px 10px;
    gap: 8px;
    height: 100%;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(0,0,0,0.05));
}
.user-action-btn:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: var(--shadow);
}
.user-action-btn:active {
    transform: scale(0.96);
}
.user-action-icon svg {
    width: 30px;
    height: 30px;
    stroke: var(--primary);
    transition: 0.2s;
}

.user-action-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
}

.user-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 25px;
}
.user-info-box {
    background: var(--surface);
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.user-info-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 700;
    margin-bottom: 8px;
}
.user-info-value {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 5px;
    color: var(--text);
}
.user-info-sub {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.user-details-box {
    background: var(--surface);
    border-radius: 15px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 25px;
}
.user-details-summary {
    padding: 18px 20px;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
}
.user-details-content {
    padding: 15px;
    background: var(--surface);
}

.user-request-item {
    background: var(--surface);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

@media all and (display-mode: standalone) {
    #install-pwa-btn {
        display: none !important;
    }
}

/* Toast Notification */
.toast {
    position: fixed; top: 20px; right: 20px; z-index: 10001;
    background: var(--surface); color: var(--text);
    padding: 12px 20px; border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15); border: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px; font-weight: 600;
    max-width: 350px;
    transform: translateX(30px) scale(0.95); opacity: 0; pointer-events: none;
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    will-change: transform, opacity;
}
.toast.show { transform: translateX(0) scale(1); opacity: 1; pointer-events: all; }
.toast-success { border-left: 5px solid var(--success); }
.toast-error { border-left: 5px solid var(--danger); }

@media (max-width: 768px) {
    /* Increase spacing for mobile views */
    .hero-card {
        margin-bottom: 25px;
    }
}

/* Password Toggle */
.password-wrapper { position: relative; }
.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}
.form-input.has-toggle { padding-right: 40px; }

/* --- AI Chat --- */

.ai-chat-layout {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.ai-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 0 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-chat-header-styled {
    background: transparent;
    border-bottom: none;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1rem;
    flex-shrink: 0;
    padding: 15px 20px;
}

.ai-chat-input-styled {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 15px 20px;
    flex-shrink: 0;
    margin-top: 8px;
}

.ai-chat-textarea-styled {
    margin-bottom: 0;
    border-radius: 999px;
    min-height: 46px;
    padding: 11px 16px;
}

.ai-chat-send-btn-styled {
    width: 46px;
    height: 46px;
    min-width: 46px;
    border-radius: 999px;
}

.ai-chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    padding: 40px 20px;
    gap: 12px;
    color: var(--text-secondary);
}

.ai-chat-welcome-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(6,182,212,0.15) 0%, rgba(16,185,129,0.15) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

.ai-chat-welcome-text {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}

.ai-chat-welcome-sub {
    font-size: 0.9rem;
    max-width: 280px;
    line-height: 1.5;
}

.ai-chat-bubble {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.55;
    word-wrap: break-word;
}

.ai-chat-bubble-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #06b6d4 0%, #10b981 100%);
    color: white;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.ai-chat-bubble-assistant {
    align-self: flex-start;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-light);
    border-bottom-left-radius: 4px;
}

.ai-chat-bubble-error {
    align-self: flex-start;
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-bottom-left-radius: 4px;
}

/* Typing indicator */
.ai-chat-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    background: var(--surface-alt);
    border: 1px solid var(--border-light);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
}

.ai-chat-typing span {
    width: 7px;
    height: 7px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: ai-typing-bounce 1.2s infinite ease-in-out;
}

.ai-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-typing-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.ai-chat-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    overflow-y: auto;
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.4;
    font-size: 0.95rem;
    margin-bottom: 0;
}

.ai-chat-send-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 14px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

@media (max-width: 767px) {
    #ai-chat.active {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        padding-bottom: 0;
    }

    #ai-chat .ai-chat-header-styled {
        padding: 10px 0 12px;
    }

    #ai-chat .ai-chat-messages {
        padding-left: 0;
        padding-right: 0;
        padding-bottom: calc(var(--mobile-ai-chat-input-height) + var(--mobile-bottom-nav-offset));
    }

    #ai-chat .ai-chat-input-styled {
        position: fixed;
        left: 0;
        right: 0;
        bottom: var(--mobile-bottom-nav-offset);
        z-index: 1001;
        margin: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        border-radius: 18px 18px 0 0;
        box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.08);
        background: var(--surface);
    }
}

@media (min-width: 768px) {
    #ai-chat {
        max-width: 800px;
        margin: 0 auto;
        padding-bottom: 100px;
    }

    #ai-chat .ai-chat-input-styled {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 40px);
        max-width: 800px;
        z-index: 1001;
        box-shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    }
}

/* Thinking / reasoning dropdown */
.ai-thinking {
    margin-bottom: 10px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    overflow: hidden;
}

.ai-thinking-summary {
    padding: 6px 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    background: var(--surface);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-thinking-summary::-webkit-details-marker { display: none; }

.ai-thinking-summary::before {
    content: '▶';
    font-size: 0.65rem;
    transition: transform 0.15s;
}

details[open] .ai-thinking-summary::before {
    transform: rotate(90deg);
}

.ai-thinking-content {
    margin: 0;
    padding: 10px 12px;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
    background: var(--surface-alt);
    white-space: pre-wrap;
    word-wrap: break-word;
    border-top: 1px solid var(--border-light);
}

/* Markdown styles inside assistant bubbles */
.ai-chat-bubble-assistant p {
    margin: 0 0 8px;
}
.ai-chat-bubble-assistant p:last-child { margin-bottom: 0; }

.ai-chat-bubble-assistant h1,
.ai-chat-bubble-assistant h2,
.ai-chat-bubble-assistant h3,
.ai-chat-bubble-assistant h4,
.ai-chat-bubble-assistant h5,
.ai-chat-bubble-assistant h6 {
    margin: 10px 0 4px;
    font-weight: 700;
    line-height: 1.3;
}
.ai-chat-bubble-assistant h1 { font-size: 1.15rem; }
.ai-chat-bubble-assistant h2 { font-size: 1.05rem; }
.ai-chat-bubble-assistant h3 { font-size: 0.98rem; }
.ai-chat-bubble-assistant h4,
.ai-chat-bubble-assistant h5,
.ai-chat-bubble-assistant h6 { font-size: 0.9rem; }

.ai-chat-bubble-assistant blockquote {
    border-left: 3px solid var(--primary);
    margin: 8px 0;
    padding: 6px 12px;
    background: rgba(14, 165, 233, 0.08);
    border-radius: 0 8px 8px 0;
    color: var(--text-secondary);
}
.ai-chat-bubble-assistant blockquote p {
    margin: 4px 0;
}
.ai-chat-bubble-assistant blockquote p:first-child { margin-top: 0; }
.ai-chat-bubble-assistant blockquote p:last-child { margin-bottom: 0; }

.ai-chat-bubble-assistant a {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.ai-chat-bubble-assistant a:hover {
    opacity: 0.85;
}

.ai-chat-bubble-assistant ul,
.ai-chat-bubble-assistant ol {
    margin: 6px 0;
    padding-left: 20px;
}
.ai-chat-bubble-assistant li { margin: 2px 0; }

.ai-chat-bubble-assistant hr {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 10px 0;
}

.ai-table-wrapper {
    overflow-x: auto;
    margin: 10px 0;
}

.ai-chat-bubble-assistant table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.ai-chat-bubble-assistant th,
.ai-chat-bubble-assistant td {
    padding: 8px 12px;
    border: 1px solid var(--border-light);
}

.ai-chat-bubble-assistant th {
    background: var(--surface-alt);
    font-weight: 600;
}

.ai-code-block {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 10px 12px;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 6px 0;
    white-space: pre;
}

.ai-inline-code {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.875em;
    font-family: monospace;
}

/* AI Math Formatting */
.ai-math-display {
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: auto;
    padding: 10px 14px;
    margin: 8px 0;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: 'Cambria Math', 'STIX Two Math', 'Latin Modern Math', 'Times New Roman', Georgia, serif;
    font-size: 1.1rem;
    color: var(--text);
    line-height: 1.4;
}

.ai-math-inline {
    display: inline-flex;
    align-items: baseline;
    font-family: 'Cambria Math', 'STIX Two Math', 'Latin Modern Math', 'Times New Roman', Georgia, serif;
    font-size: 1.05em;
    padding: 0 2px;
    color: var(--text);
    line-height: 1.2;
}

.ai-math-frac {
    display: inline-flex;
    flex-direction: column;
    vertical-align: -0.55em;
    text-align: center;
    padding: 0 3px;
    font-size: 0.88em;
    line-height: 1.1;
}

.ai-math-num {
    border-bottom: 1.5px solid currentColor;
    padding: 0 2px 1px 2px;
    display: block;
}

.ai-math-den {
    padding: 1px 2px 0 2px;
    display: block;
}

.ai-math-sqrt {
    display: inline-flex;
    align-items: center;
    vertical-align: baseline;
}

.ai-math-root-deg {
    font-size: 0.65em;
    margin-right: -2px;
    margin-bottom: 4px;
}

.ai-math-sqrt-rad {
    font-size: 1.1em;
    margin-right: 1px;
}

.ai-math-sqrt-stem {
    border-top: 1.5px solid currentColor;
    padding: 0 3px;
    display: inline-block;
}

.ai-math-text {
    font-family: var(--font-family, system-ui, -apple-system, sans-serif);
    font-style: normal;
}

.ai-math-sup {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 0;
}

.ai-math-sub {
    font-size: 0.75em;
    vertical-align: sub;
    line-height: 0;
}

/* --- Login UI Beautification --- */
.login-header {
    text-align: center;
    margin-bottom: 24px;
    padding-top: 10px;
}
.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}
.login-brand img {
    height: 40px;
    width: auto;
}
.login-brand h2 {
    font-size: 2rem;
    font-weight: 800;
    margin: 0;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.login-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 500;
}
.auth-tabs {
    display: flex;
    background: var(--surface-alt);
    padding: 4px;
    border-radius: 16px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
}
.auth-tab-btn {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    border-radius: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.auth-tab-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}
.input-with-icon {
    position: relative;
}
.input-with-icon .input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transition: color 0.2s ease;
    z-index: 2;
}
.input-with-icon .form-input {
    padding-left: 44px;
}
.input-with-icon:focus-within .input-icon {
    color: var(--primary);
}

/* --- Search Bar Overrides --- */
.search-bar-wrapper {
    margin-bottom: 12px;
}
.search-bar-wrapper .form-input.search-input {
    background: var(--surface-alt);
    border: none;
    border-radius: 14px;
    padding: 12px 12px 12px 42px;
    font-size: 1rem;
    color: var(--text);
    box-shadow: none;
}
.search-bar-wrapper .form-input.search-input:focus {
    background: var(--surface-alt);
    outline: none;
    box-shadow: inset 0 0 0 1px var(--primary);
}
.search-bar-wrapper .input-icon {
    left: 14px;
    color: var(--text-secondary);
}
.search-bar-wrapper .input-icon svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
}

/* Profile picture */
.profile-pic-section {
    display: flex;
    align-items: center;
    gap: 20px;
}
.profile-pic-preview-wrap {
    flex-shrink: 0;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--surface-alt);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}
.profile-pic-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.profile-pic-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    width: 100%;
    height: 100%;
}
.header-profile-pic {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Profile crop modal */
.profile-crop-container {
    margin-top: 12px;
}
.profile-crop-viewport {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: #111;
    border-radius: 10px;
    user-select: none;
}
.profile-crop-viewport img {
    pointer-events: none;
    display: block;
}
.profile-crop-overlay {
    position: absolute;
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.55);
    cursor: move;
    touch-action: none;
}

/* AI Chat specific slide animations to prevent position: fixed bug */
#ai-chat.tab-content.slide-in-right { animation: none; }
#ai-chat.tab-content.slide-in-left { animation: none; }

#ai-chat.tab-content.slide-in-right .ai-chat-header-styled,
#ai-chat.tab-content.slide-in-right .ai-chat-messages {
    animation: slideInRight 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

#ai-chat.tab-content.slide-in-left .ai-chat-header-styled,
#ai-chat.tab-content.slide-in-left .ai-chat-messages {
    animation: slideInLeft 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

#ai-chat.tab-content.slide-in-right .ai-chat-input-styled,
#ai-chat.tab-content.slide-in-left .ai-chat-input-styled {
    animation: aiChatFadeIn 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

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

/* --- Premium Invite Card Styling --- */
.premium-invite-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .premium-invite-card {
    /* Glassmorphism accent border/background for premium feel */
    background: linear-gradient(145deg, var(--surface) 0%, rgba(30, 41, 59, 0.8) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.premium-invite-header {
    padding: 24px 24px 12px;
    border-bottom: none;
}

.premium-invite-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.02em;
}

.premium-invite-icon {
    color: var(--text-secondary);
    opacity: 0.85;
}

.premium-invite-body {
    padding: 0 24px 24px;
}

.premium-invite-desc {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.premium-invite-display-container {
    background: var(--surface-alt);
    border: 1.5px dashed var(--border);
    border-radius: 14px;
    padding: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    transition: all 0.3s ease;
}

[data-theme="dark"] .premium-invite-display-container {
    background: rgba(15, 23, 42, 0.4);
    border-color: rgba(255, 255, 255, 0.12);
}

.premium-invite-display-container:hover {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.05);
}

.premium-invite-code-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.premium-invite-code-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    opacity: 0.8;
}

.premium-invite-code-value {
    font-family: 'Courier New', Courier, monospace;
    font-weight: 800;
    font-size: 1.85rem;
    letter-spacing: 0.08em;
    color: var(--text);
    user-select: all;
    display: inline-block;
    line-height: 1.2;
}

.premium-invite-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-premium-action {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.88rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    box-shadow: var(--shadow);
}

[data-theme="dark"] .btn-premium-action {
    background: rgba(30, 41, 59, 0.6);
    border-color: rgba(255, 255, 255, 0.1);
}

.btn-premium-action:hover {
    border-color: var(--primary);
    background: var(--surface-alt);
    color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
}

.btn-premium-action:active {
    transform: translateY(0);
}

.btn-premium-action svg {
    transition: transform 0.2s ease;
}

.btn-premium-action:hover svg {
    transform: scale(1.08);
}

/* --- EXPORT REPORT MODAL & PRINT PREVIEW --- */
.report-modal-content {
    max-width: 1200px !important;
    width: 85vw !important;
    height: 85vh !important;
    max-height: 85vh !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 0 !important;
}

.report-modal-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: var(--bg);
}

.report-config-panel {
    flex: 0 0 320px;
    padding: 20px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
    background: var(--surface);
}

.report-preview-viewport {
    flex: 1;
    background: var(--bg);
    overflow-y: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: hidden;
}

.report-preview-scale-container {
    width: calc(794px * var(--preview-scale, 1));
    height: calc(var(--preview-height, 1120px) * var(--preview-scale, 1));
    overflow: hidden;
    flex-shrink: 0;
    transition: width 0.15s ease, height 0.15s ease;
}

.report-print-preview-wrapper {
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    background: white;
    border-radius: 4px;
    width: 794px;
    min-width: 794px;
    transform: scale(var(--preview-scale, 1));
    transform-origin: top left;
    transition: transform 0.15s ease;
}

/* Print Preview Canvas - Strict Light Theme Layout */
.print-preview-canvas {
    background: #ffffff !important;
    color: #2d3748 !important;
    padding: 40px !important;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    font-size: 14px !important;
    box-sizing: border-box !important;
    line-height: 1.5 !important;
    min-height: 1120px;
}

.print-preview-canvas h1,
.print-preview-canvas h2,
.print-preview-canvas h3,
.print-preview-canvas h4 {
    color: #1a202c !important;
    margin: 0 0 10px 0 !important;
    font-weight: 700 !important;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 20px;
    margin-bottom: 25px;
}

.preview-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 800;
    color: #1e3a8a !important;
}

.preview-meta {
    text-align: right;
    font-size: 0.85rem;
    color: #718096 !important;
}

.preview-title-block {
    margin-bottom: 25px;
}

.preview-title-block h2 {
    font-size: 1.6rem !important;
    color: #1e3a8a !important;
    border: none !important;
    margin: 0 !important;
}

.preview-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 30px;
}

.preview-stat-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    break-inside: avoid;
    page-break-inside: avoid;
}

.preview-stat-label {
    font-size: 0.8rem;
    color: #718096;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 5px;
}

.preview-stat-value {
    font-size: 1.4rem;
    font-weight: 800;
}

.preview-stat-value.income { color: #10b981 !important; }
.preview-stat-value.expense { color: #ef4444 !important; }
.preview-stat-value.balance { color: #1e3a8a !important; }

.preview-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.preview-table th {
    background: #f1f5f9;
    border-bottom: 2px solid #cbd5e1;
    color: #475569;
    text-align: left;
    padding: 10px 12px;
    font-size: 0.85rem;
    font-weight: 700;
}

.preview-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.85rem;
    vertical-align: top;
    color: #334155;
}

.preview-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
}

.preview-table tr:nth-child(even) {
    background: #f8fafc;
}

.preview-table .amount-cell {
    text-align: right;
    font-weight: 700;
    white-space: nowrap;
}

.preview-table .amount-income { color: #059669 !important; }
.preview-table .amount-expense { color: #dc2626 !important; }

.preview-detail-row {
    font-size: 0.8rem !important;
    color: #64748b !important;
    background: #f8fafc;
}

.preview-detail-row td {
    padding-top: 4px !important;
    padding-bottom: 8px !important;
    border-bottom: 1px solid #e2e8f0;
}

.preview-notes {
    font-style: italic;
    margin-bottom: 4px;
}

.preview-tags-badge {
    background: #e0f2fe;
    color: #0369a1;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    display: inline-block;
    margin-right: 5px;
}

.preview-attachment-indicator {
    color: #0d9488;
    font-weight: 600;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.report-checklist-scroll {
    border: 1px solid var(--border);
    background: var(--surface-alt);
    border-radius: 12px;
    max-height: 250px;
    overflow-y: auto;
    padding: 10px;
}

.report-checklist-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
}

.report-checklist-item:last-child {
    border-bottom: none;
}

.report-checklist-item input[type="checkbox"] {
    margin-top: 3px;
    cursor: pointer;
}

.report-checklist-info {
    display: flex;
    flex-direction: column;
}

.report-checklist-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.report-placeholder-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    color: #94a3b8;
    text-align: center;
    padding: 40px;
}

.report-placeholder-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

/* Responsive modal styling for mobile viewports */
@media (max-width: 768px) {
    .report-modal-content {
        width: 95vw !important;
        height: 95vh !important;
        max-height: 95vh !important;
    }
    .report-modal-body {
        flex-direction: column;
        overflow-y: auto;
    }
    .report-config-panel {
        border-right: none !important;
        border-bottom: 1px solid var(--border);
        flex: 0 0 auto !important;
    }
    .report-preview-viewport {
        overflow: visible !important;
        padding: 15px !important;
    }
}

