:root {
  --bg: #101113;
  --panel: #181a1d;
  --soft: #222529;
  --border: #303338;
  --text: #f0f2f4;
  --muted: #93999f;
  --accent: #8be0c2;
  --up: #5ed3ae;
  --down: #ff7c87;
  --warning: #edce72;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; letter-spacing: 0; }
body { overflow: hidden; }
button, input, select { font: inherit; color: inherit; min-width: 0; }
button, input, select { border: 1px solid var(--border); border-radius: 6px; background: var(--panel); min-height: 40px; padding: 8px 12px; font-size: 13px; }
button, select { cursor: pointer; }
button:hover, select:hover { background: var(--soft); }
button:disabled { opacity: .5; cursor: wait; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #10241e; font-weight: 700; }
button.primary:hover { background: #a1e9d0; }
button.icon-button { width: 40px; height: 40px; padding: 9px; display: inline-flex; align-items: center; justify-content: center; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.muted { color: var(--muted); }
.hidden, [hidden] { display: none !important; }
.error, #auth-error, [data-direction="down"] { color: var(--down); }
[data-direction="up"] { color: var(--up); }
[data-state="fresh"] { color: var(--up); }
[data-state="stale"], [data-state="degraded"] { color: var(--warning); }
[data-state="unknown"], [data-state="empty"] { color: var(--muted); }
#app-shell { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
.app-header { flex: 0 0 auto; min-height: 60px; padding: calc(8px + env(safe-area-inset-top)) 20px 8px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); }
.brand, .header-actions { display: flex; align-items: center; gap: 10px; }
.brand { font-size: 15px; font-weight: 700; white-space: nowrap; }
.brand-mark { display: inline-flex; width: 30px; height: 30px; justify-content: center; align-items: center; border: 1px solid var(--accent); border-radius: 6px; color: var(--accent); font-weight: 800; }
.health-button { display: flex; align-items: center; gap: 10px; }
.badge { display: inline-flex; align-items: center; font-size: 11px; line-height: 16px; white-space: nowrap; }
#source-badge { padding: 2px 7px; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); }
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.market-summary { padding: 16px 20px 12px; flex: 0 0 auto; }
.market-heading, .market-values { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.market-heading h2 { font-size: 14px; margin: 0; font-weight: 600; }
.market-values { margin-top: 7px; font-variant-numeric: tabular-nums; font-size: 13px; }
#last-price { font-size: 28px; line-height: 34px; font-weight: 650; }
#change-label { font-size: 11px; }
.chart-controls { display: flex; align-items: center; gap: 16px; padding: 0 20px 10px; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
#symbol-select { width: 144px; }
.timeframe-chips { display: flex; gap: 4px; }
.timeframe-chips button { min-width: 48px; background: transparent; border-color: transparent; padding: 8px; color: var(--muted); font-weight: 600; }
.timeframe-chips button:hover { background: var(--soft); color: var(--text); }
.timeframe-chips button[aria-pressed="true"] { color: var(--accent); background: #21352e; }
.timezone { font-size: 11px; margin-left: auto; white-space: nowrap; }
.chart-workspace { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.ohlc-legend { flex: 0 0 auto; display: flex; align-items: center; flex-wrap: wrap; gap: 6px 16px; padding: 10px 20px; min-height: 40px; font-size: 11px; font-variant-numeric: tabular-nums; background: var(--bg); }
#ohlc-time { color: var(--muted); }
.ohlc-values { display: flex; flex-wrap: wrap; gap: 5px 12px; }
.ohlc-values span { white-space: nowrap; }
.chart-stage { position: relative; flex: 1; min-height: 0; }
#chart-container { position: absolute; inset: 0; z-index: 0; }
#chart-state { position: absolute; inset: 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 20px; text-align: center; background: var(--bg); font-size: 13px; }
#chart-state-title { font-weight: 600; }
.status-bar { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 20px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); min-height: 34px; }
#status { overflow-wrap: anywhere; }
#refresh-status { flex: 0 0 auto; }
.mobile-toolbar { display: none; }
#auth-overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; overflow-y: auto; padding: 24px; background: var(--bg); }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.login-card .brand-mark { width: 40px; height: 40px; font-size: 22px; margin-bottom: 4px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-subtitle { margin: -4px 0 12px; color: var(--muted); font-size: 13px; }
.login-card label, #download-range label { font-size: 12px; color: var(--muted); }
.login-card input { background: var(--bg); }
#auth-error { min-height: 32px; font-size: 12px; line-height: 16px; overflow-wrap: anywhere; }
.drawer { position: fixed; inset: 0 0 0 auto; margin: 0; border: 0; border-left: 1px solid var(--border); padding: 24px; width: min(480px, 100%); height: 100%; height: 100dvh; max-width: 100%; max-height: 100dvh; background: var(--panel); color: var(--text); overflow-y: auto; }
.drawer::backdrop { background: rgb(0 0 0 / .65); }
.drawer-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.drawer h2 { margin: 0; font-size: 18px; }
.drawer p { font-size: 13px; }
#download-range { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-top: 24px; }
#download-range label { display: block; margin-bottom: 8px; }
#download-range input { width: 100%; }
#range-error { min-height: 36px; padding-top: 8px; font-size: 12px; }
.download-actions { display: flex; gap: 10px; }
.download-actions button { flex: 1; }
#download-status { margin-top: 16px; font-size: 12px; line-height: 20px; overflow-wrap: anywhere; }
#data-freshness { font-size: 12px; line-height: 20px; overflow-wrap: anywhere; padding-bottom: 20px; }
.pair-table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 12px; line-height: 18px; }
caption { text-align: left; margin-bottom: 12px; color: var(--muted); }
th, td { padding: 12px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th:first-child, td:first-child { padding-left: 0; white-space: nowrap; }
th { font-weight: 600; color: var(--muted); }
.pair-status-badge { display: inline-block; border: 1px solid currentColor; padding: 1px 6px; border-radius: 4px; font-size: 10px; margin-bottom: 4px; }
.pair-meta { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
#pair-status-note { font-size: 11px; margin-top: 16px; line-height: 18px; }
@media (max-width: 640px) {
  .app-header { min-height: 52px; padding-left: 12px; padding-right: 12px; }
  .brand { font-size: 14px; gap: 8px; }
  .header-actions { gap: 6px; }
  .desktop-action { display: none !important; }
  .health-button { gap: 6px; padding: 7px 8px; }
  .health-button .icon { width: 16px; height: 16px; }
  .market-summary { padding: 12px 12px 10px; }
  #last-price { font-size: 25px; line-height: 30px; }
  .market-values { gap: 5px 10px; }
  .chart-controls { padding: 0 12px 8px; gap: 8px; }
  #symbol-select { display: none; }
  .timeframe-chips { flex: 1; gap: 3px; }
  .timeframe-chips button { flex: 1; min-width: 0; min-height: 40px; }
  .timezone { display: none; }
  .ohlc-legend { padding: 8px 12px; gap: 5px; font-size: 10px; }
  .ohlc-values { gap: 4px 9px; }
  .status-bar { padding: 7px 12px; font-size: 10px; }
  .mobile-toolbar { display: grid; grid-template-columns: minmax(110px, 1.6fr) repeat(3, minmax(0, 1fr)); gap: 4px; flex: 0 0 auto; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); }
  .mobile-toolbar button { background: transparent; border-color: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 5px 2px; min-height: 48px; }
  .mobile-toolbar button span, .mobile-symbol > span { color: var(--muted); font-size: 10px; }
  .mobile-symbol { display: flex; flex-direction: column; justify-content: center; gap: 3px; min-width: 0; padding: 0 4px; }
  #mobile-symbol-select { width: 100%; min-height: 28px; padding: 2px 4px; border: 0; background: transparent; font-size: 12px; }
  .drawer { inset: auto 0 0; width: 100%; height: auto; max-height: 85dvh; border-left: 0; border-top: 1px solid var(--border); border-radius: 8px 8px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  #health-dialog { height: 80dvh; }
}
@media (max-height: 500px) {
  .market-summary { padding-top: 6px; padding-bottom: 6px; }
  .market-values { margin-top: 3px; }
  #last-price { font-size: 20px; line-height: 24px; }
  .ohlc-legend { padding-top: 4px; padding-bottom: 4px; }
  .login-card { padding: 16px; gap: 8px; }
  .login-subtitle { margin-bottom: 4px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; } }


.download-kind { display: flex; flex-direction: column; gap: 8px; margin: 16px 0 10px; font-size: 12px; color: var(--muted); }
.volume-note { font-size: 12px; line-height: 1.5; }
#ohlc-v { color: var(--muted); }
