/* =============================================
   家庭财务管家 - CSS Design System
   ============================================= */

:root {
    /* Color Palette */
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #1e2130;
    --bg-card-hover: #252840;
    --border-color: rgba(255, 255, 255, 0.07);
    --border-active: rgba(99, 102, 241, 0.5);

    /* Brand Colors */
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-dark: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.25);

    /* Semantic Colors */
    --income-color: #10b981;
    --income-bg: rgba(16, 185, 129, 0.1);
    --expense-color: #f43f5e;
    --expense-bg: rgba(244, 63, 94, 0.1);
    --warning-color: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --info-color: #3b82f6;

    /* Text */
    --text-primary: #e8eaf0;
    --text-secondary: #9298b0;
    --text-muted: #5c6280;

    /* Layout */
    --sidebar-width: 240px;
    --sidebar-collapsed: 70px;
    --topbar-height: 72px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --glow: 0 0 30px var(--accent-glow);
}

/* ============ RESET & BASE ============ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    overflow: hidden;
}

/* ============ LAYOUT ============ */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    overflow: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 16px;
    min-height: var(--topbar-height);
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.logo-icon {
    font-size: 24px;
    flex-shrink: 0;
    filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.6));
}

.logo-text {
    font-size: 15px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-light), #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
    transition: opacity 0.2s;
}

.sidebar.collapsed .logo-text {
    opacity: 0;
}

.sidebar.collapsed .nav-label {
    opacity: 0;
}

.sidebar.collapsed .sidebar-footer {
    opacity: 0;
}

.nav-menu {
    list-style: none;
    padding: 12px 8px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-card-hover);
    color: var(--accent-light);
}

.nav-item.active {
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    color: white;
    box-shadow: var(--glow);
}

.nav-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.nav-label {
    font-size: 13.5px;
    font-weight: 500;
    transition: opacity 0.2s;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    transition: opacity 0.2s;
}

.main-content {
    margin-left: var(--sidebar-width);
    height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.main-content.sidebar-collapsed {
    margin-left: var(--sidebar-collapsed);
}

/* ============ TOPBAR ============ */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    height: var(--topbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.breadcrumb {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.month-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 6px 12px;
}

.current-month {
    font-size: 13px;
    font-weight: 600;
    min-width: 80px;
    text-align: center;
    color: var(--text-primary);
}

/* ============ PAGES ============ */
.page {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============ CARDS ============ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: border-color 0.2s;
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.12);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============ SUMMARY CARDS ============ */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.summary-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    opacity: 0.05;
    transform: translate(30%, -30%);
}

.income-card::before {
    background: var(--income-color);
}

.expense-card::before {
    background: var(--expense-color);
}

.balance-card::before {
    background: var(--accent);
}

.total-card::before {
    background: var(--warning-color);
}

.summary-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card-icon {
    font-size: 28px;
}

.card-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-value {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.income-card .card-value {
    color: var(--income-color);
}

.expense-card .card-value {
    color: var(--expense-color);
}

.balance-card .card-value {
    color: var(--accent-light);
}

.total-card .card-value {
    color: var(--warning-color);
}

.card-trend {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ============ GRID LAYOUTS ============ */
.dashboard-grid {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 16px;
    margin-bottom: 20px;
}

.chart-card {
    padding: 20px;
}

.chart-card-full {
    padding: 20px;
    width: 100%;
}

.chart-container {
    position: relative;
    height: 220px;
}

.chart-container-lg {
    position: relative;
    height: 320px;
}

/* ============ RECENT RECORDS ============ */
.recent-records-card {
    margin-bottom: 8px;
}

.record-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    animation: slideIn 0.3s ease;
    gap: 12px;
}

.record-item:last-child {
    border-bottom: none;
}

.record-category-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.record-info {
    flex: 1;
    min-width: 0;
}

.record-desc {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.record-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.record-amount {
    font-size: 15px;
    font-weight: 700;
    flex-shrink: 0;
}

.record-amount.income {
    color: var(--income-color);
}

.record-amount.expense {
    color: var(--expense-color);
}

/* ============ RECORDS PAGE ============ */
.records-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.records-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.records-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.records-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.records-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.records-table tbody tr:last-child td {
    border-bottom: none;
}

.type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
}

.type-badge.income {
    background: var(--income-bg);
    color: var(--income-color);
}

.type-badge.expense {
    background: var(--expense-bg);
    color: var(--expense-color);
}

.category-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 5px;
    font-size: 11px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
}

/* ============ CHARTS PAGE ============ */
.chart-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: var(--bg-card);
    padding: 6px;
    border-radius: var(--radius-md);
    width: fit-content;
    border: 1px solid var(--border-color);
}

