/* Palette: white/light surfaces, ink text, blue accent — matches the WealthSmith reference theme.
   Dark mode overrides these same tokens further down — see "Dark mode" section. */
:root {
    color-scheme: light;

    --bg: #f6f7fa;
    --bg-2: #eef1f5;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --border: #e7eaf0;
    --border-2: #d7dce5;
    --text: #0c1524;
    --text-muted: #667085;
    --text-faint: #98a2b3;
    --accent: #2f5fe8;
    --accent-dim: #2249c4;
    --accent-soft: #eef2ff;
    --accent-light: #7fa8ff;
    --accent-secondary: #4f46e5;
    --accent-border: #dbeafe;
    --success: #12b76a;
    --success-soft: #ecfdf3;
    --danger: #f04438;
    --danger-soft: #fef3f2;
    --danger-border: #fecaca;
    --danger-dim: #dc2626;
    --chart-secondary: #f59e0b;
    --on-accent: #ffffff;
    --overlay-blur: rgba(255, 255, 255, 0.75);
    --overlay-blur-strong: rgba(255, 255, 255, 0.85);
    --skel-shine: rgba(255, 255, 255, 0.7);

    /* Glass surfaces — same hue as --surface, just translucent, paired with
       backdrop-filter blur on the elements that use them (see dashboard.css). */
    --surface-glass: rgba(255, 255, 255, 0.6);
    --surface-glass-strong: rgba(255, 255, 255, 0.78);
    --glass-blur: 20px;

    /* Categorical series palette (validated: node scripts/validate_palette.js —
       see dataviz skill). Fixed hue-per-category, never reassigned by rank —
       used by the Exposure Allocation donut chart. */
    --series-equity-domestic: #2a78d6;
    --series-equity-intl: #eb6834;
    --series-debt: #1baf7a;
    --series-gold: #eda100;
    --series-liquid: #e87ba4;
    --series-silver: #008300;
    --series-hybrid: #4a3aa7;
    --series-commodity: #e34948;
    --series-other: #98a2b3;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, 0.08), 0 2px 6px -2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 16px 32px -8px rgba(16, 24, 40, 0.16), 0 4px 10px -4px rgba(16, 24, 40, 0.06);
    --shadow-blue: 0 8px 20px -6px rgba(47, 95, 232, 0.3);

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode — follows system preference by default; [data-theme] on <html>
   (set by theme.js, persisted in localStorage) overrides it explicitly in
   either direction. See static/theme.js for the toggle + no-flash init. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0a0e14;
        --bg-2: #121722;
        --surface: #161d29;
        --surface-raised: #1b2330;
        --border: #232b3a;
        --border-2: #303a4d;
        --text: #e8ecf3;
        --text-muted: #98a2b3;
        --text-faint: #64748b;
        --accent: #5b8def;
        --accent-dim: #7ba3f2;
        --accent-soft: #16233d;
        --accent-light: #5b8def;
        --accent-secondary: #7c6ff0;
        --accent-border: #2a3b5c;
        --success: #3ddc91;
        --success-soft: #0f2a1e;
        --danger: #ff6b6b;
        --danger-soft: #2f1518;
        --danger-border: #4a2328;
        --danger-dim: #ff8787;
        --chart-secondary: #fbbf24;
        --on-accent: #ffffff;
        --overlay-blur: rgba(10, 14, 20, 0.75);
        --overlay-blur-strong: rgba(10, 14, 20, 0.85);
        --skel-shine: rgba(255, 255, 255, 0.08);
        --surface-glass: rgba(22, 29, 41, 0.55);
        --surface-glass-strong: rgba(22, 29, 41, 0.72);
        --glass-blur: 20px;

        --series-equity-domestic: #3987e5;
        --series-equity-intl: #d95926;
        --series-debt: #199e70;
        --series-gold: #c98500;
        --series-liquid: #d55181;
        --series-silver: #008300;
        --series-hybrid: #9085e9;
        --series-commodity: #e66767;
        --series-other: #64748b;

        --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.32), 0 1px 2px rgba(0, 0, 0, 0.24);
        --shadow-md: 0 4px 14px -2px rgba(0, 0, 0, 0.4), 0 2px 6px -2px rgba(0, 0, 0, 0.28);
        --shadow-lg: 0 20px 36px -8px rgba(0, 0, 0, 0.5), 0 4px 12px -4px rgba(0, 0, 0, 0.3);
        --shadow-blue: 0 8px 20px -6px rgba(91, 141, 239, 0.35);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0a0e14;
    --bg-2: #121722;
    --surface: #161d29;
    --surface-raised: #1b2330;
    --border: #232b3a;
    --border-2: #303a4d;
    --text: #e8ecf3;
    --text-muted: #98a2b3;
    --text-faint: #64748b;
    --accent: #5b8def;
    --accent-dim: #7ba3f2;
    --accent-soft: #16233d;
    --accent-light: #5b8def;
    --accent-secondary: #7c6ff0;
    --accent-border: #2a3b5c;
    --success: #3ddc91;
    --success-soft: #0f2a1e;
    --danger: #ff6b6b;
    --danger-soft: #2f1518;
    --danger-border: #4a2328;
    --danger-dim: #ff8787;
    --chart-secondary: #fbbf24;
    --on-accent: #ffffff;
    --overlay-blur: rgba(10, 14, 20, 0.75);
    --overlay-blur-strong: rgba(10, 14, 20, 0.85);
    --skel-shine: rgba(255, 255, 255, 0.08);
    --surface-glass: rgba(22, 29, 41, 0.55);
    --surface-glass-strong: rgba(22, 29, 41, 0.72);
    --glass-blur: 20px;

    --series-equity-domestic: #3987e5;
    --series-equity-intl: #d95926;
    --series-debt: #199e70;
    --series-gold: #c98500;
    --series-liquid: #d55181;
    --series-silver: #008300;
    --series-hybrid: #9085e9;
    --series-commodity: #e66767;
    --series-other: #64748b;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.32), 0 1px 2px rgba(0, 0, 0, 0.24);
    --shadow-md: 0 4px 14px -2px rgba(0, 0, 0, 0.4), 0 2px 6px -2px rgba(0, 0, 0, 0.28);
    --shadow-lg: 0 20px 36px -8px rgba(0, 0, 0, 0.5), 0 4px 12px -4px rgba(0, 0, 0, 0.3);
    --shadow-blue: 0 8px 20px -6px rgba(91, 141, 239, 0.35);
}

