:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --primary-color: #bb86fc;
    --secondary-color: #03dac6;
    --error-color: #cf6679;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border-color: #333333;
    --font-family: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Auth Screen */
.screen {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    background-color: var(--bg-color);
}

.screen.active {
    display: flex;
    flex-direction: column;
}

#app-screen {
    flex-direction: row;
}

@media (max-width: 768px) {
    #app-screen {
        flex-direction: column;
    }
}

.auth-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 40px;
}

.logo-icon {
    font-size: 64px;
    margin-bottom: 10px;
}

.auth-card {
    background-color: var(--surface-color);
    padding: 30px;
    border-radius: 16px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.auth-steps {
    margin-top: 20px;
}

.step {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    color: var(--text-secondary);
}

.step-num {
    background-color: var(--primary-color);
    color: #000;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-right: 15px;
    flex-shrink: 0;
}

/* Sidebar */
#sidebar {
    width: 250px;
    background-color: var(--surface-color);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.logo-small {
    font-size: 24px;
    margin-right: 10px;
}

.logo-text {
    font-size: 20px;
    font-weight: bold;
    flex-grow: 1;
}

.nav-links {
    list-style: none;
    padding: 20px 0;
    flex-grow: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.nav-link:hover,
.nav-link.active {
    background-color: rgba(187, 134, 252, 0.1);
    color: var(--primary-color);
    border-left: 3px solid var(--primary-color);
}

.nav-icon {
    margin-right: 15px;
    font-size: 18px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.user-info {
    margin-bottom: 10px;
}

.user-name {
    display: block;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.role-badge {
    font-size: 12px;
    background-color: var(--secondary-color);
    color: #000;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Main Content */
#content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 30px;
}

.page {
    display: none;
    animation: fadeIn 0.3s;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

h2 {
    font-size: 28px;
    font-weight: 600;
}

.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #000;
}

.btn-block {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px;
    font-size: 16px;
}

.btn-text {
    background: none;
    border: none;
    color: var(--error-color);
    cursor: pointer;
    font-size: 14px;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 20px;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background-color: var(--surface-color);
    padding: 20px;
    border-radius: 12px;
}

.stat-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 24px;
    font-weight: bold;
}

.balance .stat-value {
    color: var(--primary-color);
}

.income .stat-value {
    color: var(--secondary-color);
}

.expense .stat-value {
    color: var(--error-color);
}

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.card {
    background-color: var(--surface-color);
    padding: 20px;
    border-radius: 12px;
}

.card h3 {
    margin-bottom: 20px;
    font-size: 18px;
}

.categories-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.category-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.recent-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.check-link {
    color: var(--secondary-color);
    text-decoration: none;
    margin-left: 10px;
    font-size: 12px;
    cursor: pointer;
}

/* Tables & Forms */
.filters-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.input {
    background-color: #2c2c2c;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px;
    border-radius: 8px;
    font-family: inherit;
    width: 100%;
}

.table-container {
    background-color: var(--surface-color);
    border-radius: 12px;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.data-table th,
.data-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    color: var(--text-secondary);
    font-weight: 500;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.text-expense {
    color: var(--error-color);
}

.text-income {
    color: var(--secondary-color);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background-color: var(--surface-color);
    width: 100%;
    max-width: 500px;
    border-radius: 16px;
    overflow: hidden;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

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

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

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 14px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.photo-preview {
    margin-top: 10px;
    max-height: 150px;
    overflow: hidden;
    border-radius: 8px;
}

.photo-preview img {
    max-width: 100%;
}

.photo-viewer {
    max-width: 90%;
    max-height: 90%;
    position: relative;
}

.photo-viewer img {
    max-width: 100%;
    max-height: 100vh;
    object-fit: contain;
}

.photo-close {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
    font-size: 30px;
}

/* Responsive Utility */
.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }

    /* Mobile Top Bar */
    #mobile-top-bar.mobile-only {
        display: flex !important;
        background-color: var(--surface-color);
        padding: 10px 20px;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid var(--border-color);
        position: sticky;
        top: 0;
        z-index: 30;
        height: 60px;
    }
}

.mobile-user-icon {
    font-size: 20px;
}

/* Toggle Group for Radio */
.toggle-group {
    display: flex;
    background-color: #2c2c2c;
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
}

.toggle-group input[type="radio"] {
    display: none;
}

.toggle-group label {
    flex: 1;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 0 !important;
    transition: background 0.2s, color 0.2s;
    color: var(--text-secondary);
}

.toggle-group input[type="radio"]:checked+label {
    background-color: var(--primary-color);
    color: #000;
}

/* Updated Mobile Sidebar */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%);
        z-index: 100;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }

    #sidebar.open {
        transform: translateX(0);
    }

    .mobile-sidebar-header {
        padding: 20px;
        display: flex;
        align-items: center;
        border-bottom: 1px solid var(--border-color);
        justify-content: space-between;
    }

    #content {
        height: calc(100vh - 50px);
    }

    .full-width-mobile {
        grid-column: 1 / -1;
    }

    .data-table th:nth-child(4),
    .data-table td:nth-child(4) {
        display: none;
        /* Hide description on mobile to save space */
    }
}
/* Action buttons in table */
.btn-action {
    padding: 4px 10px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    transition: opacity 0.2s;
}
.btn-action:hover { opacity: 0.8; }
.btn-edit {
    background-color: var(--primary-color);
    color: #000;
}
.btn-delete {
    background-color: var(--error-color);
    color: #fff;
}
.btn:disabled, .btn-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* User dropdown */
.mobile-user-icon {
    position: relative;
    cursor: pointer;
}
.user-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 18px;
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 200;
}
.user-dropdown.open { display: block; }
.dropdown-name {
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
}
.dropdown-role {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Fix mobile horizontal scroll on modal */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}
.modal-overlay {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}
.modal {
    max-width: min(500px, calc(100vw - 40px));
    margin: auto;
    flex-shrink: 0;
}
.modal-body {
    overflow-x: hidden;
    overscroll-behavior: contain;
}
.modal-body .input,
.modal-body textarea,
.modal-body select {
    max-width: 100%;
    box-sizing: border-box;
}
.toggle-group {
    max-width: 100%;
    overflow: hidden;
}

