/* ═══════════════════════════════════════════════════
   FinAnalyzer — Digital Vault Theme
   Premium dark banking interface
   ═══════════════════════════════════════════════════ */

:root {
    /* Core palette */
    --bg-root: #07090e;
    --bg-surface: #0d1117;
    --bg-card: #131921;
    --bg-elevated: #1a2233;
    --bg-hover: #1e2a3a;
    --bg-input: #0f1520;

    /* Borders */
    --border: #1e2d3d;
    --border-subtle: #152030;
    --border-focus: var(--accent);

    /* Text */
    --text-primary: #e6edf3;
    --text-secondary: #7d8da1;
    /* Raised from #4a5567 for WCAG AA: contrast now ~5.1 on --bg-root */
    --text-muted: #6c7a8d;
    --text-inverse: #07090e;

    /* Accent - Electric Teal */
    --accent: #22d3ee;
    --accent-dim: #0e7490;
    --accent-glow: rgba(34, 211, 238, 0.12);
    --accent-glow-strong: rgba(34, 211, 238, 0.25);

    /* Semantic */
    --emerald: #34d399;
    --emerald-dim: rgba(52, 211, 153, 0.15);
    --amber: #fbbf24;
    --amber-dim: rgba(251, 191, 36, 0.15);
    --rose: #f43f5e;
    --rose-dim: rgba(244, 63, 94, 0.15);
    --cyan: #22d3ee;
    --cyan-dim: rgba(34, 211, 238, 0.15);
    --violet: #a78bfa;
    --violet-dim: rgba(167, 139, 250, 0.15);

    /* Layout */
    --sidebar-w: 240px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;

    /* Fonts */
    --font-body: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Shadows */
    --shadow-card: 0 1px 3px rgba(0,0,0,0.4), 0 0 0 1px var(--border-subtle);
    --shadow-elevated: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px var(--border);
    --shadow-glow: 0 0 20px var(--accent-glow);
}

/* ─── Reset & Base ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background: var(--bg-root);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Noise texture overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.012'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 9999;
}

/* ─── App Shell ─── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 28px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 24px;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--accent-glow);
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    display: block;
}

.brand-sub {
    font-size: 0.7rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-weight: 600;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    transition: all 0.2s;
    position: relative;
    width: 100%;
    text-align: left;
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-item.active {
    color: var(--accent);
    background: var(--accent-glow);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

.nav-badge {
    margin-left: auto;
    background: var(--rose);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

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

.api-key-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    transition: all 0.2s;
}

.api-key-toggle:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

/* ─── Main Content ─── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 32px 40px;
    min-height: 100vh;
}

/* ─── Mobile Header ─── */
.mobile-header {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    margin-bottom: 8px;
}

.hamburger {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 6px;
}

.hamburger span {
    display: block;
    width: 100%;
    height: 1.5px;
    background: var(--text-secondary);
    border-radius: 1px;
}

.mobile-brand {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
}

/* ─── Page ─── */
.page {
    display: none;
    animation: fadeIn 0.35s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ─── Period Selector ─── */
.period-selector, .alert-filters {
    display: flex;
    gap: 4px;
    background: var(--bg-card);
    padding: 4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.period-btn {
    padding: 6px 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.period-btn:hover {
    color: var(--text-primary);
}

.period-btn.active {
    background: var(--accent);
    color: var(--text-inverse);
}

/* ─── Summary Cards ─── */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.25s;
    position: relative;
    overflow: hidden;
}

.summary-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    opacity: 0;
    transition: opacity 0.3s;
}

.summary-card:hover {
    border-color: var(--border);
    transform: translateY(-2px);
}

.summary-card:hover::after {
    opacity: 1;
}

.summary-card[data-accent="cyan"]::after { background: var(--cyan); }
.summary-card[data-accent="emerald"]::after { background: var(--emerald); }
.summary-card[data-accent="amber"]::after { background: var(--amber); }
.summary-card[data-accent="rose"]::after { background: var(--rose); }

.summary-card[data-accent="cyan"] .card-icon { background: var(--cyan-dim); color: var(--cyan); }
.summary-card[data-accent="emerald"] .card-icon { background: var(--emerald-dim); color: var(--emerald); }
.summary-card[data-accent="amber"] .card-icon { background: var(--amber-dim); color: var(--amber); }
.summary-card[data-accent="rose"] .card-icon { background: var(--rose-dim); color: var(--rose); }

.card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.card-label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
    margin-bottom: 4px;
}

.card-value {
    display: block;
    font-size: 1.35rem;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
}

/* ─── Charts ─── */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 28px;
}

.analytics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    overflow: hidden;
}

.chart-card--wide {
    grid-column: span 1;
}

.chart-header {
    padding: 18px 22px 0;
}

