:root {
  --bg: #f4f5f7; --card: #fff; --fg: #1b1f24; --muted: #6b7280; --line: #e5e7eb; --soft: #f3f4f6;
  --side: #111827; --side-fg: #d1d5db; --side-active: #1f2937;
  --pos: #15803d; --neg: #b91c1c; --warn: #b45309; --accent: #2563eb;
  --pos-bg: #dcfce7; --neg-bg: #fee2e2; --zone: rgba(245, 158, 11, .08);
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0d0f13; --card: #161a21; --fg: #e5e7eb; --muted: #9ca3af; --line: #262b35; --soft: #1d222b;
    --side: #0a0c10; --side-fg: #9ca3af; --side-active: #1d222b;
    --pos: #4ade80; --neg: #f87171; --warn: #fbbf24; --accent: #60a5fa;
    --pos-bg: rgba(74, 222, 128, .12); --neg-bg: rgba(248, 113, 113, .12); --zone: rgba(251, 191, 36, .07); }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); }
a { color: var(--accent); text-decoration: none; }
small { color: var(--muted); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
h2 small { text-transform: none; letter-spacing: 0; font-weight: normal; }

/* App shell */
.app { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-fg); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 18px; color: #fff; padding: 0 10px; }
.brand span { color: var(--accent); margin-left: 4px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--side-fg); padding: 8px 10px; border-radius: 6px; display: flex; align-items: center; gap: 10px; }
.nav-icon { width: 18px; height: 18px; flex: none; }
.side nav a:hover { background: var(--side-active); color: #fff; }
.side nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.side-foot { margin-top: auto; font-size: 12px; padding: 0 10px; opacity: .6; }
.main { min-width: 0; }
.content { padding: 16px 20px 32px; max-width: 1400px; }
.page-title { font-size: 20px; margin: 4px 0 14px; }

/* Status bar */
.status { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
.mode-group { display: inline-flex; align-items: center; gap: 6px; padding-right: 8px; margin-right: 4px; border-right: 1px solid var(--line); }
a.badge { text-decoration: none; }
.mode-card p { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.mode-card small { margin-left: 8px; color: var(--muted); }
.peer-link { padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; text-decoration: none; color: inherit; }
.peer-link:hover { background: var(--line); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; }
.badge.sim { background: #dbeafe; color: #1e40af; border-color: transparent; }
.badge.live { background: #fee2e2; color: #991b1b; border-color: transparent; font-weight: 700; }
.badge.ok { color: var(--pos); } .badge.bad { color: var(--neg); }
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--pos); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.feeds { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.dot.ok { background: var(--pos); } .dot.bad { background: var(--neg); }
.stat-chip { font-variant-numeric: tabular-nums; padding: 2px 8px; border-radius: 6px; background: var(--soft); font-size: 13px; }
.stat-chip.hot { color: var(--warn); font-weight: 600; }
button { font: inherit; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { border-color: var(--neg); color: var(--neg); }
a.btn { display: inline-block; font: inherit; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--fg); text-decoration: none; }
a.btn:hover { border-color: var(--muted); }
a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions p { flex-basis: 100%; margin: 0; }

/* Cards & grid */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 14px; }
.grid.hero { grid-template-columns: 2fr 1fr; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; margin-bottom: 14px; }
.grid > .card { margin-bottom: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.hero-row { display: flex; flex-wrap: wrap; align-items: center; gap: 24px; margin-bottom: 8px; }
.big { font-size: 40px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big.hot { color: var(--warn); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); gap: 10px 18px; flex: 1; }
.kpis div { display: flex; flex-direction: column; }
.kpis b { font-size: 17px; font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: 170px; display: block; }
.chart .zone { fill: var(--zone); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .start { stroke: var(--muted); stroke-dasharray: 5 4; stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .line.spot { stroke: var(--muted); stroke-width: 1; opacity: .5; }
.chart .line.up { stroke: var(--pos); } .chart .line.down { stroke: var(--neg); }
.chart .dot-up { fill: var(--pos); } .chart .dot-down { fill: var(--neg); }
.book { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.side-box { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; align-items: center; }
.side-box b { font-size: 26px; font-variant-numeric: tabular-nums; }
.side-box.up.lead { background: var(--pos-bg); border-color: var(--pos); }
.side-box.down.lead { background: var(--neg-bg); border-color: var(--neg); }
.side-box.up small:first-child { color: var(--pos); font-weight: 600; }
.side-box.down small:first-child { color: var(--neg); font-weight: 600; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 8px 0 0; }
dt { color: var(--muted); } dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
dl.wide dd { text-align: left; }
.decision { margin: 0 0 12px; padding: 10px; border-radius: 6px; background: var(--soft); }
.decision.go { color: var(--pos); background: var(--pos-bg); font-weight: 600; }
.pos-box { border-top: 1px solid var(--line); padding-top: 10px; }
.notice { padding: 8px 12px; border-radius: 8px; background: #fef3c7; color: #92400e; margin-bottom: 14px; }

/* Tables & scroll areas */
.scroll { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.scroll.short { max-height: 240px; }
.scroll.tall { max-height: calc(100vh - 300px); min-height: 240px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child, th.left, td.left { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
.scroll thead th { position: sticky; top: 0; background: var(--card); z-index: 1; box-shadow: inset 0 -1px 0 var(--line); }
.list tbody tr:hover { background: var(--soft); }
td.why { white-space: normal; min-width: 280px; max-width: 520px; color: var(--muted); font-size: 12px; }
td.empty, .empty { text-align: center; color: var(--muted); padding: 20px; }
td small { margin-left: 4px; }
.stats td, .stats th { padding: 5px 6px; }
.list tr.total td { font-weight: 600; border-top: 2px solid var(--line); }
h3 small { font-weight: 400; color: var(--muted); }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--soft); }
.tag.live { background: var(--neg-bg); color: var(--neg); }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.chips { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.chips a { padding: 5px 12px; color: var(--fg); border-right: 1px solid var(--line); font-size: 13px; }
.chips a:last-child { border-right: 0; }
.chips a.on { background: var(--accent); color: #fff; }
.pager { display: flex; align-items: center; gap: 14px; padding-top: 10px; color: var(--muted); font-size: 13px; }

/* Log */
.log { font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 6px 10px; }
.log time { color: var(--muted); margin-right: 8px; }
.log .hl { color: var(--accent); }

/* Flash & forms */
.flash { position: fixed; bottom: 16px; right: 16px; padding: 10px 14px; border-radius: 8px; background: var(--card); border: 1px solid var(--pos); z-index: 10; }
.flash.err { border-color: var(--neg); color: var(--neg); }
.flash:empty { display: none; }
form fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 14px; padding: 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px 18px; }
legend { color: var(--muted); padding: 0 6px; font-weight: 600; }
label { display: grid; gap: 3px; align-content: start; }
label input[type=number], label input[type=text], label input[type=password] { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); width: 100%; }
label input[type=checkbox] { justify-self: start; width: 18px; height: 18px; }
.form-foot { position: sticky; bottom: 0; background: var(--card); padding: 10px 0 2px; }

/* Shabbat */
.shabbat-strip { flex-basis: 100%; padding: 6px 10px; border-radius: 6px; background: var(--zone); color: var(--warn); font-weight: 500; }
.shabbat-strip.off { background: var(--neg-bg); color: var(--neg); }
.city-picker { display: grid; gap: 6px; align-content: start; grid-column: 1 / -1; }
.city-picker input[type=search], label select { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); width: 100%; max-width: 420px; }
.city-results { display: flex; flex-wrap: wrap; gap: 6px; }
.city-results:empty { display: none; }

/* Mobile */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  /* Pages menu: app-style tab bar fixed at the bottom */
  .side { position: fixed; inset: auto 0 0 0; height: auto; z-index: 20; padding: 0 0 env(safe-area-inset-bottom); gap: 0; border-top: 1px solid var(--side-active); }
  .brand, .side-foot { display: none; }
  .side nav { flex-direction: row; gap: 0; }
  .side nav a { flex: 1; min-width: 0; flex-direction: column; gap: 3px; padding: 8px 2px 7px; border-radius: 0; font-size: 11px; text-align: center; }
  .side nav a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
  .side nav a:hover { background: none; }
  .side nav a.active { background: none; box-shadow: inset 0 2px 0 var(--accent); color: var(--accent); }
  .nav-icon { width: 22px; height: 22px; }
  .main { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .flash { bottom: calc(72px + env(safe-area-inset-bottom)); left: 16px; }
  .status { position: static; }
  .chart { height: auto; }
  .grid.hero, .grid.two { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 14px 16px 28px; }
  .status { padding: 8px 16px; }
  .big { font-size: 32px; }
  /* Compact tables: key columns only, thin rows, no sideways scrolling. Full reasons live in the replay. */
  .content { padding: 10px 8px 24px; }
  .card { padding: 10px; }
  table.list { font-size: 12px; }
  .list th, .list td { padding: 4px 5px; line-height: 1.25; }
  .list th { font-size: 11px; }
  .list .opt, .list:not(.acts) .why { display: none; }
  .list td small { font-size: 10px; margin-left: 2px; }
}

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.login .brand { color: var(--fg); padding: 0; }
.login label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login input { font: inherit; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
.login-msg { color: var(--neg); font-size: 13px; }
.side-foot form { margin-bottom: 8px; }
button.link { background: none; border: 0; padding: 0; color: var(--side-fg); cursor: pointer; }
button.link:hover { color: #fff; }

/* Settings lock / account */
.notice { padding: 9px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--pos-bg); color: var(--pos); }
.notice.err { background: var(--neg-bg); color: var(--neg); }
.lockbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.lockbar span { flex: 1 1 260px; }
.lockbar input[type=password] { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); flex: 0 1 220px; min-width: 0; }
.account { display: flex; flex-direction: column; gap: 10px; max-width: 460px; }
.account label { display: flex; flex-direction: column; gap: 4px; }
.account input { font: inherit; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
fieldset:disabled { opacity: .65; }

/* Replay */
.intro { margin: 0 0 12px; color: var(--muted); }
.replay-ctl .scrub { width: 100%; margin-top: 12px; accent-color: var(--accent); }
.replay-ctl select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
.replay-ctl .play { min-width: 92px; }
button:disabled { opacity: .4; cursor: default; }
.chart .line.future { stroke: var(--muted); opacity: .35; }
.chart .line.spot.future { opacity: .2; }
.chart .cursor { stroke: var(--accent); stroke-width: 1.5; }
.chart .mark { stroke: var(--card); stroke-width: 2; }
.chart .mark.enter { fill: var(--accent); }
.chart .mark.cashout { fill: var(--warn); }
.chart .mark.fail { fill: var(--neg); }
.chart .hit { fill: transparent; cursor: pointer; }
.decision.cash { background: var(--zone); color: var(--warn); }
.decision.bad { background: var(--neg-bg); color: var(--neg); }
.decision.hold { background: var(--soft); border-left: 3px solid var(--accent); }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 16px; }
.check-group h3 { font-size: 13px; margin: 0; }
.check-group h3 small { margin-left: 6px; font-weight: normal; }
.group-help { display: block; margin-bottom: 4px; }
.checklist td { white-space: normal; vertical-align: top; padding: 5px 6px; }
.checklist td small { display: block; margin: 0; }
.ck { width: 26px; text-align: center !important; font-weight: 700; }
.ck.pass { color: var(--pos); } .ck.fail { color: var(--neg); } .ck.na { color: var(--muted); }
.ck.info { color: var(--accent); font-style: italic; }
tr.clickable { cursor: pointer; }

/* Balance chart */
.chart.balance { height: 200px; }
.balchart { position: relative; cursor: crosshair; touch-action: pan-y; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; border-radius: 6px; }
.balchart:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chart .line.without { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 3; opacity: .55; }
.chart .xline { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .xdot { fill: var(--accent); stroke: var(--card); stroke-width: 2; }
.chart .xdot-wo { fill: var(--card); stroke: var(--muted); stroke-width: 1.5; }
.baltip { position: absolute; top: 4px; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font-size: 12px; line-height: 1.45; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.12); font-variant-numeric: tabular-nums; }
.baltip .wo { color: var(--muted); }
.bal-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 4px; }
.bal-legend { color: var(--muted); font-size: 13px; }
.key-wo { display: inline-block; width: 18px; vertical-align: middle; border-top: 2px dashed var(--muted); opacity: .7; }
.bal-head b { font-size: 22px; font-variant-numeric: tabular-nums; }
@media (max-width: 860px) { .chart.balance { height: auto; } }

/* Settings tabs: the wrapper's data-tab (datastar $tab) decides which panels show */
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; border: 0; border-radius: 6px 6px 0 0; background: none; color: var(--muted); padding: 8px 14px; font-weight: 500; box-shadow: inset 0 -2px 0 transparent; }
.tabs button:hover { color: var(--fg); }
.stabs[data-tab=trading] [data-for=trading], .stabs[data-tab=strategy] [data-for=strategy], .stabs[data-tab=shabbat] [data-for=shabbat],
.stabs[data-tab=wallet] [data-for=wallet], .stabs[data-tab=notify] [data-for=notify], .stabs[data-tab=system] [data-for=system] { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
.stabs:not([data-tab=trading]) [data-panel=trading], .stabs:not([data-tab=strategy]) [data-panel=strategy], .stabs:not([data-tab=shabbat]) [data-panel=shabbat],
.stabs:not([data-tab=wallet]) [data-panel=wallet], .stabs:not([data-tab=notify]) [data-panel=notify], .stabs:not([data-tab=system]) [data-panel=system] { display: none; }
#settings fieldset.card { margin: 0 0 14px; padding: 14px 16px; }
#settings fieldset.card legend { float: left; width: 100%; grid-column: 1 / -1; padding: 0; margin-bottom: 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.save-bar { position: sticky; bottom: 0; z-index: 4; display: flex; align-items: center; gap: 10px; padding: 10px 0; background: var(--bg); }
.steps { margin: 8px 0; padding-left: 20px; } .steps li { margin-bottom: 4px; }
details summary { cursor: pointer; color: var(--accent); margin: 6px 0; }
#tg-chats { margin-top: 8px; }

/* Viewer's local time next to ET times */
small.lt { display: block; font-size: 11px; line-height: 1.2; }
.lt-head { text-transform: none; letter-spacing: 0; }

@media (max-width: 860px) {
  .stabs .tabs { position: sticky; top: 0; z-index: 6; background: var(--bg); margin: 0 -8px 10px; padding: 0 8px; }
  .tabs button { padding: 10px 12px; }
  .save-bar { bottom: calc(60px + env(safe-area-inset-bottom)); padding: 8px 0; }
  .save-bar button { flex: 1; padding: 10px; }
  #settings fieldset.card { padding: 10px; grid-template-columns: 1fr; }
  .lockbar input[type=password] { flex: 1 1 140px; }
  small.lt { font-size: 10px; }
}
