/* HL Autopilot admin — dark trading console. No external assets (strict CSP). */

:root {
  --bg: #0b0e12;
  --surface: #11151b;
  --surface-2: #161b22;
  --surface-3: #1c222b;
  --surface-hover: #1a2029;
  --border: #252c36;
  --divider: #1d232c;
  --text: #e4e8ee;
  --muted: #98a2b0;
  --faint: #677180;
  --accent: #8aa4ff;
  --accent-strong: #a9bcff;
  --accent-bg: rgba(138, 164, 255, .12);
  --pos: #3ecf8e;
  --pos-bg: rgba(62, 207, 142, .12);
  --neg: #f2706b;
  --neg-bg: rgba(242, 112, 107, .12);
  --warn: #f0b545;
  --warn-bg: rgba(240, 181, 69, .12);
  --info: #6cb6ff;
  --info-bg: rgba(108, 182, 255, .12);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);

  --text-xs: .75rem;
  --text-sm: .8125rem;
  --text-base: .9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
  --text-2xl: 1.875rem;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;

  --font: "Inter", "SF Pro Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar-w: 232px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-strong); text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: .92em; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
p { margin: 0; }
button { font: inherit; color: inherit; }
svg { flex-shrink: 0; }
.num, td.num, .tabular { font-variant-numeric: tabular-nums lining-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn-text { color: var(--warn); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ screens */
.screen-center { min-height: 100dvh; display: grid; place-items: center; padding: var(--sp-6); }
.boot-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.auth-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--sp-8) var(--sp-6); display: grid; gap: var(--sp-4);
  box-shadow: var(--shadow);
}
.auth-title { font-size: var(--text-lg); }
.code-block {
  margin: 0; padding: var(--sp-3) var(--sp-4); background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow-x: auto; color: var(--accent-strong); font-size: var(--text-sm);
}

.wordmark { font-weight: 800; font-size: 1.05rem; letter-spacing: -.02em; display: inline-flex; gap: 6px; align-items: baseline; }
.wordmark span { font-weight: 500; color: var(--muted); }
.wordmark-lg { font-size: 1.35rem; }
.wordmark-mobile { display: none; }

/* ------------------------------------------------------------------ shell */
.app {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100dvh;
  background: linear-gradient(to right, var(--surface) calc(var(--sidebar-w) - 1px), var(--divider) 0, var(--divider) var(--sidebar-w), transparent 0);
}
.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--divider); padding: var(--sp-4) var(--sp-3);
  overflow-y: auto; overscroll-behavior: contain;
}
.sidebar-head { padding: var(--sp-2) var(--sp-3) var(--sp-5); }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: var(--sp-3); padding: 9px var(--sp-3); border-radius: var(--radius-sm);
  color: var(--muted); font-size: var(--text-sm); font-weight: 500; text-decoration: none; white-space: nowrap;
}
.nav a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a:hover { background: var(--surface-hover); color: var(--text); }
.nav a.active { background: var(--accent-bg); color: var(--accent-strong); }
.sidebar-foot { margin-top: auto; display: grid; gap: var(--sp-2); padding: var(--sp-3); }
.ai-chip {
  font-size: var(--text-xs); color: var(--muted); padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 999px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.release-footer { margin-top: auto; padding: var(--sp-4) var(--sp-6); display: flex; flex-wrap: wrap; gap: var(--sp-4); color: var(--muted); font-size: var(--text-sm); }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4); padding: var(--sp-3) var(--sp-6); min-height: 60px;
  background: rgba(11, 14, 18, .88); backdrop-filter: blur(10px); border-bottom: 1px solid var(--divider);
}
.topbar h1 { font-size: var(--text-lg); }
.topbar-title { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.topbar-badges { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: flex-end; }
.main { padding: var(--sp-6); display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-5); align-content: start; outline: none; }
#global-banner:empty { display: none; }
#global-banner { padding: var(--sp-4) var(--sp-6) 0; display: grid; gap: var(--sp-2); }