.chart-header h3 {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.chart-body {
    padding: 16px 22px 22px;
    position: relative;
    height: 280px;
}

.chart-body--doughnut {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 280px;
}

/* ─── Tables ─── */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    background: var(--bg-card);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
    background: var(--bg-elevated);
}

.data-table td {
    padding: 11px 16px;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
    color: var(--text-secondary);
}

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

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

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

.data-table tbody tr.row-flagged {
    background: rgba(244, 63, 94, 0.06);
}

.data-table tbody tr.row-flagged:hover {
    background: rgba(244, 63, 94, 0.1);
}

.text-right {
    text-align: right !important;
}

.amount-debit {
    color: var(--rose);
    font-family: var(--font-mono);
    font-weight: 500;
}

.amount-credit {
    color: var(--emerald);
    font-family: var(--font-mono);
    font-weight: 500;
}

/* ─── Status Badge ─── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-processed {
    background: var(--emerald-dim);
    color: var(--emerald);
}

.badge-flagged {
    background: var(--rose-dim);
    color: var(--rose);
}

.badge-blocked {
    background: var(--amber-dim);
    color: var(--amber);
}

.badge-low { background: var(--cyan-dim); color: var(--cyan); }
.badge-medium { background: var(--amber-dim); color: var(--amber); }
.badge-high { background: rgba(249, 115, 22, 0.15); color: #f97316; }
.badge-critical { background: var(--rose-dim); color: var(--rose); }

/* ─── Filters Bar ─── */
.filters-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 20px;
    flex-wrap: wrap;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}

/* ─── Inputs ─── */
.input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.2s;
    width: 100%;
}

.input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-sm {
    padding: 7px 10px;
    font-size: 0.85rem;
}

.input-label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 14px 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}

select.input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%237d8da1' fill='none' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: var(--text-inverse);
}

.btn-primary:hover {
    background: #06b6d4;
    box-shadow: var(--shadow-glow);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.btn-danger {
    background: var(--rose);
    color: white;
}

.btn-danger:hover {
    background: #e11d48;
}

.btn-sm {
    padding: 7px 14px;
    font-size: 0.82rem;
}

/* ─── Pagination ─── */
.pagination {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-top: 20px;
}

.pagination button {
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.82rem;
    transition: all 0.2s;
}

.pagination button:hover {
    border-color: var(--border);
    color: var(--text-primary);
}

.pagination button.active {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: var(--accent);
}

/* ─── Alerts ─── */
.alerts-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.alert-stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    text-align: center;
}

.alert-stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    font-family: var(--font-mono);
}

.alert-stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 2px;
}

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

.alert-item {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 16px 20px;
    transition: all 0.2s;
}

.alert-item:hover {
    border-color: var(--border);
}

.alert-item.resolved {
    opacity: 0.5;
}

.alert-severity {
    width: 4px;
    height: 36px;
    border-radius: 2px;
    flex-shrink: 0;
}

.alert-severity.sev-low { background: var(--cyan); }
.alert-severity.sev-medium { background: var(--amber); }
.alert-severity.sev-high { background: #f97316; }
.alert-severity.sev-critical { background: var(--rose); }

.alert-body {
    flex: 1;
    min-width: 0;
}

.alert-message {
    font-weight: 500;
    margin-bottom: 4px;
}

.alert-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
}

.alert-actions {
    flex-shrink: 0;
}

/* ─── Budgets ─── */
.budgets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.budget-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 22px;
    transition: all 0.25s;
    cursor: pointer;
}

.budget-card:hover {
    border-color: var(--border);
    transform: translateY(-1px);
}

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

.budget-category {
    font-weight: 600;
    font-size: 1rem;
}

.budget-period {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--bg-elevated);
    padding: 3px 10px;
    border-radius: 4px;
}

.budget-progress {
    margin-bottom: 12px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-elevated);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.progress-fill.safe { background: var(--emerald); }
.progress-fill.warning { background: var(--amber); }
.progress-fill.exceeded { background: var(--rose); }

.budget-amounts {
    display: flex;
    justify-content: space-between;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.budget-amounts .spent {
    font-family: var(--font-mono);
    color: var(--text-secondary);
    font-weight: 500;
}

.budget-percentage {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.3rem;
    margin-top: 6px;
}

/* ─── Comparison ─── */
.comparison-body {
    padding: 22px;
}

.comparison-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.comparison-row:last-child {
    border-bottom: none;
}

.comparison-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.comparison-values {
    display: flex;
    gap: 16px;
    align-items: center;
    font-family: var(--font-mono);
    font-size: 0.88rem;
}

.comparison-change {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
}

.change-up {
    color: var(--rose);
    background: var(--rose-dim);
}

.change-down {
    color: var(--emerald);
    background: var(--emerald-dim);
}

/* ─── Merchants ─── */
.merchants-list {
    padding: 22px;
}

.merchant-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.merchant-row:last-child {
    border-bottom: none;
}

.merchant-rank {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-elevated);
    display: grid;
    place-items: center;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
}

