/* Shared design system for the web app (every page under /ui and /).
   Tokens first, then layout (app bar + page grid), then components. */

:root {
  --bg: #f4f7fb; --card: #ffffff; --text: #0f1f3d; --muted: #5b6b85;
  --line: #e3e9f2; --accent: #2f6fed; --accent-2: #1d4ed8; --green: #16a34a; --red: #dc2626;
  --amber: #d97706; --chip: #eaf1fd; --chip-text: #1e3a8a; --soft: #f8fafc;
  --green-soft: rgba(22,163,74,.12); --red-soft: rgba(220,38,38,.10); --amber-soft: rgba(217,119,6,.12);
  --shadow: 0 1px 2px rgba(15,31,61,.05), 0 8px 24px rgba(15,31,61,.06);
  --radius: 14px;
  --candle-up: #1fa25a; --candle-down: #e23b3b; --grid: rgba(120,135,160,.18);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --card: #121b2d; --text: #e6edf7; --muted: #94a3b8;
          --line: #243044; --chip: #1c2841; --chip-text: #c7d7ff; --soft: #0f1727;
          --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35); }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
       background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.45; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 12.5px; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em;
       background: var(--chip); padding: 1px 5px; border-radius: 5px; }

/* ---------- app bar ---------- */
.appbar { position: sticky; top: 0; z-index: 20; background: var(--card);
          border-bottom: 1px solid var(--line); }
.appbar-in { max-width: 1720px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center;
             gap: 12px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text);
         font-weight: 800; font-size: 16px; white-space: nowrap; }
.brand .mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
               background: linear-gradient(135deg, #2f6fed, #16a34a); color: #fff; flex: none; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted);
               letter-spacing: .08em; text-transform: uppercase; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 10px;
             color: var(--muted); text-decoration: none; font-weight: 600; font-size: 13px;
             white-space: nowrap; }
nav.tabs a svg { width: 16px; height: 16px; }
nav.tabs a:hover { background: var(--soft); color: var(--text); }
nav.tabs a.on { background: var(--chip); color: var(--chip-text); }
.appbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
@media (max-width: 1720px) { .brand > span { display: none; } }  /* eleven tabs: the logo alone names the app */
@media (max-width: 1420px) {
  .appbar-in { flex-wrap: wrap; padding-bottom: 8px; }
  nav.tabs { order: 3; flex-basis: 100%; }
}

