:root {
  --bg: #0d1117; --panel: #151b23; --panel-2: #1b2330; --line: #263040; --text: #e6edf3; --muted: #8b98a8;
  --accent: #d4a72c; --ok: #3fb950; --warn: #d29922; --bad: #f85149; --info: #58a6ff;
  --buy: #3fb950; --sell: #f85149; --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8; --panel: #ffffff; --panel-2: #f0f2f5; --line: #dde1e7; --text: #1b1f24; --muted: #5f6b7a;
    --accent: #9a6d00; --ok: #1a7f37; --warn: #9a6700; --bad: #cf222e; --info: #0969da; --buy: #1a7f37; --sell: #cf222e;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--info); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--muted); }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; letter-spacing: .04em; padding: 4px 10px 16px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--muted); }
.nav a.active, .nav a:hover { background: var(--panel-2); color: var(--text); }
.side .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 10px; }
main { padding: 22px 26px 60px; min-width: 0; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.topbar h1 { font-size: 20px; margin: 0 auto 0 0; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.stat { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.sub { color: var(--muted); font-size: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mono { font-family: var(--mono); font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* pills */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: var(--panel-2); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); } .pill.info { color: var(--info); } .pill.muted { color: var(--muted); }
.dir-BUY { color: var(--buy); font-weight: 700; } .dir-SELL { color: var(--sell); font-weight: 700; }

/* banner */
.banner { border-radius: var(--radius); padding: 10px 14px; border: 1px solid; }
.banner.bad { border-color: var(--bad); color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.banner.warn { border-color: var(--warn); color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.banner b { color: var(--text); }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel-2); }
.empty { color: var(--muted); padding: 18px 8px; text-align: center; }

/* RSI */
.rsi { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.rsi .tf { background: var(--panel-2); border-radius: 8px; padding: 8px; text-align: center; border: 1px solid var(--line); }
.rsi .tf b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.rsi .tf.low b { color: var(--buy); } .rsi .tf.high b { color: var(--sell); } .rsi .tf.unhealthy { opacity: .55; }
.bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

/* forms */
.btn { background: var(--panel-2); border: 1px solid var(--line); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #111; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
.field input:focus, .field select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); border-color: var(--accent); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; }
.checks label { display: flex; gap: 6px; align-items: center; }
.toggle { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.toggle:last-child { border-bottom: 0; }
.hint { font-size: 12px; color: var(--muted); }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filters button { border-radius: 999px; padding: 4px 12px; font-size: 12px; }
.filters button.on { background: var(--accent); color: #111; border-color: var(--accent); }
pre.json { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow: auto; font: 12px/1.4 var(--mono); max-height: 360px; margin: 0; }
pre.msg { white-space: pre-wrap; font: 12px/1.4 var(--mono); margin: 0; max-width: 420px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); max-width: 860px; width: 100%; max-height: 90vh; overflow: auto; padding: 18px 20px; }
.modal header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal h3 { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); font-size: 13px; }
.timeline li .sub { margin-left: 6px; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 16px; }
  .brand { padding: 4px 8px; } .side .foot { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  main { padding: 16px; }
  .g4, .g2 { grid-template-columns: 1fr; }
  .rsi { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
main > * + * { margin-top: 14px; }
.grid > .card { margin: 0; }
.timeline .sub.mono { overflow-wrap: anywhere; }

/* always-visible safety status */
.content { min-width: 0; }
.statusbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 26px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.statusbar .sub { margin-right: 6px; }
@media (max-width: 760px) { .statusbar { padding: 8px 12px; } }