.merchant-name {
    flex: 1;
    font-weight: 500;
    color: var(--text-secondary);
}

.merchant-amount {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-primary);
}

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 420px;
    max-width: 90vw;
    box-shadow: var(--shadow-elevated);
}

.modal h3 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 24px;
}

/* ─── Empty & Loading States ─── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.comparison-loader {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
}

/* ─── Section Header ─── */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.section-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.recent-section {
    margin-top: 32px;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ─── Responsive ─── */
@media (max-width: 1024px) {
    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-row {
        grid-template-columns: 1fr;
    }

    .analytics-grid {
        grid-template-columns: 1fr;
    }

    .alerts-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-elevated);
    }

    .main-content {
        margin-left: 0;
        padding: 16px 20px;
    }

    .mobile-header {
        display: flex;
    }

    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }

    .filters-bar {
        flex-direction: column;
    }

    .filter-group {
        width: 100%;
    }

    .page-header {
        flex-direction: column;
    }

    .budgets-grid {
        grid-template-columns: 1fr;
    }

    .alerts-stats {
        grid-template-columns: 1fr 1fr;
    }
}

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

    .alerts-stats {
        grid-template-columns: 1fr;
    }
}

/* ─── Toast notifications ─── */
.toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 380px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    padding: 14px 18px;
    border-radius: var(--radius);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    color: var(--text-primary);
    font-size: 0.88rem;
    box-shadow: var(--shadow-elevated);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toast-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast-success { border-left-color: var(--emerald); }
.toast-error { border-left-color: var(--rose); }
.toast-warning { border-left-color: var(--amber); }
.toast-info { border-left-color: var(--accent); }

.toast-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.toast-success .toast-icon { color: var(--emerald); }
.toast-error .toast-icon { color: var(--rose); }
.toast-warning .toast-icon { color: var(--amber); }
.toast-info .toast-icon { color: var(--accent); }

.toast-message {
    flex: 1;
    line-height: 1.4;
}

.toast-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0;
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.toast-close:hover { color: var(--text-primary); }

.toast.leaving { animation: toast-out 0.25s forwards; }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(calc(100% + 24px)); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateX(calc(100% + 24px)); }
}

@media (max-width: 640px) {
    .toast-container {
        top: auto;
        bottom: 16px;
        right: 16px;
        left: 16px;
        max-width: none;
    }

    @keyframes toast-in {
        from { opacity: 0; transform: translateY(calc(100% + 16px)); }
        to { opacity: 1; transform: translateY(0); }
    }
}

/* ─── Skeleton loaders ─── */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-elevated) 0%,
        var(--bg-hover) 50%,
        var(--bg-elevated) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite linear;
    border-radius: var(--radius-sm);
    color: transparent !important;
    user-select: none;
    pointer-events: none;
}

.skeleton-row {
    height: 44px;
    margin-bottom: 6px;
}

.skeleton-card {
    height: 92px;
    border-radius: var(--radius);
    margin-bottom: 8px;
}

.skeleton-chart {
    height: 240px;
    border-radius: var(--radius);
}

.skeleton-text {
    height: 14px;
    width: 60%;
    margin: 4px 0;
}

.skeleton-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0;
}

.skeleton-stack-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 16px;
}

.skeleton-stack-card .skeleton {
    margin-bottom: 10px;
}

@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; background: var(--bg-elevated); }
    .toast { animation: none; }
}

/* ─── Error state ─── */
.error-state {
    padding: 32px 24px;
    text-align: center;
    background: var(--bg-card);
    border: 1px dashed var(--rose);
    border-radius: var(--radius);
    color: var(--text-secondary);
}

.error-state-icon {
    width: 36px;
    height: 36px;
    margin: 0 auto 12px;
    color: var(--rose);
}

.error-state-title {
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.95rem;
}

.error-state-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ─── Transaction detail drawer ─── */
.drawer {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: none;
}

.drawer.open { display: block; }

