/* Dashboard layout. Mobile first; two columns from 1024px.

   Fixed and sticky layers, lowest to highest: top bar 20 (sticky), trading
   dock 40, chart menus 45, pair selector 46, modal backdrop 50 / modal 51
   (modal.css), market drawer 58 / 59, help popover 1000 (profile.css). The
   dock and the top bar sit under the modal backdrop; only the drawer and the
   help popover may appear above a modal. */
:root {
  --long: #16a34a;
  --short: #dc2626;
  --long-bg: rgba(22, 163, 74, 0.12);
  --short-bg: rgba(220, 38, 38, 0.12);
  --warn: #b45309;
  --warn-bg: rgba(180, 83, 9, 0.12);
  --ok-bg: rgba(21, 128, 61, 0.12);
  --bad-bg: rgba(185, 28, 28, 0.12);
  --muted-bg: rgba(107, 114, 128, 0.12);
  --accent-bg: rgba(37, 99, 235, 0.12);
  --topbar-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root { --long: #4ade80; --short: #f87171; --warn: #fbbf24; }
}

html, body { overflow-x: hidden; }
html { scroll-padding-bottom: calc(var(--dock-h, 0px) + 8px); }   /* scrolling something into view keeps it above the fixed trading dock */
body { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pos { color: var(--long); }
.neg { color: var(--short); }
[hidden] { display: none !important; }

/* ----- pills ----- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.02em; white-space: nowrap; border: 1px solid transparent; text-decoration: none; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.pill.plain::before { display: none; }
.pill-paper { background: var(--warn-bg); color: var(--warn); }
.pill-ok, .pill-fresh { background: var(--ok-bg); color: var(--ok); }
.pill-stale, .pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad, .pill-missing, .pill-error { background: var(--bad-bg); color: var(--bad); }
.pill-muted, .pill-loading, .pill-off { background: var(--muted-bg); color: var(--muted); }
.pill-long { background: var(--long-bg); color: var(--long); }
.pill-short { background: var(--short-bg); color: var(--short); }
.pill-bot { background: var(--accent-bg); color: var(--accent); }
.pill-manual { background: var(--muted-bg); color: var(--text); }
/* A link wrapping a status pill: the pill keeps its size, the anchor is the 44px touch target. */
.pill-link { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; }
.tap-link { display: inline-flex; align-items: center; min-height: 44px; }

/* ----- top bar ----- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--border); padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.exchange-box { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.exchange-box select { min-height: 44px; width: auto; padding: 4px 28px 4px 8px; font-size: 13px; }
.pair-button { min-height: 44px; min-width: 150px; display: inline-flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--input); color: var(--text); border: 1px solid var(--border); font-weight: 700; font-size: 14px; padding: 6px 12px; }
.pair-button .price { font-weight: 500; font-size: 13px; }
.stats { display: flex; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.stat { display: flex; flex-direction: column; min-width: 84px; }
.stat .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stat .v { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.links { display: flex; gap: 10px; align-items: center; }
.links a, .links button { font-size: 12px; min-height: 44px; padding: 4px 10px; }
.links a { color: var(--muted); text-decoration: none; display: inline-flex; align-items: center; }
.links a:hover { color: var(--text); }
@media (max-width: 1023px) {
  .brand { order: -2; }
  .links { order: -1; margin-left: auto; }
  .pair-button { order: 1; flex: 1 1 100%; }
  .exchange-box { order: 2; }
  .stats { order: 3; margin-left: 0; width: 100%; justify-content: space-between; }
  .stat { min-width: 0; flex: 1 1 22%; }
}
@media (max-width: 767px) {
  .topbar { padding: 8px 10px; gap: 8px 10px; }
  .exchange-box { width: 100%; }
  .pair-button { width: 100%; }
  .stat .v { font-size: 13px; }
}

/* ----- pair panel ----- */
.pair-panel { position: fixed; z-index: 46; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.35); display: flex; align-items: flex-start; justify-content: center; padding: 12px; }
.pair-panel .sheet { background: var(--card); border: 1px solid var(--border); border-radius: 10px; width: min(560px, 100%); max-height: calc(100vh - 24px); display: flex; flex-direction: column; overflow: hidden; }
.pair-panel .sheet-head { display: flex; gap: 8px; padding: 10px; border-bottom: 1px solid var(--border); align-items: center; }
.pair-panel input { flex: 1 1 auto; }
.pair-panel .sheet-body { overflow: auto; }
.pair-list { list-style: none; margin: 0; padding: 0; }
.pair-list li { min-height: 44px; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 6px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.pair-list li:hover, .pair-list li.active { background: var(--accent-bg); }
.pair-list li.unavailable { opacity: 0.6; cursor: not-allowed; }
.pair-list .sym { font-weight: 700; }
.pair-list .meta { color: var(--muted); font-size: 12px; }
.pair-list .empty { padding: 16px; color: var(--muted); grid-template-columns: 1fr; cursor: default; }

/* ----- banner ----- */
.banner { background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid var(--border); padding: 8px 12px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-weight: 600; }
.banner span { flex: 1 1 auto; }
.banner button { min-height: 44px; padding: 4px 12px; background: transparent; color: inherit; border-color: currentColor; }

/* ----- layout ----- */
/* The page ends above the fixed trading dock: --dock-h follows the dock's rendered height (watchDock). */
.layout { padding: 12px 12px calc(var(--dock-h, 0px) + 16px); display: flex; flex-direction: column; gap: 12px; max-width: 1600px; margin: 0 auto; }
.col-main, .col-side { display: contents; }
.card { padding: 12px 14px; width: 100%; margin: 0; }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.card h2 .num { font-size: 10px; color: var(--muted); font-weight: 500; }
/* One column below 1024px: chart, AI decision, last trades, regime + protection, then the workspace. */
#chart-card { order: 0; }
[data-card="ai-decision"] { order: 1; }
[data-card="last-5-trades"] { order: 3; }
.under-chart { order: 5; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; width: 100%; min-width: 0; }
#workspace { order: 7; }
@media (min-width: 1024px) {
  .layout { flex-direction: row; align-items: flex-start; }
  .col-main { display: flex; flex-direction: column; gap: 12px; flex: 1 1 0; min-width: 0; order: 1; }
  .col-side { display: flex; flex-direction: column; gap: 12px; flex: 0 0 372px; order: 2; }
  .under-chart { grid-template-columns: repeat(2, minmax(0, 1fr)); }   /* Market Regime | Risk and Protection, equal columns */
}
@media (min-width: 1440px) {
  .col-side { flex-basis: 400px; }
}

/* ----- chart ----- */
.chart-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head .sym { font-weight: 700; font-size: 16px; }
.chart-head .px { font-size: 16px; font-weight: 600; }
.chart-head .sub { color: var(--muted); font-size: 12px; }
.intervals { margin-left: auto; display: flex; gap: 4px; }
.intervals button { min-height: 44px; min-width: 44px; padding: 2px 10px; font-size: 12px; background: transparent; color: var(--muted); border-color: var(--border); }
.intervals button.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.chart-wrap { position: relative; height: 420px; }
#chart { position: absolute; inset: 0; }
/* Lightweight Charts attribution link: same logo, 44px touch target (outranks the library's injected a#tv-attr-logo rule). */
#chart a#tv-attr-logo { width: 44px; height: 44px; left: 0; bottom: 0; display: flex; align-items: center; justify-content: center; }
.chart-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; color: var(--muted); background: transparent; pointer-events: none; }
.chart-overlay.bad { color: var(--bad); }
.quote-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 6px 12px; margin-top: 8px; font-size: 12px; }
.quote-row .k { color: var(--muted); display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; }
@media (max-width: 767px) { .chart-wrap { height: 300px; } .intervals { margin-left: 0; width: 100%; } }
@media (min-width: 1440px) { .chart-wrap { height: 480px; } }

