:root {
  --bg: #0d0f17;
  --panel: #151925;
  --panel2: #1b2030;
  --line: #262c3f;
  --text: #e7e9f1;
  --muted: #8b91a7;
  --accent: #7c5cff;
  --accent2: #a48bff;
  --pos: #22c55e;
  --neg: #f05252;
  --warn: #f5a524;
  --radius: 12px;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }

.side { width: 210px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; font-size: 17px; padding: 0 8px 22px; letter-spacing: .2px; }
.logo b { color: var(--accent2); font-weight: 700; margin-left: 2px; }
nav { display: flex; flex-direction: column; gap: 4px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 500; }
nav a i { font-style: normal; width: 18px; text-align: center; }
nav a:hover { background: var(--panel2); color: var(--text); }
nav a.active { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); }
.mode { margin-top: auto; font-size: 12px; padding: 10px 12px; border-radius: 9px; background: var(--panel2); color: var(--muted); line-height: 1.4; }
.mode b { color: var(--warn); }
.mode.live b { color: var(--pos); }

main { flex: 1; min-width: 0; padding: 18px 22px 40px; }
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; }
.filters label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
select, input { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 180px; outline: none; }
select:focus, input:focus { border-color: var(--accent); }
.refresh { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }

.view { display: none; }
.view.active { display: block; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.card h3.mt { margin-top: 20px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .l { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi.pos .v { color: var(--pos); }
.kpi.neg .v { color: var(--neg); }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; margin-bottom: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 1100px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.funnel { display: flex; flex-direction: column; gap: 8px; }
.fstep { display: grid; grid-template-columns: 110px 1fr 90px; align-items: center; gap: 12px; }
.fstep .bar { height: 30px; border-radius: 6px; background: linear-gradient(90deg, var(--accent), #c04bd6); min-width: 4px; display: flex; align-items: center; padding-left: 10px; font-weight: 700; font-size: 12px; white-space: nowrap; }
.fstep .n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.fstep .name { color: var(--muted); }

.fsvg { width: 100%; height: auto; display: block; }
.fsvg .fl { stroke: var(--line); stroke-width: 1.5; }
.fsvg .fh { fill: var(--text); font-size: 17px; font-weight: 600; text-anchor: middle; }
.fsvg .fp { fill: #fff; font-size: 22px; font-weight: 800; text-anchor: middle; paint-order: stroke; stroke: #0006; stroke-width: 3px; }
.fsvg .fn { fill: var(--text); font-size: 17px; font-weight: 600; text-anchor: middle; }
.fsvg .fs { fill: var(--muted); font-size: 13px; text-anchor: middle; }
.insights { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 9px; font-size: 13px; line-height: 1.45; }
.ins-head { font-size: 13.5px; }
.ins { display: flex; gap: 9px; align-items: flex-start; }
.ins .dot { font-size: 12px; margin-top: 2px; }
.dot.warn, .warnc { color: var(--warn); }
.list { display: flex; flex-direction: column; gap: 9px; }
.li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; font-size: 13px; }
.li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .ct { font-variant-numeric: tabular-nums; font-weight: 600; }
.li .pc { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }
.li .track { grid-column: 1 / -1; height: 4px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-top: -4px; }
.li .track div { height: 100%; background: var(--accent); }
.empty { color: var(--muted); font-size: 13px; }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; }
.tabs button { background: var(--panel); border: 1px solid var(--line); border-radius: 10px 10px 0 0; padding: 12px 14px; text-align: left; font-weight: 600; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; display: flex; justify-content: space-between; align-items: center; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); background: var(--panel2); }
.chip { font-size: 11px; background: var(--accent); color: #fff; border-radius: 99px; padding: 2px 9px; cursor: pointer; }
.chip:empty { display: none; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar input { min-width: 240px; }
.bulk { position: relative; display: flex; align-items: center; gap: 10px; }
.selinfo { color: var(--muted); font-size: 12px; }
.menu { position: absolute; top: 40px; left: 0; z-index: 20; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: none; min-width: 210px; box-shadow: 0 12px 30px #0008; }
.menu.open { display: block; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.menu button:hover { background: var(--panel); }
.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border-radius: 99px; padding: 4px 11px; font-size: 12px; font-weight: 600; }

.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); max-height: calc(100vh - 230px); }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: right; }
th { position: sticky; top: 0; background: var(--panel2); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); cursor: pointer; user-select: none; z-index: 2; }
th.sorted { color: var(--text); }
td { background: var(--panel); }
tr:hover td { background: #1a1f2d; }
th.l, td.l { text-align: left; }
td.name { max-width: 280px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
td.name small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
td.c, th.c { text-align: center; }
tfoot td { position: sticky; bottom: 0; background: var(--panel2); font-weight: 700; z-index: 1; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.mut { color: var(--muted); }
input[type=checkbox] { min-width: 0; width: 16px; height: 16px; accent-color: var(--accent); }

.tg { width: 38px; height: 21px; border-radius: 99px; background: #3a4055; border: 0; position: relative; cursor: pointer; padding: 0; transition: background .15s; }
.tg::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; background: #fff; border-radius: 50%; transition: left .15s; }
.tg.on { background: var(--accent); }
.tg.on::after { left: 20px; }
.tg.busy { opacity: .5; pointer-events: none; }
.subst { display: block; font-size: 10px; color: var(--warn); margin-top: 3px; }

.budget { cursor: pointer; border-bottom: 1px dashed var(--muted); }
.budget:hover { color: var(--accent2); border-color: var(--accent2); }
.budget small { display: block; font-size: 10px; color: var(--muted); border: 0; }

.pop { position: fixed; z-index: 50; width: 290px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: 0 16px 40px #000a; }
.pop-title { font-weight: 600; margin-bottom: 10px; font-size: 13px; }
.pop-row { display: flex; align-items: center; gap: 8px; }
.pop-row input { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; }
.quick { display: flex; gap: 5px; margin: 10px 0 6px; }
.quick button { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 6px 0; font-size: 12px; cursor: pointer; }
.quick button:hover { border-color: var(--accent); }
.pop-hint { font-size: 12px; color: var(--muted); min-height: 18px; }
.pop-hint.w { color: var(--warn); }
.pop-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--pos); padding: 10px 14px; border-radius: 9px; max-width: 380px; box-shadow: 0 8px 24px #0008; }
.toast.err { border-left-color: var(--neg); }

.prose { line-height: 1.6; max-width: 900px; }
.prose h2 { font-size: 17px; margin: 22px 0 8px; }
.prose h2:first-child { margin-top: 0; }
.prose code, .prose pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font-family: Consolas, monospace; font-size: 12.5px; }
.prose pre { padding: 10px 12px; white-space: pre-wrap; word-break: break-all; position: relative; }
.prose li { margin: 4px 0; }
.copybtn { float: right; font-size: 11px; padding: 3px 8px; }
.setrow { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.setrow label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.setrow input { min-width: 160px; }
