/* Trading bot dashboard. No external assets; light/dark via prefers-color-scheme. */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74736e;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --gain: #2a78d6;
  --loss: #d03b3b;
  --gain-text: #1c5cab;
  --loss-text: #b02f2f;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4a00;
  --danger: #d03b3b;
  --danger-ink: #ffffff;
  --good: #0ca30c;
  --grid: #e6e5e0;
  --series-1: #2a78d6;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --accent: #3987e5;
    --gain: #3987e5;
    --loss: #e66767;
    --gain-text: #86b6ef;
    --loss-text: #f09a9a;
    --warn-bg: #3a2f10;
    --warn-ink: #ffd98a;
    --danger: #d03b3b;
    --good: #0ca30c;
    --grid: #2c2c29;
    --series-1: #3987e5;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 1rem; }
button, input, select { font: inherit; color: inherit; }

/* ── login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; }
.login-card h1 { font-size: 1.25rem; }
.login-card p.hint { margin: 0; color: var(--text-2); font-size: 0.9rem; }

/* ── layout ── */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: grid; gap: 10px;
  grid-template-columns: 1fr auto;
  grid-template-areas: "brand badges" "kpis kpis" "actions actions";
}
.brand { grid-area: brand; font-weight: 600; align-self: center; }
.badges { grid-area: badges; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.kpis { grid-area: kpis; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.actions { grid-area: actions; display: flex; gap: 8px; flex-wrap: wrap; }
.kpi { display: grid; min-width: 0; }
.kpi-label { color: var(--text-2); font-size: 0.8rem; }
.kpi-value { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-sub { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

@media (min-width: 900px) {
  .topbar { grid-template-columns: auto auto 1fr auto; grid-template-areas: "brand badges kpis actions"; align-items: center; gap: 16px; }
  .kpis { max-width: 560px; justify-self: center; width: 100%; }
}

main.grid {
  display: grid; gap: 12px; padding: 12px 16px 24px;
  grid-template-columns: minmax(0, 1fr);
  max-width: 1280px; margin: 0 auto;
}
@media (min-width: 900px) {
  main.grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: span 2; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.card-sub { color: var(--text-2); font-size: 0.85rem; margin: 2px 0 10px; }
.empty { color: var(--muted); padding: 8px 0; }
.foot { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 0 16px 24px; }

/* ── badges, banners, toast ── */
.badge { border-radius: 999px; padding: 2px 10px; font-size: 0.8rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.live { background: var(--accent); color: var(--accent-ink); }
.badge.paper { background: var(--surface-2); color: var(--text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.bad { background: var(--danger); color: var(--danger-ink); }
.banner { margin: 12px 16px 0; padding: 10px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn-ink); }
.toast {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  max-width: calc(100% - 32px); z-index: 20;
  background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
}
.toast.error { background: var(--danger); color: var(--danger-ink); }
.error { color: var(--loss-text); margin: 0; min-height: 1.2em; }

/* ── buttons & inputs ── */
.btn {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 8px; padding: 8px 12px; min-height: 40px; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: var(--danger); color: var(--danger-ink); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 0.85rem; }
input[type="password"], input[type="number"], select {
  width: 100%; min-height: 40px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
label { font-size: 0.9rem; color: var(--text-2); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; min-height: 34px; cursor: pointer; font-size: 0.85rem; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ── tables (become cards on phones) ── */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-weight: 500; color: var(--text-2); border-bottom: 1px solid var(--border); padding: 6px 8px; white-space: nowrap; }
.table td { border-bottom: 1px solid var(--border); padding: 8px; vertical-align: top; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .sub { display: block; color: var(--muted); font-size: 0.8rem; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.gain { color: var(--gain-text); }
.loss { color: var(--loss-text); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; }

@media (max-width: 640px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  .table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table td.num { text-align: right; }
  .table td::before { content: attr(data-label); color: var(--text-2); text-align: left; flex: none; }
  .table td.wide { display: block; text-align: left; }
  .table td.wide::before { display: block; }
  .btn-row { justify-content: flex-start; }
}

/* ── lists ── */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.list li:last-child { border-bottom: 0; }
.list .main { min-width: 0; flex: 1 1 200px; }
.list .title { font-weight: 500; }
.list .meta { color: var(--muted); font-size: 0.82rem; }
.reason { color: var(--text-2); font-size: 0.88rem; overflow-wrap: anywhere; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.up { background: var(--good); }
.dot.degraded { background: #fab219; }
.dot.down { background: var(--danger); }
.dot.off { background: var(--muted); }
.tag { font-size: 0.75rem; border-radius: 6px; padding: 1px 6px; background: var(--surface-2); color: var(--text-2); margin-left: 6px; white-space: nowrap; }
.tag.buy { background: var(--accent); color: var(--accent-ink); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.filters select { width: auto; min-width: 140px; }

/* ── settings ── */
.settings { display: grid; gap: 14px; }
.setting { display: grid; gap: 4px; }
.setting .row { display: flex; gap: 8px; align-items: center; }
.setting .row input { max-width: 140px; }
.setting .unit { color: var(--text-2); }
.setting .help { color: var(--muted); font-size: 0.82rem; }

/* ── chart ── */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1); opacity: 0.1; }
.chart .end-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .bar-gain { fill: var(--gain); }
.chart .bar-loss { fill: var(--loss); }
.chart .baseline { stroke: var(--muted); stroke-width: 1; }
.chart .hit { fill: transparent; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 0.82rem; box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tooltip .tip-title { font-weight: 600; }
.chart-caption { color: var(--text-2); font-size: 0.85rem; margin: 6px 0 0; }
details.table-view summary { cursor: pointer; color: var(--text-2); font-size: 0.85rem; margin-top: 8px; }

/* ── dialog ── */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 18px; width: min(420px, calc(100% - 32px));
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog h3 { margin-bottom: 8px; font-size: 1.05rem; }
dialog p { margin: 0 0 14px; color: var(--text-2); white-space: pre-line; overflow-wrap: anywhere; }
dialog .dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
