:root {
  --bg: #0d1117; --panel: #161b22; --panel2: #1c2330; --line: #2a3342; --text: #e6edf3; --muted: #8b98a9;
  --green: #2ea66b; --red: #e5484d; --amber: #e3a008; --blue: #4c8dff; --cyan: #22b8cf;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 17px; margin: 0; letter-spacing: .3px; }
h2 { font-size: 13px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 600; }
button, input, select { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 14px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
button.go { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
button.small { padding: 3px 9px; font-size: 12px; }
button.estop { background: var(--red); border-color: #ff8589; color: #fff; font-weight: 800; letter-spacing: .6px; padding: 9px 18px; }
button.estop:hover { background: #ff3b41; }
input, select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; width: 100%; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
input[type=checkbox] { width: auto; }
textarea { background: var(--bg); color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 9px; width: 100%; margin-top: 10px; font: 13px/1.5 ui-monospace, Consolas, monospace; }

header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 6px 13px; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); font-weight: 600; }
.seg button.on.live { background: var(--red); color: #fff; }
.seg button.on.demo { background: var(--blue); color: #fff; }
.seg button.on.sim { background: #5b6577; color: #fff; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid var(--line); white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--green); } .pill.bad { color: var(--red); } .pill.warn { color: var(--amber); } .pill.idle { color: var(--muted); }

.banner { padding: 8px 18px; font-weight: 700; text-align: center; }
.banner.live { background: #5a1417; color: #ffd7d8; }
.banner.halt { background: var(--red); color: #fff; }
.banner.err { background: #4a3605; color: #ffe6a3; font-weight: 500; }
.hidden { display: none !important; }

main { padding: 16px 18px 40px; max-width: 1500px; margin: 0 auto; display: grid; gap: 14px; }
.grid { display: grid; gap: 14px; }
main > *, .grid > * { min-width: 0; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.two { grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }
.pos { color: var(--green); } .neg { color: var(--red); } .muted { color: var(--muted); }

.scroll { overflow-x: auto; max-height: 340px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; font-weight: 600; position: sticky; top: 0; background: var(--panel); }
td.wrap { white-space: normal; min-width: 220px; }
td.num, th.num { text-align: right; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.tag.buy { background: #123d29; color: #6ee7a8; } .tag.sell { background: #4a1719; color: #ff9da0; }
.tag.yes { background: #123d29; color: #6ee7a8; } .tag.no { background: #4a1719; color: #ff9da0; }
.tag.neutral { background: var(--panel2); color: var(--muted); }
.empty { color: var(--muted); padding: 14px 4px; }

.log { max-height: 300px; overflow-y: auto; font: 12px/1.5 ui-monospace, Consolas, monospace; }
.log div { padding: 2px 0; border-bottom: 1px dashed #222a36; }
.log .error { color: #ff9da0; } .log .warn { color: #f5cf6b; } .log .t { color: var(--muted); margin-right: 8px; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 8px 12px; }
.tabs button.on { color: var(--text); border-bottom-color: var(--blue); font-weight: 600; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.form label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.form label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.note { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; max-width: 90ch; }
.msg { font-size: 13px; } .msg.ok { color: var(--green); } .msg.bad { color: #ff9da0; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; overflow-x: auto; margin: 8px 0 0; font: 12px/1.5 ui-monospace, Consolas, monospace; }
code { font: 12px ui-monospace, Consolas, monospace; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .65); }
dialog h3 { margin: 0 0 8px; } dialog p { margin: 0 0 14px; color: var(--muted); }
dialog label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); padding: 26px; }
.login h1 { margin-bottom: 4px; } .login p { color: var(--muted); margin: 0 0 18px; }
.login label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.login button { width: 100%; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.pager:empty { display: none; }
.scroll { max-height: none; }
