/* ── Theme variables ── */
:root {
    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --bg-input: #ffffff;
    --bg-nav: #0f172a;
    --bg-footer: #0f172a;
    --bg-table-head: #f1f5f9;
    --bg-code: #f1f5f9;

    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --border-input: #94a3b8;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #64748b;
    --text-muted: #94a3b8;
    --text-faint: #cbd5e1;

    --shadow-card: 0 1px 3px rgb(0 0 0 / 0.08), 0 1px 2px rgb(0 0 0 / 0.04);
    --shadow-lg: 0 10px 15px rgb(0 0 0 / 0.08);

    /* Brand */
    --accent: #0d9488;
    --accent-hover: #0f766e;

    /* Semantic */
    --green: #059669;
    --green-bg: #d1fae5;
    --green-text: #065f46;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --red-text: #991b1b;
    --yellow-bg: #fef3c7;
    --yellow-text: #92400e;
    --blue-bg: #dbeafe;
    --blue-text: #1e40af;
    --purple: #7c3aed;
    --indigo: #4f46e5;
}

[data-theme="dark"] {
    --bg-page: #0c1222;
    --bg-card: #162032;
    --bg-card-hover: #1e2d44;
    --bg-input: #162032;
    --bg-nav: #060d19;
    --bg-footer: #060d19;
    --bg-table-head: #162032;
    --bg-code: #1e2d44;

    --border: #1e2d44;
    --border-strong: #2d4158;
    --border-input: #2d4158;

    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-muted: #475569;
    --text-faint: #334155;

    --shadow-card: 0 1px 3px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px rgb(0 0 0 / 0.4);

    /* Brand */
    --accent: #2dd4bf;
    --accent-hover: #14b8a6;

    --green: #34d399;
    --green-bg: #064e3b;
    --green-text: #6ee7b7;
    --red: #f87171;
    --red-bg: #7f1d1d;
    --red-text: #fca5a5;
    --yellow-bg: #78350f;
    --yellow-text: #fde68a;
    --blue-bg: #1e3a5f;
    --blue-text: #93c5fd;
    --purple: #a78bfa;
    --indigo: #818cf8;
}

/* ── System font stack ── */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    transition: background 0.2s, color 0.2s;
}

