:root {
  --bg: #f4f5f2; --surface: #ffffff; --surface-2: #eceee9; --text: #16181a; --muted: #6a6f73;
  --line: #dcdfd8; --accent: #1f6f5c; --accent-ink: #ffffff; --pos: #1b7f4b; --neg: #c0392b;
  --warn: #b7791f; --danger: #b42318; --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1112; --surface: #171a1c; --surface-2: #1f2326; --text: #e8eae8; --muted: #9aa0a4;
    --line: #2a2f33; --accent: #3fb68f; --accent-ink: #08130f; --pos: #45c47f; --neg: #ff6b5e;
    --warn: #e0a542; --danger: #ff5a4f;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
h2 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: .01em; }
h3 { font-size: 13px; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.err { color: var(--neg); min-height: 1em; margin: 6px 0 0; font-size: 13.5px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.num { font-variant-numeric: tabular-nums; }

/* Layout */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--pos); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pos) 20%, transparent); }
.dot.bad { background: var(--neg); }
.top-actions { display: flex; gap: 8px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); letter-spacing: .05em; }
.badge.live { background: var(--danger); color: #fff; }
.banner { margin: 10px 16px 0; padding: 10px 12px; border-radius: var(--radius); background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tabs { display: flex; gap: 4px; padding: 10px 16px 0; overflow-x: auto; scrollbar-width: none; }
.tabs button { flex: 0 0 auto; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: 8px 12px; border-radius: 99px; cursor: pointer; }
.tabs button.active { background: var(--text); color: var(--bg); }
.tab { padding: 12px 16px 90px; max-width: 980px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.page-head { margin: 4px 0 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0; }
.row > input { flex: 1 1 140px; }

/* Inputs */
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
}
.row > select, .row > input[type=number] { width: auto; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px; }
.label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 9px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: none; border-color: transparent; }
.btn.ok { background: var(--pos); border-color: var(--pos); color: #fff; }
.toggle { position: relative; width: 50px; height: 30px; flex: 0 0 auto; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: .2s; cursor: pointer; }
.toggle span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(20px); }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); padding: 6px 10px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg button.on.auto { background: var(--accent); color: var(--accent-ink); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .s { font-size: 12px; color: var(--muted); }
.meter { height: 5px; background: var(--surface-2); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter i.warn { background: var(--warn); } .meter i.bad { background: var(--neg); }

/* Chart */
.chart { height: 160px; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .empty { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 13px; }

/* Listen */
.item { border-top: 1px solid var(--line); padding: 10px 0; }
.item:first-child { border-top: 0; padding-top: 0; }
.item-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.item-title { font-weight: 650; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.pos { color: var(--pos); } .chip.neg { color: var(--neg); }
.st { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); color: var(--muted); }
.st.open, .st.submitted { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.st.pending { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.st.closed.win { color: var(--pos); } .st.closed.loss { color: var(--neg); }
.reason { font-size: 13.5px; color: var(--muted); margin: 4px 0 8px; }
.events div { font-size: 13px; padding: 4px 0; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.events div:first-child { border-top: 0; }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.rules { padding-left: 20px; margin: 6px 0; }
.rules li { margin: 3px 0; font-size: 14px; }
details summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13.5px; margin: 10px 0; }
.note { font-size: 13px; padding: 8px 10px; border-radius: 9px; margin: 6px 0; background: var(--surface-2); }
.note.warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.trade-row { cursor: pointer; }
.detail { font-size: 13px; color: var(--muted); margin-top: 6px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.table td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.scroll-x { overflow-x: auto; }

/* Settings */
.set-group h2 { margin-bottom: 4px; }
.set { padding: 10px 0; border-top: 1px solid var(--line); }
.set:first-of-type { border-top: 0; }
.set-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.set-head .val { width: 110px; text-align: right; }
.set input[type=range] { padding: 0; background: none; border: 0; accent-color: var(--accent); margin-top: 6px; }
.set .cap { font-size: 12px; color: var(--muted); }
.checks label { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 6px 0; }
.checks input { width: auto; }
.sticky-save { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line); display: flex; gap: 12px; align-items: center; justify-content: center; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; padding: 22px; }
.login-card .brand { font-size: 18px; }

.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }
