/* Shared UI components (templates/components/ui.html), loaded on every page by base.html.
   Rule: only the custom properties from app.css :root, never a colour literal here.
   Catalogue and how to add a component: docs/ui-components.md. */

/* ---- Utilities --------------------------------------------------------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.strong {
  font-weight: 600;
}

/* A vertical stack of page sections (cards, tiles, banners) with the standard gap. */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.icon {
  display: inline-block;
  flex: none;
  vertical-align: middle;
}

/* ---- Error banner (ui.error_banner) ------------------------------------ */

.error-banner {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  color: var(--warn);
  overflow-wrap: anywhere;
}

/* tone "error": a validation or verification failure, in the error colours. */
.error-banner.is-error {
  border-color: var(--alert-border);
  background: var(--alert-bg);
  color: var(--alert-text);
}

/* ---- Summary tiles (ui.stat) ------------------------------------------- */

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

@media (min-width: 900px) {
  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* The smallest phones (320px): a smaller value keeps an amount or a date whole in a half-width tile
   instead of breaking it mid-number. */
@media (width < 400px) {
  .stat {
    padding: var(--space-3);
  }

  .stat-value {
    font-size: 18px;
  }
}

.stat-unit,
.stat-sub {
  color: var(--muted);
  font-size: 14px;
  font-weight: 400;
}

.stat-sub {
  font-size: 13px;
}

/* ---- Side pills (ui.side_pill) and trade sides (ui.trade_side) --------- */

.pill {
  display: inline-block;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 20px;
  white-space: nowrap;
}

.pill.side-long {
  color: var(--pos);
  background: color-mix(in srgb, var(--pos) 15%, transparent);
}

.pill.side-short {
  color: var(--neg);
  background: color-mix(in srgb, var(--neg) 15%, transparent);
}

.pill-outline.side-long {
  border-color: var(--pos);
  background: transparent;
}

.pill-outline.side-short {
  border-color: var(--neg);
  background: transparent;
}

.trade-side {
  font-weight: 600;
}

.trade-buy {
  color: var(--pos);
}

.trade-sell {
  color: var(--neg);
}

/* ---- Chips (ui.chip) ---------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 18px;
  text-transform: uppercase;
  white-space: nowrap;
}

.chip .icon {
  width: 11px;
  height: 11px;
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
}

.chip-neutral {
  color: var(--muted);
  background: var(--surface-3);
}

.chip-live {
  color: var(--pos);
  border-color: color-mix(in srgb, var(--pos) 50%, transparent);
}

.chip-closed {
  color: var(--chip-closed);
  background: var(--surface-3);
}

.chip-warn {
  color: var(--warn);
  border-color: var(--warn);
}

.chip-info {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

.chip[title] {
  cursor: help;
}

/* ---- PnL colours (ui.pnl and table cells) ------------------------------- */

.pnl-pos {
  color: var(--pos);
}

.pnl-neg {
  color: var(--neg);
}

.pnl-zero {
  color: var(--muted);
}

/* ---- Tabs (ui.tabs) ------------------------------------------------------ */

.tabs {
  display: inline-flex;
  gap: var(--space-1);
  max-width: 100%;
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-4);
  border-radius: 7px;
  color: var(--muted);
  font-weight: 500;
}

.tab:hover {
  color: var(--text);
  text-decoration: none;
}

.tab[aria-current="page"] {
  background: var(--surface-3);
  color: var(--text);
  font-weight: 600;
}

.tab-count {
  padding: 0 7px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--pos);
}

.tab[aria-current="page"] .live-dot {
  box-shadow: 0 0 0 3px var(--live-glow);
}

@media (width < 700px) {
  .tab {
    min-height: 44px;
  }

  /* The chart's interval tabs (chart page and chart dialogs) take the full row and share it, so
     all six intervals fit a phone instead of scrolling out of view. */
  .chart-toolbar .tabs,
  .chart-dialog .tabs {
    display: flex;
    width: 100%;
  }

  .chart-toolbar .tab,
  .chart-dialog .tab {
    flex: 1 1 0;
    justify-content: center;
    padding: 0 var(--space-1);
  }
}

