/* Trading-terminal layout: dense 12-column grid, hairline panels, mono tabular figures. */
:root {
  --ink-0: #0a0c0f;
  --ink-1: #0f1216;
  --ink-2: #151920;
  --line: #1d222a;
  --line-2: #29303a;
  --fg: #e6e9ed;
  --fg-2: #9aa3ae;
  --fg-3: #626b77;
  --accent: #6ea8fe;
  --accent-soft: rgba(110, 168, 254, 0.14);
  --amber: #e9b04f;
  --up: #f0866a;
  --down: #4fcf9f;
  --mix-1: #6ea8fe;
  --mix-2: #3d6db8;
  --mix-3: #e9b04f;
  --mix-4: #c7cdd5;
  --font-ui: 'Geist', ui-sans-serif, -apple-system, 'SF Pro Text', system-ui, sans-serif;
  --font-num: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --r: 6px;
  --gap: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ink-0); color: var(--fg); }
body { font: 400 13px/1.45 var(--font-ui); -webkit-font-smoothing: antialiased; padding: 0 20px 28px; max-width: 1480px; margin-inline: auto; }
.mono { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--fg-2); }
.label { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-3); font-weight: 500; }
h2 { font-size: 13px; font-weight: 600; margin: 0; letter-spacing: -0.005em; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar */
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; background: var(--ink-0); border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.brand-mark { width: 18px; height: 18px; stroke: var(--accent); stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.brand-sep { color: var(--fg-3); }
.brand-page { color: var(--fg-2); }
.bar-right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.live { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--fg-2); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-3); position: relative; }
.live[data-state="live"] .live-dot { background: var(--down); }
.live[data-state="error"] .live-dot { background: var(--up); }
.live[data-state="live"] .live-dot::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 1px solid var(--down); opacity: 0; }
.clock { color: var(--fg-2); font-size: 12px; }
.auto { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg-2); cursor: pointer; }
.auto input { accent-color: var(--accent); margin: 0; }
.btn { display: inline-flex; align-items: center; gap: 7px; background: var(--ink-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 6px 10px; font-size: 12px; font-weight: 500; cursor: pointer; transition: border-color .15s, background .15s; }
.btn:hover { border-color: var(--fg-3); background: #1a1f27; }
.btn svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.btn.spinning svg { animation: spin .8s linear infinite; }
kbd { font-family: var(--font-num); font-size: 10px; color: var(--fg-3); border: 1px solid var(--line-2); border-radius: 3px; padding: 0 4px; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap); }
.panel { grid-column: span 4; background: var(--ink-1); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.chart-panel { grid-column: span 8; }
.window-panel { grid-column: span 4; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-note { margin: 3px 0 0; color: var(--fg-3); font-size: 12px; }
.footnote { margin: 12px 0 0; color: var(--fg-3); font-size: 12px; }

/* Tickers */
.tickers { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r); background: var(--ink-1); }
.tick { padding: 14px 16px 12px; border-left: 1px solid var(--line); min-width: 0; }
.tick:first-child { border-left: 0; }
.tick-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tick-value { font-size: 30px; font-weight: 500; margin: 6px 0 6px; line-height: 1.1; transition: color .6s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tick-value.bump { color: var(--accent); transition: none; }
.tick-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; font-size: 12px; }
.tick-foot .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark { width: 96px; height: 28px; flex: none; overflow: visible; }
.chip { font-family: var(--font-num); font-size: 11px; padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.chip:empty { display: none; }
.chip.up { color: var(--up); background: rgba(240, 134, 106, 0.1); }
.chip.down { color: var(--down); background: rgba(79, 207, 159, 0.1); }

/* Segmented controls */
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r); padding: 2px; background: var(--ink-0); }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 4px; font-size: 12px; color: var(--fg-2); cursor: pointer; font-weight: 500; }
.seg button[aria-selected="true"] { background: var(--ink-2); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg button:hover { color: var(--fg); }

/* Chart */
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--fg-2); margin: -4px 0 8px; min-height: 18px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 2px; display: inline-block; background: var(--accent); }
.legend i.dash { background: repeating-linear-gradient(90deg, var(--amber) 0 4px, transparent 4px 7px); }
.legend i.sq { height: 8px; width: 8px; border-radius: 2px; }
.legend b { font-family: var(--font-num); font-weight: 500; color: var(--fg); }
.chart { position: relative; height: 320px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.axis text { fill: var(--fg-3); font: 11px var(--font-num); }
.axis line, .axis path { stroke: none; }
.gridline { stroke: var(--line); stroke-width: 1; }
.now-dot { fill: var(--accent); }
.now-ring { fill: none; stroke: var(--accent); }
.crosshair { stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 3 3; }

/* Tooltip */
.tip { position: fixed; z-index: 10; pointer-events: none; background: #11151b; border: 1px solid var(--line-2); border-radius: var(--r); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); padding: 8px 10px; font-size: 12px; min-width: 150px; }
.tip-h { color: var(--fg-3); margin-bottom: 4px; font-family: var(--font-num); font-size: 11px; }
.tip-r { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.tip-r span { display: inline-flex; align-items: center; gap: 6px; color: var(--fg-2); }
.tip-r b { font-family: var(--font-num); font-weight: 500; }
.tip-r i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Window gauge */
.pill { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line-2); color: var(--fg-2); }
.pill.on { color: var(--down); border-color: rgba(79, 207, 159, 0.35); }
.gauge { position: relative; width: min(100%, 260px); margin: 0 auto 8px; }
.gauge-svg { width: 100%; display: block; }
.gauge-track { fill: none; stroke: var(--line); stroke-width: 10; stroke-linecap: round; }
.gauge-fill { fill: none; stroke: var(--amber); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 0 100; transition: stroke-dasharray .8s cubic-bezier(.2, .8, .2, 1); }
.gauge-center { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; }
.gauge-time { font-size: 26px; font-weight: 500; margin-top: 2px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 8px 0 16px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stats div { min-width: 0; }
.stats dt { font-size: 11px; color: var(--fg-3); }
.stats dd { margin: 2px 0 0; font-size: 16px; font-weight: 500; }
.sub-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.windows { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.windows li { display: grid; grid-template-columns: 92px 1fr 64px; gap: 10px; align-items: center; font-size: 12px; }
.windows .when { color: var(--fg-2); font-family: var(--font-num); font-size: 11px; white-space: nowrap; }
.windows .track, .windows .fill, .share .fill { display: block; }
.windows .track { height: 6px; background: var(--ink-2); border-radius: 3px; overflow: hidden; }
.windows .fill { height: 100%; background: var(--fg-3); border-radius: 3px; }
.windows li.active .fill { background: var(--amber); }
.windows li.active .when { color: var(--fg); }
.windows .n { text-align: right; font-family: var(--font-num); }

/* Allocation */
.alloc { display: flex; height: 10px; border-radius: 3px; overflow: hidden; gap: 2px; margin-bottom: 14px; background: var(--ink-2); }
.alloc span { height: 100%; transition: flex-grow .6s; min-width: 2px; }
.alloc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.alloc-list li { display: grid; grid-template-columns: 10px 1fr auto 52px; gap: 10px; align-items: center; }
.alloc-list i { width: 10px; height: 10px; border-radius: 2px; }
.alloc-list .n { font-family: var(--font-num); }
.alloc-list .pct { font-family: var(--font-num); color: var(--fg-3); text-align: right; }

/* Tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.tbl th { text-align: left; font-size: 11px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; color: var(--fg-3); padding: 0 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th:first-child, .tbl td:first-child { padding-left: 0; }
.tbl th:last-child, .tbl td:last-child { padding-right: 0; }
.tbl .num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.tbl th.num { font-family: var(--font-ui); }
.tbl td.name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.tbl tbody tr:hover td { background: rgba(255, 255, 255, 0.015); }
.share { display: inline-flex; align-items: center; gap: 8px; }
.share .track { width: 48px; height: 4px; background: var(--ink-2); border-radius: 2px; overflow: hidden; }
.share .fill { height: 100%; background: var(--accent); }
.mini { width: 64px; height: 18px; vertical-align: middle; }
.scroll { max-height: 420px; overflow: auto; }
.stmt thead th { position: sticky; top: 0; background: var(--ink-1); z-index: 1; }
.stmt .bar-col { width: 22%; }
.stmt .rowbar { height: 6px; border-radius: 3px; background: var(--accent-soft); overflow: hidden; }
.stmt .rowbar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.stmt tr.current td:first-child { color: var(--accent); }

.foot { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; color: var(--fg-3); font-size: 11.5px; padding-top: 16px; }

/* Responsive */
@media (max-width: 1100px) {
  .chart-panel, .window-panel { grid-column: 1 / -1; }
  .panel { grid-column: span 6; }
  .panel.wide, .panel.projects-panel { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  body { padding: 0 16px 24px; }
  .tickers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tick:nth-child(3) { border-left: 0; }
  .tick:nth-child(n+3) { border-top: 1px solid var(--line); }
  .panel { grid-column: 1 / -1; }
  .chart { height: 260px; }
  .hide-sm { display: none; }
  .tick-value { font-size: 24px; }
}

@media (prefers-reduced-motion: no-preference) {
  .live[data-state="live"] .live-dot::after { animation: ping 2.4s cubic-bezier(0, 0, .2, 1) infinite; }
  .now-ring { animation: ring 2.4s ease-out infinite; transform-box: fill-box; transform-origin: center; }
  .panel, .tickers { animation: rise .5s cubic-bezier(.2, .8, .2, 1) both; }
  .grid > :nth-child(2) { animation-delay: .04s; }
  .grid > :nth-child(3) { animation-delay: .08s; }
  .grid > :nth-child(n+4) { animation-delay: .12s; }
}
@keyframes ping { 0% { transform: scale(.6); opacity: .9; } 80%, 100% { transform: scale(1.8); opacity: 0; } }
@keyframes ring { 0% { transform: scale(1); opacity: .8; } 100% { transform: scale(3); opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Source tabs */
.tabs { display: flex; gap: 2px; margin: -4px 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { position: relative; display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 10px 14px 12px; font-size: 13px; font-weight: 500; color: var(--fg-2); cursor: pointer; white-space: nowrap; }
.tabs button:hover { color: var(--fg); }
.tabs button[aria-selected="true"] { color: var(--fg); }
.tabs button[aria-selected="true"]::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px 2px 0 0; }
.tabs kbd { margin-left: 2px; opacity: .7; }
.tab-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-3); }
.tab-dot.ok { background: var(--down); }
.tab-dot.off { background: transparent; box-shadow: inset 0 0 0 1px var(--fg-3); }
.tab-dot.busy { background: var(--amber); }
.tab-dot.err { background: var(--up); }

/* Window panel extras */
.gauge-sub { text-align: center; color: var(--fg-2); font-size: 12px; margin: 0 0 4px; min-height: 18px; }
.gauge-fill.hot { stroke: var(--up); }

/* API setup / empty state */
.setup-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.setup-title { font-size: 20px; font-weight: 500; margin: 6px 0 8px; letter-spacing: -0.01em; }
.setup-text { color: var(--fg-2); margin: 0 0 14px; max-width: 60ch; }
.steps { margin: 0; padding-left: 18px; display: grid; gap: 8px; color: var(--fg-2); }
.steps b { color: var(--fg); font-weight: 500; }
.steps code, .setup-text code { font-family: var(--font-num); font-size: 12px; color: var(--fg); background: var(--ink-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.code { margin: 0; background: var(--ink-0); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; font-size: 12px; line-height: 1.7; color: var(--fg-2); overflow-x: auto; white-space: pre; }
.code .k { color: var(--accent); }
.setup.error .setup-title { color: var(--up); }

/* Line items */
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.items li { display: grid; gap: 6px; }
.items .row { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.items .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); }
.items .n { font-family: var(--font-num); white-space: nowrap; }
.items .track { display: block; height: 4px; background: var(--ink-2); border-radius: 2px; overflow: hidden; }
.items .fill { display: block; height: 100%; background: var(--amber); border-radius: 2px; }
.empty-line { color: var(--fg-3); font-size: 12.5px; }
.scroll.short { max-height: 320px; }

@media (max-width: 760px) {
  .setup-body { grid-template-columns: 1fr; }
}

[hidden] { display: none !important; }
a { color: var(--accent); text-decoration-color: rgba(110, 168, 254, 0.4); text-underline-offset: 2px; }

/* Custom range button + picker */
.custom-btn { display: inline-flex; align-items: center; gap: 6px; max-width: 220px; }
.custom-btn svg { width: 13px; height: 13px; flex: none; stroke: currentColor; stroke-width: 1.4; fill: none; stroke-linecap: round; }
.custom-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop { position: absolute; z-index: 20; display: grid; grid-template-columns: 150px minmax(0, 1fr); width: min(460px, calc(100vw - 32px)); background: #11151b; border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55); overflow: hidden; }
.pop-presets { display: grid; align-content: start; padding: 8px; border-right: 1px solid var(--line); gap: 2px; }
.pop-presets button { text-align: left; border: 0; background: none; padding: 6px 8px; border-radius: 4px; font-size: 12.5px; color: var(--fg-2); cursor: pointer; }
.pop-presets button:hover, .pop-presets button:focus-visible { background: var(--ink-2); color: var(--fg); }
.pop-main { display: grid; gap: 12px; padding: 14px; align-content: start; }
.field { display: grid; gap: 5px; }
.field input { font: 13px var(--font-num); color: var(--fg); background: var(--ink-0); border: 1px solid var(--line-2); border-radius: var(--r); padding: 7px 9px; color-scheme: dark; min-width: 0; }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pop-hint { margin: 0; min-height: 17px; font-size: 12px; color: var(--fg-3); }
.pop-hint.bad { color: var(--up); }
.pop-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0a0c0f; }
.btn.primary:hover { background: #8bbaff; border-color: #8bbaff; }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.range-chip { font-family: var(--font-num); font-size: 11px; color: var(--fg-2); }
@media (max-width: 520px) { .pop { grid-template-columns: 1fr; } .pop-presets { grid-template-columns: repeat(2, 1fr); border-right: 0; border-bottom: 1px solid var(--line); } }

/* Chart style toggle */
.icon-seg button { display: inline-flex; align-items: center; gap: 6px; }
.icon-seg svg { width: 13px; height: 13px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 980px) { .icon-seg span { display: none; } }
.tick .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* Phone: one-row header, no keyboard hints, cards that fit */
@media (max-width: 760px) {
  .bar { flex-wrap: nowrap; padding: 10px 0; gap: 10px; margin-bottom: 10px; }
  .brand-sep, .brand-page, .clock, kbd { display: none; }
  .bar-right { gap: 12px; flex-wrap: nowrap; }
  .live-label { max-width: 9.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .auto span { display: none; }
  #refresh { padding: 7px; font-size: 0; gap: 0; }
  #refresh svg { width: 16px; height: 16px; }
  .tabs { margin-bottom: 12px; }
  .tabs button { padding: 10px 10px 12px; }
  .tick { padding: 12px; }
  .tick .label { white-space: normal; overflow: visible; line-height: 1.3; }
  .tick-head { align-items: flex-start; flex-wrap: wrap; gap: 4px 8px; }
  .tick-foot { flex-direction: column; align-items: stretch; gap: 6px; }
  .tick-foot .muted { white-space: normal; }
  .spark { width: 100%; height: 26px; }
  .controls { width: 100%; }
  .chart { height: 240px; }
  .panel { padding: 14px; }
}

/* Phone link */
#phone-btn svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.4; fill: none; stroke-linecap: round; }
.btn.icon { padding: 6px; }
.btn.icon svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; }
.modal-back { position: fixed; inset: 0; z-index: 30; background: rgba(5, 6, 8, 0.72); display: grid; place-items: center; padding: 16px; }
.modal { width: min(420px, 100%); background: var(--ink-1); border: 1px solid var(--line-2); border-radius: 10px; padding: 18px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal h2 { font-size: 15px; }
.qr { background: #fff; border-radius: 8px; padding: 14px; width: 232px; height: 232px; margin: 4px auto 14px; display: grid; place-items: center; }
.qr svg { width: 100%; height: 100%; display: block; }
.phone-steps { margin: 0 0 12px; padding-left: 18px; display: grid; gap: 6px; color: var(--fg-2); }
.phone-steps b { color: var(--fg); font-weight: 500; }
.phone-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.phone-note { color: var(--fg-3); font-size: 12px; margin: 12px 0 0; }
.phone-note code { font-family: var(--font-num); font-size: 11px; color: var(--fg-2); }
@media (max-width: 760px) { #phone-btn { display: none; } }