/* ------------------------------------------------------------------ badges / chips */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: var(--text-xs); font-weight: 600; line-height: 1.5; white-space: nowrap;
  background: var(--surface-3); color: var(--muted); border: 1px solid transparent;
}
.badge-dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-pos { background: var(--pos-bg); color: var(--pos); }
.badge-neg { background: var(--neg-bg); color: var(--neg); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-accent { background: var(--accent-bg); color: var(--accent-strong); }
.badge-outline { background: transparent; border-color: var(--border); color: var(--muted); }
.badge-live { background: var(--neg); color: #1a0505; }
.badge-strong { border-color: color-mix(in srgb, currentColor 55%, transparent); text-transform: uppercase; letter-spacing: .04em; }
.badge svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
tr.row-danger td:first-child { box-shadow: inset 3px 0 0 var(--neg); }
tr.row-danger td { background: color-mix(in srgb, var(--neg-bg) 45%, transparent); }
.side-long { color: var(--pos); font-weight: 600; }
.side-short { color: var(--neg); font-weight: 600; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-3); color: var(--text); font-size: var(--text-sm); font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
  min-height: 36px;
}
.btn:hover { background: #232a35; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0b1020; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-danger { background: var(--neg-bg); border-color: rgba(242, 112, 107, .45); color: var(--neg); }
.btn-danger:hover { background: rgba(242, 112, 107, .22); }
.btn-danger-solid { background: var(--neg); border-color: var(--neg); color: #1a0505; }
.btn-danger-solid:hover { background: #ff8a85; }
.btn-warn { background: var(--warn-bg); border-color: rgba(240, 181, 69, .45); color: var(--warn); }
.btn-success { background: var(--pos-bg); border-color: rgba(62, 207, 142, .45); color: var(--pos); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { padding: 5px 10px; min-height: 30px; font-size: var(--text-xs); }
.btn-lg { padding: 12px 20px; min-height: 48px; font-size: var(--text-base); }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* ------------------------------------------------------------------ cards / layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.card-pad { padding: var(--sp-5); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--divider);
}
.card-head h2, .card-head h3 { font-size: var(--text-base); }
.card-body { padding: var(--sp-4) var(--sp-5); }
.card-body > .alert { margin-bottom: var(--sp-4); }
.section-title { font-size: var(--text-sm); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-ov { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--sp-4); }
.kpi { padding: var(--sp-4) var(--sp-5); display: grid; gap: 6px; align-content: start; }
.kpi-label { font-size: var(--text-xs); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: var(--text-xl); font-weight: 700; font-variant-numeric: tabular-nums lining-nums; letter-spacing: -.02em; line-height: 1.2; }
.kpi-sub { font-size: var(--text-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.kpi-split { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.kpi-split > div { display: grid; gap: 2px; }
.kpi-split .v { font-size: var(--text-lg); font-weight: 700; font-variant-numeric: tabular-nums; }

/* control panel */
.control { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-5); align-items: center; padding: var(--sp-5); }
.control-status { display: grid; gap: var(--sp-3); min-width: 0; }
.control-badges { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.control-meta { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-6); font-size: var(--text-sm); color: var(--muted); }
.control-meta b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.control-actions { display: flex; gap: var(--sp-3); flex-wrap: wrap; justify-content: flex-end; }

.bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .4s ease; }
.bar.warn > span { background: var(--warn); }
.bar.danger > span { background: var(--neg); }

.alert {
  display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius); border: 1px solid; font-size: var(--text-sm);
}
.alert svg { width: 18px; height: 18px; margin-top: 1px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.alert b { font-weight: 700; }
.alert-warn { background: var(--warn-bg); border-color: rgba(240, 181, 69, .35); color: #f6d08a; }
.alert-danger { background: var(--neg-bg); border-color: rgba(242, 112, 107, .4); color: #ffb3ae; }
.alert-info { background: var(--info-bg); border-color: rgba(108, 182, 255, .3); color: #b5d8ff; }
.alert .alert-body { display: grid; gap: 4px; flex: 1; min-width: 0; }

.market-view { white-space: pre-wrap; line-height: 1.6; font-size: var(--text-sm); color: #cfd5de; max-height: 340px; overflow-y: auto; overscroll-behavior: contain; }
.ai-head { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.kv-list { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--sp-4); font-size: var(--text-sm); }
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--divider); white-space: nowrap; vertical-align: middle; }
th { font-size: var(--text-xs); color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; background: var(--surface); position: sticky; top: 0; z-index: 1; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums lining-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-hover); }
td.wrap { white-space: normal; min-width: 240px; max-width: 520px; }
td.src-name { white-space: normal; min-width: 200px; max-width: 320px; }
.only-mobile { display: none; }
.coin { font-weight: 700; letter-spacing: .01em; }
.tp-list { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.tp {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 6px; border-radius: 4px;
  background: var(--surface-3); color: var(--muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums;
}
.tp.filled { background: var(--pos-bg); color: var(--pos); }
.tp svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ tabs / filters */
.toolbar { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; justify-content: space-between; }
.toolbar-left, .toolbar-right { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; min-width: 0; max-width: 100%; }
.seg::-webkit-scrollbar { display: none; }
.seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 4px;
  font-size: var(--text-sm); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--surface-3); color: var(--text); }
.seg button .count { color: var(--faint); font-weight: 500; margin-left: 4px; }

/* ------------------------------------------------------------------ forms */
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.field-help { font-size: var(--text-xs); color: var(--muted); line-height: 1.45; }
.field-error { font-size: var(--text-xs); color: var(--neg); font-weight: 600; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], select, textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 11px; font: inherit; font-size: var(--text-sm); min-height: 38px;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
select { appearance: none; padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
input::placeholder, textarea::placeholder { color: var(--faint); }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--neg); }
.field.changed .field-label::after { content: " •"; color: var(--accent); }
.inline-input { display: flex; gap: var(--sp-2); }
.inline-input > input { flex: 1; min-width: 0; }
.form-error { color: var(--neg); font-size: var(--text-sm); font-weight: 600; }
.toolbar select, .toolbar input { width: auto; min-width: 150px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 40px; height: 22px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border); position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + .track { background: var(--accent-bg); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); background: var(--accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .switch-text { font-size: var(--text-sm); color: var(--muted); }

.settings-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--sp-6); align-items: start; }
.settings-nav { position: sticky; top: 76px; display: grid; gap: 2px; }
.settings-nav a { color: var(--muted); padding: 6px 10px; border-radius: var(--radius-sm); font-size: var(--text-sm); text-decoration: none; }
.settings-nav a:hover { background: var(--surface-hover); color: var(--text); }
.settings-groups { display: grid; gap: var(--sp-5); min-width: 0; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5) var(--sp-6); }
.settings-grid .span-2 { grid-column: 1 / -1; }
.advanced { border-top: 1px dashed var(--border); margin-top: var(--sp-5); padding-top: var(--sp-4); }
.advanced summary { cursor: pointer; color: var(--muted); font-size: var(--text-sm); font-weight: 600; margin-bottom: var(--sp-4); list-style: none; display: flex; align-items: center; gap: 6px; }
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before { content: "▸"; transition: transform .15s; }
.advanced[open] summary::before { transform: rotate(90deg); }
.secret-state { font-size: var(--text-xs); color: var(--muted); }
.secret-state.set { color: var(--pos); }
.secret-state.clear { color: var(--neg); }
.savebar {
  position: sticky; bottom: 0; z-index: 15; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5); background: rgba(22, 27, 34, .95); backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); flex-wrap: wrap;
}

/* ------------------------------------------------------------------ idea cards */
.ideas-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: var(--sp-4); }
.idea { display: grid; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); align-content: start; }
.idea-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); flex-wrap: wrap; }
.idea-title { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--text-lg); font-weight: 700; }
.idea-levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: var(--sp-2); }
.lvl { background: var(--surface-2); border-radius: var(--radius-sm); padding: 6px 9px; display: grid; gap: 1px; min-width: 0; }
.lvl .l { font-size: 10.5px; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.lvl .v { font-size: var(--text-sm); font-weight: 600; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.thesis { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: var(--text-sm); color: #cfd5de; }
.idea-note { font-size: var(--text-sm); color: var(--muted); }
.idea-note b { color: var(--text); font-weight: 600; }
.idea-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); flex-wrap: wrap; border-top: 1px solid var(--divider); padding-top: var(--sp-3); font-size: var(--text-xs); color: var(--muted); }
.reason { font-size: var(--text-sm); padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--muted); }
.idea-enter { display: flex; justify-content: flex-end; }
.idea-enter .btn { min-width: 132px; }
.entry-preview { display: grid; gap: var(--sp-3); }
.entry-head { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; color: var(--text); font-size: var(--text-base); }
.entry-bound { margin: 0; font-size: var(--text-sm); color: var(--text); }
.entry-bound b { font-variant-numeric: tabular-nums; }
.conf { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.conf .bar { width: 60px; height: 6px; }

/* ------------------------------------------------------------------ chart */
.chart { position: relative; width: 100%; height: 240px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--divider); stroke-width: 1; }
.chart .axis-label { fill: var(--faint); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.pos { stroke: var(--pos); }
.chart .line.neg { stroke: var(--neg); }
.chart .zero { stroke: var(--faint); stroke-dasharray: 3 4; stroke-width: 1; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .dot { fill: var(--accent); stroke: var(--bg); stroke-width: 2; }
.chart-tip {
  position: absolute; top: 6px; pointer-events: none; background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 9px; font-size: var(--text-xs); white-space: nowrap; box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums; transform: translateX(-50%);
}
.chart-empty { height: 240px; display: grid; place-items: center; color: var(--faint); font-size: var(--text-sm); text-align: center; padding: var(--sp-4); }

/* ------------------------------------------------------------------ states */
.empty { padding: var(--sp-8) var(--sp-5); text-align: center; color: var(--muted); display: grid; gap: var(--sp-2); justify-items: center; }
.empty svg { width: 32px; height: 32px; fill: none; stroke: var(--faint); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.empty b { color: var(--text); font-weight: 600; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-line { height: 14px; margin: 8px 0; }
.sk-block { height: 110px; }
.dot-status { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); margin-right: 6px; vertical-align: middle; }
.dot-status.ok { background: var(--pos); box-shadow: 0 0 0 3px var(--pos-bg); }
.dot-status.bad { background: var(--neg); box-shadow: 0 0 0 3px var(--neg-bg); }
.dot-status.off { background: var(--faint); }
.pulse { animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

/* ------------------------------------------------------------------ drawer / modal / toast */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100%); z-index: 41; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(105%); transition: transform .22s ease; visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--divider); }
.drawer-head h2 { font-size: var(--text-lg); display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.drawer-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-5); display: grid; gap: var(--sp-5); align-content: start; }
.drawer-section { display: grid; gap: var(--sp-3); min-width: 0; }
.drawer-section > h3 { font-size: var(--text-sm); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--sp-2); }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 11px; display: grid; gap: 2px; min-width: 0; }
.stat .l { font-size: var(--text-xs); color: var(--faint); }
.stat .v { font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
body.no-scroll { overflow: hidden; }

.modal { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); padding: 0; width: min(480px, calc(100% - 32px)); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(0, 0, 0, .6); }
.modal-inner { padding: var(--sp-6); display: grid; gap: var(--sp-4); }
.modal-title { font-size: var(--text-lg); }
.modal-body { color: var(--muted); font-size: var(--text-sm); display: grid; gap: var(--sp-3); }
.modal-body b { color: var(--text); }
.modal-body ul { margin: 0; padding-left: var(--sp-5); display: grid; gap: var(--sp-1); }
.modal-body .check { display: flex; gap: var(--sp-2); align-items: flex-start; color: var(--text); cursor: pointer; }
.modal-body .check input { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.modal-body .hist-list { margin: 0; padding-left: var(--sp-5); display: grid; gap: var(--sp-2); max-height: min(32vh, 260px); overflow-y: auto; overscroll-behavior: contain; }
.modal-body .hist-list li { overflow-wrap: anywhere; }
.modal-body .hist-list .mono { word-break: break-all; }
.modal-body .warn-text { color: var(--warn); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); flex-wrap: wrap; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: var(--sp-2); width: min(380px, calc(100% - 32px)); }
.toast { background: var(--surface-3); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: 10px 14px; font-size: var(--text-sm); box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.ok { border-left-color: var(--pos); }
.toast.err { border-left-color: var(--neg); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* JSON / context tree */
.json { margin: 0; background: var(--bg); border: 1px solid var(--divider); border-radius: var(--radius-sm); padding: var(--sp-3); font-size: 12px; max-height: 360px; overflow: auto; overscroll-behavior: contain; white-space: pre-wrap; word-break: break-word; color: #c9d1dc; }
.ctx { display: grid; gap: var(--sp-2); }
.ctx details { background: var(--surface-2); border-radius: var(--radius-sm); }
.ctx summary { cursor: pointer; padding: 8px 12px; font-size: var(--text-sm); font-weight: 600; display: flex; justify-content: space-between; gap: var(--sp-3); }
.ctx summary .faint { font-weight: 400; }
.ctx .ctx-body { padding: 0 12px 10px; }
.ctx table td { padding: 5px 8px; font-size: var(--text-xs); }
.ctx table td:first-child { color: var(--muted); }
.check-result { display: grid; gap: var(--sp-2); }
.load-more { display: flex; justify-content: center; padding: var(--sp-3); }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1180px) {
  .grid-ov { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); background: none; }
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center;
    padding: 0 var(--sp-2); border-right: 0; border-bottom: 1px solid var(--divider); overflow: visible;
  }
  .sidebar-head { display: none; }
  .nav { display: flex; overflow-x: auto; gap: 2px; padding: 6px 0; scrollbar-width: none; flex: 1; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 8px 10px; }
  .nav a svg { display: none; }
  .sidebar-foot { margin: 0; padding: 0 0 0 var(--sp-2); display: flex; }
  .sidebar-foot .ai-chip { display: none; }
  .topbar { position: static; padding: var(--sp-3) var(--sp-4); flex-wrap: wrap; }
  .topbar h1 { display: none; }
  .wordmark-mobile { display: inline-flex; }
  .topbar-badges { justify-content: flex-start; }
  .main { padding: var(--sp-4); gap: var(--sp-4); }
  #global-banner { padding: var(--sp-3) var(--sp-4) 0; }
  .control { grid-template-columns: minmax(0, 1fr); }
  .control-actions { justify-content: stretch; }
  .control-actions .btn { flex: 1 1 auto; }
  .settings-layout { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { display: none; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .only-desktop { display: none !important; }
  .only-mobile { display: revert; }
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody { display: block; width: 100%; }
  .table-stack tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; padding: 12px 16px; border-bottom: 1px solid var(--divider); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack tr.row-danger { box-shadow: inset 3px 0 0 var(--neg); }
  .table-stack tr.row-danger td:first-child { box-shadow: none; }
  .table-stack td { display: block; padding: 0; border: 0; white-space: normal; text-align: left; min-width: 0; max-width: none; }
  .table-stack td:empty { display: none; }
  .table-stack td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 2px;
    font-size: 11px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  }
  .table-stack td.cell-head { grid-column: 1 / -1; font-size: var(--text-base); }
  .table-stack td.cell-full { grid-column: 1 / -1; }
  .table-stack td.cell-action { grid-column: 1 / -1; text-align: left; }
  .table-stack td.cell-action .btn { width: 100%; justify-content: center; }
  .table-stack tbody tr.clickable:hover td { background: none; }
  .table-stack tbody tr.clickable:active { background: var(--surface-hover); }
  .table-stack td.ev-time { grid-column: 1; }
  .table-stack td.ev-level { grid-column: 2; justify-self: end; }
  .table-stack td.ev-src { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
  .kpi { padding: var(--sp-3); }
  .kpi-value { font-size: var(--text-lg); }
  .kpi.span-mobile { grid-column: 1 / -1; }
  .ideas-grid { grid-template-columns: minmax(0, 1fr); }
  .card-head, .card-body { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .card-pad, .control { padding: var(--sp-4); }
  .toolbar select, .toolbar input { min-width: 0; flex: 1; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .drawer-body { padding: var(--sp-4); }
  .chart, .chart-empty { height: 200px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------------ history reconciliation card */
.history-card { border-color: color-mix(in srgb, var(--neg) 45%, var(--border)); }
.history-card .card-body { display: grid; gap: var(--sp-3); }
.history-card p { margin: 0; }
.history-card .mono { word-break: break-all; }
.chain-list { display: grid; gap: var(--sp-4); }
#ov-history:empty, .chain-list:empty { display: none; }
.chain-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-2) var(--sp-4); margin: 0; font-size: var(--text-sm); }
.chain-meta div { min-width: 0; }
.chain-meta dt { color: var(--muted); font-size: var(--text-xs); }
.chain-meta dd { margin: 0; overflow-wrap: anywhere; }
.chain-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: var(--sp-3); align-items: end; }
@media (max-width: 760px) { .chain-form { grid-template-columns: minmax(0, 1fr); } .chain-form .btn { width: 100%; justify-content: center; } }
.modal-body .hist-trunc { display: grid; gap: 6px; margin-top: 6px; padding: var(--sp-2) var(--sp-3); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--border)); border-radius: var(--radius-sm, 6px); }
.modal-body .hist-trunc .field input { max-width: 220px; }
