/* ── Tokens ─────────────────────────────────────────── */
:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --surface: #121722;
  --surface-2: #182030;
  --surface-3: #1f293b;
  --border: #253046;
  --text: #e6e9ef;
  --muted: #8b95a7;
  --accent: #4c8dff;
  --accent-text: #ffffff;
  --up: #16a394;
  --down: #ef5350;
  --warn: #f5b942;
  --vwap: #f5b942;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgb(0 0 0 / .35);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f2f4f8;
    --surface-3: #e8ecf3;
    --border: #dde3ec;
    --text: #111827;
    --muted: #5b6577;
    --accent: #2563eb;
    --up: #0d8f82;
    --down: #dc2626;
    --warn: #b7791f;
    --vwap: #d69e2e;
    --shadow: 0 8px 24px rgb(15 23 42 / .12);
  }
}

/* ── Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; font-weight: 600; }
h3 { font-size: .92rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }
.warn { color: var(--warn); }
.small { font-size: .82rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── App shell: web view ────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "side top" "side main";
  min-height: 100dvh;
}
.sidebar {
  grid-area: side;
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 8px 16px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a, .tabbar a {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); text-decoration: none;
  border-radius: var(--radius-sm);
}
.side-nav a { padding: 10px 12px; font-weight: 500; }
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a[aria-current="page"] { background: var(--surface-3); color: var(--text); }
.side-nav svg, .tabbar svg { width: 20px; height: 20px; flex: none; }
.side-foot { margin-top: auto; }
.user-chip { font-size: .85rem; color: var(--muted); padding: 8px 12px; overflow-wrap: anywhere; }

.topbar {
  grid-area: top;
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { display: none; }
.topbar h1 { font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
@media (width < 560px) { .view-switch > span { display: none; } .topbar { padding-inline: 12px; } }
.view { grid-area: main; padding: 24px; min-width: 0; outline: none; }
.tabbar { display: none; }

/* Narrow desktop window in web view: icon-only sidebar */
@media (width < 900px) {
  html[data-view="web"] .app { grid-template-columns: 64px minmax(0, 1fr); }
  html[data-view="web"] .brand span, html[data-view="web"] .side-nav span, html[data-view="web"] .user-chip { display: none; }
  html[data-view="web"] .side-nav a { justify-content: center; }
  html[data-view="web"] .view { padding: 16px; }
}

/* ── App shell: mobile view ─────────────────────────── */
html[data-view="mobile"] body { background: var(--bg); }
html[data-view="mobile"] .app {
  display: block;
  max-width: 480px;
  margin-inline: auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
}
html[data-view="mobile"][data-phone="0"] .app {
  /* Mobile view on a desktop browser: show it framed like a phone */
  border-inline: 1px solid var(--border);
  box-shadow: var(--shadow);
}
html[data-view="mobile"] .sidebar { display: none; }
html[data-view="mobile"] .topbar { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
html[data-view="mobile"] .topbar-logo { display: block; }
html[data-view="mobile"] .topbar h1 { font-size: 1.05rem; }
html[data-view="mobile"] .view { padding: 12px 12px 20px; }
html[data-view="mobile"] .tabbar {
  display: grid;
  grid-auto-flow: column; grid-auto-columns: 1fr;
  position: fixed; bottom: 0; z-index: 20;
  left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
html[data-view="mobile"] .tabbar a {
  flex-direction: column; justify-content: center; gap: 3px;
  font-size: .7rem; font-weight: 500; border-radius: 0;
  min-height: 44px;
}
html[data-view="mobile"] .tabbar a[aria-current="page"] { color: var(--accent); }
html[data-phone="1"] .view-switch { display: none; }

/* ── View switch / toggles ──────────────────────────── */
.view-switch { display: inline-flex; align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); cursor: pointer; user-select: none; }
input[type="checkbox"][role="switch"] {
  appearance: none; -webkit-appearance: none;
  position: relative; flex: none;
  width: 40px; height: 24px; margin: 0;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}
input[type="checkbox"][role="switch"]::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text);
  transition: translate .15s;
}
input[type="checkbox"][role="switch"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"][role="switch"]:checked::after { translate: 16px 0; background: #fff; }
input[type="checkbox"][role="switch"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Building blocks ───────────────────────────────── */
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 0;
}
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
html[data-view="mobile"] .card { padding: 14px; }
html[data-view="mobile"] .cols-2 { grid-template-columns: 1fr; }
html[data-view="mobile"] .stack { gap: 12px; }

.kpis { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
html[data-view="mobile"] .kpis { grid-template-columns: repeat(2, 1fr); }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-width: 0;
}
.kpi .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font: 600 1.25rem/1.3 var(--mono); font-variant-numeric: tabular-nums; margin-top: 4px; overflow-wrap: anywhere; }
.kpi .sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; letter-spacing: .03em;
  background: var(--surface-3); color: var(--muted);
  white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.on { color: var(--up); background: color-mix(in srgb, var(--up) 15%, transparent); }