.chart-tab {
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.chart-tab.active {
    background: var(--accent);
    color: white;
    box-shadow: var(--glow);
}

.chart-panel {
    display: none;
}

.chart-panel.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.pie-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ============ AI ANALYSIS PAGE ============ */
.ai-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    align-items: start;
}

.ai-config-panel {
    position: sticky;
    top: 0;
}

.ai-result-panel {
    min-width: 0;
}

.ai-welcome {
    text-align: center;
    padding: 40px 20px;
}

.ai-avatar {
    font-size: 56px;
    margin-bottom: 16px;
    filter: drop-shadow(0 0 20px rgba(99, 102, 241, 0.5));
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

.ai-welcome h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--accent-light), #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.ai-welcome p {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.7;
    margin-bottom: 20px;
}

.ai-features {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.feature-tag {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* AI Loading */
.ai-loading {
    text-align: center;
    padding: 48px 20px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 24px;
    text-align: left;
    max-width: 260px;
    margin-left: auto;
    margin-right: auto;
}

.loading-step {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    transition: all 0.3s;
}

.loading-step.active {
    color: var(--accent-light);
    border-color: var(--accent);
    background: var(--accent-glow);
}

.loading-step.done {
    color: var(--income-color);
    border-color: rgba(16, 185, 129, 0.3);
}

/* AI Report */
.report-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.report-title {
    font-size: 22px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-light), #c084fc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.report-date {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.health-score-badge {
    text-align: center;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--accent);
    background: var(--accent-glow);
    box-shadow: var(--glow);
    flex-shrink: 0;
}

.score-number {
    font-size: 24px;
    font-weight: 800;
    color: var(--accent-light);
    line-height: 1;
}

.score-label {
    font-size: 9px;
    color: var(--text-muted);
    text-align: center;
}

.ai-report-content {
    font-size: 13.5px;
    line-height: 1.8;
    color: var(--text-secondary);
    white-space: pre-wrap;
    min-height: 100px;
}

.ai-report-content h2,
.ai-report-content h3 {
    color: var(--text-primary);
    margin: 16px 0 8px;
}

.ai-report-content strong {
    color: var(--accent-light);
}

.report-charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.report-charts-grid .chart-card-full {
    grid-column: 1 / -1;
}

.score-cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-top: 16px;
}

.score-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
    transition: transform 0.2s;
}

.score-card:hover {
    transform: translateY(-2px);
}

.score-card-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.score-card-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.score-card-value {
    font-size: 20px;
    font-weight: 800;
}

.ai-report-container>*+* {
    margin-top: 16px;
}

/* ============ SETTINGS PAGE ============ */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.settings-section {
    padding: 16px 0;
    border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

.settings-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.6;
}

.category-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.category-tag {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.category-tag .remove-btn {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    transition: color 0.2s;
}

.category-tag .remove-btn:hover {
    color: var(--expense-color);
}

.add-category-row {
    display: flex;
    gap: 8px;
}

/* ============ MODAL ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 28px;
    width: 480px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-sm {
    width: 380px;
}

@keyframes modalIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.type-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 20px;
    background: var(--bg-primary);
    padding: 5px;
    border-radius: var(--radius-md);
}

.type-btn {
    padding: 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.type-btn.active[data-type="expense"] {
    background: var(--expense-bg);
    color: var(--expense-color);
    border: 1px solid rgba(244, 63, 94, 0.3);
}

.type-btn.active[data-type="income"] {
    background: var(--income-bg);
    color: var(--income-color);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
}

.category-btn {
    padding: 8px 4px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    font-family: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.category-btn:hover {
    border-color: var(--accent);
    color: var(--accent-light);
    background: var(--accent-glow);
}

.category-btn.selected {
    border-color: var(--accent);
    background: var(--accent-glow);
    color: var(--accent-light);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.category-btn .cat-icon {
    font-size: 18px;
}

/* ============ FORM CONTROLS ============ */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.text-input,
.select-input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    padding: 10px 14px;
    transition: border-color 0.2s;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.text-input:focus,
.select-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.select-input {
    cursor: pointer;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%239298b0' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.select-sm {
    width: auto;
    padding: 6px 30px 6px 10px;
    font-size: 12px;
}

.amount-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.currency-prefix {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
}

.amount-input {
    padding-left: 28px !important;
}

.input-with-toggle {
    position: relative;
}

.input-with-toggle .text-input {
    padding-right: 44px;
}

.input-with-toggle .btn-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox-label input {
    accent-color: var(--accent);
}

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    outline: none;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent-light);
}

