:root {
  --bg: #f4f5f7; --panel: #ffffff; --line: #dfe2e7; --text: #1b1f27; --muted: #667085;
  --accent: #1f4e8c; --accent-dark: #173c6c; --up: #1a7f4b; --down: #c0392b; --warn: #9a6700;
  --radius: 4px; --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13px/1.45 var(--font); color: var(--text); background: var(--bg); display: flex; flex-direction: column; }
h2 { font-size: 15px; margin: 0 0 12px; }
.brand { font-weight: 700; letter-spacing: .08em; font-size: 14px; color: var(--accent); }
.brand span { font-weight: 400; color: var(--text); }

.topbar { display: flex; align-items: center; justify-content: space-between; height: 44px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.live-pill { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 12px;
  font: inherit; color: var(--muted); cursor: pointer; }
.live-pill.on { border-color: var(--up); color: var(--up); }
.live-pill b { font-weight: 600; }

.layout { flex: 1 1 auto; min-height: 0; display: flex; }
.pane { display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.chart-pane { flex: 1 1 58%; }
.editor-pane { flex: 0 0 42%; }
.divider { flex: 0 0 5px; cursor: col-resize; background: var(--line); }
.divider:hover { background: #c5cad3; }

.toolbar { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line);
  flex: none; flex-wrap: wrap; min-height: 44px; }
.toolbar label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.toolbar-note { color: var(--muted); margin-left: auto; }
.spacer { flex: 1; }
select, input { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 5px 8px; min-height: 30px; }
select:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: var(--radius); padding: 5px 12px; min-height: 30px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.danger { background: var(--down); border-color: var(--down); color: #fff; font-weight: 600; }
.btn.quiet { border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 4px 2px 10px; background: #f8f9fb; }
.chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1;
  padding: 2px 6px; border-radius: 50%; }
.chip button:hover { background: #e6e9ee; color: var(--text); }

.chart, .editor { flex: 1 1 auto; min-height: 0; }

.bottom { flex: 0 0 230px; display: flex; flex-direction: column; background: var(--panel);
  border-top: 1px solid var(--line); min-height: 0; }
.tabs { display: flex; align-items: center; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line); flex: none; }
.tabs button { font: inherit; border: 0; background: none; padding: 9px 12px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-status { margin-left: auto; color: var(--muted); }
.tab-status.error { color: var(--down); }
.tab-body { flex: 1 1 auto; overflow: auto; padding: 12px 14px; }
.empty { color: var(--muted); margin: 6px 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.stat small { display: block; color: var(--muted); }
.stat strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.pos { color: var(--up); } .neg { color: var(--down); }
.result-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.result-head b { font-size: 14px; }
.result-head span { color: var(--muted); }
.linkish { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }
.error-box { border: 1px solid #e6b8b2; background: #fdf3f2; color: #8a231a; border-radius: var(--radius);
  padding: 10px 12px; white-space: pre-wrap; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; margin-bottom: 10px; }
.notice { border: 1px solid #e3d7b0; background: #fdf9ec; color: #5c4a10; border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }

table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 5px 10px; border-bottom: 1px solid #eceef1; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; position: sticky; top: -12px; background: var(--panel); }
td.num, th.num { text-align: right; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: #f6f8fa; }
pre.log { margin: 0; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
code { background: #f0f2f5; padding: 1px 5px; border-radius: 3px; font-size: 12px; }

dialog { border: 1px solid var(--line); border-radius: 6px; padding: 18px; width: 340px; max-width: 92vw;
  box-shadow: 0 10px 30px rgba(20, 30, 50, .18); color: var(--text); }
dialog::backdrop { background: rgba(20, 30, 50, .3); }
dialog label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); margin-bottom: 10px; }
.param-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.hint { color: var(--muted); font-size: 12px; margin: 2px 0 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: #1b1f27; color: #fff;
  padding: 8px 14px; border-radius: var(--radius); z-index: 50; max-width: 80vw; }
.toast.error { background: var(--down); }

.login-body { align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 26px; width: 320px;
  max-width: 92vw; display: flex; flex-direction: column; gap: 8px; }
.login-card .brand { font-size: 16px; margin-bottom: 12px; }
.login-card label { color: var(--muted); }
.login-card .btn { margin-top: 8px; min-height: 36px; }
.login-error { color: var(--down); margin: 0; }

@media (max-width: 900px) {
  body { height: auto; min-height: 100%; }
  .layout { flex-direction: column; }
  .chart-pane { flex: none; height: 60vh; } .editor-pane { flex: none; height: 60vh; }
  .divider { display: none; } .bottom { flex: none; min-height: 260px; }
}
