/* ==========================================================================
   backtester.app — design system
   A local-first signal validation terminal. Flat surfaces, hairline rules,
   restrained teal, and numbers that line up.
   ========================================================================== */

:root {
  /* Surfaces */
  --bg: #080d13;
  --bg-deep: #060a0f;
  --surface: #0c131b;
  --surface-2: #101923;
  --surface-3: #141f2b;

  /* Rules */
  --line: #1a2430;
  --line-soft: #141d27;
  --line-strong: #27333f;

  /* Type */
  --text: #e7eaee;
  --text-2: #c2cbd5;
  --muted: #8b98a6;
  --faint: #78858f;

  /* Accents */
  --teal: #3fbfae;
  --teal-bright: #5cd8c6;
  --teal-ink: #041310;
  --teal-wash: rgba(63, 191, 174, 0.08);

  /* Performance only */
  --positive: #4cc38a;
  --negative: #e06060;
  --warning: #d2a54c;
  --neutral: #93a1af;

  --positive-wash: rgba(76, 195, 138, 0.08);
  --negative-wash: rgba(224, 96, 96, 0.08);
  --warning-wash: rgba(210, 165, 76, 0.08);

  /* Structure */
  --radius: 6px;
  --radius-sm: 4px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
  --num: "SF Mono", "Cascadia Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  font-feature-settings: "tnum" 1, "cv05" 1;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(63, 191, 174, 0.28); color: #fff; }

h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }
a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--teal-bright); text-decoration: underline; text-underline-offset: 2px; }
code {
  font-family: var(--num);
  font-size: 11px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
}
button, input, select, textarea { font-family: inherit; }
strong { font-weight: 600; }

:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: #2a3746 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: #253241;
  border: 3px solid var(--bg);
  border-radius: 8px;
}
*::-webkit-scrollbar-thumb:hover { background: #334456; }

/* ==========================================================================
   Shell
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: 56px;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.wordmark {
  display: inline-flex;
  align-items: baseline;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1;
  white-space: nowrap;
}
.wordmark span {
  color: var(--teal);
  font-family: var(--num);
  font-size: 0.84em;
  font-weight: 500;
  letter-spacing: 0;
}
.wordmark:hover { color: var(--text); text-decoration: none; }
.wordmark:hover span { color: var(--teal-bright); }

.brand-sub {
  padding-left: 14px;
  border-left: 1px solid var(--line-strong);
  color: var(--faint);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
}

.top-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.version { color: var(--faint); font-family: var(--num); font-size: 10px; margin-left: 2px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 5px;
  height: 5px;
  flex: 0 0 5px;
  border-radius: 50%;
  background: var(--faint);
}
.pill.ok::before { background: var(--teal); }
.pill.warn::before { background: var(--warning); }
.pill.bad::before { background: var(--negative); }
.pill.muted { color: var(--muted); }
.pill.local { border-color: var(--line); color: var(--muted); }
.pill.local::before { display: none; }

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 20px 24px 40px;
  align-items: start;
}

/* Account, admin and Telegram pages keep the same chrome without the sidebar. */
.shell.single { grid-template-columns: minmax(0, 1fr); max-width: 1460px; }

.sidebar { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.content { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
/* The column scrolls instead of shrinking: a child with its own overflow
   (tabs, tables) would otherwise collapse to its border. */
.content > * { flex: 0 0 auto; }

.card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.card-head h2,
.card-head h3 {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.stack { display: flex; flex-direction: column; gap: 10px; }

/* Collapsible sidebar panels: the header row is the control. */
.collapse > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.collapse > summary::-webkit-details-marker { display: none; }
.collapse:not([open]) > summary { margin-bottom: 0; }
.collapse > summary:hover h2 { color: var(--text-2); }
.collapse[open] > summary .drawer-chevron { transform: rotate(180deg); }
.summary-right { display: flex; align-items: center; gap: 8px; }

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1680px;
  margin: 0 auto;
  padding: 16px 24px 28px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 10.5px;
}
.app-footer .foot-brand { color: var(--muted); font-weight: 500; letter-spacing: -0.01em; }

/* ==========================================================================
   Controls
   ========================================================================== */

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
button:hover:not(:disabled), .button:hover { background: var(--surface-3); border-color: #34424f; color: var(--text); }
button:active:not(:disabled) { background: #0b121a; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

button.primary {
  border-color: var(--teal);
  background: var(--teal);
  color: var(--teal-ink);
  font-weight: 650;
}
button.primary:hover:not(:disabled) { background: var(--teal-bright); border-color: var(--teal-bright); color: var(--teal-ink); }
button.primary:active:not(:disabled) { background: #35ab9c; }

button.secondary {
  border-color: rgba(63, 191, 174, 0.32);
  background: var(--teal-wash);
  color: #8fe3d6;
}
button.secondary:hover:not(:disabled) { background: rgba(63, 191, 174, 0.14); border-color: rgba(63, 191, 174, 0.48); color: #a9eee4; }

button.ghost, a.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
button.ghost:hover:not(:disabled), a.ghost:hover { background: var(--surface-2); border-color: var(--line); color: var(--text); }

button.small, a.small { height: 26px; padding: 0 9px; font-size: 10.5px; }
button.wide { width: 100%; height: 34px; font-size: 12px; }
a.ghost { display: inline-flex; align-items: center; height: 30px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
a.ghost.small { height: 26px; padding: 0 9px; }
a.ghost.hidden { display: none; }
a.ghost.disabled, a.ghost[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }

button.busy { position: relative; color: transparent !important; }
button.busy::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 12px;
  height: 12px;
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
button.primary.busy::after { border-color: rgba(4, 19, 16, 0.25); border-top-color: var(--teal-ink); }
@keyframes spin { to { transform: rotate(360deg); } }

input, select, textarea {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
textarea { height: auto; padding: 8px 9px; line-height: 1.55; }
select { cursor: pointer; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover { border-color: #34424f; }
input:focus, select:focus, textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(63, 191, 174, 0.14);
}
input[type="checkbox"] { width: 13px; height: 13px; accent-color: var(--teal); }
input[type="date"] { font-family: var(--num); font-size: 11px; }

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
label.check {
  flex-direction: row;
  align-items: center;
  gap: 7px;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 400;
  white-space: normal;
  letter-spacing: 0;
}
label.check input { flex: 0 0 auto; }

.search { margin-bottom: 8px; }

/* One vertical rhythm for the whole panel: every control is a flex child of
   the form, so nothing can end up touching the field above it. */
#validate-form { display: flex; flex-direction: column; gap: 11px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 10px; }
.advanced {
  margin-top: 1px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}
/* A <details> lays its content out as a block even when styled as flex, so the
   spacing between the advanced controls is a sibling rule, not a gap. */
.advanced > * + * { margin-top: 9px; }
.advanced > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.advanced > summary::-webkit-details-marker { display: none; }
.advanced > summary::after { content: "+"; font-family: var(--num); font-size: 12px; color: var(--faint); }
.advanced[open] > summary { margin-bottom: 0; color: var(--text-2); }
.advanced[open] > summary::after { content: "−"; }
.advanced > summary:hover { color: var(--text); }

.field-block { margin-top: 1px; padding-top: 11px; border-top: 1px solid var(--line); }
#validate-form > button.primary { margin-top: 0; }
#validate-form > .hint { margin-top: 0; }
#validateBtn { margin-top: 12px; }
.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.range-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
/* Four equal cells keep All history / This month / Last month / Last 30 days aligned. */
.preset-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 8px; }
.preset-row .mini { width: 100%; padding: 0 4px; }

.mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.mini:hover:not(:disabled) { background: var(--surface-2); border-color: #34424f; color: var(--text); }
.mini:disabled { opacity: 0.35; cursor: default; }
.mini.primary { border-color: var(--teal); background: var(--teal); color: var(--teal-ink); }
.mini.primary:hover:not(:disabled) { background: var(--teal-bright); color: var(--teal-ink); }

.hint { margin-top: 8px; color: var(--faint); font-size: 10.5px; line-height: 1.55; }
.hint strong { color: var(--muted); font-weight: 500; }
.small { font-size: 11px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.pos { color: var(--positive); }
.neg { color: var(--negative); }
.warn { color: var(--warning); }

/* ==========================================================================
   Telegram account
   ========================================================================== */

.mini-status {
  color: var(--faint);
  font-family: var(--num);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.mini-status.on { color: var(--teal); }

.tg-account { display: flex; align-items: center; gap: 10px; }
.tg-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--teal);
  font-family: var(--num);
  font-size: 10px;
  font-weight: 500;
}
.tg-copy { min-width: 0; }
.tg-name { color: var(--text); font-size: 12.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-handle { color: var(--faint); font-size: 10.5px; }
.tg-actions { display: flex; gap: 6px; margin-top: 12px; }
.tg-actions button { flex: 1; }
.tg-note { color: var(--faint); font-size: 10px; line-height: 1.5; }
.tg-steps { color: var(--muted); font-size: 11px; line-height: 1.55; }
.tg-steps strong { color: var(--text-2); }
.tg-error, .form-error {
  color: #f0a5a5;
  font-size: 10.5px;
  line-height: 1.5;
  padding: 6px 8px;
  border: 1px solid rgba(224, 96, 96, 0.24);
  border-radius: 3px;
  background: var(--negative-wash);
}
/* An unused error slot must not draw an empty red box. */
.form-error { margin-top: 2px; }
.form-error:empty { display: none; }

/* ==========================================================================
   Channels
   ========================================================================== */

.channels-drawer > summary { list-style: none; cursor: pointer; margin-bottom: 0; }
.channels-drawer > summary::-webkit-details-marker { display: none; }
.channels-drawer[open] > summary { margin-bottom: 12px; }
.drawer-head { align-items: flex-start; }
.drawer-copy { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.current-channel {
  max-width: 240px;
  overflow: hidden;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channels-drawer[open] .current-channel { color: var(--text); }
.drawer-chevron {
  color: var(--faint);
  font-family: var(--num);
  font-size: 10px;
  line-height: 1;
  margin-top: 3px;
  transition: transform 140ms ease;
}
.channels-drawer[open] .drawer-chevron { transform: rotate(180deg); }
.drawer-body { margin-top: 0; }
.drawer-actions { display: flex; gap: 6px; align-items: flex-start; }
.drawer-actions .search { flex: 1; margin-bottom: 8px; }
.drawer-actions button { flex: 0 0 auto; }

.channel-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 248px;
  overflow-y: auto;
  padding: 1px 0;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}
.channel-list > p { padding: 10px 2px; }
.channel-item {
  display: flex;
  align-items: center;
  width: 100%;
  height: auto;
  min-height: 30px;
  padding: 6px 8px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--text-2);
  text-align: left;
  cursor: pointer;
}
.channel-item + .channel-item { border-top: 1px solid var(--line-soft); }
.channel-item:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.channel-item.active { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--teal); }
.channel-item .ch-title {
  overflow: hidden;
  font-size: 11.5px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.sync-row button { flex: 1; }
.sync-row .check { flex: 0 0 auto; }

/* ==========================================================================
   Run header and job progress
   ========================================================================== */

.run-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  flex-wrap: wrap;
}
.run-title { min-width: 0; flex: 1 1 360px; }
.run-kicker {
  display: block;
  margin-bottom: 6px;
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.run-title h2 { color: var(--text); font-size: 17px; font-weight: 600; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.run-title p { margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.5; }
/* Stacked and right-aligned: Export PDF on top, Replay Backtest under it.
   A quiet button here still gets the link's border, so the column reads as a
   pair instead of one button and one label. */
.run-actions {
  display: flex; flex-direction: column; align-items: flex-end;
  gap: 6px; flex: 0 0 auto;
}
.run-actions button.ghost {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.jobbar {
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.jobbar.error { border-color: rgba(224, 96, 96, 0.4); }
.progress { height: 3px; overflow: hidden; border-radius: 2px; background: var(--line-soft); }
.progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 2px;
  background: var(--teal);
  transition: width 300ms ease;
}
.progress.indeterminate span { width: 30%; animation: indeterminate 1.4s ease-in-out infinite; }
@keyframes indeterminate {
  0% { margin-left: -30%; }
  100% { margin-left: 100%; }
}
.jobtext {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  font-size: 11px;
}
#jobMessage { color: var(--text-2); }
#jobMessage.error { color: #eda0a0; }
#jobPercent { color: var(--faint); font-family: var(--num); font-size: 10px; }

/* ==========================================================================
   Empty and warning states
   ========================================================================== */

.empty {
  padding: 40px 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.empty-inner { max-width: 560px; }
.empty-kicker {
  color: var(--teal);
  font-family: var(--num);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.empty h3 { margin: 10px 0 8px; color: var(--text); font-size: 19px; font-weight: 600; letter-spacing: -0.02em; }
.empty p { color: var(--muted); font-size: 12px; line-height: 1.65; }
.empty-path { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--faint) !important; font-size: 10.5px !important; }
.empty-path code { margin-left: 4px; }

.warnings {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(210, 165, 76, 0.24);
  border-left: 2px solid var(--warning);
  border-radius: 3px;
  background: var(--warning-wash);
  color: #d9bd80;
  font-size: 11px;
  line-height: 1.55;
}
.warnings ul { margin: 0; padding-left: 16px; }
.warnings li + li { margin-top: 3px; }

/* ==========================================================================
   Metrics and performance
   ========================================================================== */

/* One tile per metric, all on a single row: the seven read as one strip, so
   the columns shrink to a minimum instead of wrapping onto a second row. */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
/* Separate tiles instead of one panel cut up by hairline dividers. */
.metric {
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.metric .label {
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}
.metric .value {
  margin-top: 6px;
  color: var(--text);
  font-family: var(--num);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.metric .value.pos { color: var(--positive); }
.metric .value.neg { color: var(--negative); }
.metric .value.warn { color: var(--warning); }
.metric .sub {
  margin-top: 4px;
  color: var(--faint);
  font-size: 9px;
  line-height: 1.35;
}

.performance {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px 14px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.perf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.perf-title {
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.perf-values { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; font-family: var(--num); font-size: 11px; }
.perf-values .perf-equity { color: var(--text-2); }
.perf-values .perf-change { font-weight: 500; }
.perf-chart { line-height: 0; }
.perf-chart svg { display: block; width: 100%; height: 64px; }
.perf-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 2px;
  color: var(--faint);
  font-size: 10px;
}
.perf-foot .perf-dd { color: var(--negative); font-family: var(--num); }

/* The PDF breakdown: a section title and two columns filled left to right,
   label left, value right, in the printed order and with no dividers. */
.breakdown-block { margin-bottom: 2px; }
.breakdown-title {
  margin-bottom: 8px;
  color: var(--faint);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.breakdown {
  display: grid;
  /* Two PDF-width columns rather than one stretched across the screen. */
  grid-template-columns: repeat(2, minmax(0, 380px));
  grid-auto-flow: row;
  column-gap: 40px;
  justify-content: start;
}
.breakdown-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding: 4px 0;
}
.breakdown-row span {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.breakdown-row strong {
  color: var(--text);
  font-family: var(--num);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  white-space: nowrap;
}

/* ==========================================================================
   Tabs and panels
   ========================================================================== */

.tabs {
  display: flex;
  gap: 22px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
  /* Scrolled into view when a save returns to this page: clear the sticky bar. */
  scroll-margin-top: 64px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.tab::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: transparent;
}
.tab:hover:not(:disabled) { background: transparent; border: 0; color: var(--text-2); }
.tab.active { background: transparent; color: var(--text); }
.tab.active::after { background: var(--teal); }

.tab-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--surface);
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filters { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
.filters select, .filters input { width: auto; min-width: 132px; font-size: 11px; }
.filters input { min-width: 200px; }
.mini-actions { display: flex; align-items: center; gap: 10px; }

/* ==========================================================================
   Tables
   ========================================================================== */

.table-wrap {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
}
.data-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 7px;
  border-bottom: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--muted);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.data-table td {
  padding: 6px 7px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--text-2);
  vertical-align: middle;
}
.data-table td:nth-child(2) { white-space: nowrap; }
.data-table tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.012); }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:focus-visible { outline: 1px solid var(--teal); outline-offset: -1px; }
.data-table tbody tr:focus-visible td { background: var(--surface-2); color: var(--text); }
.data-table tbody tr:hover td { background: var(--surface-2); color: var(--text); }
.data-table tbody tr:last-child td { border-bottom: 0; }
/* How many follow-ups hang off a trade: a channel that keeps talking about a
   post is often the one worth opening. */
.replies-cell { white-space: nowrap; }
.reply-count {
  display: inline-block;
  min-width: 17px;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-2);
  font-size: 10px;
  text-align: center;
}
.data-table tbody tr:hover .reply-count { background: rgba(255, 255, 255, 0.1); color: var(--text); }

/* Keep the timestamp in view while a dense table is scrolled sideways. */
.data-table th:first-child { left: 0; z-index: 3; }
.data-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--bg-deep);
  box-shadow: 1px 0 0 var(--line-soft);
}
.data-table tbody tr:hover td:first-child { background: var(--surface-2); }
.data-table tbody tr:nth-child(even) td:first-child { background: #080c11; }
.data-table .num, .data-table td.num {
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.data-table .pair { color: var(--text); font-weight: 500; white-space: nowrap; }
.data-table .time { color: var(--muted); font-family: var(--num); font-size: 10.5px; white-space: nowrap; }
.data-table .note-cell {
  max-width: 200px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-table .dir { display: inline-block; margin-left: 5px; vertical-align: 1px; }
.dir-buy, .dir-sell {
  padding: 1px 4px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-family: var(--num);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.dir-buy { color: var(--positive); border-color: rgba(76, 195, 138, 0.28); background: var(--positive-wash); }
.dir-sell { color: var(--negative); border-color: rgba(224, 96, 96, 0.28); background: var(--negative-wash); }

.badge {
  --badge-rgb: 147, 161, 175;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 6px;
  border: 1px solid rgba(var(--badge-rgb), 0.26);
  border-radius: 3px;
  background: rgba(var(--badge-rgb), 0.07);
  color: rgb(var(--badge-rgb));
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.6;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }
.badge.win { --badge-rgb: 76, 195, 138; }
.badge.loss { --badge-rgb: 224, 96, 96; }
.badge.breakeven { --badge-rgb: 147, 161, 175; }
.badge.open_at_end,
.badge.not_filled,
.badge.cancelled,
.badge.ambiguous_same_bar,
.badge.ambiguous { --badge-rgb: 210, 165, 76; }
.badge.ambiguous_signal,
.badge.no_market_data,
.badge.no_price_data,
.badge.invalid_levels,
.badge.out_of_range,
.badge.skip { --badge-rgb: 126, 140, 154; }
.badge.parsed { --badge-rgb: 76, 195, 138; }
.badge.synthetic { --badge-rgb: 140, 160, 180; }

.tag {
  display: inline-block;
  padding: 0 4px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  color: var(--muted);
  font-family: var(--num);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.04em;
  line-height: 1.6;
  text-transform: uppercase;
  vertical-align: 1px;
}
.tag.ai { color: var(--teal); border-color: rgba(63, 191, 174, 0.32); background: var(--teal-wash); }

/* ==========================================================================
   Chart
   ========================================================================== */

.chart-wrap {
  overflow: hidden;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
}
#chartCanvas { display: block; width: 100%; height: 380px; cursor: crosshair; }
.chart-legend {
  display: flex;
  align-items: center;
  gap: 8px 20px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
  font-size: 10px;
}
.chart-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; }
.legend-dot.buy { background: var(--positive); }
.legend-dot.sell { background: var(--negative); }
.legend-line { display: inline-block; width: 14px; border-top: 1px dashed currentColor; }
.legend-line.entry { color: #8fb8d8; }
.legend-line.stop { color: var(--negative); }
.legend-line.target { color: var(--positive); }

.chart-detail {
  display: grid;
  gap: 9px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 11.5px;
}
.chart-detail-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chart-detail-head strong { color: var(--text); font-family: var(--num); font-size: 11px; font-weight: 500; }
.chart-detail .kv { grid-template-columns: 92px minmax(0, 1fr); font-size: 11px; }
.chart-detail .hint { margin-top: 0; }

/* ==========================================================================
   AI fallback and parser rules
   ========================================================================== */

.ai-details > summary { list-style: none; cursor: pointer; margin-bottom: 0; }
.ai-details > summary::-webkit-details-marker { display: none; }
.ai-details[open] > summary { margin-bottom: 12px; }
.ai-summary { align-items: flex-start; }
.ai-summary-copy { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.summary-sub { color: var(--faint); font-size: 10px; font-weight: 400; line-height: 1.4; }
.ai-summary-right { display: flex; align-items: center; gap: 8px; padding-top: 1px; }
.ai-details[open] .drawer-chevron { transform: rotate(180deg); }
.ai-body { min-width: 0; }

.ai-card .ai-privacy { margin-bottom: 10px; line-height: 1.55; }
.ai-toggles { gap: 7px; margin-bottom: 10px; }
.ai-toggles .check { font-size: 10.5px; }
.ai-usage {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 9.5px;
}
.ai-usage-line { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.ai-usage-line strong { color: var(--text-2); font-family: var(--num); font-weight: 500; }
.ai-usage-line strong.warn { color: var(--warning); }
.ai-actions { display: flex; gap: 6px; margin-top: 10px; }
.ai-actions button { flex: 1; }
.ai-actions button.ghost { flex: 0 0 auto; }

.ai-reviews, .parser-rules {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.ai-reviews-head, .parser-rules-head {
  display: flex;
  align-items: baseline;
  gap: 4px 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  font-size: 11px;
}
.ai-reviews-head strong, .parser-rules-head strong {
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.ai-reviews ul, .parser-rules ul { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.ai-reviews li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.ai-reviews li:first-child { padding-top: 0; border-top: 0; }
.ai-reviews li:last-child { padding-bottom: 0; }
.ai-review-copy { flex: 1; min-width: 0; }
.ai-review-title { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; font-size: 11px; }
.ai-review-title strong { color: var(--text-2); font-weight: 500; }
.ai-review-summary { margin-top: 4px; color: var(--text-2); font-family: var(--num); font-size: 10.5px; }
.ai-review-errors { margin-top: 4px; color: #e79c9c; font-size: 10px; overflow-wrap: anywhere; }
.ai-review-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; max-width: 220px; }
.ai-reviews .rule-sample, .parser-rules .rule-sample {
  max-height: 48px;
  margin: 6px 0 0;
  overflow: hidden;
  color: var(--faint);
  font-family: var(--num);
  font-size: 9.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.parser-rules li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}
.parser-rules li:first-child { padding-top: 0; border-top: 0; }
.rule-copy { min-width: 0; color: var(--muted); font-size: 11px; }

/* ==========================================================================
   Forms inside the review modal
   ========================================================================== */

.raw-input {
  width: 100%;
  min-height: 126px;
  padding: 9px 10px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  color: var(--text-2);
  font-family: var(--num);
  font-size: 10.5px;
  line-height: 1.6;
  outline: none;
}
.raw-input:focus { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(63, 191, 174, 0.14); }

.review-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.review-form .wide { grid-column: 1 / -1; }
.review-form label.inline {
  flex-direction: row;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
}
.review-form label.inline input { flex: 0 0 auto; width: 13px; }
.review-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.review-actions button { width: auto; }
.modal-actions { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ==========================================================================
   Modal and toast
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 6, 10, 0.78);
}
.modal-card {
  width: min(740px, 100%);
  max-height: 88vh;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.modal-head h3 { color: var(--text); font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.modal-body { padding: 16px; }
.modal-body h4 {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.modal-body h4:first-child { margin-top: 0; }

.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 6px 12px; font-size: 11.5px; }
.kv dt { color: var(--faint); }
.kv dd { margin: 0; color: var(--text-2); overflow-wrap: anywhere; }
.kv dd.pos { color: var(--positive); }
.kv dd.neg { color: var(--negative); }

.raw-message {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
  color: var(--text-2);
  font-family: var(--num);
  font-size: 10.5px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.exit-list, .update-list { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.exit-list li, .update-list li {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--bg-deep);
  color: var(--text-2);
  font-size: 10.5px;
}
.exit-list .exit-meta, .update-list .update-meta { color: var(--faint); font-size: 9.5px; }
.flag-row { display: flex; flex-wrap: wrap; gap: 4px; }
.flag {
  padding: 1px 5px;
  border: 1px solid rgba(210, 165, 76, 0.22);
  border-radius: 3px;
  background: var(--warning-wash);
  color: #d9bd80;
  font-family: var(--num);
  font-size: 9px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  max-width: min(420px, calc(100vw - 40px));
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  border-left: 2px solid var(--teal);
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-2);
  box-shadow: var(--shadow);
  font-size: 11.5px;
  line-height: 1.5;
}
.toast.error { border-left-color: var(--negative); color: #f0b5b5; }
.toast.success { border-left-color: var(--positive); }

/* ==========================================================================
   Responsive
   ========================================================================== */

/* The free-text detail only fits next to every numeric column on a wide screen. */
@media (max-width: 1640px) {
  .data-table .detail-col { display: none; }
}

/* Desktop: the two columns are independent scroll regions. Scrolling over the
   settings moves only the settings; the report keeps its own position. */
@media (min-width: 1121px) {
  html, body { height: 100%; }
  body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .topbar { flex: 0 0 auto; }
  .shell {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
    padding-top: 0;
    padding-bottom: 0;
  }
  .sidebar,
  .content {
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding-top: 20px;
    padding-bottom: 36px;
  }
  .app-footer { flex: 0 0 auto; padding: 10px 24px; }
}

@media (max-width: 1360px) {
  .breakdown { column-gap: 28px; }
  .filters input { min-width: 160px; }
}

@media (max-width: 1120px) {
  .shell { grid-template-columns: minmax(0, 1fr); padding: 16px 18px 32px; }
  .sidebar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .sidebar .ai-card { grid-column: span 2; }
  .topbar { padding: 0 18px; }
  .filters input { min-width: 200px; }
}

@media (max-width: 780px) {
  body { font-size: 12.5px; }
  .topbar { height: auto; min-height: 52px; padding: 10px 14px; gap: 10px; flex-wrap: wrap; }
  .brand-sub { display: none; }
  .top-status { gap: 6px; }
  .pill { height: 22px; padding: 0 7px; font-size: 10px; }
  .pill.local { display: none; }
  .version { display: none; }
  .shell { padding: 12px 14px 26px; gap: 12px; }
  .sidebar { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .sidebar .ai-card { grid-column: auto; }
  .run-head { padding: 14px; gap: 12px; }
  .run-title h2 { font-size: 16px; }
  .run-actions { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .run-actions .ghost, .run-actions button { flex: 1; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { padding: 10px 12px; }
  .metric .value { font-size: 18px; }
  .performance { padding: 10px 12px; }
  .perf-chart svg { height: 56px; }
  .breakdown { grid-template-columns: minmax(0, 1fr); }
  .tab-panel { padding: 12px; }
  .filters { width: 100%; }
  .filters select, .filters input { flex: 1 1 40%; min-width: 0; }
  .mini-actions { width: 100%; justify-content: space-between; }
  .table-wrap { max-height: 58vh; }
  .modal { padding: 12px; }
  .modal-card { max-height: 92vh; }
  .review-form { grid-template-columns: 1fr; }
  .review-form .wide { grid-column: auto; }
  .kv { grid-template-columns: 104px minmax(0, 1fr); gap: 5px 10px; font-size: 11px; }
  .ai-reviews li { flex-direction: column; gap: 8px; }
  .ai-review-actions { justify-content: flex-start; max-width: none; }
  .app-footer { padding: 14px; flex-direction: column; align-items: flex-start; gap: 4px; font-size: 10px; }
}

@media (max-width: 480px) {
  .top-status .pill:nth-of-type(1) { display: none; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { padding: 10px; }
  .metric .value { font-size: 17px; }
  .metric .sub { white-space: normal; }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .range-row { grid-template-columns: 1fr; }
  .preset-row { gap: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ------------------------------------------------------------------ */
/* Hosted dashboard additions (account nav, quota, report picker, SVG) */
/* ------------------------------------------------------------------ */
.topnav { display: flex; align-items: center; gap: 14px; }
.topnav a { color: var(--muted); font-size: 11px; text-decoration: none; letter-spacing: 0.02em; }
.topnav a:hover { color: var(--text); }
.topnav a.on { color: var(--teal); }
.topnav button.logout { background: none; border: 0; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer; padding: 0; }
.topnav button.logout:hover { color: var(--text); }

.quota { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.quota-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-2); }
.quota-row .num { font-family: var(--num); color: var(--muted); }
.quota-track { height: 4px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.quota-track > span { display: block; height: 100%; background: var(--teal); border-radius: 99px; }

.report-list { display: flex; flex-direction: column; gap: 2px; }
.report-row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 8px; border-radius: 7px; text-decoration: none; color: var(--text-2); font-size: 11px; }
.report-row:hover { background: var(--surface-2); color: var(--text); }
.report-row.on { background: var(--surface-2); color: var(--text); }
.report-row .when { color: var(--faint); font-family: var(--num); font-size: 10px; }
.report-row .state { font-family: var(--num); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); }
.report-row .state.ok { color: var(--teal); }
.report-row .state.bad { color: var(--negative); }

.chart-block { padding: 14px 16px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.chart-block h3 { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); font-weight: 500; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.chart-head .range { font-family: var(--num); font-size: 11px; color: var(--muted); }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; color: var(--faint); font-size: 10px; }

.flag { display: inline-block; padding: 1px 5px; border-radius: 4px; background: rgba(224, 96, 96, 0.12);
  color: #e08a8a; font-family: var(--num); font-size: 9px; letter-spacing: 0.04em; }
.flag.neutral { background: rgba(255, 255, 255, 0.05); color: var(--faint); }
.dir-buy { color: var(--positive); }
.dir-sell { color: var(--negative); }
.table-wrap { max-height: 620px; overflow: auto; }
.sidebar .card { padding: 14px 15px; }
.brand-note { margin-top: 2px; color: var(--faint); font-size: 10px; }

.chart-stats { display: flex; flex-wrap: wrap; gap: 18px; margin: 2px 0 10px; }
.chart-stats > div { display: flex; flex-direction: column; gap: 2px; }
.chart-stats span { font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); }
.chart-stats strong { font-family: var(--num); font-size: 12.5px; font-weight: 500; color: var(--text); }
.chart-stats strong.pos { color: var(--positive); }
.chart-stats strong.neg { color: var(--negative); }
.chart-stats strong.warn { color: var(--warning); }
a.ghost { display: inline-flex; align-items: center; justify-content: center; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2);
  color: var(--text-2); font-size: 11px; text-decoration: none; }
a.ghost:hover { border-color: #34424f; color: var(--text); }

/* ------------------------------------------------------------------ */
/* Shared signed-in pages: account, admin, Telegram                    */
/* Reuses the dashboard tokens so these pages never fall back to the    */
/* public marketing stylesheet.                                        */
/* ------------------------------------------------------------------ */
.mono { font-family: var(--num); }
.nowrap { white-space: nowrap; }
.inline-form { display: inline; margin: 0; }
.link-button { padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: 11px; cursor: pointer; }
.link-button:hover { color: var(--teal); text-decoration: underline; text-underline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 30px; padding: 0 12px;
  border: 1px solid var(--teal); border-radius: var(--radius-sm);
  background: var(--teal); color: var(--teal-ink);
  font-size: 11px; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--teal-bright); border-color: var(--teal-bright); color: var(--teal-ink); text-decoration: none; }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: #34424f; color: var(--text); }
.btn-small { height: 26px; padding: 0 9px; font-size: 10.5px; }
.btn-danger { background: transparent; border-color: rgba(224, 96, 96, 0.45); color: #e08a8a; }
.btn-danger:hover { background: var(--negative-wash); border-color: rgba(224, 96, 96, 0.6); color: #f0b5b5; }
.btn-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 12px; align-items: start; }

.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 10px; margin-bottom: 10px; }
.form-row > div { min-width: 0; }
/* Forms stacked inside a card need breathing room between fields. */
.card form > label { margin-top: 12px; }
.card form > label:first-child { margin-top: 0; }
.card form > button { margin-top: 14px; }
/* Inline controls keep their row alignment. */
.card-head form > button,
.btn-row button,
.btn-row .btn { margin-top: 0; }
.card ul, .card ol { margin: 0; padding-left: 1.2rem; }
.card li + li { margin-top: 4px; }
.card p + form { margin-top: 12px; }
.card p + .btn { margin-top: 10px; }
.card > .empty { padding: 22px 16px; }
.form-check { display: flex; align-items: flex-start; gap: 7px; margin: 10px 0; }
.form-check input { flex: 0 0 auto; width: 13px; height: 13px; margin-top: 2px; }
.form-check label { margin: 0; color: var(--text-2); font-size: 11px; }
.footer-note { margin-top: 10px; color: var(--faint); font-size: 10px; line-height: 1.55; }
.copy-once {
  margin-top: 10px; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--bg-deep); color: var(--teal);
  font-family: var(--num); font-size: 12px; overflow-wrap: anywhere;
}

.notice { margin-bottom: 12px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-2); font-size: 11.5px; line-height: 1.5; }
.notice.info { border-color: rgba(63, 191, 174, 0.3); background: var(--teal-wash); color: #b7e9e1; }
.notice.ok { border-color: rgba(76, 195, 138, 0.3); background: var(--positive-wash); color: #bdebd3; }
.notice.warn { border-color: rgba(210, 165, 76, 0.3); background: var(--warning-wash); color: #e6cd9c; }
.notice.error { border-color: rgba(224, 96, 96, 0.32); background: var(--negative-wash); color: #f0b5b5; }

.badge.badge-queued { --badge-rgb: 210, 165, 76; }
.badge.badge-processing { --badge-rgb: 111, 178, 255; }
.badge.badge-completed, .badge.badge-active { --badge-rgb: 76, 195, 138; }
.badge.badge-failed, .badge.badge-suspended, .badge.badge-deactivated { --badge-rgb: 224, 96, 96; }
.badge.badge-cancelled, .badge.badge-pending { --badge-rgb: 147, 161, 175; }
.badge.badge-draft { --badge-rgb: 126, 140, 154; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat .label { color: var(--muted); font-size: 9.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.stat .value { margin-top: 6px; color: var(--text); font-family: var(--num); font-size: 19px; font-weight: 500; letter-spacing: -0.03em; line-height: 1.1; }
.stat .hint { margin-top: 4px; color: var(--faint); font-size: 9.5px; line-height: 1.4; }

table.data { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; }
table.data th { padding: 7px; border-bottom: 1px solid var(--line-strong); background: var(--surface);
  color: var(--muted); font-size: 9px; font-weight: 600; letter-spacing: 0.07em; text-align: left; text-transform: uppercase; white-space: nowrap; }
table.data td { padding: 7px; border-bottom: 1px solid var(--line-soft); color: var(--text-2); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); color: var(--text); }
table.data .num, table.data td.num { font-family: var(--num); text-align: right; white-space: nowrap; }
.table-scroll { overflow-x: auto; }

.tabs a { position: relative; display: inline-flex; align-items: center; height: 34px; padding: 0 2px;
  color: var(--muted); font-size: 11.5px; text-decoration: none; white-space: nowrap; }
.tabs a:hover { color: var(--text-2); text-decoration: none; }
.tabs a.on { color: var(--text); }
.tabs a.on::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: var(--teal); }

.health-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--faint); }
.health-dot.ok { background: var(--positive); box-shadow: 0 0 8px rgba(76, 195, 138, 0.55); }
.health-dot.bad { background: var(--negative); }

@media (max-width: 1080px) {
  .dash-grid, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-row { grid-template-columns: minmax(0, 1fr); }
}

/* A person or channel name inside a card head: readable, not a section label. */
.entity-name { color: var(--text); font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }

/* ==========================================================================
   Signal review dialog
   A correction is made against the post the report shows, so the message sits
   above the fields and the numbers are edited in place.
   ========================================================================== */

.review-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0 0 10px; padding: 9px 12px;
  border: 1px solid var(--line-strong); border-left: 2px solid var(--teal);
  border-radius: var(--radius-sm); background: var(--surface);
  font-size: 11.5px; color: var(--text-2);
}
.review-bar form { margin: 0; }
.review-bar strong { color: var(--text); font-weight: 600; }

.review-dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow);
}
.review-dialog::backdrop { background: rgba(3, 6, 10, 0.72); }
.review-dialog form { margin: 0; padding: 16px; }
.review-dialog form + form { padding-top: 0; }
.review-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.review-head h3 { margin: 2px 0 2px; color: var(--text); font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }
.review-message {
  margin: 0 0 12px; padding: 10px 12px;
  max-height: 200px; overflow: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-deep); color: var(--text-2);
  font-family: var(--num); font-size: 11px; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.review-thread { margin: 0 0 12px; }
.review-thread-title { margin: 0 0 6px; color: var(--muted); font-size: 10px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; }
.review-thread-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none;
  max-height: 220px; overflow: auto; }
.review-thread-list li { padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); }
.review-thread-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.review-thread-text { margin: 0; color: var(--text-2); font-family: var(--num); font-size: 11px;
  line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.review-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px 10px; }
.review-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 10px;
  font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; }
.review-grid input, .review-grid select {
  height: 30px; width: 100%; padding: 0 8px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font-family: var(--num); font-size: 12px;
}
.review-grid input:focus, .review-grid select:focus { outline: 1px solid var(--teal); outline-offset: 0; }
.review-check {
  grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 7px;
  color: var(--text-2); font-size: 11px; font-weight: 400; letter-spacing: 0; text-transform: none;
}
/* Only the radios are square: the outcome form also has a text input in the
   same row, and a blanket rule here made it 13px wide. */
.review-check input[type="radio"] { width: 13px; height: 13px; flex: none; }
/* ==========================================================================
   Trade review
   The list keeps a compact action per row; the dialog is where the trade is
   judged, with the signal, the numbers and the price action side by side.
   ========================================================================== */

.review-cell { width: 1%; white-space: nowrap; text-align: right; }
.btn-review {
  height: 22px; padding: 0 8px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: transparent; color: var(--text-2);
  font-family: var(--sans); font-size: 10px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer;
}
.btn-review:hover, .btn-review:focus-visible { border-color: var(--teal); color: var(--teal-bright); outline: none; }
.btn-review.flagged {
  border-color: rgba(210, 165, 76, 0.45); background: var(--warning-wash); color: var(--warning);
}
.btn-review.flagged:hover, .btn-review.flagged:focus-visible { border-color: var(--warning); color: #e4bd70; }

.filter-chip {
  height: 28px; padding: 0 10px;
  border: 1px solid rgba(210, 165, 76, 0.45); border-radius: 999px;
  background: var(--warning-wash); color: var(--warning);
  font-family: var(--sans); font-size: 11px; font-weight: 600; cursor: pointer;
}
.filter-chip:hover { border-color: var(--warning); }
.filter-chip.active { background: rgba(210, 165, 76, 0.22); color: #e4bd70; }

.trade-dialog { width: min(1040px, calc(100vw - 32px)); }
.trade-panel {
  max-height: calc(100vh - 64px); overflow: auto;
  padding: 16px;
}
/* The close button should not scroll away with the trade: the header sticks to
   the top of the panel, however far down the chart and the follow-ups go. */
.trade-panel > .review-head {
  position: sticky;
  top: -16px;
  z-index: 6;
  margin: -16px -16px 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
/* The signal correction form lives in the trade dialog now. */
.trade-fix {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-deep);
}
.trade-fix summary {
  cursor: pointer;
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
}
.trade-fix[open] summary { margin-bottom: 10px; }
.trade-fix form { margin: 0; padding: 0; }
.trade-fix .review-actions { margin-top: 10px; }
.trade-figures {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px;
  margin: 0 0 14px;
}
.trade-figure {
  display: flex; flex-direction: column; gap: 3px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.trade-figure span { color: var(--muted); font-size: 9.5px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; }
.trade-figure strong { color: var(--text); font-family: var(--num); font-size: 13px; font-weight: 600; }
.trade-figure strong.pos { color: var(--positive); }
.trade-figure strong.neg { color: var(--negative); }

.trade-chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.trade-legend { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 10px; }
.trade-legend span { display: inline-flex; align-items: center; gap: 5px; }
.trade-dot { display: inline-block; width: 7px; height: 7px; border-radius: 2px; }
.trade-dot.entry { background: #7aa2f7; }
.trade-dot.stop { background: #e06060; }
.trade-dot.target { background: #4cc38a; }
.trade-dot.exit { background: #d2a54c; border-radius: 50%; }
.trade-chart {
  width: 100%; height: 380px; margin: 0 0 6px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-deep); overflow: hidden;
}
.trade-chart-note { margin: 0 0 12px; }

.trade-review {
  margin: 4px 0 16px; padding: 12px;
  border: 1px solid rgba(210, 165, 76, 0.35); border-left: 2px solid var(--warning);
  border-radius: var(--radius-sm); background: var(--warning-wash);
}
.trade-review .review-thread-title { color: var(--warning); }
.trade-reason { margin: 0 0 4px; color: var(--text); font-size: 12.5px; }
.trade-review .review-outcome { margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(210, 165, 76, 0.25); }

.trade-cols { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; }
.trade-cols .review-message { max-height: 260px; }
.trade-kv { display: flex; flex-direction: column; gap: 0; margin: 0 0 12px; }
.trade-kv-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 5px 0; border-bottom: 1px solid var(--line-soft); }
.trade-kv-row dt { color: var(--muted); font-size: 10.5px; letter-spacing: 0.02em; }
.trade-kv-row dd { margin: 0; color: var(--text-2); font-family: var(--num); font-size: 11px; text-align: right;
  overflow-wrap: anywhere; }
.trade-kv-row dd.pos { color: var(--positive); }
.trade-kv-row dd.neg { color: var(--negative); }
.trade-credit { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--line-soft); font-size: 10px; }
.trade-credit a { color: var(--muted); }
.trade-credit a:hover { color: var(--text-2); }

@media (max-width: 780px) {
  .trade-figures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trade-cols { grid-template-columns: minmax(0, 1fr); }
  .trade-chart { height: 280px; }
  .trade-legend { display: none; }
}
.review-outcome {
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
}
.review-outcome-fields { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.review-outcome .review-check {
  grid-column: auto; display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  color: var(--text-2); font-size: 12px;
}
.review-outcome .review-check input[type="radio"] { width: 14px; height: 14px; flex: none; }
.review-check-text { flex: 1 1 200px; }
.review-price {
  width: 120px; height: 28px; padding: 0 8px; flex: none;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font-family: var(--num); font-size: 12px;
}
.review-price::placeholder { color: var(--muted); }
.review-price-out { min-width: 52px; font-family: var(--num); font-size: 11px; font-variant-numeric: tabular-nums; }
.review-price-out.pos { color: var(--positive); }
.review-price-out.neg { color: var(--negative); }
.review-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.review-clear { margin-top: 10px; }
@media (max-width: 620px) {
  .review-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ==========================================================================
   Replay Backtest
   The statistics keep their strip; the replay button sits above it, and the
   window it opens is a chart with a transport. The chart is the only tall
   thing in the dialog, so the controls never scroll out of reach.
   ========================================================================== */

.replay-dialog { width: min(1180px, calc(100vw - 28px)); }
.replay-panel {
  display: flex; flex-direction: column; gap: 10px;
  max-height: calc(100vh - 48px);
  padding: 14px 16px 16px;
}
.replay-panel .review-head { margin-bottom: 0; }
.replay-head-tools { display: flex; align-items: flex-end; gap: 10px; }
/* The global dialog rule pads every form; the close button needs none. */
.replay-head-tools form { margin: 0; padding: 0; }

.replay-pick {
  display: flex; flex-direction: column; gap: 4px;
  color: var(--muted); font-size: 10px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
}
.replay-pick select {
  height: 28px; min-width: 96px; padding: 0 8px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font-family: var(--num); font-size: 12px; letter-spacing: 0;
  text-transform: none;
}
.replay-pick select:focus { outline: 1px solid var(--teal); outline-offset: 0; }

.replay-controls {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-deep);
}
.replay-controls .button { height: 28px; padding: 0 12px; font-size: 12px; }
.replay-controls .replay-pick { flex-direction: row; align-items: center; gap: 6px; }
.replay-controls .replay-pick select { min-width: 62px; }
.replay-clock {
  margin-left: auto; color: var(--text); font-size: 12px; font-variant-numeric: tabular-nums;
}
.replay-progress { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

.replay-chart {
  position: relative;
  height: clamp(300px, 50vh, 560px);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-deep);
  overflow: hidden;
}
.replay-notes { display: flex; flex-direction: column; gap: 6px; }
.replay-legend {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  color: var(--text-2); font-size: 11px;
}
.replay-legend span { display: inline-flex; align-items: center; gap: 6px; }
.replay-swatch {
  width: 14px; height: 9px; border-radius: 2px; display: inline-block;
}
.replay-swatch.profit { background: rgba(76, 195, 138, 0.35); border: 1px solid rgba(76, 195, 138, 0.6); }
.replay-swatch.risk { background: rgba(224, 96, 96, 0.35); border: 1px solid rgba(224, 96, 96, 0.6); }
.replay-note {
  margin: 0; padding: 7px 10px;
  border: 1px solid rgba(210, 165, 76, 0.35); border-radius: var(--radius-sm);
  background: var(--warning-wash); color: var(--warning);
  font-size: 11.5px;
}
@media (max-width: 720px) {
  .replay-head-tools { flex-wrap: wrap; justify-content: flex-end; }
  .replay-clock { margin-left: 0; }
}

/* A flash notice answers an action and then gets out of the way (see
   /flash.js, which removes it after fifteen seconds; a click does it now). */
.notice[data-flash] { cursor: default; }
.notice.is-dismissing {
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