.drawer-overlay {
    position: absolute;
    inset: 0;
    background: rgba(7, 9, 14, 0.72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: drawer-fade 0.2s;
}

.drawer-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 480px;
    max-width: 100%;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: -20px 0 40px rgba(0, 0, 0, 0.5);
    animation: drawer-slide 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes drawer-slide {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

@keyframes drawer-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.drawer-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.drawer-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-top: 2px;
}

.drawer-close {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.drawer-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--border);
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.drawer-amount-hero {
    font-family: var(--font-mono);
    font-size: 2.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.drawer-amount-hero.debit { color: var(--rose); }
.drawer-amount-hero.credit { color: var(--emerald); }

.drawer-merchant {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 24px;
}

.drawer-section {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.drawer-section:last-child { border-bottom: none; }

.drawer-section-title {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.drawer-kv {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 10px 16px;
    font-size: 0.86rem;
}

.drawer-kv dt {
    color: var(--text-muted);
}

.drawer-kv dd {
    color: var(--text-primary);
    font-family: var(--font-mono);
    word-break: break-word;
}

.drawer-metadata {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 240px;
    overflow-y: auto;
}

.drawer-tx-row {
    cursor: pointer;
    transition: background 0.12s;
}

/* Suspicious reason block in tx drawer */
.drawer-section.suspicious-reason {
    background: rgba(244, 63, 94, 0.06);
    border: 1px solid rgba(244, 63, 94, 0.35);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 18px;
}

.drawer-section.suspicious-reason .drawer-section-title {
    color: var(--rose);
    margin-bottom: 10px;
}

.suspicious-reason-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.suspicious-reason-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.suspicious-reason-icon {
    color: var(--rose);
    font-size: 0.95rem;
    line-height: 1.4;
    flex-shrink: 0;
}

.suspicious-reason-msg {
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.45;
}

.suspicious-reason-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 6px;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.drawer-tx-row:hover {
    background: var(--bg-hover);
}

@media (max-width: 640px) {
    .drawer-panel { width: 100%; }
}

/* ─── Focus-visible accessibility ─── */
button:focus-visible,
.nav-item:focus-visible,
.period-btn:focus-visible,
.input:focus-visible,
select.input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ─── Amount in summary cards — use monospace ─── */
.summary-card .card-value,
.alert-stat-value,
.budget-percentage {
    font-family: var(--font-mono);
    font-feature-settings: "tnum";
}

/* ─── Summary card — delta + sparkline ─── */
.summary-card {
    position: relative;
    overflow: hidden;
}

.card-delta {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-top: 4px;
    font-size: 0.72rem;
    font-family: var(--font-mono);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.card-delta.neutral { color: var(--text-muted); }
/* For spending cards: growth is BAD (red), decline is GOOD (green) */
.card-delta.up { color: var(--rose); }
.card-delta.down { color: var(--emerald); }
/* For neutral metrics (count, etc): default growth=green, decline=red */
.card-delta.up.positive { color: var(--emerald); }
.card-delta.down.positive { color: var(--rose); }

.card-delta-arrow {
    font-size: 0.85em;
    line-height: 1;
}

.card-spark {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 92px;
    height: 34px;
    opacity: 0.62;
    pointer-events: none;
}

@media (max-width: 480px) {
    .card-spark { display: none; }
}

/* ─── Heatmap (GitHub-style activity calendar) ─── */
.heatmap-wrap {
    padding: 8px 4px 4px;
    overflow-x: auto;
    overflow-y: hidden;
}

.heatmap-months {
    display: flex;
    gap: 3px;
    padding-left: 22px;
    margin-bottom: 6px;
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    min-width: max-content;
}

.heatmap-month-label {
    flex-shrink: 0;
}

.heatmap-body {
    display: flex;
    gap: 6px;
    min-width: max-content;
}

.heatmap-days {
    display: grid;
    grid-template-rows: repeat(7, 13px);
    gap: 3px;
    font-size: 0.62rem;
    color: var(--text-muted);
    text-align: right;
    padding-right: 2px;
}

.heatmap-days span {
    line-height: 13px;
}

.heatmap-grid {
    display: grid;
    grid-template-rows: repeat(7, 13px);
    grid-auto-flow: column;
    grid-auto-columns: 13px;
    gap: 3px;
}

.heat-cell {
    background: var(--bg-elevated);
    border-radius: 2px;
    cursor: pointer;
    transition: transform 0.12s ease, outline-color 0.12s;
    outline: 1px solid transparent;
}

.heat-cell[data-empty="true"] {
    visibility: hidden;
}

.heat-cell:hover {
    outline-color: var(--accent);
    transform: scale(1.25);
    z-index: 2;
}

.heat-cell[data-level="0"] { background: var(--bg-elevated); }
.heat-cell[data-level="1"] { background: rgba(34, 211, 238, 0.18); }
.heat-cell[data-level="2"] { background: rgba(34, 211, 238, 0.38); }
.heat-cell[data-level="3"] { background: rgba(34, 211, 238, 0.6); }
.heat-cell[data-level="4"] { background: rgba(34, 211, 238, 0.82); }
.heat-cell[data-level="5"] {
    background: rgba(34, 211, 238, 1);
    box-shadow: 0 0 6px rgba(34, 211, 238, 0.45);
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
    padding: 10px 6px 2px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.heatmap-legend .heat-cell {
    width: 11px;
    height: 11px;
    cursor: default;
}

.heatmap-legend .heat-cell:hover {
    transform: none;
    outline: 1px solid transparent;
}

/* ─── Forecast indicator in summary ─── */
.forecast-hint {
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--bg-surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.forecast-hint-label {
    color: var(--text-muted);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.forecast-hint-value {
    font-family: var(--font-mono);
    color: var(--text-primary);
    font-weight: 600;
}

.chart-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 8px;
}

/* ─── Period selector with custom range ─── */
.period-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.period-custom {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
}

.period-custom .input {
    min-width: 140px;
    padding: 5px 8px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color-scheme: dark;
}

.period-dash {
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.period-badge {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    padding: 4px 8px;
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

@media (max-width: 640px) {
    .period-wrap {
        align-items: stretch;
        width: 100%;
    }
    .period-selector {
        flex-wrap: wrap;
    }
    .period-custom {
        flex-wrap: wrap;
    }
    .period-custom .input {
        min-width: 120px;
        flex: 1;
    }
}

/* ══════════════════════════════════════════
   v4 additions — chips, sort, palette, rules,
   status page, tour, ptr, light theme, etc.
   ══════════════════════════════════════════ */

/* ─── Page header actions row ─── */
.page-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ─── Filter chips ─── */
.chip-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.chip:hover {
    border-color: var(--border);
    color: var(--text-primary);
}

.chip.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
}

.chip-clear {
    margin-left: auto;
    color: var(--text-muted);
    background: transparent;
    border-color: transparent;
}

.chip-clear:hover {
    color: var(--rose);
    background: var(--rose-dim);
}

.filter-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
    padding: 8px 4px;
}

/* ─── Sortable table headers ─── */
.data-table--sortable th[data-sort] {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
    position: relative;
}

.data-table--sortable th[data-sort]:hover {
    color: var(--text-primary);
}

.sort-ind {
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 6px;
    opacity: 0;
    transition: opacity 0.15s;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    vertical-align: middle;
}

.data-table--sortable th.sorted.desc .sort-ind {
    opacity: 1;
    border-top: 5px solid var(--accent);
    margin-bottom: 2px;
}

.data-table--sortable th.sorted.asc .sort-ind {
    opacity: 1;
    border-bottom: 5px solid var(--accent);
    margin-top: 2px;
}

.data-table--sortable th.sorted {
    color: var(--text-primary);
}

/* ─── Bulk actions toolbar ─── */
.bulk-toolbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    margin-bottom: 12px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: 0 0 0 3px var(--accent-glow);
    animation: bulk-pop 0.25s ease;
}

@keyframes bulk-pop {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.bulk-select-all {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.88rem;
    cursor: pointer;
    flex: 1;
}

/* Custom styled checkboxes — dark premium theme */
.bulk-select-all input[type="checkbox"],
.alert-item .alert-check {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--border);
    border-radius: 5px;
    background: var(--bg-tertiary);
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
    margin: 0;
}

.bulk-select-all input[type="checkbox"]:hover,
.alert-item .alert-check:hover {
    border-color: var(--accent);
}

.bulk-select-all input[type="checkbox"]:focus-visible,
.alert-item .alert-check:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-glow);
    border-color: var(--accent);
}

.bulk-select-all input[type="checkbox"]:checked,
.alert-item .alert-check:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.bulk-select-all input[type="checkbox"]:checked::after,
.alert-item .alert-check:checked::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.bulk-select-all input[type="checkbox"]:indeterminate {
    background: var(--accent);
    border-color: var(--accent);
}

.bulk-select-all input[type="checkbox"]:indeterminate::after {
    content: "";
    position: absolute;
    left: 3px;
    right: 3px;
    top: 50%;
    height: 2px;
    background: #fff;
    transform: translateY(-50%);
    border-radius: 1px;
}

.alert-item.selected {
    border-color: var(--accent);
    background: var(--accent-glow);
}

/* ─── Resolve animation (#44) ─── */
.alert-item.resolving {
    animation: resolve-fade 0.6s forwards;
}

.alert-item.resolving .alert-severity {
    background: var(--emerald) !important;
    animation: resolve-tick 0.4s forwards;
}

@keyframes resolve-fade {
    0%   { opacity: 1; transform: scale(1); }
    60%  { opacity: 1; transform: scale(1.02); background: var(--emerald-dim); }
    100% { opacity: 0; transform: scale(0.92); max-height: 0; padding: 0; margin: 0; border-width: 0; }
}

@keyframes resolve-tick {
    from { transform: scaleY(1); }
    50%  { transform: scaleY(1.5); }
    to   { transform: scaleY(1); }
}

/* ─── Command palette (#13) ─── */
.palette {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
}

.palette.open { display: block; }

.palette-overlay {
    position: absolute;
    inset: 0;
    background: rgba(7, 9, 14, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: drawer-fade 0.15s;
}

.palette-panel {
    position: absolute;
    top: 12vh;
    left: 50%;
    transform: translateX(-50%);
    width: min(640px, calc(100vw - 32px));
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    animation: palette-in 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes palette-in {
    from { opacity: 0; transform: translate(-50%, -8px) scale(0.98); }
    to   { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.palette-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-muted);
}

.palette-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
}

.palette-input::placeholder {
    color: var(--text-muted);
}

.palette-hint {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-elevated);
    padding: 3px 7px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

.palette-results {
    max-height: 56vh;
    overflow-y: auto;
    padding: 6px;
}

.palette-section-title {
    padding: 8px 12px 4px;
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
}

.palette-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: background 0.1s;
}

.palette-item:hover,
.palette-item.focused {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.palette-item-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    background: var(--bg-elevated);
    border-radius: 6px;
    flex-shrink: 0;
    color: var(--accent);
}

.palette-item-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.palette-item-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    flex-shrink: 0;
}

.palette-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ─── Fraud rules page (#28) ─── */
.rules-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rule-card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px 20px;
    padding: 18px 22px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s;
}

.rule-card:hover {
    border-color: var(--border);
}

.rule-card.inactive {
    opacity: 0.5;
}

.rule-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.rule-desc {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-top: 2px;
}

.rule-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.rule-toggle {
    font-size: 0.72rem;
    padding: 4px 10px;
    border-radius: 10px;
    font-weight: 600;
}

.rule-toggle.on {
    background: var(--emerald-dim);
    color: var(--emerald);
}

.rule-toggle.off {
    background: var(--bg-elevated);
    color: var(--text-muted);
}

.modal-wide { width: 480px; }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-secondary);
}

.checkbox-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* ─── Status page (#49) ─── */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.status-card {
    padding: 18px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    display: flex;
    gap: 14px;
    align-items: center;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
}

.status-dot.ok {
    background: var(--emerald);
    box-shadow: 0 0 0 3px var(--emerald-dim);
}

.status-dot.ok::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: var(--emerald);
    opacity: 0.35;
    animation: pulse-dot 2s infinite;
}