/* ----- generic card bits ----- */
.empty-state { padding: 14px 4px; color: var(--muted); text-align: center; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.bar { height: 8px; border-radius: 999px; background: var(--muted-bg); overflow: hidden; display: flex; margin: 8px 0; }
.bar .fill { background: var(--long); }
.bar .fill.alt { background: var(--short); }
.bar .fill.warn { background: var(--warn); }
.bar .fill.bad { background: var(--bad); }
.ring { display: inline-grid; place-items: center; width: 84px; height: 84px; border-radius: 50%; background: conic-gradient(var(--accent) calc(var(--pct, 0) * 1%), var(--muted-bg) 0); }
.ring.warn { background: conic-gradient(var(--warn) calc(var(--pct, 0) * 1%), var(--muted-bg) 0); }
.ring.bad { background: conic-gradient(var(--bad) calc(var(--pct, 0) * 1%), var(--muted-bg) 0); }
.ring > span { width: 66px; height: 66px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.risk-grid { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; }

/* ----- trade lists (rows that stay readable at every width) ----- */
.rows { display: flex; flex-direction: column; gap: 4px; }
.trow { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(64px, auto); gap: 8px; align-items: center; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; min-height: 40px; }
.trow-main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.trow .sym { font-weight: 700; font-size: 13px; line-height: 1.2; }
.trow .when { color: var(--muted); font-size: 10px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow .when .ex { opacity: 0.7; }
.trow-tags { display: flex; gap: 4px; }
.trow-tags .pill { padding: 2px 7px; font-size: 10px; }
.trow .pnl { text-align: right; font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }

/* ----- positions ----- */
.positions { display: flex; flex-direction: column; gap: 8px; }
.position { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; }
.position.selected { outline: 2px solid var(--accent); }
.position .head { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.position .head .sym { font-weight: 700; font-size: 14px; }
.position .head .pnl { margin-left: auto; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.position .f { display: flex; flex-direction: column; min-width: 0; }
.position .f .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.position .f .v { font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.position .foot { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.position .foot button { min-height: 44px; padding: 4px 12px; }
.position .foot .when { color: var(--muted); font-size: 11px; margin-left: auto; }
@media (min-width: 768px) { .position { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1440px) { .position { grid-template-columns: repeat(7, minmax(0, 1fr)); } }

/* ----- recent trades table ----- */
.trades-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.trades-table th, .trades-table td { padding: 6px 6px; white-space: nowrap; }
.trades-table td.r, .trades-table th.r { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* ----- quick trade: the trading dock, fixed to the bottom of the viewport -----
   One compact row from 1440px (about 74px tall): market, Long / Short, the fields, Open / Defaults, the
   preview mini-summary with Details, then the emergency button. Two rows from 1024 to 1439px, a
   collapsible stacked sheet below. --dock-h (bindDock) always reports the rendered height. */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; width: auto; border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0; border-top: 2px solid var(--accent); box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.16); padding: 4px 10px calc(4px + env(safe-area-inset-bottom, 0px)); background: var(--card); }
.dock-toggle { display: none; width: 100%; min-height: 44px; padding: 4px 8px; background: transparent; color: var(--text); border: 0; border-radius: 6px; align-items: center; gap: 8px; text-align: left; font-weight: 600; }
.dock-toggle-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.dock-toggle-market { font-weight: 700; flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.dock-toggle-caret { color: var(--muted); }
.dock-body { display: flex; flex-direction: column; gap: 4px; }
.dock-row { display: flex; align-items: flex-end; gap: 4px 6px; flex-wrap: wrap; }
.dock-market { display: flex; flex-direction: column; justify-content: center; min-height: 44px; min-width: 0; max-width: 150px; padding-right: 8px; margin-right: 2px; border-right: 1px solid var(--border); }
.dock-market .k { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); white-space: nowrap; }
.qt-market-line { display: flex; flex-direction: column; white-space: nowrap; line-height: 1.15; }
.qt-market-line .sym { font-weight: 700; font-size: 14px; letter-spacing: -0.01em; }
.qt-market-line .small { font-size: 10px; }
/* Long / Short keep their colours: the lit side is filled, the other stays an outline in its own colour. */
.qt-side { display: inline-flex; gap: 6px; }
.qt-side button { min-height: 44px; min-width: 100px; padding: 4px 10px; font-weight: 700; font-size: 13px; letter-spacing: 0.02em; border-width: 2px; background: transparent; transition: background-color 120ms, color 120ms, box-shadow 120ms; }
.qt-side .long { color: var(--long); border-color: var(--long); }
.qt-side .short { color: var(--short); border-color: var(--short); }
.qt-side .long:hover { background: var(--long-bg); }
.qt-side .short:hover { background: var(--short-bg); }
.qt-side .long.active { background: var(--long); border-color: var(--long); color: #fff; box-shadow: 0 0 0 3px var(--long-bg), inset 0 -2px 0 rgba(0, 0, 0, 0.18); }
.qt-side .short.active { background: var(--short); border-color: var(--short); color: #fff; box-shadow: 0 0 0 3px var(--short-bg), inset 0 -2px 0 rgba(0, 0, 0, 0.18); }
.qt-side button.active::before { content: "●"; font-size: 8px; margin-right: 6px; vertical-align: middle; }
.qt-grid { display: flex; align-items: flex-end; gap: 4px 6px; flex-wrap: wrap; min-width: 0; }
.qt-field { display: flex; flex-direction: column; min-width: 0; }
.qt-field label { display: flex; align-items: center; flex-wrap: nowrap; gap: 0 2px; margin: 0 0 1px; min-height: 18px; font-size: 10.5px; white-space: nowrap; color: var(--muted); }
.qt-field label .hint { display: none; }   /* the contract maximum lives in the Details popover and the field's title */
.qt-field label .help-btn { margin: -2px 0 -2px 2px; }
.qt-field input, .qt-field select { width: 68px; min-height: 44px; padding: 6px 8px; font-size: 13px; }
.qt-field-sizing select { width: 184px; padding-right: 22px; }   /* "Automatic, from risk" in full */
.qt-grid input.invalid, .qt-grid select.invalid { border-color: var(--bad); outline: 1px solid var(--bad); }
.dock-break { display: none; flex-basis: 100%; height: 0; }
@media (min-width: 1024px) and (max-width: 1439px) {
  /* Two deliberate rows: market, side and fields; then the actions, the preview and the emergency button. */
  .dock-break { display: block; }
  .qt-defaults-body { left: 0; right: auto; }   /* Defaults sits at the left of its row here: the popover opens to the right */
}
.qt-actions { display: flex; gap: 6px; }
.qt-actions button { min-height: 44px; padding: 6px 10px; white-space: nowrap; }
.qt-actions .primary-long { background: var(--long); border-color: var(--long); }
.qt-actions .primary-short { background: var(--short); border-color: var(--short); }
/* The emergency action stands apart from the trade controls: pushed to the far right, separated, red. */
.qt-emergency { margin-left: auto; padding-left: 10px; border-left: 2px solid var(--border); display: flex; align-items: flex-end; }
.qt-emergency button.danger { min-height: 44px; padding: 6px 10px; background: var(--short); border-color: var(--short); color: #fff; font-weight: 700; white-space: nowrap; }
/* The status block: the preview mini-summary, Details, validation and messages, in smaller type than the controls. */
.dock-status { flex: 1 1 170px; min-width: 150px; max-width: 320px; min-height: 44px; display: flex; flex-wrap: wrap; align-items: center; align-content: center; gap: 0 8px; font-size: 10.5px; line-height: 1.3; color: var(--muted); }
.qt-issues, .qt-preview { display: flex; flex-wrap: wrap; align-items: center; gap: 0 8px; }
.qt-issues { flex: 1 1 100%; }
.qt-issues:empty, .qt-preview:empty, #qt-message:empty, .qt-limits:empty { display: none; }
.qt-issues .issue, .qt-preview .issue { color: var(--bad); font-weight: 600; flex: 1 1 100%; white-space: normal; }
.qt-issues .notice, .qt-preview .notice { color: var(--warn); font-weight: 600; flex: 1 1 100%; white-space: normal; }
.qt-preview .pv { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--text); }
.qt-preview .pv .k { color: var(--muted); }
.qt-preview .pv.neg { color: var(--short); }
.qt-preview .pv.pos { color: var(--long); }
/* Secondary figures (notional, margin, fee, loss at stop, margin after) and the contract limits: a popover, not permanent space. */
.qt-more { position: static; display: inline-block; }   /* its popover is positioned against the dock (bindDock sets --more-left) */
.qt-more > summary { position: relative; list-style: none; display: inline-flex; align-items: center; gap: 3px; height: 22px; padding: 0 6px; cursor: pointer; color: var(--accent); font-weight: 700; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; border-radius: 4px; }
.qt-more > summary::-webkit-details-marker { display: none; }
.qt-more > summary::after { content: ""; position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 6px; }   /* the hit area; invisible */
.qt-more > summary > span::after { content: " ▾"; }
.qt-more[open] > summary > span::after { content: " ▴"; }
.qt-more > summary:hover, .qt-more > summary:focus-visible { background: var(--accent-bg); outline: none; }
.qt-more-body { position: absolute; left: var(--more-left, 10px); bottom: calc(100% + 6px); width: min(420px, calc(100vw - 24px)); background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); padding: 10px 12px; z-index: 1; font-size: 12px; color: var(--text); text-transform: none; letter-spacing: 0; font-weight: 400; }
.qt-more-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 4px; }
.qt-more-title + .qt-more-title, .qt-preview-more + .qt-more-title { margin-top: 8px; }
.qt-preview-more { display: flex; flex-direction: column; align-items: stretch; gap: 3px; }
.qt-preview-more .pv { display: flex; justify-content: space-between; gap: 12px; white-space: normal; }
.qt-preview-more .pv .k { color: var(--muted); }
.qt-preview-more:empty::before { content: "No preview yet: pick a market and complete the fields."; color: var(--muted); }
.qt-limits { font-size: 11px; white-space: normal; line-height: 1.4; display: block; }
#qt-message { margin: 0; min-height: 0; flex: 1 1 100%; }
#qt-message.ok { color: var(--ok); font-weight: 600; }
#qt-message.bad { color: var(--bad); font-weight: 600; }
.qt-confirm { padding: 8px 12px; border: 2px solid var(--warn); border-radius: 6px; background: var(--warn-bg); display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; font-size: 12px; }
.qt-confirm-text { flex: 1 1 320px; min-width: 0; }
.qt-confirm ul { margin: 2px 0; padding-left: 18px; }
.qt-confirm-actions { display: flex; gap: 8px; }
.qt-confirm-actions button { min-height: 44px; }
/* Saved manual defaults: a small popover opened from the dock, never permanent space. */
.qt-defaults { position: relative; }
.qt-defaults > summary { list-style: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 8px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 12px; border: 1px solid var(--border); border-radius: 6px; white-space: nowrap; }
.qt-defaults > summary::-webkit-details-marker { display: none; }
.qt-defaults > summary::after { content: "▾"; }
.qt-defaults[open] > summary::after { content: "▴"; }
.qt-defaults-body { position: absolute; right: 0; bottom: calc(100% + 8px); width: min(380px, calc(100vw - 24px)); background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); padding: 10px 12px; z-index: 1; }
.qt-defaults-head { display: flex; align-items: center; gap: 8px; }
.qt-defaults-head .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.qt-defaults-summary { font-size: 12px; margin-top: 4px; white-space: normal; }
.qt-defaults-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.qt-defaults-actions button { min-height: 44px; }
.qt-defaults .message:empty { display: none; }
@media (max-width: 1023px) {
  /* A collapsible sheet: the toggle bar is always visible, the form stacks when opened. */
  .dock { padding-top: 4px; }
  .dock-toggle { display: flex; }
  .dock.collapsed .dock-body { display: none; }
  .dock-body { max-height: min(70vh, 520px); overflow: auto; padding-top: 4px; -webkit-overflow-scrolling: touch; }
  .dock-market .k { display: none; }   /* the toggle bar already says Quick Trade */
  .dock-market { width: 100%; max-width: none; min-height: 0; border-right: 0; padding-right: 0; margin-right: 0; }
  .qt-market-line { flex-direction: row; align-items: baseline; gap: 6px; }
  .dock-row { align-items: stretch; }
  .qt-side { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .qt-side button { min-width: 0; }
  .qt-grid { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .qt-field input, .qt-field select, .qt-field-sizing select { width: 100%; }
  .qt-field label { white-space: normal; }
  .qt-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr auto; }
  .dock-status { width: 100%; max-width: none; flex-basis: 100%; min-height: 0; padding: 2px 0; }
  .qt-emergency { width: 100%; margin-left: 0; padding-left: 0; border-left: 0; padding-top: 6px; border-top: 1px solid var(--border); }
  .qt-emergency button.danger { width: 100%; }
  .qt-limits { white-space: normal; }
  .qt-defaults-body { right: 0; left: auto; }
}
@media (max-width: 479px) {
  .qt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.status-list { display: flex; flex-direction: column; gap: 6px; }
.bot-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -6px 0 2px; }
.bot-head .tap-link { font-size: 12px; }
.risk-sub { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
#ai-body .kv dd { white-space: normal; }
#ai-body .big { margin: 4px 0 8px; }
.status-list .line { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 28px; }

/* ----- status strip (phase 9.5): local time, next analysis, mode, live data, bot, profile ----- */
.status-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; padding: 6px 12px; background: var(--card); border-bottom: 1px solid var(--border); font-size: 12px; }
/* ----- top summary: status + KPIs on the left, the detailed Net P&L card on the right from 1024px ----- */
.summary { display: grid; grid-template-columns: minmax(0, 1fr); background: var(--card); border-bottom: 1px solid var(--border); }
.summary-left { display: flex; flex-direction: column; min-width: 0; }
.summary-pnl { border: 0; border-top: 1px solid var(--border); border-radius: 0; padding: 10px 16px; background: linear-gradient(180deg, var(--card), var(--bg)); }
.summary-pnl h2 { margin-bottom: 4px; font-size: 11px; letter-spacing: 0.1em; }
.summary-pnl .big { font-size: 28px; letter-spacing: -0.02em; line-height: 1.05; }
.summary-pnl .muted { font-size: 11px; margin: 3px 0 6px; line-height: 1.3; }
.summary-pnl .kv { font-size: 12px; gap: 0 10px; }
.summary-pnl .kv dt, .summary-pnl .kv dd { padding: 2px 0; border-top: 1px solid var(--border); }
.summary-pnl .kv dd { font-weight: 600; }
.summary-pnl .bar { margin: 10px 0 0; height: 5px; }
@media (min-width: 1024px) {
  .summary { grid-template-columns: minmax(0, 1fr) 300px; align-items: stretch; }
  .summary-pnl { border-top: 0; border-left: 1px solid var(--border); }
  .kpi-strip { flex: 1 1 auto; border-bottom: 0; }
  .kpi { justify-content: center; }
}
@media (min-width: 1440px) { .summary { grid-template-columns: minmax(0, 1fr) 340px; } }
.strip-item { display: flex; flex-direction: column; min-width: 0; justify-content: center; min-height: 36px; gap: 1px; }
.strip-item .k { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.strip-item .v { font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; min-height: 18px; }
.strip-item .v.muted { color: var(--muted); font-weight: 500; }
.strip-settings { margin-left: auto; min-height: 44px; padding: 4px 14px; }
@media (max-width: 767px) {
  .status-strip { gap: 4px 12px; padding: 6px 10px; }
  .strip-item { flex: 1 1 28%; }
  .strip-item .v, .strip-item .v .pill { white-space: normal; }   /* long pills wrap instead of leaving the viewport */
  .strip-settings { flex: 1 1 100%; margin-left: 0; }
}

/* ----- settings drawer: side panel from 1024px, full-width sheet below ----- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 58; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--card); border-left: 1px solid var(--border); z-index: 59; display: flex; flex-direction: column; box-shadow: -8px 0 24px rgba(0, 0, 0, 0.2); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.drawer-head button { min-height: 44px; flex: none; }
.drawer-title { font-weight: 700; font-size: 15px; }
.drawer-body { overflow: auto; padding: 12px 14px; flex: 1 1 auto; -webkit-overflow-scrolling: touch; }
.drawer-foot { padding: 4px 14px; border-top: 1px solid var(--border); font-size: 12px; }
.drawer-foot .tap-link { text-decoration: none; }
@media (max-width: 1023px) { .drawer { width: 100%; left: 0; border-left: 0; box-shadow: none; } }

/* ----- profile context under the AI decision ----- */
.profile-context { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.profile-context:empty { display: none; }
.profile-line { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; align-items: center; }
.profile-context button { min-height: 44px; }

/* ----- phase 9.6: KPI strip, hierarchy, favourites ----- */
.flat { color: var(--muted); }
.kpi-strip { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--border); }
.kpi { display: flex; flex-direction: column; min-width: 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); gap: 1px; }
.kpi .k { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.kpi .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 14px; }
.kpi-equity .v { font-size: 20px; }
.kpi-pnl .v { font-size: 20px; }
@media (min-width: 1024px) and (max-width: 1279px) { .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.kpi-pnl .v.pos { color: var(--long); }
.kpi-pnl .v.neg { color: var(--short); }
.kpi-pnl .v.flat { color: var(--muted); }
.kpi-pnl .v.pos::before { content: "▲ "; font-size: 12px; vertical-align: middle; }
.kpi-pnl .v.neg::before { content: "▼ "; font-size: 12px; vertical-align: middle; }
@media (max-width: 1023px) { .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 767px) { .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 8px 10px; gap: 6px; } .kpi .v, .kpi-equity .v, .kpi-pnl .v { font-size: 20px; } }
.topbar .links { margin-left: auto; }

/* quieter secondary cards and folded details */
.card.quiet { background: transparent; }
.card.quiet h2 { font-size: 12px; }
details.more > summary, #account-more > summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 600; margin-top: 6px; }
details.more[open] > summary, #account-more[open] > summary { margin-bottom: 4px; }
#account-details { padding-top: 4px; }
#account-details .kv { font-size: 12px; }

/* AI decision: verdict first */
.ai-top { display: flex; align-items: flex-start; gap: 12px; margin: 4px 0 10px; }
.ai-top .big { font-size: 34px; margin: 0; line-height: 1; letter-spacing: -0.02em; flex: none; }
.ai-verdict.muted { color: var(--muted); }
.ai-side { min-width: 0; display: flex; flex-direction: column; gap: 3px; padding-top: 2px; }
.ai-outcome { font-weight: 700; font-size: 11.5px; letter-spacing: 0.03em; }   /* no text-transform: tests read the outcome text as written */
.ai-outcome.neg { color: var(--warn); }
.ai-outcome.muted { color: var(--muted); }
.ai-reason { font-size: 12.5px; line-height: 1.35; color: var(--text); }
.ai-scores { display: flex; gap: 0; margin-bottom: 6px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.ai-score { flex: 1 1 0; display: flex; flex-direction: column; padding: 5px 8px 5px 0; min-width: 0; }
.ai-score + .ai-score { padding-left: 10px; border-left: 1px solid var(--border); }
.ai-score .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ai-score .v { font-size: 17px; font-weight: 700; line-height: 1.15; }
.ai-when { margin-bottom: 4px; font-size: 11px; }

/* risk: state first */
.risk-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.risk-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.risk-item { border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; display: flex; flex-direction: column; min-width: 0; }
.risk-item .k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.risk-item .v { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.risk-item .v.warn { color: var(--warn); }
.risk-item .v.neg { color: var(--short); }

/* positions: P&L is the headline of every card */
.position .head .pnl-box { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; }
.position .head .pnl { margin-left: 0; font-size: 20px; }
.position .head .pnl.flat { color: var(--muted); }
.position .head .pnl-k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.position .f .v.neg { color: var(--short); }
.position .f .v.pos { color: var(--long); }

/* pair selector: favourites first, a 44px star on every row */
.pair-section-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 8px 12px 2px; }
.pair-list li { grid-template-columns: 44px minmax(0, 1fr) auto; }
.star { min-width: 44px; min-height: 44px; width: 44px; height: 44px; padding: 0; background: transparent; border: 0; color: var(--muted); font-size: 22px; line-height: 1; border-radius: 50%; }
.star.on { color: var(--warn); }
.star:hover, .star:focus-visible { background: var(--muted-bg); outline: none; }
.star:focus-visible { box-shadow: 0 0 0 2px var(--accent); }

/* ----- phase 9.7: chart toolbar, menus, drawing layer, panes, TradingView, tabs ----- */
.chart-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button { min-height: 44px; min-width: 44px; padding: 2px 10px; font-size: 12px; background: transparent; color: var(--muted); border: 0; border-radius: 0; }
.segmented button.active { background: var(--accent-bg); color: var(--accent); }
.intervals { margin-left: 0; }
.menu { position: relative; }
.menu-button { min-height: 44px; padding: 2px 10px; font-size: 12px; color: var(--muted); border-color: var(--border); }
.menu-button.on { color: var(--accent); border-color: var(--accent); background: var(--accent-bg); }
.menu-panel { position: fixed; z-index: 45; min-width: 240px; max-width: calc(100vw - 16px); background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); padding: 8px; display: flex; flex-direction: column; gap: 4px; box-sizing: border-box; }
.menu-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); display: flex; align-items: center; min-height: 24px; }
.menu-panel label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0; padding: 0 4px; color: var(--text); cursor: pointer; }
.menu-panel label.check input { width: 44px; height: 44px; min-height: 44px; margin: 0; padding: 0; appearance: none; -webkit-appearance: none; position: relative; border: 0; background: transparent; cursor: pointer; flex: none; }
.menu-panel label.check input::before { content: ""; position: absolute; inset: 12px; border: 2px solid var(--muted); border-radius: 4px; background: var(--input); }
.menu-panel label.check input:checked::before { background: var(--accent); border-color: var(--accent); }
.menu-panel label.check input:checked::after { content: "✓"; position: absolute; inset: 12px; color: #fff; font-size: 13px; line-height: 20px; text-align: center; font-weight: 700; }
.menu-panel .tool { min-height: 44px; text-align: left; background: transparent; color: var(--text); border-color: var(--border); font-weight: 500; }
.menu-panel .tool.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.chart-wrap.panes-1 { height: 560px; }
.chart-wrap.panes-2 { height: 700px; }
@media (max-width: 767px) { .chart-wrap.panes-1 { height: 420px; } .chart-wrap.panes-2 { height: 540px; } .chart-tools { width: 100%; margin-left: 0; } }
@media (min-width: 1440px) { .chart-wrap.panes-1 { height: 620px; } .chart-wrap.panes-2 { height: 760px; } }
.draw-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; overflow: visible; }
.draw-capture { position: absolute; inset: 0; z-index: 4; cursor: crosshair; touch-action: none; }
.draw-layer line { stroke: var(--accent); stroke-width: 1.5; }
.draw-layer .draw-hline, .draw-layer .draw-vline { stroke-dasharray: 6 4; }
.draw-layer .draw-trend { stroke: var(--warn); stroke-width: 2; }
.draw-layer .draw-ruler { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 3; }
.draw-layer .draw-ruler-box { fill: var(--accent-bg); stroke: none; }
.draw-layer .draw-ruler-box.down { fill: var(--short-bg); }
.draw-layer .draw-ruler-box.up { fill: var(--long-bg); }
.draw-layer .preview { opacity: 0.7; }
.draw-layer .draw-label { font-size: 11px; fill: var(--text); font-family: system-ui, sans-serif; }
.draw-layer .draw-label-bg { fill: var(--card); stroke: var(--border); }
.chart-note { margin-top: 6px; min-height: 0; }
.chart-note:empty { display: none; }
.tv-wrap { position: absolute; inset: 0; }
.tv-wrap .tradingview-widget-container { height: 100%; width: 100%; }
.tv-wrap .tradingview-widget-container__widget { height: calc(100% - 44px); width: 100%; }
.tv-wrap .tradingview-widget-copyright { font-size: 12px; line-height: 44px; min-height: 44px; text-align: center; color: var(--muted); }
.tv-wrap .tradingview-widget-copyright a { text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; }
.tv-empty { padding: 24px 12px 4px; text-align: center; font-weight: 600; }
.tv-empty.muted { font-weight: 400; }

/* lower workspace: one card, three tabs */
.workspace { padding-top: 6px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.tabs .tab { min-height: 44px; padding: 4px 12px; background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent; border-radius: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.tabs .tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tabs .tab .num { font-size: 10px; font-weight: 500; color: var(--muted); }
.tab-panel { padding: 0; }
.tab-panel.quiet { background: transparent; }

/* ----- phase 9.8: AI Trading block under the AI decision ----- */
.ai-trading-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.ai-trading-title { font-weight: 700; font-size: 12px; letter-spacing: 0.02em; color: var(--muted); }
.ai-tag { font-size: 10px; font-weight: 700; letter-spacing: 0.08em; color: var(--warn); }
.ai-status { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.ai-status-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; flex-wrap: wrap; min-width: 0; }
.ai-status-line .k { color: var(--muted); font-size: 12px; }
/* A state is a dot and a word, not another pill. */
.ai-state { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: 0.03em; text-align: right; }
.ai-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.ai-state-ok { color: var(--ok); }
.ai-state-warn { color: var(--warn); }
.ai-state-off { color: var(--muted); }
.ai-profile-summary { font-size: 12px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 2px; padding: 6px 8px; border-radius: 6px; background: var(--muted-bg); }
.ai-no-profile { font-size: 12px; margin-bottom: 6px; }
.ai-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-actions button { min-height: 44px; flex: 1 1 auto; }
.ai-actions button.start { background: var(--long); border-color: var(--long); color: #fff; flex-basis: 100%; }
.ai-actions button.stop { border-color: var(--short); color: var(--short); flex-basis: 100%; }
.ai-confirm { margin: 6px 0 8px; padding: 10px 12px; border: 2px solid var(--warn); border-radius: 8px; background: var(--warn-bg); font-size: 12px; }
.ai-confirm-title { font-weight: 700; margin-bottom: 6px; font-size: 13px; }
.ai-confirm .kv dd { text-align: right; }
.ai-confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.ai-confirm-actions button { min-height: 44px; }
.ai-message { margin-top: 6px; font-size: 12px; }
.ai-message:empty { display: none; }