* {
    box-sizing: border-box;
}

html {
    max-width: 100%;
}

body {
    margin: 0;
    max-width: 100%;
    background:
        radial-gradient(1100px 600px at 90% -10%, var(--accent-soft), transparent 60%),
        radial-gradient(900px 500px at -10% 30%, var(--success-soft), transparent 55%),
        var(--bg);
    color: var(--text);
    transition: background 0.2s var(--ease), color 0.2s var(--ease);
    font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: "tnum" 1, "cv11" 1;
}

::selection {
    background: var(--accent-soft);
    color: var(--accent-dim);
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border-2);
    border-radius: var(--radius-full);
    border: 2px solid var(--bg);
}

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

.auth-link-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
}

.auth-link-btn:hover {
    color: var(--text);
}

.mode-toggle {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 3px;
    margin-bottom: 20px;
}

.mode-btn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: 6px;
    padding: 7px 16px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

.mode-btn.active {
    background: var(--accent);
    color: var(--on-accent);
}

.mode-btn:not(.active):hover {
    color: var(--text);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.controls #fetch-btn {
    flex-shrink: 0;
}

.quote-ltp-label {
    font-size: 12px;
    color: var(--text-muted);
    text-align: right;
}

.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 200px;
}

input, button {
    font-family: inherit;
    font-size: 15px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 10px 14px;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}

input {
    width: 100%;
    background: var(--surface);
    color: var(--text);
}

