:root {
  --bg: #0b0e13; --panel: #12161d; --panel2: #181d26; --raise: #1e2430; --input: #0e1218;
  --line: #222934; --line2: #2e3644; --text: #e6e9ef; --muted: #8a94a6; --faint: #5f6979;
  --accent: #5b9dff; --accent-2: #3d84f5; --accent-weak: rgba(91, 157, 255, .14);
  --good: #3ecf8e; --good-weak: rgba(62, 207, 142, .12);
  --bad: #f2626b; --bad-weak: rgba(242, 98, 107, .12);
  --warn: #f0b44c; --warn-weak: rgba(240, 180, 76, .12);
  --violet: #a78bfa; --violet-weak: rgba(167, 139, 250, .13);
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .02) inset, 0 8px 24px -12px rgba(0, 0, 0, .6);
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: radial-gradient(1200px 500px at 50% -200px, rgba(91, 157, 255, .07), transparent 70%), var(--bg);
  background-attachment: fixed;
  color: var(--text); font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: #86b6ff; }
h1 { font-size: 24px; font-weight: 650; letter-spacing: -.015em; margin: 4px 0 6px; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; letter-spacing: -.005em; }
h3 { font-size: 12px; font-weight: 600; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.card h2:not(:first-child) { margin-top: 22px; }
p { margin: 8px 0; }
code, .mono, pre { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
pre { white-space: pre-wrap; word-break: break-word; margin: 4px 0; }
pre.code { background: var(--input); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; max-height: 480px; overflow: auto; }
.pre { white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
::selection { background: rgba(91, 157, 255, .35); }

/* ------------------------------------------------------------------ layout */
header.top {
  display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 56px;
  background: rgba(13, 16, 22, .82); backdrop-filter: saturate(160%) blur(10px); -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
header .brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); letter-spacing: -.01em; white-space: nowrap; }
header .brand img { width: 24px; height: 24px; display: block; }
header .brand:hover { color: var(--text); }
header nav { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
header nav::-webkit-scrollbar { display: none; }
header nav a { color: var(--muted); padding: 6px 11px; border-radius: 7px; font-weight: 500; white-space: nowrap; transition: color .15s, background .15s; }
header nav a:hover { color: var(--text); background: var(--panel2); }
header nav a.on { color: var(--text); background: var(--raise); box-shadow: inset 0 0 0 1px var(--line2); }
header .logout { color: var(--muted); }
main { width: 100%; max-width: 1280px; margin: 0 auto; padding: 22px 20px 48px; flex: 1; }
footer { text-align: center; padding: 14px; font-size: 12px; color: var(--faint); border-top: 1px solid var(--line); }
@media (max-width: 640px) {
  header.top { gap: 10px; padding: 0 12px; }
  header .brand span { display: none; }
  main { padding: 16px 12px 40px; }
}

.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card > .head { margin-bottom: 4px; }
.card > .head h2 { margin: 6px 0; }
.sub { color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.actions, .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row { margin: 10px 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.stack label:has(> input[type=checkbox]) { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; font-weight: 400; }
.stack label .muted { font-weight: 400; color: var(--faint); }
label.inline { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; }
form.inline { display: inline; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 16px 0; min-width: 0; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .table-wrap { margin: 0; }
.card.flush tbody tr:last-child td { border-bottom: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .card { margin: 0; }
section.grid2 { margin: 16px 0; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ controls */
input, select, textarea, button, .button {
  background: var(--input); color: var(--text); border: 1px solid var(--line2); border-radius: var(--radius-sm);
  padding: 7px 11px; font: inherit; font-size: 14px; font-weight: 400; line-height: 1.4; max-width: 100%;
  transition: border-color .15s, background .15s, box-shadow .15s, color .15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { width: 100%; resize: vertical; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238a94a6' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
input:hover, select:hover, textarea:hover { border-color: #3a4454; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
input:disabled, select:disabled { opacity: .55; cursor: not-allowed; }
input[type=checkbox] { width: 16px; height: 16px; padding: 0; margin: 0; accent-color: var(--accent); cursor: pointer; flex: none; }
input[type=date] { color-scheme: dark; }

button, .button {
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  background: var(--raise); color: var(--text); font-weight: 500; padding: 7px 14px;
}
button:hover, .button:hover { background: #262e3c; border-color: #3d4758; color: var(--text); }
button:focus-visible, .button:focus-visible, header nav a:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-weak); border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; transform: none; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
button.primary:hover { background: #5294ff; border-color: #5294ff; }
button.danger { background: var(--bad-weak); border-color: rgba(242, 98, 107, .35); color: #ff8f96; }
button.danger:hover { background: rgba(242, 98, 107, .2); border-color: var(--bad); color: #ffb0b5; }
button.small, .small.button { padding: 3px 9px; font-size: 12px; border-radius: 6px; }
button.link { background: none; border-color: transparent; color: var(--muted); padding: 6px 10px; }
button.link:hover { background: var(--panel2); color: var(--text); border-color: transparent; }

/* on/off switch; the button's text is kept for screen readers only */
button.toggle {
  position: relative; width: 36px; height: 20px; padding: 0; border-radius: 999px; font-size: 0; color: transparent;
  background: var(--line2); border: 0; vertical-align: middle;
}
button.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%;
  background: #c9d0db; transition: transform .15s, background .15s;
}
button.toggle:hover { background: #3a4454; }
button.toggle.on { background: var(--good); }
button.toggle.on:hover { background: #5ad9a0; }
button.toggle.on::after { transform: translateX(16px); background: #fff; }

/* ------------------------------------------------------------------ banners & tags */
.banner {
  padding: 10px 14px; border-radius: var(--radius-sm); margin: 10px 0; border: 1px solid var(--line);
  border-left-width: 3px; background: var(--panel);
}
.banner.bad { border-color: rgba(242, 98, 107, .35); border-left-color: var(--bad); background: var(--bad-weak); }
.banner.warn { border-color: rgba(240, 180, 76, .3); border-left-color: var(--warn); background: var(--warn-weak); }
.banner.good { border-color: rgba(62, 207, 142, .3); border-left-color: var(--good); background: var(--good-weak); }
.banner pre { margin: 6px 0 0; }
.banner form.inline button { margin-left: 6px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px; border-radius: 999px; vertical-align: middle;
  background: var(--panel2); border: 1px solid var(--line2); font-size: 11.5px; font-weight: 500; line-height: 1; color: var(--muted); white-space: nowrap;
}
.tag.good, .tag.st-queued, .tag.st-validated, .tag.st-sent { color: var(--good); background: var(--good-weak); border-color: transparent; }
.tag.bad { color: var(--bad); background: var(--bad-weak); border-color: transparent; }
.tag.warn, .tag.st-candidate, .tag.st-paused, .tag.st-late { color: var(--warn); background: var(--warn-weak); border-color: transparent; }
.tag.st-experimental { color: var(--violet); background: var(--violet-weak); border-color: transparent; }
.tag.st-deprecated, .tag.st-suppressed { color: var(--faint); }
.tag.good::before, .tag.bad::before, .tag.warn::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
.card > .table-wrap, .card > details > .table-wrap, #results > .table-wrap, #results > details > .table-wrap, #out > .table-wrap { margin: 0 -18px; }
table.grid { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.grid th, table.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th:first-child, table.grid td:first-child { padding-left: 18px; }
table.grid th:last-child, table.grid td:last-child { padding-right: 18px; }
table.grid th {
  color: var(--faint); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
  background: rgba(255, 255, 255, .015);
}
table.grid tbody tr { transition: background .1s; }
table.grid tbody tr:hover td { background: rgba(255, 255, 255, .025); }
table.grid tr.archived td { opacity: .5; }
table.grid tr.bad td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
table.grid td[colspan] { padding: 22px 18px; text-align: center; }
table.grid td.num, table.grid th.num { text-align: right; }
td .name { font-weight: 600; color: var(--text); }
td .name:hover { color: var(--accent); }
td .id { display: block; font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.help table.grid td { padding-left: 12px; }
table.grid tr.main td { background: rgba(91, 157, 255, .06); }
table.grid tr.main td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.hint { border-bottom: 1px dotted currentColor; cursor: help; }

/* ------------------------------------------------------------------ indicator card */
.verdict { border: 1px solid var(--line); border-left: 3px solid var(--line2); border-radius: var(--radius-sm); padding: 12px 14px; margin: 4px 0 12px; background: var(--panel2); }
.verdict > b { font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.verdict p { margin: 6px 0 0; color: var(--muted); }
.verdict.good { border-left-color: var(--good); background: var(--good-weak); }
.verdict.good > b { color: var(--good); }
.verdict.warn { border-left-color: var(--warn); background: var(--warn-weak); }
.verdict.warn > b { color: var(--warn); }
.verdict.bad { border-left-color: var(--bad); background: var(--bad-weak); }
.verdict.bad > b { color: var(--bad); }
ol.steps { list-style: none; counter-reset: step; padding: 0; margin: 12px 0 0; }
ol.steps > li { counter-increment: step; position: relative; padding: 0 0 14px 34px; line-height: 1.55; }
ol.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 0; width: 22px; height: 22px; border-radius: 50%;
  background: var(--panel2); border: 1px solid var(--line2); color: var(--muted); font-size: 12px; font-weight: 600;
  display: grid; place-items: center;
}
ol.steps > li:not(:last-child)::after { content: ""; position: absolute; left: 11px; top: 26px; bottom: 4px; width: 1px; background: var(--line); }
ol.steps .small { margin-top: 4px; }
ol.steps code.formula { white-space: normal; word-break: break-word; }
ul.stages { margin: 6px 0 2px; }
ul.plain.stages li { margin: 0; padding: 3px 0; border: 0; }
details.desc { margin: 0 0 10px; }
details.explain { margin: 8px 0 4px; }
details.explain ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); }
details.explain li { margin: 6px 0; line-height: 1.55; }
details.explain b { color: var(--text); }
.card .grid2 h3:first-child { margin-top: 4px; }
.metrics.wide { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.metrics.wide b { font-size: 19px; }
figure.equity-wrap { margin: 4px 0 8px; }
svg.equity { display: block; width: 100%; height: 160px; background: var(--input); border: 1px solid var(--line); border-radius: var(--radius-sm); }
svg.equity polyline { fill: none; stroke: var(--good); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
svg.equity.down polyline { stroke: var(--bad); }
svg.equity line.zero { stroke: var(--line2); stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
details.fill { margin-top: 6px; }
details.fill .row label { flex: 1; min-width: 140px; }
.metrics.overview { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
table.ideas td.idea { min-width: 280px; max-width: 420px; }
table.ideas .hyp { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); line-height: 1.4; }
table.ideas td.spark { width: 104px; }
table.ideas svg.equity { width: 96px; height: 28px; border: 0; background: none; }
table.ideas .num .id { font-family: inherit; }
@media (max-width: 640px) {
  table.ideas thead { display: none; }
  table.ideas, table.ideas tbody { display: block; }
  table.ideas tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 10px; padding: 12px; border-bottom: 1px solid var(--line); }
  table.ideas td { display: block; padding: 0; border: 0; text-align: left !important; }
  table.ideas td.idea { grid-column: 1 / 3; grid-row: 1; min-width: 0; max-width: none; }
  table.ideas td.toggle-cell { grid-column: 3; grid-row: 1; justify-self: end; }
  table.ideas td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
  table.ideas td[data-l="Вердикт"] { grid-column: span 2; }
  table.ideas td[colspan] { grid-column: 1 / -1; }
}

.dir { font-weight: 700; }
.dir.long { color: var(--good); }
.dir.short { color: var(--bad); }
.oc { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.oc > span { display: inline-flex; gap: 5px; padding: 1px 7px; border-radius: 6px; background: var(--panel2); font-size: 12px; white-space: nowrap; }
.oc b { font-weight: 500; }
.oc i { font-style: normal; color: var(--faint); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; margin: 6px 0 12px; }
dl.kv dt, dl.kv dd { padding: 7px 0; border-bottom: 1px dashed var(--line); }
dl.kv dt { color: var(--muted); padding-right: 18px; }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
dl.kv dt:last-of-type, dl.kv dd:last-of-type { border-bottom: 0; }
@media (max-width: 520px) { dl.kv { grid-template-columns: 1fr; } dl.kv dt { border-bottom: 0; padding-bottom: 0; } }
ul.plain { list-style: none; padding: 0; margin: 6px 0; }
ul.plain li { padding: 5px 0; border-bottom: 1px dashed var(--line); }
ul.plain li:last-child { border-bottom: 0; }

.filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0 10px; padding: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.filters input:not([type]), .filters input[name] { min-width: 0; }
.pager { display: flex; gap: 6px; justify-content: center; align-items: center; margin: 18px 0; color: var(--muted); }
.pager a { padding: 6px 12px; border: 1px solid var(--line2); border-radius: var(--radius-sm); background: var(--panel); color: var(--text); }
.pager a:hover { border-color: var(--accent); }
.pager span { padding: 0 10px; }
img.chart { display: block; width: 100%; height: auto; border-radius: var(--radius-sm); background: var(--panel); min-height: 80px; border: 1px solid var(--line); }
details summary { cursor: pointer; color: var(--accent); margin: 10px 0; font-weight: 500; }
details summary:hover { color: #86b6ff; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 8px 0 14px; }
.metrics > div { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.metrics b { display: block; font-size: 22px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.metrics > div > span { color: var(--muted); font-size: 12px; }
#summary .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 72px; margin: 10px 0; padding: 6px; background: var(--input); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.bars span { flex: 1; background: linear-gradient(to top, var(--accent-2), var(--accent)); min-height: 1px; border-radius: 2px 2px 0 0; opacity: .85; }
.bars span:hover { opacity: 1; }

/* ------------------------------------------------------------------ login */
.login { max-width: 380px; margin: 12vh auto 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login .logo { display: block; width: 44px; height: 44px; margin: 0 auto 10px; }
.login h1 { text-align: center; margin-bottom: 4px; }
.login .sub { justify-content: center; margin-bottom: 18px; }
.login input { width: 100%; }
.login button.primary { width: 100%; padding: 9px; margin-top: 4px; }

/* ------------------------------------------------------------------ editor */
.tabs { display: inline-flex; gap: 2px; margin: 12px 0 0; padding: 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.tabs button { background: none; border-color: transparent; color: var(--muted); padding: 5px 14px; border-radius: 7px; }
.tabs button:hover { background: var(--panel2); color: var(--text); }
.tabs button.on { background: var(--raise); color: var(--text); box-shadow: inset 0 0 0 1px var(--line2); }
.sticky {
  position: sticky; bottom: 12px; z-index: 5; padding: 10px; margin: 16px 0;
  background: rgba(18, 22, 29, .9); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line2); border-radius: var(--radius); box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .7);
}
.sticky input { flex: 1; min-width: 160px; }
.results { display: flex; flex-wrap: wrap; gap: 6px; }
.results:empty { display: none; }
.results button { font-size: 12px; padding: 3px 9px; }
.formula.hl { white-space: pre-wrap; padding: 4px 2px; min-height: 1em; font-family: var(--mono); font-size: 12.5px; color: var(--text); font-weight: 400; }
code.formula { overflow-wrap: anywhere; }
textarea.code { background: var(--input); }
.hl .f { color: #ffb74d; } .hl .n { color: #4fc3f7; } .hl .k { color: #ba68c8; } .hl .u { color: var(--bad); text-decoration: underline wavy; } .hl .num { color: #aed581; }
.errors li { color: var(--bad); }
.help { max-width: 960px; }
.help h2 { margin-top: 26px; }
.help td:first-child { white-space: nowrap; }
.help table.grid { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); }