/* ---------- page ---------- */
main.page { max-width: 1720px; margin: 0 auto; padding: 22px 16px 60px; display: grid; gap: 16px; }
main.page > * { min-width: 0; }  /* a wide child (a canvas backing store on a HiDPI screen) never widens the page */
.page-head { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 800; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.cols > .span2 { grid-column: 1 / -1; }
@media (min-width: 900px) { .cols-2-1 { grid-template-columns: 2fr 1fr; } }
.breadcrumb { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.breadcrumb a { text-decoration: none; font-weight: 600; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
        padding: 18px 20px; box-shadow: var(--shadow); }
.card > h2, .card-head h2 { font-size: 15.5px; font-weight: 700; display: flex; align-items: center;
                            gap: 10px; flex-wrap: wrap; margin: 0 0 4px; }
.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head .spacer, .spacer { flex: 1; }
.card.accent { border-color: transparent;
  background: linear-gradient(135deg, rgba(47,111,237,.10), rgba(22,163,74,.08)), var(--card); }
.card.danger-border { border-color: rgba(220,38,38,.35); }

/* ---------- hero ---------- */
.hero { border-radius: var(--radius); overflow: hidden; background: #fff; border: 1px solid var(--line);
        box-shadow: var(--shadow); }
.hero img { display: block; width: 100%; height: auto; }
/* the banner art is 4:3 with its headline and illustration spread over the whole image: show all of
   it, scaled into a fixed-height strip (the art's own background is white, like the box), never cropped */
.hero.banner { height: clamp(200px, 26vw, 420px); }
.hero.banner img { width: 100%; height: 100%; object-fit: contain; object-position: center; }
.hero.split { display: grid; grid-template-columns: 1.15fr 1fr; align-items: stretch; }
.hero.split .side { padding: 28px 28px; display: grid; gap: 16px; align-content: center;
                    background: var(--card); border-left: 1px solid var(--line); }
@media (max-width: 860px) { .hero.split { grid-template-columns: 1fr; } .hero.split .side { border-left: 0; border-top: 1px solid var(--line); } }
.features { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.feature { display: grid; gap: 8px; padding: 16px; border-radius: 12px; background: var(--card);
           border: 1px solid var(--line); }
.feature .ic { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
               background: var(--chip); color: var(--accent); }
.feature .ic.green { background: var(--green-soft); color: var(--green); }
.feature .ic.amber { background: var(--amber-soft); color: var(--amber); }
.feature b { font-size: 14.5px; }
.feature span { color: var(--muted); font-size: 13px; }

/* ---------- buttons & inputs ---------- */
button, .btn { font: inherit; border: 0; border-radius: 9px; padding: 9px 16px; cursor: pointer;
               background: var(--accent); color: #fff; font-weight: 600; text-decoration: none;
               display: inline-flex; align-items: center; gap: 6px; line-height: 1.2; }
button:hover, .btn:hover { filter: brightness(1.05); }
button.secondary, .btn.secondary { background: var(--chip); color: var(--chip-text); }
button.ghost, .btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
button.danger { background: var(--red); }
button.warn { background: var(--amber); }
button.success { background: var(--green); }
button.small, .btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
select.inline { width: auto; display: inline-block; padding: 6px 28px 6px 10px; margin: 0; vertical-align: middle; }
select.inline.small { padding: 4px 24px 4px 8px; font-size: 12.5px; }
.pair { display: inline-flex; gap: 6px; align-items: center; }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; }
input, select, textarea { font: inherit; width: 100%; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--soft); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,111,237,.35); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.field { display: grid; gap: 4px; min-width: 140px; flex: 1; }
.field > label, .field .lbl { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 13.5px; }
.form-grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.form-section { margin-top: 16px; }
.form-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
                   margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }

/* ---------- badges & stats ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px;
         font-size: 12.5px; font-weight: 600; background: var(--chip); color: var(--chip-text);
         white-space: nowrap; }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.badge.ok { background: var(--green-soft); color: var(--green); } .badge.ok .dot { background: var(--green); }
.badge.bad { background: var(--red-soft); color: var(--red); } .badge.bad .dot { background: var(--red); }
.badge.warn-b { background: var(--amber-soft); color: var(--amber); } .badge.warn-b .dot { background: var(--amber); }
.badge.live { background: var(--red-soft); color: var(--red); }
.badge.paper { background: var(--amber-soft); color: var(--amber); }
.badge.manual { background: var(--chip); color: var(--accent); }
.badge.tag { cursor: pointer; }
.grid, .stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; }
/* a long single word (GAP_DOWN_CASCADE, a symbol) wraps inside the tile instead of spilling out of it */
.stat .k, .stat .v, .stat .s { overflow-wrap: anywhere; }
.stat .k { hyphens: auto; }
.stat .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .v { font-size: 17px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stat .badge { white-space: normal; text-align: left; line-height: 1.25; }
.stat input { padding: 4px 8px; font-size: 16px; font-weight: 700; margin-top: 2px; }
.pnl-pos, .pos { color: var(--green); font-weight: 600; } .pnl-neg, .neg { color: var(--red); font-weight: 600; }
.buy { color: var(--green); font-weight: 700; } .sell { color: var(--red); font-weight: 700; }
.warn-text { color: var(--amber); font-size: 13px; }
.notice { padding: 10px 14px; border-radius: 10px; font-size: 13.5px; }
.notice.amber { background: var(--amber-soft); color: var(--amber); }
.notice.red { background: var(--red-soft); color: var(--red); }
.notice.green { background: var(--green-soft); color: var(--green); }
.notice.blue { background: var(--chip); color: var(--chip-text); }

/* ---------- tables & pagination ---------- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 9px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
     white-space: nowrap; }
td { white-space: nowrap; }
td.wrap { white-space: normal; word-break: break-word; max-width: 360px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--soft); }
tr.dim td { opacity: .5; }
tbody tr:last-child td { border-bottom: 0; }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 12px;
         font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.pager button { padding: 5px 11px; font-size: 12.5px; }
.pager select { width: auto; padding: 5px 8px; font-size: 12.5px; }

/* ---------- sub-tabs (within a page) ---------- */
.subtabs { display: inline-flex; gap: 3px; background: var(--chip); border-radius: 11px; padding: 3px; }
.subtabs a, .subtabs button { padding: 7px 14px; border-radius: 9px; font-size: 13.5px; font-weight: 600;
  color: var(--chip-text); background: transparent; text-decoration: none; }
.subtabs a.on, .subtabs button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.10); }