/* ===== New Dashboard ===== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
@media (max-width: 900px) { .stats-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .stats-row { grid-template-columns: 1fr; gap: 10px; } }

.stat-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    border-radius: 14px;
    transition: transform 0.15s;
}
.stat-card:hover { transform: translateY(-2px); }

.stat-balance { background: linear-gradient(135deg, #7c3aed 0%, #a855f7 100%); }
.stat-income  { background: linear-gradient(135deg, #059669 0%, #10b981 100%); }
.stat-expense { background: linear-gradient(135deg, #dc2626 0%, #f87171 100%); }
.stat-users   { background: linear-gradient(135deg, #2563eb 0%, #60a5fa 100%); }

.stat-icon {
    font-size: 28px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.15);
    border-radius: 12px;
    flex-shrink: 0;
}
.stat-body { min-width: 0; }
.stat-card .stat-label {
    font-size: 13px;
    color: rgba(255,255,255,0.75);
    margin-bottom: 2px;
}
.stat-card .stat-value {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Dashboard rows */
.dash-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
@media (max-width: 768px) { .dash-row { grid-template-columns: 1fr; } }

.card-header {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Collection progress bars */
.coll-item {
    margin-bottom: 14px;
}
.coll-item:last-child { margin-bottom: 0; }
.coll-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 14px;
}
.coll-name { font-weight: 500; }
.coll-amount { font-weight: 600; color: var(--secondary-color); }
.coll-bar {
    height: 8px;
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
    overflow: hidden;
}
.coll-bar-fill {
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--secondary-color), #34d399);
    transition: width 0.6s ease;
}
.coll-bar-fill.negative {
    background: linear-gradient(90deg, #f87171, #dc2626);
}

/* Expense donut / bars */
.expense-bar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.expense-bar-item:last-child { margin-bottom: 0; }
.expense-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.expense-label { flex: 1; font-size: 14px; }
.expense-amount { font-weight: 600; font-size: 14px; color: var(--error-color); }
.expense-pct {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 36px;
    text-align: right;
}
.expense-visual {
    margin-top: 16px;
    display: flex;
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    gap: 2px;
}
.expense-visual-seg {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
}

/* Recent transactions cards */
.tx-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(255,255,255,0.03);
    margin-bottom: 8px;
    border-left: 3px solid transparent;
    transition: background 0.15s;
}
.tx-card:hover { background: rgba(255,255,255,0.06); }
.tx-card:last-child { margin-bottom: 0; }
.tx-card.tx-income { border-left-color: var(--secondary-color); }
.tx-card.tx-expense { border-left-color: var(--error-color); }

