/* tokens.md §2 — 17 vars. Dark is default. Do not copy MexcScalp light-on-:root. */
:root, html[data-theme="dark"] {
  --bg: #070707;
  --panel: #0a0a0a;
  --surface: #141414;
  --line: #1f1f1f;
  --border: #2a2a2a;
  --ink: #f2f3f5;
  --ink2: #ababab;
  --ink3: #8a8a8a;
  --accent: #f5b841;
  --on-accent: #1a1204;
  --up: #3be08a;
  --dn: #ff5a47;
  --info: #48d0e0;
  --bar: #141418;
  --pad: 8px;
  --fs: 12px;
  --fs-sm: 10px;
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: var(--fs);
  line-height: 1.25;
}
html[data-theme="light"] {
  --bg: #8b8b8b;
  --panel: #9b9b9b;
  --surface: #b3b3b3;
  --line: #7f7f7f;
  --border: #6e6e6e;
  --ink: #000;
  --ink2: #292929;
  --ink3: #414141;
  --accent: #164d47;
  --on-accent: #f3f3f3;
  --up: #006642;
  --dn: #932d2a;
  --info: #125562;
  --bar: #929292;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none; }

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  background: var(--bg);
}
#app.gate-only { padding-bottom: env(safe-area-inset-bottom); }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px var(--pad) 6px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 0;
  border-right: 0;
  position: sticky;
  top: 0;
  z-index: 2;
}
.brand {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink2);
  font-weight: 600;
}
.top-actions { display: flex; align-items: center; gap: 6px; min-width: 0; }
.theme-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink2);
  font-size: 10px;
  padding: 2px 7px;
  height: 22px;
  border-radius: 0;
  white-space: nowrap;
  cursor: pointer;
}
.head-meta {
  font-size: var(--fs-sm);
  color: var(--ink2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}
main { flex: 1; padding: 6px 10px 12px; }

.seg {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  background: var(--bg);
  border: 1px solid var(--border);
  height: 26px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none;
  min-width: 64px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink3);
  font-size: 11px;
  line-height: 1;
  padding: 0 8px;
  height: 100%;
  white-space: nowrap;
  cursor: pointer;
}
.seg button.on {
  background: var(--surface);
  color: var(--ink);
}
.seg.seg-equal button { flex: 1 1 0; min-width: 0; }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 6;
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
}

.card {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 6px 8px;
  margin-bottom: 4px;
}
.card.tap {
  min-height: 44px;
  cursor: pointer;
}
.card-top, .row, .audit {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.card-top { margin: 0; }
.row, .audit { margin-bottom: 4px; }
.card-sub, .meta {
  color: var(--ink2);
  font-size: var(--fs-sm);
  margin-top: 2px;
}
.meta.who, .audit .who {
  color: var(--ink3);
  font-size: 9px;
  margin-top: 1px;
}
.card-title { min-width: 0; font-weight: 600; }
.card .big {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

.k { color: var(--ink2); font-size: var(--fs-sm); }
.n { font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.dn { color: var(--dn); }
.swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 1px;
  margin-right: 6px;
  vertical-align: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,.18) inset;
  background: var(--accent);
}
html[data-theme="dark"] .swatch { box-shadow: 0 0 0 1px rgba(255,255,255,.12) inset; }
.dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink3);
  margin-right: 5px;
  vertical-align: 1px;
}
.dot.on { background: var(--up); }
.dot.off { background: var(--dn); }

.kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 2px 0 6px;
}
.kpi {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 6px 8px;
}
.kpi-l, .kpi .k {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 9px;
  color: var(--ink2);
}
.kpi-n, .kpi .v {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.kpi .d {
  font-size: 9px;
  color: var(--ink3);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h2 {
  margin: 10px 0 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink2);
}

.acts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.acts.under { margin: -2px 0 8px; }
.acts button, .btn {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 10px;
  padding: 0 7px;
  line-height: 20px;
  height: 22px;
  box-sizing: border-box;
  border-radius: 0;
  cursor: pointer;
}
.acts button.danger, .btn.danger { color: var(--dn); border-color: var(--dn); }
.acts button:disabled, .btn:disabled { opacity: 0.45; cursor: default; }
.hint, .empty { color: var(--ink2); font-size: var(--fs-sm); padding: 6px 0; }
.hint:empty { display: none; padding: 0; }
.err { color: var(--dn); font-size: var(--fs-sm); padding: 6px 0; }
.ok { color: var(--up); font-size: var(--fs-sm); padding: 6px 0; }

.form-tight label {
  display: block;
  color: var(--ink2);
  font-size: 10px;
  margin: 5px 0 2px;
}
.form-tight input,
.form-tight select {
  width: 100%;
  height: 28px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 2px 6px;
  font-size: 12px;
}
.form-row {
  display: flex;
  gap: 4px;
  align-items: flex-end;
}
.form-row > * { flex: 1; min-width: 0; }
.form-row .btn { flex: 0 0 auto; height: 28px; margin-top: 0; width: auto; padding: 0 8px; }

.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 11px;
  color: var(--ink2);
}
.switch-row.on { color: var(--ink); }
.switch {
  width: 28px;
  height: 14px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 1px;
  background: transparent;
  position: relative;
  flex: none;
  cursor: pointer;
}
.switch::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  top: 2px;
  left: 2px;
  background: var(--ink3);
}
.switch.on { border-color: var(--accent); }
.switch.on::after { left: 16px; background: var(--accent); }

.sheet {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 5;
  display: flex;
  align-items: flex-end;
}
.sheet.hidden { display: none; }
.sheet-card {
  width: 100%;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 10px var(--pad) calc(12px + env(safe-area-inset-bottom));
  max-height: 86vh;
  overflow: auto;
}
.sheet-card h3 { margin: 0 0 8px; font-size: 12px; font-weight: 600; }
.sheet-card label { display: block; color: var(--ink2); font-size: 10px; margin: 7px 0 2px; }
.sheet-card input,
.sheet-card select {
  width: 100%;
  height: 28px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 2px 6px;
  font-size: 12px;
}
.btn { width: 100%; margin-top: 8px; padding: 6px; }
.stack { display: flex; gap: 6px; }
.stack .btn { width: auto; flex: 1; }

.badge {
  display: inline-block;
  border: 1px solid var(--line);
  color: var(--ink2);
  font-size: 9px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: 1px;
}
.badge.dn { color: var(--dn); border-color: var(--dn); }
.badge.warn { color: var(--accent); border-color: var(--accent); }

.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--ink2);
}

.gate {
  margin-top: 28px;
  border: 1px solid var(--line);
  padding: 16px 12px;
}
.gate .t {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.gate .s { color: var(--ink2); font-size: 12px; }

.bot {
  min-height: 44px;
  cursor: pointer;
}
.bot.on { border-color: var(--accent); }
.bot-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

canvas.pnl {
  width: 100%;
  height: 120px;
  display: block;
  margin: 4px 0 2px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.back {
  width: auto;
  margin: 0 0 6px;
  padding: 3px 8px;
}

@media (min-width: 720px) {
  #app {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
  .tabs {
    max-width: 480px;
    left: 50%;
    right: auto;
    width: 480px;
    transform: translateX(-50%);
  }
}

/* ========================================================================
   Child 32 — home density only (2026-09-26)
   Scoped to .home / #home-audit. Do not change :root tokens.
   MexcScalp KPI grid is 2-col / 4px gap / 6–8px cell pad; home is flush.
   Does not restyle device / chart / blocked screens.
   ======================================================================== */
.home {
  margin: 0;
  padding: 0;
}
.home .kpis,
.home .home-kpis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  margin: 0;
  border: 1px solid var(--line);
}
.home .kpi,
.home .home-kpi {
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 4px 6px;
  margin: 0;
  background: var(--bg);
}
.home .kpi:nth-child(2n),
.home .home-kpi:nth-child(2n) {
  border-right: 0;
}
.home .kpi:nth-last-child(-n+2),
.home .home-kpi:nth-last-child(-n+2) {
  border-bottom: 0;
}
.home .kpi .k,
.home .home-kpi .k {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 9px;
  color: var(--ink2);
  line-height: 1.1;
}
.home .kpi .v,
.home .home-kpi .v {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
  line-height: 1.15;
}
.home .home-teaser {
  padding: 4px 6px;
  margin: 4px 0 0;
}
.home .home-teaser .hint,
.home .home-teaser-copy {
  padding: 0;
  margin: 0;
  line-height: 1.2;
}
.home-audit,
#home-audit {
  margin: 0;
  padding: 0;
}
#home-audit h2,
#home-audit .home-audit-h {
  margin: 6px 0 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink2);
}
#home-audit .row,
#home-audit .audit,
#home-audit .home-audit-row {
  margin: 0;
  padding: 3px 0;
  gap: 6px;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
}
#home-audit .home-audit-row:last-child,
#home-audit .row:last-child {
  border-bottom: 0;
}
#home-audit .home-audit-main {
  min-width: 0;
}
#home-audit .home-audit-act {
  font-weight: 600;
  line-height: 1.15;
}
#home-audit .meta,
#home-audit .home-audit-who,
#home-audit .home-audit-detail {
  margin-top: 0;
  line-height: 1.15;
}
#home-audit .home-audit-at {
  font-size: var(--fs-sm);
  color: var(--ink3);
  white-space: nowrap;
  flex: none;
}
#home-audit .hint,
#home-audit .empty,
#home-audit .err {
  padding: 3px 0;
  margin: 0;
}