.status-dot.warn {
    background: var(--amber);
    box-shadow: 0 0 0 3px var(--amber-dim);
}

.status-dot.err {
    background: var(--rose);
    box-shadow: 0 0 0 3px var(--rose-dim);
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 0.35; }
    50%      { transform: scale(1.6); opacity: 0; }
}

.status-meta {
    flex: 1;
    min-width: 0;
}

.status-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.94rem;
}

.status-sub {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 2px;
    font-family: var(--font-mono);
}

/* Activity log (#50) */
.activity-log {
    padding: 12px 18px;
    max-height: 360px;
    overflow-y: auto;
}

.activity-row {
    display: grid;
    grid-template-columns: 92px 24px 1fr;
    gap: 10px;
    padding: 10px 4px;
    align-items: center;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.86rem;
}

.activity-row:last-child { border-bottom: none; }

.activity-time {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

.activity-icon {
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    background: var(--bg-elevated);
    border-radius: 6px;
    color: var(--accent);
    flex-shrink: 0;
}

.activity-icon.fraud { color: var(--rose); }
.activity-icon.budget { color: var(--amber); }
.activity-icon.create { color: var(--emerald); }

/* ─── Icon-only buttons in sidebar footer ─── */
.btn-icon {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.82rem;
    width: 100%;
    text-align: left;
    transition: all 0.15s;
    margin-bottom: 4px;
}

.btn-icon:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.mobile-search-btn {
    margin-left: auto;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
}

/* ─── Collapsed sidebar (#39) ─── */
@media (min-width: 769px) {
    .app-shell.sidebar-collapsed .sidebar {
        width: 72px;
    }
    .app-shell.sidebar-collapsed .main-content {
        margin-left: 72px;
    }
    .app-shell.sidebar-collapsed .nav-item span,
    .app-shell.sidebar-collapsed .brand-text,
    .app-shell.sidebar-collapsed .api-key-toggle span,
    .app-shell.sidebar-collapsed .theme-toggle-label {
        display: none;
    }
    .app-shell.sidebar-collapsed .sidebar-brand {
        justify-content: center;
    }
    .app-shell.sidebar-collapsed .nav-item {
        justify-content: center;
        padding: 10px;
    }
    .app-shell.sidebar-collapsed .api-key-toggle {
        justify-content: center;
    }
    .app-shell.sidebar-collapsed .sidebar-collapse-btn svg {
        transform: rotate(180deg);
    }
    .app-shell.sidebar-collapsed .nav-badge {
        position: absolute;
        top: 4px;
        right: 4px;
        margin-left: 0;
    }
}

/* ─── Pull-to-refresh indicator (#26) ─── */
.ptr-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    justify-content: center;
    height: 0;
    overflow: hidden;
    transition: height 0.2s ease;
    color: var(--accent);
    font-size: 0.82rem;
}

