:root {
  --bg: #0b0d11; --bg2: #10131a; --panel: #151922; --panel2: #1b202b; --border: #242a36; --border2: #2e3644;
  --text: #e8eaf0; --muted: #8e97a8; --dim: #5f6879; --accent: #5b8cff; --accent2: #8b5cf6;
  --pos: #2ed3a0; --neg: #f25f6b; --warn: #f5b74a; --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; --radius: 12px; --sidebar: 400px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 13px; -webkit-font-smoothing: antialiased; }
body { display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; } ::-webkit-scrollbar-thumb { background: #2a3140; border-radius: 6px; border: 2px solid var(--bg); } ::-webkit-scrollbar-track { background: transparent; }

/* ---------- top bar ---------- */
.topbar { height: 56px; display: flex; align-items: center; padding: 0 20px; gap: 24px; border-bottom: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; letter-spacing: .2px; }
.brand .logo { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: grid; place-items: center; }
.brand .logo svg { width: 15px; height: 15px; }
.brand small { color: var(--dim); font-weight: 500; margin-left: 4px; }
.tabs { display: flex; gap: 2px; margin-left: 12px; }
.tabs button { background: none; border: 0; padding: 8px 14px; border-radius: 8px; color: var(--muted); font-weight: 500; cursor: pointer; transition: .15s; }
.tabs button:hover { color: var(--text); background: var(--panel); }
.tabs button.active { color: var(--text); background: var(--panel2); }
.topbar .spacer { flex: 1; }
.dataset-pill { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: 12px; background: var(--panel); }
.dataset-pill b { color: var(--text); font-weight: 600; }
.dataset-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pos); box-shadow: 0 0 8px var(--pos); }
.dataset-pill .dot.busy { background: var(--warn); box-shadow: 0 0 8px var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.iconbtn { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; color: var(--muted); cursor: pointer; }
.iconbtn:hover { color: var(--text); border-color: var(--border2); }

/* ---------- layout ---------- */
.main { flex: 1; display: flex; min-height: 0; min-width: 0; overflow: hidden; }
.page { display: none; flex: 1; min-height: 0; min-width: 0; }
.page.active { display: flex; }
.sidebar { width: var(--sidebar); flex-shrink: 0; border-right: 1px solid var(--border); background: var(--bg2); display: flex; flex-direction: column; min-height: 0; }
.sidebar .scroll { flex: 1; overflow-y: auto; padding: 8px 0 20px; }
.sidebar .foot { border-top: 1px solid var(--border); padding: 12px 16px; display: flex; gap: 8px; align-items: center; background: var(--bg2); }
.content { flex: 1; overflow-y: auto; padding: 20px 24px 60px; min-width: 0; }

/* ---------- sections ---------- */
.sec { border-bottom: 1px solid var(--border); }
.sec-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; user-select: none; }
.sec-h:hover { background: rgba(255,255,255,.02); }
.sec-h .chev { width: 16px; height: 16px; color: var(--dim); transition: transform .15s; }
.sec.open .sec-h .chev { transform: rotate(90deg); }
.sec-h h3 { margin: 0; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); flex: 1; }
.sec-h .badge { font-family: var(--mono); font-size: 11px; color: var(--dim); background: var(--panel); border: 1px solid var(--border); padding: 2px 7px; border-radius: 6px; }
.sec-b { display: none; padding: 4px 16px 16px; }
.sec.open .sec-b { display: block; }
.field { display: grid; grid-template-columns: 1fr 128px; align-items: center; gap: 10px; padding: 5px 0; }
.field label { color: var(--text); font-size: 12.5px; }
.field label small { display: block; color: var(--dim); font-size: 11px; margin-top: 1px; }
.field .ctl { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
input[type=number], input[type=text], input[type=password], select, input[type=datetime-local], input[type=date] {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; width: 100%; outline: none; font-family: var(--mono); font-size: 12px; transition: border .15s; color: var(--text); }
input:focus, select:focus { border-color: var(--accent); }
input[type=number] { text-align: right; -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }
select { font-family: var(--sans); cursor: pointer; appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%238e97a8' stroke-width='1.5' fill='none'/></svg>"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 24px; }
.unit { color: var(--dim); font-family: var(--mono); font-size: 11px; width: 28px; flex-shrink: 0; }
.toggle { position: relative; width: 34px; height: 20px; background: var(--border2); border-radius: 999px; cursor: pointer; transition: .15s; flex-shrink: 0; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: .15s; }
.toggle.on { background: var(--accent); } .toggle.on::after { left: 17px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; color: var(--muted); padding: 4px 9px; border-radius: 6px; cursor: pointer; font-size: 11.5px; }
.seg button.on { background: var(--panel2); color: var(--text); }
.row-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.row-table th { text-align: left; color: var(--dim); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; padding: 4px 4px; }
.row-table td { padding: 3px 4px; }
.row-table td input, .row-table td select { padding: 5px 6px; }
.row-table td select { min-width: 74px; padding-right: 20px; background-position: right 6px center; font-size: 11px; }
.row-table td:first-child { width: 34px; }
.row-table .off { opacity: .4; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { padding: 4px 9px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); cursor: pointer; font-size: 11.5px; }
.chip.on { border-color: var(--accent); color: var(--text); background: rgba(91,140,255,.12); }
.hint { color: var(--dim); font-size: 11px; line-height: 1.4; margin: 4px 0 6px; }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; cursor: pointer; transition: .15s; white-space: nowrap; }
.btn:hover { filter: brightness(1.1); }
.btn.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--border); font-weight: 500; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { background: transparent; color: var(--neg); border: 1px solid var(--border); }
.btn:disabled { opacity: .5; cursor: default; }
.mini { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); padding: 3px 8px; cursor: pointer; font-size: 11px; }
.mini:hover { color: var(--text); }
.preset-row { display: flex; gap: 6px; width: 100%; }
.preset-row select { flex: 1; }