/* ---- Segmented radio control (ui.segmented) and selects ------------------ */

.segmented {
  display: flex;
  gap: 2px;
  min-width: 0;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.segmented-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented-option {
  display: flex;
  align-items: center;
  min-height: 30px;
  padding: 0 var(--space-3);
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.segmented-option:hover {
  color: var(--text);
}

.segmented-input:checked + .segmented-option {
  background: var(--surface-3);
  color: var(--text);
  font-weight: 600;
}

.segmented-input:focus-visible + .segmented-option {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.select {
  min-height: 38px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---- Page toolbar and filter form (Closed positions, Strategies) ---------- */

/* Tabs or title on the left, filters on the right; they wrap on narrow screens. */
.page-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
}

/* A label wrapping a checkbox and its text (the positions pages' "Show external" filter, the
   sign-in's "Trust this device"). */
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--muted);
  cursor: pointer;
}

/* ---- Pager (ui.pager): Prev, "Page n of m", Next in a card head ---------- */

.pager {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.pager-status {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.btn.is-disabled {
  opacity: var(--disabled-opacity);
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Combobox (typeahead input + suggestion list, static/combobox.js) ---- */

.combobox {
  position: relative;
  min-width: calc(var(--space-6) * 5);
}

.combobox .combobox-input {
  min-height: 38px;
  padding: 0 var(--space-3);
  background: var(--surface);
  font-size: 13px;
  font-family: var(--font-mono);
}

/* Under the input, above the chart (whose own layers are isolated in .price-chart) and below
   the sticky topbar. */
.combobox-list {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  z-index: 5;
  max-height: calc(var(--space-6) * 8);
  margin: 0;
  padding: var(--space-1);
  overflow-y: auto;
  list-style: none;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 var(--space-2) var(--space-5) var(--shadow-drawer);
}

.combobox-list[hidden] {
  display: none;
}

.combobox-option,
.combobox-empty {
  padding: var(--space-1) var(--space-2);
  border-radius: calc(var(--radius) / 2);
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
}

.combobox-option {
  color: var(--text);
  cursor: pointer;
}

.combobox-option:hover,
.combobox-option.is-active {
  background: var(--surface-3);
}

.combobox-option mark {
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}

.combobox-empty {
  color: var(--muted);
  cursor: default;
}

/* ---- Icon button --------------------------------------------------------- */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  vertical-align: middle;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* ---- Table card (ui.card) and data table (ui.data_table) ----------------- */

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

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.card-foot {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}

.updated.is-stale {
  color: var(--warn);
}

.poll-hint {
  color: var(--muted);
}

/* Only the table scrolls sideways on narrow screens; the page never does. The wrapper is the
   containing block of the table's absolutely positioned parts (.visually-hidden header labels,
   a stacked table's hidden thead): without it they escape the scroll clip and widen the page. */
.table-wrap {
  position: relative;
  max-width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table th,
.data-table td {
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.data-table thead th {
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table .num {
  text-align: right;
}

.data-table .muted {
  color: var(--muted);
}

.data-table tr.row-link {
  cursor: pointer;
}

.data-table tr.row-link:hover td {
  background: var(--surface-2);
}

.data-table td.cell-action {
  padding-top: var(--space-1);
  padding-bottom: var(--space-1);
  text-align: right;
}

.data-table th.col-action {
  width: 48px;
}

.cell-sub {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.symbol {
  font-weight: 600;
}

.side-text-long {
  color: var(--pos);
}

.side-text-short {
  color: var(--neg);
}

.iso-tag, .ext-tag {
  margin-left: var(--space-1);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.empty-state {
  padding: var(--space-6) var(--space-4);
  color: var(--muted);
  text-align: center;
}

.data-table td.empty-state {
  text-align: center;
}

@media (max-width: 699px) {
  .data-table .col-symbol {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
  }

  .data-table th,
  .data-table td {
    padding: var(--space-2) var(--space-3);
  }
}

/* Stacked rows (ui.data_table(stacked=True)): below 900px each row is a card of labelled cells,
   the label taken from the cell's data-label. The chart action (td.cell-action) and the Setup
   cell (td.col-setup) share the first row; an action column (td.col-actions) spans the card. */
@media (max-width: 899px) {
  .data-table.is-stacked {
    white-space: normal;
  }

  .data-table.is-stacked,
  .data-table.is-stacked tbody {
    display: block;
  }

  .data-table.is-stacked thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .data-table.is-stacked tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
  }

  .data-table.is-stacked tbody tr:last-child {
    border-bottom: 0;
  }

  .data-table.is-stacked td {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 0;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere; /* a long unbroken token (an id, a message) wraps inside the card */
    text-align: left;
  }

  /* A chip in a stacked cell keeps its own width instead of the cell's. */
  .data-table.is-stacked td > .chip {
    align-self: flex-start;
  }

  .data-table.is-stacked td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  /* No label above an unlabelled cell or an action column (its button says what it does). */
  .data-table.is-stacked td[data-label=""]::before,
  .data-table.is-stacked td.col-actions::before {
    content: none;
  }

  .data-table.is-stacked td.col-setup {
    grid-row: 1;
    grid-column: 1;
  }

  .data-table.is-stacked td.cell-action {
    grid-row: 1;
    grid-column: 2;
    justify-self: end;
  }

  .data-table.is-stacked td.empty-state,
  .data-table.is-stacked td.col-actions {
    grid-column: 1 / -1;
  }

  .data-table.is-stacked td.empty-state {
    padding: var(--space-3) 0;
    text-align: center;
  }
}

/* ---- Dialog (dialog.confirm in #dialog-root, opened by static/dialog.js) ---- */

dialog.confirm {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  overflow: auto;
}

dialog.confirm::backdrop {
  background: color-mix(in srgb, var(--bg) 70%, transparent);
}

.confirm-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.confirm-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.confirm-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 16px;
  min-width: 0;
}

.confirm-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* The setup chart dialog (strategies/_chart_dialog.html): wide, with the chart frame inside. */
dialog.confirm.chart-dialog {
  width: min(96vw, 1100px);
  max-width: none;
}

.chart-dialog-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chart-dialog .tabs {
  align-self: flex-start;
  max-width: 100%;
  overflow-x: auto;
}

.chart-dialog-foot {
  align-items: center;
  justify-content: space-between;
}

/* ---- Drawer (ui.drawer, opened by static/drawer.js) ---------------------- */

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(520px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: -24px 0 48px var(--shadow-drawer);
}

.drawer[open] {
  display: flex;
  flex-direction: column;
  animation: drawer-in 180ms ease-out;
}

.drawer::backdrop {
  background: var(--overlay);
}

@keyframes drawer-in {
  from {
    transform: translateX(100%);
  }

  to {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .drawer[open] {
    animation: none;
  }
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 20px var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border);
}

/* The close button's <form method="dialog"> takes no box of its own in the header row. */
.drawer-close-form {
  display: contents;
}

.drawer-head .icon-btn {
  width: 40px;
  height: 40px;
  margin: -4px -8px 0 0;
}

.drawer-head .icon-btn .icon {
  width: 18px;
  height: 18px;
}

.drawer-head-main {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.drawer-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.drawer-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.drawer-sub {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.drawer-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0;
  padding: var(--space-4) var(--space-5);
  overflow-y: auto;
}

/* The body scrolls; its children keep their height (a kv-grid with overflow: hidden would
   otherwise shrink to a sliver). */
.drawer-body > * {
  flex-shrink: 0;
}

.drawer-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.drawer-foot .muted {
  color: var(--muted);
}

.drawer-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
}

.figure {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.figure-label {
  color: var(--muted);
  font-size: 13px;
}

.figure-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.figure-list {
  display: grid;
  grid-template-columns: max-content max-content;
  gap: 2px var(--space-4);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.figure-list .num {
  text-align: right;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.section-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.section-head .muted {
  color: var(--muted);
  font-size: 12px;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.drawer-section .warning {
  margin: 0;
}

.drawer-section .empty-state {
  margin: 0;
  padding: var(--space-3) 0;
  text-align: left;
}

@media (max-width: 599px) {
  .drawer {
    width: 100vw;
    border-left: 0;
  }

  .drawer-head {
    padding: var(--space-3) var(--space-4);
  }

  .drawer-head .icon-btn {
    width: 44px;
    height: 44px;
  }

  .drawer-body,
  .drawer-foot {
    padding-right: var(--space-4);
    padding-left: var(--space-4);
  }
}

/* ---- Definition grid (ui.kv_grid) --------------------------------------- */

.kv-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--border);
  font-variant-numeric: tabular-nums;
}

.kv-item {
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
}

.kv-grid dt {
  color: var(--muted);
  font-size: 12px;
}

.kv-grid dd {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ---- Timeline (ui.timeline / ui.timeline_item) --------------------------- */

.timeline {
  margin: 0;
  padding: 0;
  list-style: none;
  font-variant-numeric: tabular-nums;
}

.timeline-item {
  position: relative;
  padding: var(--space-2) 0 var(--space-2) 26px;
}

.timeline-item::before {
  content: "";
  position: absolute;
  top: 17px;
  bottom: -9px;
  left: 4px;
  width: 2px;
  background: var(--border);
}

.timeline-item:last-child::before {
  display: none;
}

.timeline-dot {
  position: absolute;
  top: 13px;
  left: 0;
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
}

.timeline-funding .timeline-dot {
  border-color: var(--border-strong);
  background: var(--surface);
}

.timeline-order .timeline-dot {
  border-color: var(--muted);
  background: var(--surface);
}

.timeline-check .timeline-dot {
  border-color: var(--border-strong);
  background: var(--surface);
}

.timeline-sentinel .timeline-dot {
  border-color: var(--warn);
  background: var(--warn);
}

.timeline-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
}

.timeline-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.timeline-badge {
  min-width: 56px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--chip-closed);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  white-space: nowrap;
}

.timeline-funding .timeline-badge {
  border: 1px dashed var(--border-strong);
  background: transparent;
  color: var(--muted);
}

.timeline-funding .timeline-text {
  color: var(--muted);
}

.timeline-value {
  font-weight: 600;
  white-space: nowrap;
}

.timeline-meta {
  color: var(--muted);
  font-size: 12px;
}

.timeline-aside {
  white-space: nowrap;
}

/* On a phone the right-hand value and aside go under the text instead of taking a column. */
@media (width < 700px) {
  .timeline-row {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .timeline-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-1);
  }
}

.timeline .muted {
  color: var(--muted);
}

/* ---- Form fields (ui.field / ui.choice_field / ui.field_error) ----------- */

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

/* Side by side in a row; a field outside a row (in a column flex body) keeps its own height. */
.form-row > .form-field {
  flex: 1 1 200px;
}

.form-label {
  color: var(--muted);
  font-size: 13px;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.form-field.has-error .form-input {
  border-color: var(--neg);
}

.field-error {
  margin: 0;
  color: var(--neg);
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* ---- Order dialogs (templates/orders/) ---------------------------------- */

/* The LIMIT-only fields show only while LIMIT is the checked order type. */
.order-form:not(:has(input[name="order_type"][value="LIMIT"]:checked)) .order-limit-fields {
  display: none;
}

.order-problems,
.order-protections {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.order-problems li,
.order-protections li {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

.order-problems li {
  border-left-color: var(--warn);
  color: var(--warning-text);
}

.order-protections li[data-status="placed"] {
  border-left-color: var(--pos);
}

.order-protections li[data-status="skipped"] {
  border-left-color: var(--border-strong);
  color: var(--muted);
}

.order-protections li[data-status="failed"],
.order-protections li[data-status="unknown"] {
  border-left-color: var(--neg);
}

.order-message {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.order-failed,
.order-unknown {
  color: var(--neg);
}

.order-not_sent {
  color: var(--warn);
}

.unprotected {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--alert-border);
  border-radius: var(--radius);
  background: var(--alert-bg);
  color: var(--alert-text);
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ---- Price chart (templates/chart/index.html, drawn by static/chart.js) -- */

.chart-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

/* Symbol picker on the left, interval tabs on the right; they wrap on narrow screens. */
.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.chart-symbol-form {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
}

.chart-toolbar .tabs {
  overflow-x: auto;
}

/* The chart frame (templates/chart/_frame.html): the notice above the chart. static/chart.js
   mounts every [data-chart-frame], on the chart page and in the setup chart dialog. */
.chart-frame {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

/* Lightweight Charts sizes itself to this box (autoSize). isolation keeps the library's own
   z-indexes inside it, under the symbol combobox's list. */
.price-chart {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: calc(var(--space-6) * 16);
  min-width: 0;
  overflow: hidden;
}

/* The suggested trade plan under a setup chart (templates/chart/_plan.html). */
.chart-plan {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

/* A WCT thesis's sections under its chart (templates/wct/_thesis_body.html): desk, engine,
   briefing. A disclosure inside spans the section's width. */
.chart-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3);
  border-top: 1px solid var(--border);
}

.chart-section p {
  margin: 0;
}

.chart-section > .disclosure,
.chart-section .transcript > .disclosure {
  width: 100%;
}

.chart-section .transcript {
  padding: 0;
}

@media (width < 700px) {
  .price-chart {
    height: calc(var(--space-6) * 11);
  }
}

/* ---- Transcript (ui.turn), disclosure (ui.disclosure) and text blocks ------ */

.transcript {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
}

.turn {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.turn-scout {
  border-left: 3px solid var(--accent);
}

.turn-adversary {
  border-left: 3px solid var(--warn);
}

.turn-system {
  border-left: 3px solid var(--muted);
}

.turn-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
}

.turn-role {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.turn-meta {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.turn-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3);
}

.turn-body p {
  margin: 0;
}

.prewrap {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

pre.mono-block {
  max-height: 60vh;
  margin: 0;
  padding: var(--space-3);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.disclosure {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.disclosure-summary {
  padding: var(--space-2) var(--space-3);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.disclosure-body {
  padding: 0 var(--space-3) var(--space-3);
}

.premise-list {
  margin: 0;
  padding-left: var(--space-5);
  font-family: var(--font-mono);
  font-size: 12px;
}

.premise-list li + li {
  margin-top: var(--space-1);
}

.objection {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
}

.cell-truncate {
  display: inline-block;
  max-width: 28ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.card-note {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  color: var(--muted);
  font-size: 13px;
}

/* ---- Settings (templates/settings/) -------------------------------------- */

/* A settings group on /settings: a full-width link card. */
.settings-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.settings-group:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.settings-group-text {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.settings-group-title {
  font-weight: 600;
}

.settings-group-help {
  color: var(--muted);
  font-size: 13px;
}

/* The rows of one section of the trading settings form. */
.settings-list {
  display: flex;
  flex-direction: column;
  padding: 0 var(--space-4);
}

.settings-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) 0;
  min-width: 0;
}

.settings-row + .settings-row {
  border-top: 1px solid var(--border);
}

.settings-help {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.settings-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  min-width: 0;
}

.settings-env {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}