.ptr-indicator.active {
    display: flex;
    height: 48px;
}

.ptr-indicator.loading svg {
    animation: spin 0.8s linear infinite;
}

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

/* ─── Onboarding tour (#42) ─── */
.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: none;
}

.tour-overlay.open {
    display: block;
}

.tour-mask {
    position: absolute;
    inset: 0;
    background: rgba(7, 9, 14, 0.82);
    pointer-events: none;
    transition: clip-path 0.3s ease;
}

.tour-tooltip {
    position: absolute;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 22px;
    box-shadow: var(--shadow-elevated);
    max-width: 340px;
    animation: tour-pop 0.2s ease;
}

@keyframes tour-pop {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.tour-step-count {
    font-size: 0.72rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    margin-bottom: 6px;
}

.tour-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.tour-text {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 14px;
}

.tour-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ─── Empty states with illustrations (#41) ─── */
.empty-state-hero {
    padding: 60px 24px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state-hero svg {
    display: block;
    margin: 0 auto 16px;
    max-width: 120px;
    opacity: 0.7;
}

.empty-state-hero-title {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 6px;
}

.empty-state-hero-text {
    font-size: 0.88rem;
    max-width: 340px;
    margin: 0 auto 16px;
    line-height: 1.5;
}

/* ─── Mobile cards (#25) ─── */
@media (max-width: 640px) {
    .data-table--mobile-cards thead { display: none; }
    .data-table--mobile-cards,
    .data-table--mobile-cards tbody,
    .data-table--mobile-cards tr,
    .data-table--mobile-cards td {
        display: block;
        width: 100%;
        white-space: normal;
    }
    .data-table--mobile-cards tr {
        background: var(--bg-card);
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius);
        padding: 12px 14px;
        margin-bottom: 10px;
    }
    .data-table--mobile-cards tr.row-flagged {
        border-color: var(--rose);
    }
    .data-table--mobile-cards td {
        display: flex;
        justify-content: space-between;
        padding: 4px 0;
        border-bottom: none;
    }
    .data-table--mobile-cards td::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        font-weight: 500;
        margin-right: 8px;
    }
    .data-table--mobile-cards td.text-right {
        text-align: left !important;
    }
    .table-wrap {
        background: transparent;
        border: none;
    }
}

/* ─── Bottom sheet for modals on mobile (#27) ─── */
@media (max-width: 640px) {
    .modal-overlay {
        align-items: flex-end;
    }
    .modal {
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        animation: sheet-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        max-height: 92vh;
        overflow-y: auto;
    }
    @keyframes sheet-up {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }
    .palette-panel {
        top: 4vh;
    }
    .bulk-toolbar {
        flex-wrap: wrap;
    }
}

/* ─── Count-up animation state (#40) ─── */
.counting {
    color: var(--accent);
    transition: color 0.3s;
}

/* ─── Reduced motion — full coverage (#23) ─── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .sidebar { transition: none !important; }
    .drawer-panel { animation: none !important; }
    .drawer-overlay { animation: none !important; }
    .modal-overlay, .modal { animation: none !important; }
    .palette-panel { animation: none !important; }
    .status-dot.ok::before { animation: none !important; }
    .heat-cell:hover { transform: none !important; }
}

/* ─── Enhanced focus-visible (#20) ─── */
a:focus-visible,
[role="button"]:focus-visible,
[tabindex="0"]:focus-visible,
input[type="checkbox"]:focus-visible,
.chip:focus-visible,
.drawer-close:focus-visible,
.palette-item:focus-visible,
.budget-card:focus-visible,
.rule-card:focus-visible,
.nav-item:focus-visible,
.btn-icon:focus-visible,
.mobile-search-btn:focus-visible,
.hamburger:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.data-table--sortable th[data-sort]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* ─── Light theme (#38) ─── */
:root[data-theme="light"] {
    --bg-root: #f5f7fa;
    --bg-surface: #ffffff;
    --bg-card: #ffffff;
    --bg-elevated: #edf1f5;
    --bg-hover: #e6ebf1;
    --bg-input: #fafbfc;

    --border: #d1d9e2;
    --border-subtle: #e3e8ee;

    --text-primary: #1a2233;
    --text-secondary: #5a6878;
    --text-muted: #6c7a8d;
    --text-inverse: #ffffff;

    --accent-dim: #0891b2;
    --accent-glow: rgba(8, 145, 178, 0.12);
    --accent-glow-strong: rgba(8, 145, 178, 0.22);

    --shadow-card: 0 1px 3px rgba(30, 45, 61, 0.08), 0 0 0 1px var(--border-subtle);
    --shadow-elevated: 0 8px 32px rgba(30, 45, 61, 0.15), 0 0 0 1px var(--border);
}

:root[data-theme="light"] body {
    background: var(--bg-root);
}

:root[data-theme="light"] body::before {
    opacity: 0.5;
}

:root[data-theme="light"] .heat-cell[data-level="0"] {
    background: #e3e8ee;
}

:root[data-theme="light"] .heat-cell[data-level="1"] { background: rgba(8, 145, 178, 0.2); }
:root[data-theme="light"] .heat-cell[data-level="2"] { background: rgba(8, 145, 178, 0.4); }
:root[data-theme="light"] .heat-cell[data-level="3"] { background: rgba(8, 145, 178, 0.6); }
:root[data-theme="light"] .heat-cell[data-level="4"] { background: rgba(8, 145, 178, 0.8); }
:root[data-theme="light"] .heat-cell[data-level="5"] { background: rgba(8, 145, 178, 1); }

:root[data-theme="light"] select.input {
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235a6878' fill='none' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

:root[data-theme="light"] .period-custom .input,
:root[data-theme="light"] .filter-group input[type="date"] {
    color-scheme: light;
}

/* Fallback: follow OS preference only when user hasn't explicitly chosen */
@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        --bg-root: #f5f7fa;
        --bg-surface: #ffffff;
        --bg-card: #ffffff;
        --bg-elevated: #edf1f5;
        --bg-hover: #e6ebf1;
        --bg-input: #fafbfc;
        --border: #d1d9e2;
        --border-subtle: #e3e8ee;
        --text-primary: #1a2233;
        --text-secondary: #5a6878;
        --text-muted: #6c7a8d;
        --text-inverse: #ffffff;
    }
}

/* ─── Drawer — editable notes/tags (#34) ─── */
.drawer-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: var(--accent-glow);
    color: var(--accent);
    border-radius: 12px;
    font-size: 0.76rem;
    font-weight: 500;
}