/* ---------- results ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; position: relative; overflow: hidden; }
.kpi .k { color: var(--muted); font-size: 11.5px; font-weight: 500; margin-bottom: 6px; }
.kpi .v { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: -.5px; line-height: 1.1; }
.kpi .s { color: var(--dim); font-family: var(--mono); font-size: 11.5px; margin-top: 5px; }
.kpi.pos .v { color: var(--pos); } .kpi.neg .v { color: var(--neg); }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--border2); }
.kpi.pos::before { background: var(--pos); } .kpi.neg::before { background: var(--neg); }
.warnings { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.warn { background: rgba(245,183,74,.08); border: 1px solid rgba(245,183,74,.3); color: #f6c86e; padding: 9px 12px; border-radius: 10px; font-size: 12.5px; display: flex; gap: 10px; align-items: flex-start; }
.warn svg { flex-shrink: 0; margin-top: 1px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card h4 { margin: 0 0 12px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.card h4 .sub { text-transform: none; letter-spacing: 0; color: var(--dim); font-weight: 400; margin-left: auto; font-family: var(--mono); font-size: 11px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.grid .span2 { grid-column: span 2; } .grid .span3 { grid-column: span 3; }
.stat { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--border); gap: 12px; }
.stat:last-child { border-bottom: 0; }
.stat .n { color: var(--muted); font-size: 12.5px; }
.stat .n small { color: var(--dim); display: block; font-size: 11px; }
.stat .val { font-family: var(--mono); font-size: 13px; text-align: right; white-space: nowrap; }
.stat .val small { color: var(--dim); font-size: 11px; margin-left: 4px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); }
canvas.chart { width: 100%; display: block; }
.chart-wrap { position: relative; }
.chart-legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
.chart-legend span::before { content: ""; display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; background: var(--c); }
.tooltip { position: absolute; pointer-events: none; background: #0f1218; border: 1px solid var(--border2); border-radius: 8px; padding: 8px 10px; font-family: var(--mono); font-size: 11px; line-height: 1.5; color: var(--text); display: none; z-index: 5; white-space: nowrap; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
table.data { width: 100%; border-collapse: collapse; font-size: 12px; }
table.data th { text-align: left; color: var(--dim); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--panel); cursor: pointer; }
table.data th.sorted { color: var(--text); }
table.data td { padding: 6px 8px; border-bottom: 1px solid var(--border); font-family: var(--mono); white-space: nowrap; }
table.data td.t { font-family: var(--sans); max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
table.data tr:hover td { background: rgba(255,255,255,.02); }
table.data tr.click { cursor: pointer; }
.num { text-align: right; }
.list li { display: flex; justify-content: space-between; padding: 4px 0; font-family: var(--mono); font-size: 12px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li span:first-child { color: var(--text); font-family: var(--sans); max-width: 55%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li span:last-child { white-space: nowrap; }
.bar-h { display: grid; grid-template-columns: 90px 1fr 60px; align-items: center; gap: 10px; padding: 4px 0; font-size: 12px; }
.bar-h .b { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; } .bar-h .b i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar-h .v { font-family: var(--mono); text-align: right; color: var(--muted); }
.empty { color: var(--dim); text-align: center; padding: 40px; }
.loading-bar { position: fixed; top: 56px; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 200% 100%; animation: slide .9s linear infinite; display: none; z-index: 20; }
.loading-bar.on { display: block; }
@keyframes slide { from { background-position: 200% 0 } to { background-position: -200% 0 } }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.toolbar input[type=text] { width: 240px; }
.pill { font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--panel2); color: var(--muted); border: 1px solid var(--border); }
.pill.tp { color: var(--pos); } .pill.stop { color: var(--neg); } .pill.force { color: var(--warn); } .pill.dead { color: var(--dim); } .pill.trailing { color: var(--accent); } .pill.twap, .pill.pump { color: var(--accent2); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; z-index: 50; align-items: center; justify-content: center; backdrop-filter: blur(3px); }
.modal-bg.on { display: flex; }
.modal { width: min(1100px, 94vw); max-height: 90vh; overflow: auto; background: var(--bg2); border: 1px solid var(--border2); border-radius: 16px; padding: 20px 22px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.modal h3 { margin: 0 0 4px; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.modal .close { margin-left: auto; }
.modal .meta { color: var(--muted); font-family: var(--mono); font-size: 11.5px; margin-bottom: 12px; }
.drop { border: 1px dashed var(--border2); border-radius: 12px; padding: 30px; text-align: center; color: var(--muted); cursor: pointer; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: rgba(91,140,255,.05); }
.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login { width: 340px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.login h2 { margin: 0 0 8px; font-size: 18px; }
.err { color: var(--neg); font-size: 12px; min-height: 16px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
@media (max-width: 1400px) { .kpis { grid-template-columns: repeat(3, 1fr); } .grid { grid-template-columns: repeat(2, 1fr); } .grid .span3 { grid-column: span 2; } }

/* ---- rules lab ---- */
.sidebar.wide { width: 560px; }
.rule { border: 1px solid var(--border); border-radius: 10px; margin: 8px 0; background: var(--panel); }
.rule.off { opacity: .5; }
.rule-h { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.rule-h .rname { flex: 1; font-size: 12.5px; font-weight: 500; background: transparent; border: 0; border-bottom: 1px dashed var(--border); color: var(--text); padding: 2px 0; }
.rule-h .rfired { color: var(--dim); font-family: var(--mono); font-size: 11px; }
.rule-b { padding: 8px 10px; }
.group { border-left: 2px solid var(--border2); padding: 4px 0 4px 8px; margin: 4px 0; }
.orsep, .andsep { font-family: var(--mono); font-size: 10.5px; color: var(--accent2); letter-spacing: .5px; margin: 2px 0 2px 8px; }
.orsep { color: var(--warn); margin: 6px 0; font-weight: 600; }
.cond { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 4px 0; }
.cond .metric { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.cond .mrest { display: inline-flex; align-items: center; gap: 4px; }
.cond select, .cond input { font-size: 11.5px; padding: 3px 5px; height: 26px; }
.cond .mparam { max-width: 200px; }
.cond .magg { max-width: 150px; }
.cond .mwin, .cond .mmult { width: 54px; }
.cond .mval { width: 90px; }
.cond .mop { width: 52px; font-family: var(--mono); font-weight: 600; }
.cond .unit { width: auto; }
.ccount { color: var(--dim); font-family: var(--mono); font-size: 10.5px; white-space: nowrap; margin-left: 4px; }
.gfoot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.ract { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.ract .af { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
.ract .af input { width: 64px; height: 26px; font-size: 11.5px; padding: 3px 5px; }
.ract .af select { height: 26px; font-size: 11.5px; padding: 2px 5px; max-width: 190px; }
.rfoot { margin-top: 6px; }
.rfoot select { width: 100%; }