/* ---------- misc ---------- */
.step { display: flex; gap: 12px; margin: 14px 0; }
.step-n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--chip); color: var(--chip-text);
          display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.step.done .step-n { background: var(--green); color: #fff; }
.step-body { flex: 1; display: grid; gap: 8px; } .step-body p { margin: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
        background: var(--chip); color: var(--chip-text); font-size: 12.5px; }
.chip button { padding: 0 2px; background: transparent; color: var(--muted); font-size: 14px; }
.eventlog { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; max-height: 260px;
            overflow-y: auto; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.eventlog div { padding: 2px 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eventlog div b { color: var(--text); font-weight: 600; }
.chartwrap { position: relative; margin-top: 8px; min-width: 0; overflow: hidden; }
canvas.chart { width: 100%; height: 300px; display: block; cursor: crosshair; }  /* the dashboard chart sets its own size when it adds indicator panes */
.tip { position: absolute; pointer-events: none; z-index: 5; background: var(--text); color: var(--card);
       padding: 6px 9px; border-radius: 6px; font: 11.5px ui-monospace, monospace; white-space: pre; }
.empty { color: var(--muted); font-size: 13.5px; padding: 18px 6px; text-align: center; }
.strategy-card { display: grid; gap: 10px; }
.strategy-card .name { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.strategy-card .desc { color: var(--muted); font-size: 13.5px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--card); padding: 10px 18px; border-radius: 10px; font-size: 14px;
  opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 90%; }
#toast.show { opacity: 1; }

/* ---------- quote capsules (dashboard + Review → Quotes preview) ---------- */
.quotes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
/* dashboard: the quotes split over two rows (5 → 3 + 2), each row's cards sharing its full width;
   --qcols (set by the page) is the number of cards in the first row */
.quotes.two-rows { display: flex; flex-wrap: wrap; }
.quotes.two-rows > .quote-card { flex: 1 1 calc((100% - (var(--qcols, 3) - 1) * 12px) / var(--qcols, 3));
  min-width: min(100%, 240px); }
@media (max-width: 760px) { .quotes.two-rows > .quote-card { flex-basis: 100%; } }
.quote-card { position: relative; margin: 0; padding: 16px 18px 14px 46px; border-radius: 18px;
  border: 1px solid var(--line); box-shadow: var(--shadow);
  background: linear-gradient(135deg, rgba(47,111,237,.08), rgba(22,163,74,.05)), var(--card);
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px; }
.quote-card::before { content: "\201C"; position: absolute; left: 14px; top: 6px; font: 700 44px/1 Georgia, serif;
  color: var(--accent); opacity: .55; }
.quote-card blockquote { margin: 0; font: italic 15.5px/1.5 Georgia, "Times New Roman", serif; color: var(--text);
  overflow-wrap: anywhere; }
.quote-card figcaption { font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.quote-card figcaption::before { content: "— "; }