.btn-ghost {
    background: transparent;
    color: var(--accent-light);
    font-size: 12px;
}

.btn-ghost:hover {
    background: var(--accent-glow);
}

.btn-danger {
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: var(--expense-color);
}

.btn-danger:hover {
    background: rgba(244, 63, 94, 0.25);
}

.btn-sm {
    padding: 7px 14px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
}

.btn-icon-left {
    font-size: 14px;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: color 0.2s, background 0.2s;
}

.btn-icon:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

/* Action buttons in table */
.action-btns {
    display: flex;
    gap: 4px;
}

.btn-edit {
    color: var(--info-color);
    font-size: 13px;
}

.btn-delete {
    color: var(--expense-color);
    font-size: 13px;
}

/* ============ EMPTY STATE ============ */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 13px;
}

.empty-state.hidden {
    display: none;
}

.hidden {
    display: none !important;
}

/* ============ TOAST ============ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideUp 0.3s ease;
    max-width: 320px;
}

.toast-success {
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--income-color);
}

.toast-error {
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: var(--expense-color);
}

.toast-info {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: var(--accent-light);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1200px) {
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .score-cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .ai-layout {
        grid-template-columns: 1fr;
    }

    .pie-charts-grid {
        grid-template-columns: 1fr;
    }

    .report-charts-grid {
        grid-template-columns: 1fr;
    }

    .report-charts-grid .chart-card-full {
        grid-column: 1;
    }
}

@media (max-width: 600px) {
    .summary-cards {
        grid-template-columns: 1fr 1fr;
    }

    .topbar {
        padding: 0 16px;
    }

    .page {
        padding: 16px;
    }
}

/* ============ PRINT / PDF ============ */
@media print {

    .sidebar,
    .topbar,
    .ai-config-panel,
    .btn,
    .chart-tabs,
    .records-toolbar {
        display: none !important;
    }

    .main-content {
        margin-left: 0;
    }

    .page {
        overflow: visible;
    }
}

/* ============ CHART.JS OVERRIDE ============ */
canvas {
    display: block;
}

/* ============ AUTH BUTTON ============ */
.btn-auth {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-auth:hover {
    border-color: var(--accent);
    color: var(--accent-light);
}

.btn-auth.logged-in {
    border-color: rgba(16, 185, 129, 0.4);
    color: var(--income-color);
    background: rgba(16, 185, 129, 0.08);
}

.auth-btn-text {
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============ AUTH MODAL ============ */
.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    background: var(--bg-primary);
    padding: 4px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
}

.auth-tab {
    padding: 9px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.auth-tab.active {
    background: var(--accent);
    color: white;
}

.auth-error {
    color: var(--expense-color);
    font-size: 12px;
    padding: 10px 14px;
    background: var(--expense-bg);
    border: 1px solid rgba(244, 63, 94, 0.2);
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
}

.auth-hint {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 14px;
}

.auth-hint a {
    color: var(--accent-light);
    text-decoration: none;
    font-weight: 600;
}

.user-info-card {
    text-align: center;
    padding: 20px 0;
}

.user-avatar {
    font-size: 48px;
    margin-bottom: 12px;
}

.user-email {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 8px;
    word-break: break-all;
}

.user-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    background: var(--income-bg);
    color: var(--income-color);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* ============ SUPABASE SETTINGS ============ */
.sb-status-row {
    margin-bottom: 12px;
}

.sb-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.sb-status.connected {
    background: var(--income-bg);
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--income-color);
}

.sb-status.error {
    background: var(--expense-bg);
    border-color: rgba(244, 63, 94, 0.2);
    color: var(--expense-color);
}

/* ============ MOBILE BOTTOM NAV ============ */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 200;
    align-items: center;
    justify-content: space-around;
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mob-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    flex: 1;
    padding: 8px 4px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: color 0.2s;
    min-height: 44px;
}