input::placeholder {
    color: var(--text-faint);
}

input:disabled {
    color: var(--text-muted);
    background: var(--bg-2);
}

input:hover:not(:disabled):not(:focus) {
    border-color: var(--border-2);
}

input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3.5px var(--accent-soft);
}

/* <select> had no styling anywhere in the app — a bare browser-default
   dropdown sitting next to a styled input looks broken. Matches input's
   shape/border/focus ring; appearance:none + a hand-drawn chevron replaces
   the native arrow (inconsistent across browsers, invisible in dark mode
   otherwise) with one that respects theme colors. */
select {
    font-family: inherit;
    font-size: 15px;
    color: var(--text);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 38px 10px 14px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none' stroke='%2398a2b3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='5 8 10 13 15 8'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}

select:hover:not(:disabled):not(:focus) {
    border-color: var(--border-2);
}

select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3.5px var(--accent-soft);
}

select:disabled {
    color: var(--text-muted);
    background-color: var(--bg-2);
    cursor: not-allowed;
}

.suggestions {
    list-style: none;
    margin: 8px 0 0;
    padding: 6px;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 320px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 10;
}

.suggestions.hidden {
    display: none;
}

.suggestions li {
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    transition: background 0.1s var(--ease);
}

.suggestions li .sugg-symbol {
    font-weight: 600;
    white-space: nowrap;
}

.suggestions li .sugg-name {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.suggestions li:hover,
.suggestions li.active {
    background: var(--accent-soft);
}

.suggestions li:hover .sugg-name,
.suggestions li.active .sugg-name {
    color: var(--accent-dim);
}

.suggestions .no-results {
    padding: 8px 10px;
    color: var(--text-muted);
    font-size: 14px;
    cursor: default;
}

button {
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.1s var(--ease);
}

button:hover:not(:disabled) {
    background: var(--accent-dim);
    box-shadow: var(--shadow-blue);
}

button:active:not(:disabled) {
    transform: translateY(1px);
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:disabled {
    background: var(--bg-2);
    color: var(--text-faint);
    cursor: not-allowed;
}

.status {
    min-height: 20px;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.status.error {
    color: var(--danger);
}

.status.warning {
    color: var(--chart-secondary);
}

.quote-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.quote-card.hidden {
    display: none;
}

.quote-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.quote-symbol {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.quote-name {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

.quote-ltp-block {
    text-align: right;
}

.quote-ltp {
    font-size: 26px;
    font-weight: 700;
    color: var(--accent);
}

.quote-change {
    font-size: 13px;
    margin-top: 2px;
    color: var(--text-muted);
}

.quote-change.up {
    color: var(--success);
}

.quote-change.down {
    color: var(--danger);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px 24px;
}

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

.metric {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border);
}

.metric-label {
    color: var(--text-muted);
}

.metric-value {
    font-weight: 600;
}

/* Chart section */

.chart-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.period-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.period-chip {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 5px 13px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s var(--ease);
}

.period-chip:hover:not(.active) {
    color: var(--text);
    border-color: var(--border-2);
    background: var(--bg-2);
}

.period-chip.active {
    background: var(--accent);
    color: var(--on-accent);
    border-color: var(--accent);
    box-shadow: var(--shadow-blue);
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 260px;
}

#price-chart {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
}

.chart-tooltip {
    position: absolute;
    top: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 11px;
    pointer-events: none;
    box-shadow: var(--shadow-lg);
    white-space: nowrap;
}

.chart-tooltip.hidden {
    display: none;
}

.chart-tooltip-date {
    font-size: 11px;
    color: var(--text-muted);
}

.chart-tooltip-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

/* Insights (stat tiles) */

.insights-grid {
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.stat-tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 13px;
    transition: border-color 0.15s var(--ease);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

.stat-value {
    font-size: 15px;
    font-weight: 700;
}

.stat-value.up {
    color: var(--success);
}

.stat-value.down {
    color: var(--danger);
}

@media (max-width: 480px) {
    .insights-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