/* ========================================================================
   Child 33 — DEVICE LAYOUT only (2026-09-26)
   Scoped to .dev-list / .device / #device-actions / .bot / #device-bots.
   Do not change :root tokens. Do not undo Child 32 home.
   MexcScalp cards: hairline, title+sub stack, .acts wrap 4px.
   Device: name + short fp + badges on one tight stack.
   ======================================================================== */
.dev-list {
  margin: 0;
  padding: 0;
}
.dev-list .card.tap.dev,
.device > .card.dev {
  padding: 4px 6px;
  margin: 0 0 2px;
  min-height: 0;
}
.dev-list .card.tap.dev:last-child,
.device > .card.dev:last-child {
  margin-bottom: 0;
}
.dev-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.dev-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}
.dev-head .card-title {
  min-width: 0;
  font-weight: 600;
  line-height: 1.15;
}
.dev-seen {
  flex: none;
  font-size: var(--fs-sm);
  color: var(--ink3);
  white-space: nowrap;
}
.dev-fp,
.dev-stack .dev-fp {
  margin-top: 0;
  line-height: 1.15;
}
.dev-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: 0;
}
.dev-badges .badge {
  margin-left: 0;
}
.dev-host,
.dev-note,
.dev-stack .card-sub,
.dev-stack .meta {
  margin-top: 0;
  line-height: 1.15;
}

.device {
  margin: 0;
  padding: 0;
}

#device-actions.acts,
#device-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 3px;
  margin: 4px 0 2px;
  padding: 0;
}
#device-actions button,
#device-actions .btn {
  width: auto;
  margin: 0;
  flex: 0 0 auto;
  padding: 3px 7px;
}

#device-bots {
  margin: 2px 0 0;
  padding: 0;
}
#device-bots .bot,
.device .bot {
  min-height: 0;
  padding: 3px 6px;
  margin: 0 0 2px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
}
#device-bots .bot:last-child {
  margin-bottom: 0;
}
#device-bots .bot .card-top,
#device-bots .bot .bot-row {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  gap: 6px;
}
#device-bots .bot .card-sub {
  flex: 1 1 100%;
  margin-top: 0;
  line-height: 1.15;
}
#device-bots .bot button,
#device-bots .bot .btn {
  width: auto;
  margin: 0;
  flex: 0 0 auto;
  padding: 2px 6px;
}
#device-bots .hint,
#device-bots .empty,
#device-bots .err {
  padding: 3px 0;
  margin: 0;
}

/* ========================================================================
   Child 34 — CHART LAYOUT (2026-09-26)
   Scoped to #device-chart. Do not change :root tokens.
   Keep Child 32 home and Child 33 device sections.
   MexcScalp bots-pnl canvas: 120px / 1px --border / --bg; empty is
   centered muted on the same 120px slot (no canvas, no fake series).
   Flush under #device-bots. No extra chrome.
   ======================================================================== */
#device-chart,
#device-chart.device-chart {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 120px;
  overflow-x: hidden;
  box-sizing: border-box;
}
#device-bots + #device-chart {
  margin-top: 0;
}
#device-chart canvas.pnl {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  height: 120px;
  min-height: 120px;
  margin: 0;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  touch-action: none;
}
#device-chart .hint,
#device-chart .chart-empty,
#device-chart .err {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 100%;
  height: 120px;
  min-height: 120px;
  margin: 0;
  padding: 0;
  text-align: center;
  font-size: var(--fs-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}
