:root {
    color-scheme: dark;
    --bg: #080d14;
    --surface: #0d141e;
    --surface-2: #111b28;
    --surface-3: #172332;
    --line: rgba(148, 163, 184, .14);
    --line-strong: rgba(148, 163, 184, .26);
    --text: #e7edf5;
    --muted: #8997aa;
    --accent: #27d7a1;
    --accent-soft: rgba(39, 215, 161, .12);
    --cyan: #46bcec;
    --danger: #f05d72;
    --danger-soft: rgba(240, 93, 114, .12);
    --warning: #f1b84b;
    --shadow: 0 16px 40px rgba(0, 0, 0, .24);
    --topbar-height: 58px;
}

html[data-theme="light"] {
    color-scheme: light;
    --bg: #f3f6f9;
    --surface: #ffffff;
    --surface-2: #f7f9fb;
    --surface-3: #edf2f6;
    --line: rgba(21, 38, 56, .10);
    --line-strong: rgba(21, 38, 56, .20);
    --text: #17212d;
    --muted: #617083;
    --accent: #0b9f77;
    --accent-soft: rgba(11, 159, 119, .10);
    --cyan: #087da9;
    --danger: #d94159;
    --danger-soft: rgba(217, 65, 89, .10);
    --warning: #a86a00;
    --shadow: 0 14px 34px rgba(37, 54, 71, .10);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 13px;
    overflow: hidden;
}
button, input, select { color: inherit; font: inherit; }
button, select { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.terminal {
    min-height: 100vh;
    height: 100vh;
    display: grid;
    grid-template-rows: var(--topbar-height) 44px minmax(0, 1fr) 28px;
    background:
        radial-gradient(circle at 65% -20%, rgba(39, 215, 161, .07), transparent 32%),
        var(--bg);
}

.topbar {
    z-index: 5;
    display: grid;
    grid-template-columns: 210px minmax(190px, 300px) minmax(180px, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
    display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
    background: linear-gradient(145deg, var(--accent), #1189a8); color: #03130e; font-weight: 950; font-size: 17px;
    box-shadow: 0 0 28px rgba(39, 215, 161, .20);
}
.brand strong, .brand small { display: block; white-space: nowrap; }
.brand strong { font-size: 14px; letter-spacing: .01em; }
.brand small { color: var(--muted); font-size: 10px; margin-top: 1px; }

.symbol-search { display: flex; height: 34px; }
.symbol-search input {
    min-width: 0; width: 100%; border: 1px solid var(--line-strong); border-right: 0; border-radius: 8px 0 0 8px;
    background: var(--surface-2); padding: 0 11px; text-transform: uppercase; font-weight: 800; outline: none;
}
.symbol-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.symbol-search .icon-btn { border-radius: 0 8px 8px 0; min-width: 48px; }

.live-quote { display: flex; align-items: center; gap: 8px; min-width: 0; }
.live-quote strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.live-quote small { font-weight: 750; color: var(--muted); }
.live-quote.positive small { color: var(--accent); }
.live-quote.negative small { color: var(--danger); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); flex: 0 0 auto; }
.top-actions { display: flex; gap: 6px; }
.icon-btn, .text-btn, .panel-title button {
    border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; height: 34px; min-width: 34px; padding: 0 10px;
}
.icon-btn:hover, .text-btn:hover, .panel-title button:hover { border-color: var(--accent); background: var(--accent-soft); }
.icon-btn.accent { background: var(--accent); border-color: var(--accent); color: #04150f; font-weight: 900; }

.timeframe-bar {
    z-index: 4; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 5px 14px;
    border-bottom: 1px solid var(--line); background: var(--surface);
}
.timeframes { display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.timeframes::-webkit-scrollbar { display: none; }
.timeframes button {
    height: 30px; min-width: 38px; padding: 0 8px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-weight: 800;
}
.timeframes button:hover { color: var(--text); background: var(--surface-3); }
.timeframes button.active { color: var(--accent); background: var(--accent-soft); }
.toolbar-selects { display: flex; align-items: center; gap: 6px; }
.toolbar-selects label { position: relative; display: block; font-size: 0; }
.toolbar-selects select, .text-btn {
    height: 30px; max-width: 142px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); padding: 0 26px 0 9px; font-size: 11px; font-weight: 750;
}
.toolbar-selects option, .toolbar-selects optgroup { background: var(--surface); color: var(--text); }
.text-btn { padding: 0 9px; color: var(--muted); }

.workspace {
    min-height: 0; display: grid; grid-template-columns: 182px minmax(0, 1fr) 292px; gap: 8px; padding: 8px;
}
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.panel-title {
    min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px;
    border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 900; letter-spacing: .07em; text-transform: uppercase;
}
.panel-title button { height: 26px; min-width: 26px; padding: 0; color: var(--muted); }
.mini-status { color: var(--warning); font-size: 9px; letter-spacing: .02em; }
.mini-status.ready { color: var(--accent); }

.watchlist { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.watchlist-items { min-height: 0; overflow: auto; padding: 5px; }
.watch-item {
    width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 7px; padding: 9px 8px; margin: 0 0 3px;
    border: 1px solid transparent; border-radius: 7px; background: transparent; text-align: left;
}
.watch-item:hover { background: var(--surface-2); }
.watch-item.active { background: var(--accent-soft); border-color: rgba(39, 215, 161, .25); }
.watch-item strong { font-size: 11px; }
.watch-item span { font-variant-numeric: tabular-nums; font-weight: 750; }
.watch-item small { color: var(--muted); font-size: 9px; }
.watch-item em { font-style: normal; font-size: 9px; text-align: right; }
.watch-item em.positive { color: var(--accent); }
.watch-item em.negative { color: var(--danger); }
.market-pulse { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); background: var(--surface-2); }
.market-pulse small, .market-pulse span, .market-pulse strong { display: block; }
.market-pulse small, .market-pulse span { color: var(--muted); font-size: 9px; }
.market-pulse strong { margin: 4px 0 2px; font-size: 11px; }

.chart-column { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 6px; }
.indicator-chips { min-height: 27px; display: flex; align-items: center; gap: 5px; overflow-x: auto; }
.indicator-chip {
    flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 5px 0 8px;
    border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--muted); font-size: 10px; font-weight: 800;
}
.indicator-chip button { width: 18px; height: 18px; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--muted); }
.indicator-chip button:hover { background: var(--danger-soft); color: var(--danger); }
.chart-wrap { position: relative; min-height: 0; overflow: hidden; }
.chart { position: absolute; inset: 0; }
.chart-loader, .chart-error {
    position: absolute; inset: 0; z-index: 3; display: grid; align-content: center; justify-items: center; gap: 10px;
    background: color-mix(in srgb, var(--surface) 94%, transparent); text-align: center;
}
.chart-error[hidden] { display: none; }
.chart-loader span { width: 26px; height: 26px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.chart-loader strong, .chart-error strong { font-size: 12px; }
.chart-error span { max-width: 340px; color: var(--muted); font-size: 11px; }
.chart-error button { height: 32px; padding: 0 14px; border: 1px solid var(--accent); border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.chart-status {
    position: absolute; z-index: 2; right: 9px; bottom: 7px; display: flex; align-items: center; gap: 7px; padding: 4px 7px;
    border: 1px solid var(--line); border-radius: 6px; background: color-mix(in srgb, var(--surface) 82%, transparent); color: var(--muted); font-size: 9px;
    pointer-events: none;
}
.status-pill { color: var(--accent); font-weight: 900; letter-spacing: .05em; }
.status-pill.connecting { color: var(--warning); }
.status-pill.error { color: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }

.intelligence { min-width: 0; overflow: auto; }
.score-card { display: grid; grid-template-columns: 72px minmax(0, 1fr); align-items: center; gap: 12px; padding: 14px 12px; }
.score-ring {
    --score: 0; width: 68px; height: 68px; display: grid; place-content: center; grid-template-columns: auto auto; align-items: baseline;
    border-radius: 50%; background: radial-gradient(circle, var(--surface) 57%, transparent 59%), conic-gradient(var(--accent) calc(var(--score) * 1%), var(--surface-3) 0);
}
.score-ring strong { font-size: 21px; font-variant-numeric: tabular-nums; }
.score-ring span { color: var(--muted); font-size: 9px; }
.score-card > div:last-child small, .score-card > div:last-child strong, .score-card > div:last-child span { display: block; }
.score-card > div:last-child small { color: var(--muted); font-size: 9px; }
.score-card > div:last-child strong { margin: 4px 0; font-size: 13px; }
.score-card > div:last-child span { color: var(--cyan); font-size: 10px; }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 0 10px 10px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.metric-grid div { min-width: 0; padding: 9px; background: var(--surface-2); }
.metric-grid small, .metric-grid strong { display: block; }
.metric-grid small { color: var(--muted); font-size: 9px; }
.metric-grid strong { margin-top: 4px; font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.intel-section { padding: 11px 12px; border-top: 1px solid var(--line); }
.intel-section h2 { margin: 0 0 9px; color: var(--muted); font-size: 9px; letter-spacing: .07em; text-transform: uppercase; }
.level-row, .risk-plan div { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 10px; }
.level-row span, .risk-plan span { color: var(--muted); }
.level-row strong, .risk-plan strong { font-variant-numeric: tabular-nums; }
.risk-plan p { margin: 8px 0 0; color: var(--muted); font-size: 9px; line-height: 1.45; }
.rationale ul { margin: 0; padding: 0 0 0 14px; color: var(--muted); font-size: 10px; line-height: 1.5; }
.rationale li + li { margin-top: 5px; }
.ask-button {
    width: calc(100% - 24px); min-height: 36px; margin: 2px 12px 13px; padding: 7px 10px; border: 1px solid var(--accent); border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #21a9be); color: #03150f; font-size: 11px; font-weight: 900;
}

.terminal-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; }
.terminal-footer span { display: flex; align-items: center; gap: 7px; }
.terminal-footer .live-dot { width: 5px; height: 5px; }
.toast {
    position: fixed; z-index: 20; left: 50%; bottom: 40px; translate: -50% 16px; max-width: min(90vw, 420px); padding: 9px 13px;
    border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface-3); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .18s ease;
}
.toast.visible { opacity: 1; translate: -50% 0; }

@media (max-width: 1100px) {
    .workspace { grid-template-columns: minmax(0, 1fr) 270px; }
    .watchlist { display: none; }
    .topbar { grid-template-columns: 44px minmax(150px, 250px) minmax(150px, 1fr) auto; }
    .brand > span:last-child { display: none; }
}
@media (max-width: 760px) {
    :root { --topbar-height: 54px; }
    body { overflow: auto; }
    .terminal { height: auto; min-height: 100dvh; grid-template-rows: var(--topbar-height) auto auto 28px; }
    .topbar { grid-template-columns: minmax(138px, 1fr) auto auto; gap: 6px; padding: 0 8px; }
    .brand { display: none; }
    .live-quote { justify-content: center; }
    .live-quote strong { font-size: 14px; }
    .live-quote small { font-size: 9px; }
    .top-actions .icon-btn:first-child { display: none; }
    .timeframe-bar { align-items: stretch; flex-direction: column; gap: 4px; padding: 5px 8px; }
    .toolbar-selects { overflow-x: auto; }
    .workspace { display: flex; flex-direction: column; min-height: 0; padding: 6px; }
    .chart-column { order: 1; height: min(68dvh, 570px); min-height: 410px; }
    .intelligence { order: 2; max-height: none; box-shadow: none; }
    .watchlist { display: none; }
    .indicator-chips { min-height: 26px; }
    .chart-status { bottom: 5px; }
    .terminal-footer span:nth-child(2) { display: none; }
}
@media (max-width: 430px) {
    .topbar { grid-template-columns: minmax(122px, 1fr) minmax(110px, auto) auto; }
    .symbol-search .icon-btn { min-width: 40px; padding: 0 7px; }
    .live-quote { display: block; text-align: right; }
    .live-quote .live-dot { display: none; }
    .top-actions .icon-btn:nth-child(2) { display: none; }
    .metric-grid { grid-template-columns: repeat(4, 1fr); }
    .metric-grid div { padding: 8px 5px; }
}