.tx-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.tx-income .tx-card-icon { background: rgba(16,185,129,0.15); color: var(--secondary-color); }
.tx-expense .tx-card-icon { background: rgba(248,113,113,0.15); color: var(--error-color); }

.tx-card-info { flex: 1; min-width: 0; }
.tx-card-title {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tx-card-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}
.tx-card-amount {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
}
.dash-empty {
    color: var(--text-secondary);
    font-size: 14px;
    padding: 20px 0;
    text-align: center;
}

/* ===== Dashboard v2 ===== */
.hero-balance {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    border-radius: 20px;
    padding: 32px 36px;
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}
.hero-balance::before {
    content: '';
    position: absolute;
    top: -40%;
    right: -10%;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(187,134,252,0.12) 0%, transparent 70%);
    border-radius: 50%;
}
.hero-balance-inner { position: relative; z-index: 1; }
.hero-label {
    font-size: 14px;
    color: rgba(255,255,255,0.5);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}
.hero-amount {
    font-size: 42px;
    font-weight: 800;
    background: linear-gradient(135deg, #bb86fc, #60a5fa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 20px;
    line-height: 1.1;
}
@media (max-width: 480px) {
    .hero-balance { padding: 24px 20px; }
    .hero-amount { font-size: 32px; }
}

/* Ratio bar */
.ratio-bar {
    height: 10px;
    border-radius: 5px;
    display: flex;
    overflow: hidden;
    gap: 3px;
    margin-bottom: 12px;
    background: rgba(255,255,255,0.06);
}
.ratio-seg {
    height: 100%;
    border-radius: 5px;
    transition: width 0.8s ease;
}
.ratio-seg-income { background: linear-gradient(90deg, #10b981, #34d399); }
.ratio-seg-expense { background: linear-gradient(90deg, #f87171, #ef4444); }

.ratio-legend {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}
.ratio-leg-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: rgba(255,255,255,0.6);
}
.ratio-leg-item b { color: #fff; font-weight: 600; }
.leg-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.leg-income .leg-dot { background: #10b981; }
.leg-expense .leg-dot { background: #f87171; }

/* Donut chart */
.donut-section {
    display: flex;
    align-items: center;
    gap: 24px;
}
@media (max-width: 480px) {
    .donut-section { flex-direction: column; }
}
.donut {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
    transition: background 0.6s;
}
.donut::after {
    content: '';
    position: absolute;
    top: 30px;
    left: 30px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--surface-color);
}
.donut-center {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1;
    font-size: 13px;
    color: var(--text-secondary);
}
.donut-center b {
    font-size: 18px;
    color: var(--text-primary);
    display: block;
}
.donut-legend { flex: 1; min-width: 0; }
.donut-leg-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    font-size: 14px;
}
.donut-leg-color {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}
.donut-leg-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.donut-leg-val {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

/* Collection details */
.coll-clickable { cursor: pointer; transition: background 0.15s; padding: 10px; border-radius: 8px; margin: -10px; margin-bottom: 6px; }
.coll-clickable:hover { background: rgba(255,255,255,0.04); }
.coll-details { display: flex; gap: 16px; margin-bottom: 6px; font-size: 13px; }
.cd-income { color: var(--secondary-color); }
.cd-expense { color: var(--error-color); }
.coll-bar { position: relative; }
.coll-bar-spent {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(248,113,113,0.4), rgba(220,38,38,0.4));
}
.coll-amount.negative { color: var(--error-color); }

/* Category chips */
.cat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.cat-chip {
    padding: 7px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}
.cat-chip:hover {
    border-color: var(--primary-color);
    color: var(--text-primary);
}
.cat-chip.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #000;
    font-weight: 500;
}
