:root {
  color-scheme: light;
  --bg: #f4f4f2; --card: #fff; --line: #d4d4cf; --line-soft: #e6e6e2;
  --text: #1a1a1a; --muted: #5f5f5b; --label: #3d3d3a;
  --accent: #1f4fd1; --accent-ink: #fff;
  --up: #17703a; --down: #b42318;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
h1 { margin: 0; font-size: 24px; }
h2 { margin: 0; font-size: 17px; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.up { color: var(--up); } .down { color: var(--down); }

/* header */
.top { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px;
  padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 18px; }
.top nav { display: flex; gap: 4px; }
.top nav a { padding: 9px 14px; border-radius: 6px; color: var(--label); text-decoration: none; }
.top nav a.on { background: #e6e6e2; color: var(--text); font-weight: 600; }

/* controls */
.btn { min-height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid #8a8a86; background: #fff; color: var(--text);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn:hover { background: #f0f0ec; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #1a43b3; }
.btn.danger { border: 2px solid var(--down); color: var(--down); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.pill { min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: #fff; font: inherit;
  font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.pill::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #999; }
.pill.ok::before { background: var(--up); } .pill.bad::before { background: var(--down); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 10px; border: 1px solid #8a8a86;
  white-space: nowrap; }
.badge.live { background: var(--text); color: #fff; border-color: var(--text); }
.badge.run { border-color: var(--up); color: var(--up); }

label.lbl, .lbl { display: block; font-size: 13px; font-weight: 600; color: var(--label); margin-bottom: 5px; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: pre-line; }
input[type=text], input[type=number], input[type=time], select {
  width: 100%; height: 40px; padding: 0 10px; border: 1px solid #9a9a96; border-radius: 6px; background: #fff; font: inherit; color: var(--text); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid #9db4f5; outline-offset: 1px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; flex: none; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid #8a8a86; border-radius: 8px; overflow: hidden; }
.seg button { min-height: 38px; padding: 0 14px; border: 0; border-right: 1px solid var(--line); background: #fff; font: inherit; font-size: 14px; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed=true] { background: #e3e8f8; font-weight: 600; }

/* layout */
.page { max-width: 1440px; margin: 0 auto; padding: 20px 24px 48px; }
.split { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.side { flex: 1 1 260px; max-width: 330px; display: flex; flex-direction: column; gap: 10px; }
.content { flex: 999 1 640px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.grid.wide { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.box { border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.readout { background: var(--bg); border-radius: 6px; padding: 10px 12px; font-size: 13px; }

.runitem { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 11px 13px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; font: inherit; color: inherit; }
.runitem[aria-current=true] { border: 2px solid var(--accent); padding: 10px 12px; }
.runitem .top-line { display: flex; justify-content: space-between; gap: 8px; align-items: center; }

.strat { display: flex; flex-direction: column; border-bottom: 1px solid var(--line-soft); padding: 10px 0; gap: 10px; }
.strat:last-child { border-bottom: 0; }
.strat .head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.strat .name { font-weight: 600; min-width: 170px; }
.order { display: flex; flex-direction: column; }
.order button { width: 30px; height: 20px; border: 1px solid var(--line); background: #fff; font-size: 10px; cursor: pointer; padding: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 6px 0 12px; border: 1px solid #8a8a86; border-radius: 18px; background: #fff; font-size: 14px; }
.chip button { width: 28px; height: 28px; border: 0; background: none; font-size: 17px; cursor: pointer; border-radius: 14px; }

.kpi { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi.sm { font-size: 22px; }
.k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.tablebox { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--label); padding: 9px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 18px; text-align: center; color: var(--muted); font-size: 14px; }

.banner { border-radius: 8px; padding: 10px 14px; font-size: 14px; border: 1px solid var(--line); background: #fff; }
.banner.err { border-color: var(--down); color: var(--down); background: #fdf1f0; }
.banner.ok { border-color: var(--up); background: #eff8f2; }
pre.log { max-height: 320px; overflow: auto; background: #1a1a1a; color: #e8e8e4; padding: 12px; border-radius: 8px; font-size: 12px; margin: 0; white-space: pre-wrap; }
details summary { cursor: pointer; font-weight: 600; }

dialog { border: 1px solid #8a8a86; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20, 20, 19, .45); }
.dlg { display: flex; flex-direction: column; max-height: 88vh; }
.dlg header { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg header h2 { flex: 1; font-size: 18px; }
.dlg .body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; overflow: auto; }
.dlg footer { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); }
.dlg footer .btn { flex: 1; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.kv span:first-child { color: var(--muted); }
.option { border: 1px solid #9a9a96; border-radius: 8px; padding: 12px; }
.option:has(input:checked) { border: 2px solid var(--accent); padding: 11px; }

#toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; display: flex; flex-direction: column; gap: 8px; }
#toast div { background: var(--text); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 14px; max-width: 420px; }
#toast div.err { background: var(--down); }

@media (max-width: 700px) {
  .top { padding: 10px 16px; } .page { padding: 16px; }
  .side { max-width: none; }
}

/* ── phones and tablets ───────────────────────────────────────────────── */
body { padding-bottom: env(safe-area-inset-bottom); }
.top { padding-top: max(12px, env(safe-area-inset-top)); }
@media (hover: none) {                         /* touch screens: fingers, not cursors */
  .btn, .btn.sm, .pill, .seg button { min-height: 44px; }
  .order button { width: 40px; height: 28px; }
}
@media (max-width: 700px) {
  body { font-size: 16px; }                    /* 16px inputs: iOS doesn't zoom in on focus */
  /* header in rows: brand + sign out / sections + enter now / broker status */
  .top { gap: 8px 10px; padding-left: 12px; padding-right: 12px; }
  .top > * { min-width: 0; }
  .brand { font-size: 16px; flex: 1 1 calc(100% - 130px); order: 0; }    /* fills row 1 with Sign out */
  #signout { order: 0; }
  .top nav { order: 1; flex: 1 1 auto; }
  #enter-now { order: 1; }
  #broker { order: 2; flex: 1 1 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;
            text-align: left; line-height: 42px; }
  .top .grow, #user, .wide-only { display: none; }
  .page { padding: 12px 12px 32px; }
  .card { padding: 14px; }
  h1 { font-size: 20px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid.wide { grid-template-columns: minmax(0, 1fr); }
  .kpi { font-size: 26px; } .kpi.sm { font-size: 19px; }
  .pnl-day { grid-column: 1 / -1; }

  /* trade tables become one card per trade */
  .tablebox { overflow: visible; }
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tfoot { display: block; }
  table.cards tr { display: block; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; margin-bottom: 10px; }
  table.cards td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 6px 0;
                   white-space: normal; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: 13px; font-weight: 600; text-align: left; }
  table.cards td.actions::before { content: none; }
  table.cards td.actions .row { width: 100%; }
  table.cards td.actions .btn { flex: 1; min-height: 48px; font-size: 15px; }
  table.cards tfoot tr { background: var(--bg); }

  dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  .dlg { max-height: calc(100dvh - 16px); }
  .dlg footer .btn { min-height: 48px; }
  #toast { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
}