#device-chart .hint,
#device-chart .chart-empty {
  color: var(--ink3);
}
#device-chart .err {
  color: var(--dn);
}

/* ========================================================================
   Child 35 — MOBILE WIDTH only (2026-09-26)
   Telegram phone: full-bleed column, no page x-scroll, ~44px taps,
   safe-area insets. viewport-fit=cover already on html.
   max-width: 480px only — no min-width desktop rules (child 36).
   Do not change :root. Keep Child 32/33/34 sections.
   MexcScalp refs (READ): Telegram/MiniApp/wwwroot/app.css +
   docs/tg-miniapp/05-mobile/agents/06-telegram-shell.md
   ======================================================================== */
@media (max-width: 480px) {
  html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    overscroll-behavior-x: none;
    touch-action: manipulation;
  }
  #app {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    border-left: 0;
    border-right: 0;
    overflow-x: hidden;
    padding-bottom: calc(52px + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)));
  }
  #app.gate-only {
    padding-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  }

  .top {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-left: calc(var(--pad) + max(0px, env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px)));
    padding-right: calc(var(--pad) + max(0px, env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)));
    padding-top: calc(8px + max(0px, env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px)));
  }
  .theme-btn {
    min-width: 0;
    min-height: 0;
    height: 22px;
    padding: 0 7px;
    line-height: 20px;
  }
  .head-meta {
    max-width: min(42vw, 100%);
    min-width: 0;
  }

  main, #views,
  .home, .dev-list, .device, .gate,
  .card, .kpis, .home-kpis,
  .sheet-card, canvas, canvas.pnl, img, svg, video {
    max-width: 100%;
    min-width: 0;
  }
  main {
    padding-left: calc(10px + max(0px, env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px)));
    padding-right: calc(10px + max(0px, env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)));
  }
  #views {
    overflow-x: hidden;
  }
  .card-title, .dev-fp, .mono, .dev-note, .dev-host {
    overflow-wrap: anywhere;
  }

  .tabs.seg {
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 44px;
    overflow-x: hidden;
    overflow-y: hidden;
    transform: none;
    padding-left: max(0px, env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px));
    padding-right: max(0px, env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px));
    padding-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  }
  .tabs.seg button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    height: 44px;
    padding: 0 4px;
  }

  .acts button, .btn, .back,
  .sheet-card .btn, .stack .btn,
  .form-row .btn,
  #device-actions button,
  #device-actions .btn,
  #device-bots .bot button,
  #device-bots .bot .btn,
  #bots-screen .bot button,
  #bots-screen .bot .btn,
  .bots-screen .bot > button,
  .device-bots-open,
  .pheme-bots-pnl-ranges button {
    min-height: 0;
    min-width: 0;
    height: 22px;
    padding: 0 7px;
    line-height: 20px;
    box-sizing: border-box;
  }
  .card.tap,
  .dev-list .card.tap.dev,
  .device > .card.dev,
  .bot,
  #device-bots .bot,
  .device .bot {
    min-height: 44px;
  }
  .form-tight input,
  .form-tight select,
  .sheet-card input,
  .sheet-card select {
    min-height: 44px;
    height: 44px;
  }
  .switch {
    min-width: 44px;
    min-height: 44px;
  }

  .sheet-card {
    width: 100%;
    max-width: 100%;
    padding-left: calc(var(--pad) + max(0px, env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px)));
    padding-right: calc(var(--pad) + max(0px, env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px)));
    padding-bottom: calc(12px + max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px)));
  }
}

/* ========================================================================
   Child 36 — DESKTOP only (2026-09-26)
   Telegram Desktop WebApp / wide iframe: viewports >480px.
   Center a ~480px hairline column (same optional tablet column as
   MexcScalp docs/tg-miniapp/05-mobile/agents/06-telegram-shell.md
   and the existing 720px block). KPI row stays desk-width, not stretched.
   Tabs stay under the column (fixed, centered, reachable).
   min-width: 481px only — does not override Child 35 mobile full-bleed.
   Do not change :root. Keep Child 32–35 sections. No JS.
   ======================================================================== */
@media (min-width: 481px) {
  #app {
    width: 100%;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
  .tabs,
  .tabs.seg {
    left: 50%;
    right: auto;
    width: 480px;
    max-width: 480px;
    transform: translateX(-50%);
  }
}