.pill.off { color: var(--muted); }
.pill.bad { color: var(--down); background: color-mix(in srgb, var(--down) 15%, transparent); }
.pill.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 15%, transparent); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  background: var(--surface-3); color: var(--muted);
}
.badge.live { background: var(--down); color: #fff; }
.badge.testnet { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); }
.badge.paper { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.badge.long { background: color-mix(in srgb, var(--up) 18%, transparent); color: var(--up); }
.badge.short { background: color-mix(in srgb, var(--down) 18%, transparent); color: var(--down); }

/* ── Buttons & forms ───────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600; cursor: pointer;
  text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.good { background: var(--up); border-color: var(--up); color: #fff; }
.btn.danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.btn.block { width: 100%; }
html[data-view="mobile"] .btn { min-height: 44px; }
html[data-view="mobile"] .btn.sm { min-height: 36px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: .85rem; font-weight: 500; }
.field .help { font-size: .78rem; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field.inline > div { min-width: 0; }
input:not([type="checkbox"]), select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
}
html[data-view="mobile"] input:not([type="checkbox"]), html[data-view="mobile"] select { min-height: 44px; font-size: 16px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
input:user-invalid { border-color: var(--down); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
html[data-view="mobile"] .form-grid { grid-template-columns: 1fr; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  overflow-x: auto; max-width: 100%;
  scrollbar-width: none;
}
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 6px;
  color: var(--muted); font-weight: 600; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
html[data-view="mobile"] .seg button { padding: 8px 12px; }

details.disclosure > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.settings-panel {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.settings-panel > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: baseline; gap: 4px 12px; flex-wrap: wrap;
  padding: 12px 14px;
}
.settings-panel > summary::-webkit-details-marker { display: none; }
.settings-panel > summary::before {
  content: ""; flex: none; align-self: center;
  width: 8px; height: 8px; margin-right: 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  rotate: -45deg; transition: rotate .15s;
}
.settings-panel[open] > summary::before { rotate: 45deg; }
.settings-panel[open] > summary { border-bottom: 1px solid var(--border); }
.settings-title { font-weight: 600; }
.settings-body { padding: 14px; }
.pane-label { padding: 8px 16px 0; font-size: .8rem; font-weight: 600; color: var(--muted); }
.settings-actions { align-items: center; padding-top: 14px; margin-top: 16px; border-top: 1px solid var(--border); }
.settings-actions .js-saved-status { margin-right: auto; }
details.disclosure[open] > summary { margin-bottom: 12px; }

/* ── Tables (stack into cards when narrow) ─────────── */
.table-wrap {
  overflow: auto;
  max-block-size: min(640px, 75vh);
  container-type: inline-size;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .87rem; }
table.data th, table.data td { padding: 9px 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--border); }
table.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); color: var(--muted);
  font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.r, table.data th.r { text-align: right; }