.tag-pill .tag-remove {
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1;
    opacity: 0.6;
}

.tag-pill .tag-remove:hover { opacity: 1; }

.drawer-notes-input {
    width: 100%;
    min-height: 72px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    resize: vertical;
    outline: none;
}

.drawer-notes-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.drawer-save-row {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ─── Category hover preview (#43) ─── */
.cat-preview-tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    box-shadow: var(--shadow-elevated);
    z-index: 3000;
    font-size: 0.82rem;
    max-width: 260px;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.15s, transform 0.15s;
}

.cat-preview-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.cat-preview-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.cat-preview-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--text-secondary);
    padding: 2px 0;
}

.cat-preview-row .m-amt {
    font-family: var(--font-mono);
    color: var(--accent);
}

/* ═════════════════════════════════════════════════════
   Operator: per-page client filter + click-to-filter chips
   ═════════════════════════════════════════════════════ */

/* Typeahead combobox — scales to any number of customers (server-side search) */
.client-combo {
    position: relative;
    display: inline-block;
    min-width: 180px;
}

.client-combo-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 10px;
    min-height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}

.client-combo-btn:hover:not(:disabled) {
    border-color: var(--accent);
}

.client-combo-btn:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.client-combo-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.client-combo-val {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
}

.client-combo-val.client-combo-val--set {
    color: var(--accent);
}

