/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --surface-3: #e8e7e3;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7873;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --up: #006300;
  --down: #c62f2f;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --up-wash: rgba(12, 163, 12, 0.10);
  --down-wash: rgba(208, 59, 59, 0.10);
  --warn-wash: rgba(250, 178, 25, 0.16);
  /* social sources = fixed categorical slots 1..5 */
  --s-twitter: #2a78d6;
  --s-reddit: #eb6834;
  --s-telegram: #1baf7a;
  --s-fourchan: #eda100;
  --s-coingecko: #e87ba4;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --surface-3: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.18);
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8d86; --grid: #2c2c2a; --axis: #383835;
    --accent: #3987e5; --accent-wash: rgba(57, 135, 229, 0.16);
    --up: #0ca30c; --down: #e66767; --up-wash: rgba(12, 163, 12, 0.14); --down-wash: rgba(230, 103, 103, 0.14);
    --warn-wash: rgba(250, 178, 25, 0.14);
    --s-twitter: #3987e5; --s-reddit: #d95926; --s-telegram: #199e70; --s-fourchan: #c98500; --s-coingecko: #d55181;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.18);
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8d86; --grid: #2c2c2a; --axis: #383835;
  --accent: #3987e5; --accent-wash: rgba(57, 135, 229, 0.16);
  --up: #0ca30c; --down: #e66767; --up-wash: rgba(12, 163, 12, 0.14); --down-wash: rgba(230, 103, 103, 0.14);
  --warn-wash: rgba(250, 178, 25, 0.14);
  --s-twitter: #3987e5; --s-reddit: #d95926; --s-telegram: #199e70; --s-fourchan: #c98500; --s-coingecko: #d55181;
  --shadow: none;
}

/* ------------------------------------------------------------------- base */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.num, table td.n, table th.n { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.up { color: var(--up); }
.down { color: var(--down); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.gap-4 { gap: 4px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----------------------------------------------------------------- layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; font-size: 15px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent-wash); display: grid; place-items: center; font-size: 17px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-wash); color: var(--accent); }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.sidebar .foot { margin-top: auto; padding: 8px; font-size: 12px; color: var(--muted); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.content { padding: 20px 24px 48px; max-width: 1600px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

/* ------------------------------------------------------------------ cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 0; flex-wrap: wrap; }
.card-head .sub { color: var(--muted); font-size: 12px; }
.card-body { padding: 14px 16px 16px; }
.card-body.flush { padding: 8px 0 4px; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .label { color: var(--text-2); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 2px; letter-spacing: -0.01em; }
.kpi .hint { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer;
  font-weight: 550; white-space: nowrap; transition: background .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.buy { background: var(--good); border-color: var(--good); color: #fff; }
.btn.sell { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.buy:hover, .btn.sell:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.xs { height: 24px; padding: 0 8px; font-size: 12px; border-radius: 6px; }
.btn.block { width: 100%; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 550; font-size: 13px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.seg.buy-sell button.on.b { background: var(--good); color: #fff; }
.seg.buy-sell button.on.s { background: var(--critical); color: #fff; }

/* ------------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > .label { font-size: 12px; color: var(--text-2); font-weight: 550; }
.field .help { font-size: 11.5px; color: var(--muted); }
.input, select.input, textarea.input {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg); width: 100%; min-width: 0;
}
textarea.input { height: auto; min-height: 80px; padding: 8px 10px; resize: vertical; line-height: 1.4; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .addon {
  display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--border-strong); border-left: 0;
  border-radius: 0 8px 8px 0; background: var(--surface-2); color: var(--text-2); font-size: 12px;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px 16px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .track { width: 36px; height: 20px; border-radius: 99px; background: var(--surface-3); position: relative; transition: background .15s; flex: none; border: 1px solid var(--border); }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }

/* ----------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: var(--surface); position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.n, td.n { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.click { cursor: pointer; }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; }
.sym { font-weight: 650; }
.sym-cell { display: flex; align-items: center; gap: 8px; }
.sym-cell > div { min-width: 0; max-width: 190px; }
td .btn + .btn { margin-left: 4px; }
table.compact th, table.compact td { padding: 6px 8px; font-size: 12.5px; }
.coin-dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #fff; flex: none; }

/* ------------------------------------------------------------ indicators */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good { background: var(--up-wash); color: var(--up); }
.badge.bad { background: var(--down-wash); color: var(--down); }
.badge.warn { background: var(--warn-wash); color: var(--text); }
.badge.accent { background: var(--accent-wash); color: var(--accent); }
.badge.live { background: var(--critical); color: #fff; }
.badge.paper { background: var(--accent-wash); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.src { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2); white-space: nowrap; }
.srcs { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.scorebar { display: flex; align-items: center; gap: 8px; min-width: 90px; }
.scorebar .track { flex: 1; height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.scorebar .fill { height: 100%; border-radius: 99px; background: var(--accent); }
.scorebar .v { width: 28px; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; font-size: 13px; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > div { height: 100%; border-radius: 99px; background: var(--good); }
.pill-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.state-ok { color: var(--up); } .state-error { color: var(--down); } .state-warn { color: var(--serious); }

/* ------------------------------------------------------------- lists/feed */
.feed { display: flex; flex-direction: column; }
.feed-item { padding: 10px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; }
.feed-item:last-child { border-bottom: 0; }
.feed-item .text { color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.feed-item .meta { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.activity-item { padding: 8px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; font-size: 13px; align-items: baseline; }
.activity-item:last-child { border-bottom: 0; }
.activity-item .ic { width: 16px; flex: none; text-align: center; }
.scroll { max-height: 520px; overflow-y: auto; }
.scroll.sm { max-height: 360px; }
.reasons { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.reasons li { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.reasons li .ic { flex: none; width: 16px; text-align: center; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--accent-wash); color: var(--text); font-size: 13px; display: flex; gap: 8px; align-items: baseline; }
.notice.warning { background: var(--warn-wash); }
.notice.danger { background: var(--down-wash); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.kv .k { font-size: 11.5px; color: var(--muted); }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- charts */
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 380px; }
.chart-box.short { height: 180px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.depth { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 12.5px; }
.depth-row { display: flex; justify-content: space-between; padding: 2px 6px; position: relative; font-variant-numeric: tabular-nums; }
.depth-row .bar { position: absolute; top: 0; bottom: 0; right: 0; opacity: .18; border-radius: 3px; }

/* ------------------------------------------------------------------ modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 0; }
.modal-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 14px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--border-strong); border-left: 4px solid var(--accent); border-radius: 10px; padding: 10px 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 13px; }
.toast.error { border-left-color: var(--critical); }
.toast.success { border-left-color: var(--good); }

/* ------------------------------------------------------------------ login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { padding: 0 0 20px; font-size: 18px; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .g-main, .g-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; overflow-x: auto; gap: 2px; }
  .brand { padding: 0 8px 0 0; }
  .brand .name, .sidebar .foot { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 6px 8px; white-space: nowrap; }
  .nav a .lbl { display: none; }
  .topbar { position: static; padding: 10px 16px; }
  .content { padding: 16px 16px 40px; }
  .g-2 { grid-template-columns: minmax(0, 1fr); }
  .depth { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------------ print */
@media print {
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  .layout { display: block; }
  body { background: #fff; color: #000; }
  .card, .kpi { break-inside: avoid; box-shadow: none; }
  .scroll { max-height: none; overflow: visible; }
}