/* ── Nav ── */
.nav-link { color: rgb(148 163 184); padding: 0.25rem 0.5rem; border-radius: 0.25rem; transition: all 0.15s; }
.nav-link:hover { color: white; background: rgb(30 45 68); }
.nav-link.active { color: #2dd4bf; background: rgb(30 45 68); }

/* ── Pills ── */
.pill { display: inline-block; padding: 0.25rem 0.75rem; border-radius: 0.25rem; font-size: 0.875rem; transition: all 0.15s; }
.pill:hover { opacity: 0.85; }
.pill-default { background: var(--border-strong); color: var(--text-secondary); }
.pill-active { background: var(--text-primary); color: var(--bg-page); }
.pill-yellow { background: var(--yellow-bg); color: var(--yellow-text); }
.pill-green { background: var(--green); color: white; }
.pill-red { background: var(--red); color: white; }
.pill-purple { background: var(--purple); color: white; }

/* ── Cards ── */
.stat-card { background: var(--bg-card); border-radius: 0.5rem; box-shadow: var(--shadow-card); padding: 1rem; }
.stat-card .stat-label { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-tertiary); margin-bottom: 0.125rem; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-sub { font-size: 0.6875rem; color: var(--text-muted); margin-top: 0.125rem; }

.card { background: var(--bg-card); border-radius: 0.5rem; box-shadow: var(--shadow-card); overflow-x: auto; }
.card-header { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-body { padding: 0.75rem 1rem; }

/* ── Report tab ── */
.report-tab { display: inline-block; padding: 0.375rem 0.75rem; border-radius: 0.375rem; font-size: 0.875rem; color: var(--text-tertiary); transition: all 0.15s; }
.report-tab:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.report-tab.active { background: var(--text-primary); color: var(--bg-page); }

/* ── Tables ── */
.data-table { width: 100%; font-size: 0.875rem; }
.data-table thead { background: var(--bg-table-head); }
.data-table th { text-align: left; padding: 0.5rem 1rem; font-weight: 500; font-size: 0.75rem; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.025em; }
.data-table td { padding: 0.5rem 1rem; }
.data-table tbody tr { border-top: 1px solid var(--border); }
.data-table tbody tr:hover { background: var(--bg-card-hover); }

@media (max-width: 639px) {
    .data-table th, .data-table td { padding: 0.375rem 0.5rem; }
}

/* ── Badges ── */
.badge { display: inline-block; font-size: 0.6875rem; padding: 0.125rem 0.5rem; border-radius: 0.25rem; font-weight: 500; }
.badge-pending { background: var(--yellow-bg); color: var(--yellow-text); }
.badge-won { background: var(--green-bg); color: var(--green-text); }
.badge-lost { background: var(--red-bg); color: var(--red-text); }
.badge-void { background: var(--border-strong); color: var(--text-secondary); }
.badge-cashout { background: var(--border-strong); color: var(--text-secondary); }

/* ── Amounts ── */
.amount { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; }
.amount-positive { color: var(--green); }
.amount-negative { color: var(--red); }

/* ── Scrollable containers ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Theme overrides for Tailwind utility classes ──
   These ensure Tailwind's bg-white, bg-gray-50, text-gray-*, shadow etc.
   pick up the theme in elements we don't control with custom classes. */
[data-theme="dark"] .bg-white { background: var(--bg-card) !important; }
[data-theme="dark"] .bg-gray-50 { background: var(--bg-page) !important; }
[data-theme="dark"] .bg-gray-100 { background: var(--bg-card) !important; }
[data-theme="dark"] .hover\:bg-gray-50:hover { background: var(--bg-card-hover) !important; }
[data-theme="dark"] .text-gray-900 { color: var(--text-primary) !important; }
[data-theme="dark"] .text-gray-800 { color: var(--text-primary) !important; }
[data-theme="dark"] .text-gray-700 { color: var(--text-secondary) !important; }
[data-theme="dark"] .text-gray-600 { color: var(--text-secondary) !important; }
[data-theme="dark"] .text-gray-500 { color: var(--text-tertiary) !important; }
[data-theme="dark"] .text-gray-400 { color: var(--text-muted) !important; }
[data-theme="dark"] .text-gray-300 { color: var(--text-faint) !important; }
[data-theme="dark"] .border-b { border-color: var(--border) !important; }
[data-theme="dark"] .border-t { border-color: var(--border) !important; }
[data-theme="dark"] .border-gray-200 { border-color: var(--border) !important; }
[data-theme="dark"] .border { border-color: var(--border-input) !important; }
[data-theme="dark"] .shadow { box-shadow: var(--shadow-card) !important; }
[data-theme="dark"] .rounded-lg.shadow { background: var(--bg-card); }
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
    background: var(--bg-input) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-input) !important;
}
[data-theme="dark"] summary { color: var(--text-primary); }

/* Confidence bands */
[data-theme="dark"] .bg-green-50 { background: var(--green-bg) !important; }
[data-theme="dark"] .bg-yellow-50 { background: var(--yellow-bg) !important; }
[data-theme="dark"] .bg-red-50 { background: var(--red-bg) !important; }
[data-theme="dark"] .text-green-700 { color: var(--green-text) !important; }
[data-theme="dark"] .text-yellow-700 { color: var(--yellow-text) !important; }
[data-theme="dark"] .text-red-700 { color: var(--red-text) !important; }

/* Market/tag chips */
[data-theme="dark"] .bg-indigo-100 { background: #312e81 !important; }
[data-theme="dark"] .text-indigo-700 { color: #a5b4fc !important; }
[data-theme="dark"] .bg-purple-100 { background: #581c87 !important; }
[data-theme="dark"] .text-purple-700 { color: #c084fc !important; }

/* Footer */
.footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.25rem 0.75rem;
}
.footer-bk {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
    font-size: 0.6875rem;
    color: var(--text-muted);
    transition: color 0.15s;
}
.footer-bk:hover { color: var(--text-secondary); }
.footer-bk .bk-balance { color: var(--green); font-family: ui-monospace, SFMono-Regular, monospace; }

/* ── Theme toggle button ── */
.theme-toggle {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: rgb(209 213 219);
    transition: all 0.15s;
    background: transparent;
    border: none;
    font-size: 0.875rem;
}
.theme-toggle:hover { color: white; background: rgb(30 45 68); }