.mob-nav-item.active {
    color: var(--accent-light);
}

.mob-nav-icon {
    font-size: 20px;
}

.mob-nav-label {
    font-size: 10px;
    font-weight: 500;
}

.mob-nav-add {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    border: none;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.45);
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s;
    margin: 0 4px;
}

.mob-nav-add:active {
    transform: scale(0.93);
}

/* ============ MOBILE RESPONSIVE OVERHAUL ============ */
@media (max-width: 768px) {

    /* Hide desktop sidebar, show mobile bottom nav */
    .sidebar {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding-bottom: 72px;
        /* space for bottom nav */
    }

    .mobile-bottom-nav {
        display: flex;
    }

    /* Topbar mobile */
    .topbar {
        padding: 0 14px;
        height: 56px;
    }

    .page-title {
        font-size: 16px;
    }

    .breadcrumb {
        display: none;
    }

    #addRecordBtn {
        display: none;
    }

    /* use mobile fab instead */
    .month-selector {
        padding: 4px 8px;
        gap: 4px;
    }

    .current-month {
        font-size: 12px;
        min-width: 64px;
    }

    .auth-btn-text {
        display: none;
    }

    /* show only icon on mobile */
    .btn-auth {
        padding: 7px 10px;
    }

    /* Pages */
    .page {
        padding: 12px 12px 16px;
    }

    /* Summary cards: 2 columns */
    .summary-cards {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .summary-card {
        padding: 14px;
        gap: 10px;
    }

    .card-value {
        font-size: 17px;
    }

    .card-icon {
        font-size: 22px;
    }

    /* Dashboard 1 col */
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .chart-container {
        height: 180px;
    }

    .chart-container-lg {
        height: 240px;
    }

    /* Charts page */
    .pie-charts-grid {
        grid-template-columns: 1fr;
    }

    .chart-tabs {
        width: 100%;
    }

    .chart-tab {
        flex: 1;
        padding: 8px 4px;
        font-size: 12px;
    }

    /* AI page stacked */
    .ai-layout {
        grid-template-columns: 1fr;
    }

    .ai-config-panel {
        position: static;
    }

    .report-charts-grid {
        grid-template-columns: 1fr;
    }

    .report-charts-grid .chart-card-full {
        grid-column: 1;
    }

    .score-cards-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Settings */
    .settings-grid {
        grid-template-columns: 1fr;
    }

    /* Records: scrollable table */
    .records-toolbar {
        gap: 8px;
    }

    .filter-group {
        gap: 6px;
    }

    .select-input {
        font-size: 12px;
        padding: 8px 30px 8px 10px;
    }

    .card {
        padding: 14px;
        border-radius: var(--radius-md);
    }

    .records-table {
        font-size: 12px;
    }

    .records-table th {
        font-size: 10px;
        padding: 8px 8px;
    }

    .records-table td {
        padding: 10px 8px;
    }

    /* Hide description column on mobile */
    .records-table th:nth-child(4),
    .records-table td:nth-child(4) {
        display: none;
    }

    /* Modal: slide up from bottom */
    .modal-overlay {
        align-items: flex-end;
    }

    .modal {
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        width: 100%;
        max-width: 100%;
        max-height: 92vh;
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }

    .modal-sm {
        width: 100%;
        max-width: 100%;
    }

    @keyframes modalIn {
        from {
            transform: translateY(60px);
            opacity: 0;
        }

        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Category grid larger tap targets */
    .category-btn {
        padding: 10px 4px;
    }

    .cat-icon {
        font-size: 22px;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .text-input {
        font-size: 16px;
    }

    /* prevent zoom on iOS */

    /* Report */
    .report-title {
        font-size: 18px;
    }

    .health-score-badge {
        width: 64px;
        height: 64px;
    }

    .score-number {
        font-size: 20px;
    }
}

@media (max-width: 400px) {
    .summary-cards {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .card-value {
        font-size: 15px;
    }

    .score-cards-grid {
        grid-template-columns: 1fr 1fr;
    }
}