table.data tbody th { font-weight: 600; background: var(--surface); position: sticky; left: 0; }
table.data tbody tr:hover th { background: var(--surface-2); }
table.data tbody th > * + * { margin-left: 8px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

@container (width < 640px) {
  table.data, table.data thead, table.data tbody, table.data tr, table.data th, table.data td { display: block; }
  table.data thead { display: none; }
  table.data tr { padding: 4px 0; border-bottom: 1px solid var(--border); }
  table.data tbody th { position: static; border: 0; padding: 10px 14px 4px; display: flex; justify-content: space-between; gap: 8px; background: transparent; }
  table.data td {
    display: flex; justify-content: space-between; gap: 12px;
    border: 0; padding: 3px 14px; white-space: normal; text-align: right;
  }
  table.data td::before {
    content: attr(data-label);
    content: attr(data-label) / attr(data-label);
    color: var(--muted); text-align: left; font-family: var(--font);
  }
  table.data td.r { text-align: right; }
}

/* ── Charts ────────────────────────────────────────── */
.chart-box { position: relative; height: 420px; min-height: 240px; }
.chart-box.tall { height: calc(100dvh - 230px); min-height: 360px; }
html[data-view="mobile"] .chart-box.tall { height: calc(100dvh - 300px - var(--tabbar-h)); min-height: 320px; }
html[data-view="mobile"] .chart-box { height: 260px; }
.chart-legend {
  position: absolute; top: 8px; left: 10px; z-index: 3; pointer-events: none;
  font: .78rem/1.4 var(--mono); color: var(--muted);
  display: flex; gap: 10px; flex-wrap: wrap; max-width: calc(100% - 80px);
}
.chart-legend b { color: var(--text); font-weight: 600; }
.chart-legend.static { position: static; pointer-events: auto; padding: 10px 16px 0; max-width: none; align-items: center; }
.legend-chip { font-family: var(--font); }
.legend-chip[aria-pressed="false"] { opacity: .45; text-decoration: line-through; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar select { width: auto; min-width: 110px; }
html[data-view="mobile"] .toolbar select { flex: 1 1 40%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: .8rem; cursor: pointer; user-select: none;
}
.chip input { margin: 0; accent-color: var(--accent); }

/* ── Symbol cards ──────────────────────────────────── */
.sym-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.sym-card .price { font: 600 1.6rem/1.2 var(--mono); }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: .87rem; margin: 10px 0 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── Events ────────────────────────────────────────── */
.events { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.events li { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); font-family: var(--mono); font-size: .78rem; white-space: nowrap; }
.events .msg { overflow-wrap: anywhere; }
.events .lvl-error .msg { color: var(--down); }
.events .lvl-warning .msg { color: var(--warn); }
.events .lvl-trade .msg { color: var(--text); font-weight: 600; }
html[data-view="mobile"] .events li { grid-template-columns: 1fr; }

/* ── Auth ──────────────────────────────────────────── */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); }
.auth-card .brand { justify-content: center; font-size: 1.2rem; padding-bottom: 20px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.error-text { color: var(--down); font-size: .87rem; min-height: 1.2em; }

/* ── Dialog & toast ────────────────────────────────── */
.dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 0; width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
.dialog.wide { width: min(760px, calc(100vw - 32px)); }
.dialog-body h3 { margin-top: 4px; }
.dialog { max-height: calc(100dvh - 32px); }
.dialog::backdrop { background: rgb(0 0 0 / .55); }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog-body p { margin: 0; color: var(--muted); white-space: pre-line; }
.toast-wrap {
  position: fixed; z-index: 100; left: 50%; translate: -50% 0;
  bottom: calc(24px + var(--safe-b));
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(440px, calc(100vw - 32px));
}
html[data-view="mobile"] .toast-wrap { bottom: calc(var(--tabbar-h) + 12px + var(--safe-b)); }
.toast {
  background: var(--surface-3); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: .9rem; width: 100%;
}
.toast.error { border-color: var(--down); }
.toast.ok { border-color: var(--up); }
.copy-row { display: flex; gap: 8px; }
form .unsaved { display: none; }
form[data-dirty] .unsaved { display: inline-flex; }
form[data-dirty] { border-color: var(--warn); }
form[data-dirty] [type="submit"] { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.copy-row input { font-family: var(--mono); font-size: .8rem; }

.banner {
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  font-size: .87rem;
}
.banner.danger {
  background: color-mix(in srgb, var(--down) 14%, transparent);
  border-color: color-mix(in srgb, var(--down) 45%, transparent);
}
.skeleton { color: var(--muted); padding: 24px; text-align: center; }

/* ── Colour-coded settings sections (Pairs) ─────────── */
.pset {
  --c: var(--muted);
  margin: 0 0 14px; padding: 12px 14px 16px;
  border: 1px solid color-mix(in srgb, var(--c) 30%, var(--border));
  border-left: 5px solid var(--c);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--c) 6%, var(--surface));
  min-width: 0;
}
.pset > legend {
  padding: 2px 10px; border-radius: 999px;
  font-weight: 700; font-size: .85rem; letter-spacing: .02em;
  color: #fff; background: var(--c);
}
.pset-desc { margin: 2px 0 12px; font-size: .82rem; color: var(--muted); }
.pset .field > span { color: var(--text); }
.pset-blue   { --c: #2563eb; }
.pset-green  { --c: #0d9488; }
.pset-purple { --c: #7c3aed; }
.pset-orange { --c: #ea580c; }
.pset-grey   { --c: #64748b; }

.data-range-box {
  min-height: 40px; display: flex; align-items: center; padding: 8px 12px;
  border-radius: var(--radius-sm); border: 1px dashed var(--border);
  font-family: var(--mono); font-weight: 600;
}

.level-guide {
  margin-top: 14px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, #3b82f6 8%, transparent); border-left: 3px solid #3b82f6;
  font-size: .85rem; line-height: 1.5;
}
.level-guide p { margin: 4px 0; }
.level-guide-title { font-weight: 600; margin-bottom: 4px; }

.pair-presets { margin-top: 14px; display: grid; gap: 8px; }
.pair-presets-title { font-weight: 600; font-size: .9rem; }
.pair-preset { display: flex; gap: 12px; align-items: center; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); }
.pair-preset .btn { flex: none; }
@media (max-width: 600px) { .pair-preset { flex-direction: column; align-items: stretch; } }

.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; align-content: start; }
.field-pair > .help { grid-column: 1 / -1; }

.search-box { margin-top: 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.progress { height: 8px; border-radius: 4px; background: var(--border); overflow: hidden; margin: 10px 0 6px; }
.progress > div { height: 100%; background: #2962ff; transition: width .4s; }
.search-table td, .search-table th { white-space: nowrap; }
.search-table tr.dim td { opacity: .55; }
.small-btn { padding: 4px 10px; min-height: 0; font-size: .82rem; }
.search-table td, .search-table th { padding: 6px 8px; }
.search-table td .small { font-size: .75rem; }
.progress.big { height: 12px; border-radius: 6px; }

.test-result { margin-top: 14px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); display: grid; gap: 10px; }
.test-result[hidden] { display: none; }

/* ── Bots ── */
.bot-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.bot-card { display: grid; gap: 8px; color: inherit; text-decoration: none; }
.bot-card:hover { border-color: #2962ff; }
.bot-card-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.bot-card-kpis > div { display: grid; }
.inst-pick { display: grid; gap: 6px; align-content: start; }
.combo { position: relative; }
.combo input { width: 100%; }
.combo-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 280px; overflow: auto;
  background: var(--surface, #fff); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,.12);
  display: grid; padding: 4px; gap: 2px; }
.combo-row { text-align: left; padding: 7px 10px; border: 0; background: transparent; border-radius: var(--radius-sm); cursor: pointer; color: inherit; font: inherit; }
.combo-row:hover, .combo-row.on { background: color-mix(in srgb, #2962ff 10%, transparent); }
.combo-empty { padding: 7px 10px; }
.inst-chosen { padding: 8px 12px; border: 1px dashed var(--border); border-radius: var(--radius-sm); min-height: 40px; }
.inst-pick .row input { flex: 1; min-width: 0; }
.inst-results { display: grid; gap: 4px; max-height: 260px; overflow: auto; }
.inst-row { text-align: left; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: inherit; cursor: pointer; font: inherit; }
.inst-row:hover { border-color: #2962ff; }
.event-list { display: grid; gap: 4px; max-height: 360px; overflow: auto; font-size: .88rem; }
.ev-error { color: var(--down); }
.ev-warn { color: #b45309; }
.ev-trade { font-weight: 600; }

.period-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); }
.period-line b { font-size: 1.05rem; }

.chart-latest { position: absolute; right: 70px; bottom: 34px; z-index: 5; width: 30px; height: 30px; padding: 0;
  display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: inherit; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.chart-latest[hidden] { display: none; }
.chart-latest svg { width: 18px; height: 18px; }
.chart-latest:hover { border-color: #2962ff; color: #2962ff; }

.opt-head { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.opt-head input[type=checkbox] { width: 18px; height: 18px; margin: 0; flex: none; }
.opt-field { display: grid; gap: 6px; align-content: start; }
input:disabled, select:disabled { opacity: .45; cursor: not-allowed; }

/* ── Settings as rows ── */
.pset { container-type: inline-size; }
.prows { display: grid; }
.prow { display: grid; align-items: center; gap: 8px 14px; padding: 9px 4px; border-top: 1px solid var(--border);
  grid-template-columns: minmax(150px, 1fr) minmax(220px, 2fr) 34px; grid-template-areas: "label ctrls info"; }
.prow:has(.pstate) { grid-template-columns: 64px minmax(150px, 1fr) minmax(220px, 2fr) 34px;
  grid-template-areas: "state label ctrls info"; }
.with-prio .prow { grid-template-columns: 56px 92px minmax(150px, 1fr) minmax(220px, 2fr) 34px;
  grid-template-areas: "prio state label ctrls info"; }
.prio { grid-area: prio; } .pstate { grid-area: state; } .plabel { grid-area: label; }
.pctls { grid-area: ctrls; } .pinfo { grid-area: info; }
.prow.phead { border-top: 0; padding-top: 0; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.prow.phead > span:nth-child(1) { grid-area: prio; } .prow.phead > span:nth-child(2) { grid-area: state; }
.prow.phead > span:nth-child(3) { grid-area: label; } .prow.phead > span:nth-child(4) { grid-area: ctrls; }
.prow.phead > span:nth-child(5) { grid-area: info; }
.prio { display: inline-grid; place-items: center; justify-self: start; min-width: 40px; padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); font-weight: 700; font-size: .82rem; }
.prio:empty { background: none; }
.pstate { display: flex; align-items: center; }
.pstate input[type=checkbox]:not([role=switch]) { width: 20px; height: 20px; margin: 0; }
.plabel { font-weight: 600; }
.pctls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.pctl { display: flex; align-items: center; gap: 6px; margin: 0; }
.pctl > span { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.pctls select { width: auto; max-width: 100%; min-width: 0; }
.pctls input[type=number] { width: 7.5em; }
.pinfo { justify-self: end; }
.info { position: relative; width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--border); padding: 0;
  background: var(--surface); color: var(--muted); font: italic 700 .8rem Georgia, serif; cursor: help; }
.info:hover, .info:focus-visible { color: var(--c, #2563eb); border-color: var(--c, #2563eb); }
.info:hover::after, .info:focus::after {
  content: attr(data-tip); position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 20; width: min(340px, 80vw);
  padding: 10px 12px; border-radius: 8px; background: #1e293b; color: #f8fafc; font: 400 .82rem/1.45 system-ui, sans-serif;
  text-align: left; white-space: normal; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
@container (max-width: 700px) {
  .prow { grid-template-columns: 1fr 34px; grid-template-areas: "label info" "ctrls ctrls"; }
  .prow:has(.pstate) { grid-template-columns: auto 1fr 34px; grid-template-areas: "state label info" "ctrls ctrls ctrls"; }
  .with-prio .prow { grid-template-columns: auto auto 1fr 34px; grid-template-areas: "prio state label info" "ctrls ctrls ctrls ctrls"; }
  .prow.phead { display: none; }
  .pctls:empty { display: none; }
}
html[data-view="mobile"] .prow { grid-template-columns: 1fr 34px; grid-template-areas: "label info" "ctrls ctrls"; }
html[data-view="mobile"] .prow:has(.pstate) { grid-template-columns: auto 1fr 34px; grid-template-areas: "state label info" "ctrls ctrls ctrls"; }
html[data-view="mobile"] .with-prio .prow { grid-template-columns: auto auto 1fr 34px; grid-template-areas: "prio state label info" "ctrls ctrls ctrls ctrls"; }
html[data-view="mobile"] .prow.phead { display: none; }

/* Settings: no overall fold; each section folds on its title */
.settings-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); }
.pset-toggle { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.pset-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; border-radius: 999px; }
.pset-toggle .chev { display: inline-block; transition: rotate .15s; }
.pset.folded .pset-toggle .chev { rotate: -90deg; }
.pset.folded > :not(legend) { display: none; }
.pset.folded { padding-bottom: 4px; }
.fold-all { display: inline-flex; gap: 6px; margin-left: auto; }
.btn.pause { background: #f97316; border-color: #f97316; color: #fff; }
.btn.pause:hover { background: #ea580c; border-color: #ea580c; }

/* pair trades: one row per leg, the pair's cells span its legs */
.pair-table td { vertical-align: middle; }
.pair-table tr.pair-first td { border-top: 2px solid var(--border); }
.pair-table tr.pair-next td { border-top: 1px dashed var(--border); }
.pair-table td.pair-dir { min-width: 110px; line-height: 1.35; }
.pair-table .nowrap { white-space: nowrap; }
.pair-table td.reason { min-width: 220px; }
.leg-state { display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  padding: 1px 7px; border-radius: 999px; vertical-align: middle; line-height: 1.5; white-space: nowrap; }
.leg-state.o { color: #fff; background: #2563eb; }
.leg-state.c { color: var(--muted); background: transparent; border: 1px solid var(--border, #cbd5e1); }
.pair-kpi { grid-column: span 2; min-width: 300px; }
.pair-kpi .leg-line { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto auto; align-items: center; gap: 8px; margin: 4px 0; }
.pair-kpi .leg-name { font-weight: 600; }
.pair-kpi .leg-pnl { font-family: var(--mono); font-size: 1.15rem; text-align: right; }
.pair-kpi .badge { text-align: center; }
.pair-kpi .badge.long { background: #16a34a; color: #fff; }
.pair-kpi .badge.short { background: #dc2626; color: #fff; }
.level-guide:empty { display: none; }
.pair-table .target { color: #2563eb; font-weight: 600; }

/* Strategies group in the navigation */
.side-nav a.nav-group { font-weight: 600; }
.side-nav a.nav-sub { padding: 7px 12px 7px 30px; font-size: .92rem; }
.side-nav a.nav-sub svg { width: 16px; height: 16px; opacity: .8; }
.strat-switch { display: none; }
html[data-view="mobile"] .strat-switch { display: flex; margin-bottom: 12px; overflow-x: auto; }
.strat-switch a { flex: 1; text-align: center; padding: 8px 10px; border-radius: 8px; color: inherit; text-decoration: none; white-space: nowrap; font-weight: 500; }
.strat-switch a[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
@media (width < 900px) { html[data-view="web"] .side-nav a.nav-sub { padding: 7px 12px; } }
/* settings rows: controls never spill out of the card (long dropdowns shrink and truncate) */
.prow > * { min-width: 0; }
.pctls { min-width: 0; max-width: 100%; }
.pctl { min-width: 0; max-width: 100%; }
.pctl select, .pctls select { min-width: 0; max-width: 100%; flex: 0 1 auto; text-overflow: ellipsis; }
/* Open / Closed pills: same width so the column lines up, never clipped */
.pair-kpi .leg-state { min-width: 64px; text-align: center; box-sizing: border-box; }
.pair-kpi .leg-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Trend bot: positions table + per-position rules */
.rules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 14px; align-items: end; }
.rules-grid .field.check { flex-direction: row; align-items: center; gap: 8px; padding-bottom: 8px; }
.rules-grid .help { margin-top: 2px; }
.rules-row td { background: var(--surface-2, rgba(0,0,0,.03)); }
.pos-table td.nowrap { white-space: nowrap; }
.pill.you { background: #7c3aed; color: #fff; }
.pill.danger-pill { background: #dc2626; color: #fff; }
.trend-now p { line-height: 1.6; }
/* Learning page */
.sug { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border, #e5e7eb); flex-wrap: wrap; }
.sug:first-of-type { border-top: 0; }
.sug-test { margin-top: 4px; }
.apply-switch { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--border, #cbd5e1); cursor: pointer; }
.apply-switch.on { border-color: #16a34a; background: rgba(22, 163, 74, .08); }
.apply-switch input { width: 20px; height: 20px; }
.apply-switch > span { display: flex; flex-direction: column; }

/* Line Angle: legend chips for the position background */
.bg-chip { display: inline-block; width: 12px; height: 10px; border-radius: 2px; vertical-align: middle; }
.bg-chip.long { background: rgba(34, 197, 94, 0.35); }
.bg-chip.short { background: rgba(249, 115, 22, 0.4); }

/* Admin -> Data: foldable panels */
.data-panels .fold-bar { display: flex; justify-content: flex-start; }
.data-panels .pset { margin: 0; }
.data-panels .pset .card { box-shadow: none; }
.data-panels .spread > p { flex: 1 1 360px; }
.data-panels .fold-bar .fold-all { margin-left: 0; margin-right: auto; }

/* a setting that only applies to another setting's value is hidden otherwise */
.prow[hidden], .field[hidden] { display: none; }
