/* Gonogo — mobile-first financial dashboard. Dark by default, optional light. */
:root {
  --bg: #0b0e11;
  --surface: #161a1f;
  --surface-2: #1e2329;
  --border: #2b3139;
  --fg: #eaecef;
  --muted: #8b949e;
  --accent: #f0b90b;
  --accent-ink: #0b0e11;
  --up: #0ecb81;
  --down: #f6465d;
  --warn: #f0b90b;
  --info: #3d8bfd;
  --chart-bg: #0f1216;
  --chart-grid: #1f2630;
  --ema20: #f0b90b;
  --ema50: #3d8bfd;
  --ema200: #b37feb;
  --bb: #5e6673;
  --go-bg: rgba(14, 203, 129, 0.12);
  --nogo-bg: rgba(246, 70, 93, 0.12);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --fg: #1e2329;
  --muted: #5e6673;
  --accent: #c99400;
  --accent-ink: #ffffff;
  --up: #03a66d;
  --down: #cf304a;
  --chart-bg: #ffffff;
  --chart-grid: #edf0f3;
  --ema20: #c99400;
  --bb: #aab2bd;
  --go-bg: rgba(3, 166, 109, 0.10);
  --nogo-bg: rgba(207, 48, 74, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(68px + var(--safe-bottom));
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.up { color: var(--up); }
.down { color: var(--down); }
.accent { color: var(--accent); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; letter-spacing: 0.2px; }
.brand img { display: block; border-radius: 7px; }
.chips { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  white-space: nowrap;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.live { color: var(--up); border-color: color-mix(in srgb, var(--up) 40%, transparent); }
.chip.refreshing { color: var(--info); }
.chip.stale, .chip.unverified, .chip.insufficient { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.chip.offline, .chip.error { color: var(--down); border-color: color-mix(in srgb, var(--down) 40%, transparent); }
.chip.refreshing::before { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--down); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.refresh-btn .count { font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 3ch; }
.refresh-btn svg { width: 18px; height: 18px; }
.refresh-btn.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 14px 16px 24px; }
.view { display: none; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.grid2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .grid2 { grid-template-columns: 1fr 1fr; } .span2 { grid-column: 1 / -1; } }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; min-width: 0;
}
.grid2 > .card { margin-bottom: 0; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin: 0 0 12px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card h2 .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; }
.card h3 { font-size: 14px; margin: 14px 0 8px; }
.note { font-size: 12.5px; color: var(--muted); margin: 10px 0 0; }
.note.warn { color: var(--warn); }

/* ---------- Decision hero ---------- */
.hero { padding: 18px; position: relative; overflow: hidden; }
.hero.go { background: linear-gradient(180deg, var(--go-bg), transparent 70%), var(--surface); border-color: color-mix(in srgb, var(--up) 45%, var(--border)); }
.hero.nogo { background: linear-gradient(180deg, var(--nogo-bg), transparent 70%), var(--surface); border-color: color-mix(in srgb, var(--down) 35%, var(--border)); }
.hero-top { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.decision {
  font-size: 44px; line-height: 1; font-weight: 800; letter-spacing: 1px; padding: 10px 16px; border-radius: 12px;
  border: 2px solid currentColor; white-space: nowrap;
}
.decision.go { color: var(--up); }
.decision.nogo { color: var(--down); }
.price-block { margin-left: auto; text-align: right; }
.price-block .pair { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: 0.5px; }
.price-block .price { font-family: var(--mono); font-size: 28px; font-weight: 700; }
.price-block .chg { font-family: var(--mono); font-size: 13px; }
.reason { margin: 14px 0 12px; font-size: 15px; font-weight: 500; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 600px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--surface-2); border-radius: 10px; padding: 9px 11px; min-width: 0; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stat .v { font-family: var(--mono); font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.historical {
  border: 1px dashed var(--warn); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin-top: 12px; font-size: 13px;
}

/* Score ring */
.score { display: flex; align-items: center; gap: 12px; }
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring span { width: 50px; height: 50px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-family: var(--mono); font-weight: 700; }

/* ---------- Key/value tables ---------- */
.kv { display: grid; grid-template-columns: minmax(110px, 44%) minmax(0, 1fr); gap: 6px 12px; align-items: baseline; }
.kv .k { color: var(--muted); font-size: 13.5px; }
.kv .v { font-family: var(--mono); text-align: right; font-size: 13.5px; overflow-wrap: anywhere; }
.kv .v.strong { font-weight: 700; color: var(--fg); }
.kv hr { grid-column: 1 / -1; border: 0; border-top: 1px solid var(--border); margin: 4px 0; width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 6px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
td { font-family: var(--mono); }
td.text { font-family: var(--font); white-space: normal; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }

/* ---------- Checks ---------- */
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.checks li:last-child { border-bottom: 0; }
.checks .ic { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 800; margin-top: 1px; }
.checks .pass .ic { background: color-mix(in srgb, var(--up) 20%, transparent); color: var(--up); }
.checks .fail .ic { background: color-mix(in srgb, var(--down) 20%, transparent); color: var(--down); }
.checks .off .ic { background: var(--surface-2); color: var(--muted); }
.checks .lbl { font-weight: 600; font-size: 14px; }
.checks .det { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.checks .group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); padding: 10px 0 2px; border: 0; display: block; }
.dots { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--down); display: inline-block; }
.dots i.ok { background: var(--up); }

.bar { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; width: 0; }
.fam { margin-bottom: 12px; }
.fam-head { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 4px; }
.fam-comp { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }

/* Entry range ladder */
.ladder { position: relative; height: 34px; background: var(--surface-2); border-radius: 8px; margin: 6px 0 14px; overflow: hidden; }
.ladder .zone { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 22%, transparent); border-left: 1px solid var(--accent); border-right: 1px solid var(--accent); }
.ladder .pref { position: absolute; top: 8px; bottom: 8px; background: color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 3px; }
.ladder .mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--fg); }
.ladder .lvl { position: absolute; top: 0; bottom: 0; width: 2px; }
.ladder .lvl.s { background: var(--up); }
.ladder .lvl.r { background: var(--down); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ---------- Chart ---------- */
.chart-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,0.25); }
.toggles { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; }
.toggles label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
canvas.chart { width: 100%; height: 440px; display: block; border-radius: 10px; }
@media (max-width: 600px) { canvas.chart { height: 400px; } }
canvas.equity { width: 100%; height: 260px; display: block; border-radius: 10px; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .field { flex: 1 1 140px; }
input[type="text"], input[type="number"], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 10px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); font-family: var(--mono);
}
textarea { min-height: 150px; font-size: 12.5px; resize: vertical; }
input[aria-invalid="true"] { border-color: var(--down); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.switch:last-child { border-bottom: 0; }
.switch .t { font-size: 14px; }
.switch .d { font-size: 12px; color: var(--muted); }
.switch input { width: 44px; height: 26px; appearance: none; -webkit-appearance: none; background: var(--border); border-radius: 999px; position: relative; cursor: pointer; flex: none; transition: background 0.15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform 0.15s; }
.switch input:checked { background: var(--up); }
.switch input:checked::after { transform: translateX(18px); }
details.adv > summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.progress { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; margin: 10px 0; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* ---------- Banners ---------- */
#banner-area { position: fixed; left: 0; right: 0; top: calc(64px + var(--safe-top)); z-index: 30; display: grid; gap: 8px; padding: 0 16px; pointer-events: none; max-width: 720px; margin: 0 auto; }
.banner { pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,0.35); font-size: 14px; animation: fade 0.2s; }
.banner.go { border-color: var(--up); }
.banner.nogo, .banner.error { border-color: var(--down); }
.banner.update { border-color: var(--accent); }
.banner .x { margin-left: auto; background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 4px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tab { display: grid; justify-items: center; gap: 2px; padding: 8px 0 7px; background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 600; cursor: pointer; min-height: 56px; }
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--accent); }
@media (min-width: 860px) {
  .tabbar { position: sticky; top: 61px; bottom: auto; max-width: 1080px; margin: 0 auto; border: 0; border-bottom: 1px solid var(--border); grid-template-columns: repeat(3, auto); justify-content: start; gap: 6px; padding: 0 16px; background: var(--bg); }
  .tab { grid-auto-flow: column; gap: 6px; font-size: 14px; padding: 10px 12px; min-height: 0; }
  .tab svg { width: 18px; height: 18px; }
  .tab[aria-current="page"] { box-shadow: inset 0 -2px 0 var(--accent); }
  body { padding-bottom: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Simple mode */
details.more { margin-top: 4px; }
details.more > summary, details.adv-settings > summary {
  list-style: none; cursor: pointer; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; margin-bottom: 14px;
}
details.more > summary::-webkit-details-marker, details.adv-settings > summary::-webkit-details-marker { display: none; }
details.more > summary::after, details.adv-settings > summary::after { content: "▾"; }
details[open].more > summary::after, details[open].adv-settings > summary::after { content: "▴"; }
.hero .reason { font-size: 16px; }