.client-combo-chevron {
    color: var(--text-muted);
    flex-shrink: 0;
}

.client-combo-pop {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 240px;
    max-width: 320px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.client-combo-pop[hidden] { display: none; }

.client-combo-search {
    margin: 8px;
    padding: 6px 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font-body);
}

.client-combo-search:focus {
    outline: none;
    border-color: var(--accent);
}

.client-combo-list {
    overflow-y: auto;
    max-height: 280px;
    padding: 2px 4px 4px;
}

.client-combo-section {
    padding: 8px 10px 4px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.client-combo-item {
    display: flex;
    flex-direction: column;
    width: 100%;
    text-align: left;
    padding: 7px 10px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.3;
}

.client-combo-item:hover,
.client-combo-item.is-focused {
    background: var(--bg-hover);
}

.client-combo-item.is-active {
    background: var(--accent-glow);
    color: var(--accent);
}

.client-combo-item-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-family: var(--font-body);
    margin-top: 2px;
}

.client-combo-loader,
.client-combo-empty {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.client-combo-hint {
    padding: 6px 10px;
    border-top: 1px solid var(--border-subtle);
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
}

.client-combo--disabled { opacity: 0.6; }

/* Compact chip showing a bank customer's id. Click-to-filter. */
.client-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    line-height: 1.4;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.client-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

/* Budget card footer: percentage + client chip side by side */
.budget-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
}
