:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #17202e;
  --ink-2: #4a5568;
  --muted: #7a8699;
  --line: #e3e8ef;
  --line-2: #cfd7e2;
  --accent: #1f5eff;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --top: #0f1b2d;
  --ok: #157f3b;
  --ok-soft: #e3f5e9;
  --warn: #9a5b00;
  --warn-soft: #fff3dd;
  --err: #b42318;
  --err-soft: #fde8e7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  font-size: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0 0 .5rem; }
h3 { font-size: .95rem; margin: 0 0 .75rem; color: var(--ink-2); font-weight: 600; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: var(--bg); padding: .1rem .3rem; border-radius: 4px; }
.muted { color: var(--muted); }
.sm { font-size: .85em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.error { color: var(--err); }
.hint { color: var(--muted); font-size: .85em; margin: .4rem 0 0; }
.notice { background: var(--accent-soft); border: 1px solid #c9d8ff; padding: .6rem .8rem; border-radius: var(--radius); }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.row.gap { gap: .5rem; flex-wrap: wrap; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .6rem 1.25rem; background: var(--top); color: #fff;
}
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a { color: #c8d3e6; padding: .4rem .7rem; border-radius: 8px; }
.topbar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
.topbar nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 600; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark { background: var(--accent); color: #fff; font-weight: 800; font-size: .75rem; padding: .2rem .45rem; border-radius: 6px; letter-spacing: .04em; }
.dot-live { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; background: #3ddc84; margin-left: .2rem; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

main.page { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; min-width: 0; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.split > .card { margin-bottom: 0; }
.split { margin-bottom: 1rem; }
.split3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.split3 > .card { margin-bottom: 0; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink); padding: .5rem .85rem; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
}
.btn:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.sm { padding: .3rem .55rem; font-size: .85rem; }
.btn.danger { color: var(--err); }
input, select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 7px;
  padding: .42rem .55rem; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label.lbl, p.lbl { display: block; font-size: .82rem; color: var(--ink-2); margin: .5rem 0 0; }
label.lbl > input, label.lbl > select { margin-top: .2rem; }
label.check { display: flex; align-items: center; gap: .45rem; margin: .4rem 0; cursor: pointer; }
label.check.sm { font-size: .85rem; margin: .2rem 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .5rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.chip { border: 1px dashed var(--line-2); background: transparent; border-radius: 999px; padding: .15rem .55rem; font: inherit; font-size: .8rem; color: var(--ink-2); cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.inline-form input { width: auto; flex: 1 1 10rem; }

/* explorer layout */
main.explore { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 1rem; padding: 1rem 1.25rem; align-items: start; }
.filters {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem;
  position: sticky; top: 4.2rem; max-height: calc(100vh - 5.2rem); overflow: auto; box-shadow: var(--shadow);
}
.filters details { border-top: 1px solid var(--line); padding: .5rem 0 .6rem; }
.filters summary { cursor: pointer; font-weight: 600; color: var(--ink); padding: .25rem 0; list-style: none; display: flex; justify-content: space-between; }
.filters summary::after { content: "+"; color: var(--muted); }
.filters details[open] summary::after { content: "–"; }
.filters summary::-webkit-details-marker { display: none; }
.preset-bar { padding-bottom: .75rem; }
.preset-desc { font-size: .82rem; margin: .4rem 0; min-height: 1em; }
.results { min-width: 0; }
.summary { display: grid; grid-template-columns: auto 1fr auto; gap: 1.25rem; align-items: center; transition: opacity .2s; }
.summary.loading { opacity: .55; }
.big { display: flex; flex-direction: column; }
.big span { font-size: 2.2rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.big small { color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .5rem; }
.kpis div { background: var(--bg); border-radius: 8px; padding: .5rem .6rem; display: flex; flex-direction: column; }
.kpis b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.kpis span { font-size: .75rem; color: var(--muted); }
.exports { display: flex; flex-direction: column; align-items: flex-end; gap: .4rem; }
.exports form { display: flex; gap: .5rem; }
.bars { display: grid; gap: .3rem; }
.bar { display: grid; grid-template-columns: 3rem 1fr 4.5rem; align-items: center; gap: .5rem; font-size: .85rem; }
.bk { color: var(--ink-2); }
.bt { background: var(--bg); border-radius: 4px; height: .7rem; overflow: hidden; }
.bt i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bv { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.table-card { padding-bottom: .5rem; }
.table-wrap { overflow: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { text-align: left; padding: .42rem .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; position: sticky; top: 0; background: var(--surface); }
#rows tbody tr { cursor: pointer; }
#rows tbody tr:hover { background: var(--accent-soft); }
.empty { border-style: dashed; }
.pill { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 999px; background: var(--bg); color: var(--ink-2); border: 1px solid var(--line); }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: #b9e3c7; }
.pill.warn, .pill.partial, .pill.due_soon, .pill.interrupted { background: var(--warn-soft); color: var(--warn); border-color: #f2d49b; }
.pill.error, .pill.overdue { background: var(--err-soft); color: var(--err); border-color: #f5c2bf; }
.pill.running { background: var(--accent-soft); color: var(--accent); border-color: #c9d8ff; }
dl.kv { display: grid; grid-template-columns: 9.5rem 1fr; gap: .35rem .75rem; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .85rem; }
dl.kv dd { margin: 0; }
pre.log { background: #0f1b2d; color: #cfe1ff; padding: .75rem; border-radius: 8px; max-height: 320px; overflow: auto; font-size: .78rem; white-space: pre-wrap; margin: 0 0 1rem; }
pre.log:empty { display: none; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; background: var(--top); padding: 16px; }
.login-card { background: var(--surface); border-radius: 14px; padding: 1.75rem; width: min(380px, 100%); display: grid; gap: .8rem; }
.login-card .brand { color: var(--ink); font-size: 1.1rem; }

@media (max-width: 1100px) {
  main.explore { grid-template-columns: 1fr; }
  .filters { position: static; max-height: none; }
  .summary { grid-template-columns: 1fr; }
  .exports { align-items: flex-start; }
  .split, .split3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  main.page, main.explore { padding: 1rem 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-wrap: wrap; padding: .6rem 16px; }
  dl.kv { grid-template-columns: 1fr; }
}

/* qualified-lead box on the search page */
.qual-box { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; background: var(--accent-soft);
  border: 1px solid #c9d8ff; border-radius: var(--radius); padding: .55rem .7rem; margin: .25rem 0 .75rem; }
.qual-box .check { margin: 0; }
.qual-box select { width: auto; max-width: 12rem; padding: .25rem .4rem; }
.check.strong { font-weight: 600; }

/* qualified-lead settings */
.qual-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.qual-layout .sticky { position: sticky; top: 4rem; }
.rules { width: 100%; border-collapse: collapse; }
.rules td { padding: .45rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.rules tr.off td:not(:first-child) { opacity: .45; }
.rules .grp td { background: var(--bg); font-weight: 600; color: var(--ink-2); font-size: .85rem; }
.rules input[type=number] { width: 5.2rem; }
.rules select { width: auto; }
.rules .params { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.statbig { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }
.lift-up { color: var(--ok); font-weight: 600; }
.lift-down { color: var(--err); font-weight: 600; }
.cmp td, .cmp th { text-align: right; }
.cmp td:first-child, .cmp th:first-child { text-align: left; }
@media (max-width: 900px) { .qual-layout { grid-template-columns: 1fr; } .qual-layout .sticky { position: static; } }
.bins .bin-row { display: flex; gap: .3rem; align-items: center; margin: .2rem 0; flex-wrap: wrap; }
.bins .bin-row input { width: 4.6rem; }
.vp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr)); gap: .2rem .8rem; margin-top: .3rem; }
.vp { display: flex; justify-content: space-between; align-items: center; gap: .4rem; font-size: .85rem; }
.vp input { width: 4.2rem; padding: .15rem .3rem; }
#cuts a { white-space: nowrap; }

/* ---------------------------------------------------------------- CRM mirror */
.pipe-box { background: var(--accent-soft); border: 1px solid #c9d8ff; border-radius: var(--radius); padding: .55rem .7rem; margin: .25rem 0 .75rem; }
.badge { display: inline-block; min-width: 1.3rem; padding: 0 .35rem; border-radius: 999px; background: #ff5a4f; color: #fff; font-size: .72rem; font-weight: 700; text-align: center; line-height: 1.25rem; }
.nav-sep { width: 1px; background: rgba(255,255,255,.18); margin: .25rem .35rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .8rem; }
.stat.accent { border-color: #c9d8ff; background: var(--accent-soft); }
.tier { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 6px; white-space: nowrap; }
.tier.A { background: var(--ok-soft); color: var(--ok); }
.tier.B { background: var(--accent-soft); color: var(--accent); }
.tier.C { background: var(--warn-soft); color: var(--warn); }
.tier.LTV { background: #f1e8ff; color: #6b2fb3; }
.tier.manual, .tier.рачно { background: var(--bg); color: var(--ink-2); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .8rem; border-radius: 8px 8px 0 0; color: var(--ink-2); border: 1px solid transparent; border-bottom: none; margin-bottom: -1px; }
.tabs a.active { background: var(--surface); border-color: var(--line); color: var(--ink); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs .count { color: var(--muted); font-weight: 400; margin-left: .2rem; }
.qtable td { white-space: normal; }
.qtable td.nw { white-space: nowrap; }
.touches { margin: 0; padding: 0; list-style: none; font-size: .82rem; }
.touches li { margin: .1rem 0; }
.touches .why { color: var(--muted); }
.decide { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }
.decide select { width: 11rem; padding: .25rem .35rem; font-size: .82rem; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.mbars { display: grid; gap: .35rem; }
.mbar { display: grid; grid-template-columns: 4.5rem 1fr 6.5rem; gap: .6rem; align-items: center; font-size: .85rem; }
.mbar .track { display: flex; height: .9rem; background: var(--bg); border-radius: 4px; overflow: hidden; }
.mbar .new { background: var(--accent); }
.mbar .ltv { background: #9b6bdc; }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--ink-2); margin: .2rem 0 .6rem; }
.legend i { display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg a { padding: .3rem .7rem; color: var(--ink-2); font-size: .85rem; }
.seg a.active { background: var(--accent); color: #fff; }
.seg a:hover { text-decoration: none; }
.filters-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters-row label { font-size: .78rem; color: var(--ink-2); display: flex; flex-direction: column; gap: .2rem; }
.filters-row select, .filters-row input { width: auto; min-width: 9rem; }
.news li { margin: .2rem 0; }
.ok-dot, .no-dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; margin-right: .3rem; }
.ok-dot { background: var(--ok); } .no-dot { background: var(--line-2); }
.wrap { white-space: normal !important; }
.clip { max-width: 22rem; overflow: hidden; text-overflow: ellipsis; }
.tier.New { background: var(--accent-soft); color: var(--accent); }

/* ---------------------------------------------------------------- v2: period filter, compact cards, pipeline board */
.page-head { align-items: center; margin-bottom: .25rem; }
.page-head h1 { margin: .2rem 0; }
.explain { margin: .2rem 0 1rem; max-width: 70rem; }
.period { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.period select { width: auto; min-width: 10rem; }
.period input[type=month] { width: auto; }
.period-lbl { font-size: .8rem; color: var(--ink-2); }
.split3.compact .card, .split.compact .card { padding: .8rem .9rem; }
.mbars.sm { gap: .25rem; }
.mbars.sm .mbar { grid-template-columns: 4.5rem 1fr 2.5rem; font-size: .8rem; }
.mbars.sm .mbar.wide { grid-template-columns: 8.5rem 1fr 2.5rem; }
.mbars.sm .track { height: .6rem; }
.funnel td { vertical-align: middle; }
.fbar { position: relative; height: 1.25rem; background: var(--bg); border-radius: 5px; overflow: hidden; }
.fbar i { display: block; height: 100%; opacity: .85; border-radius: 5px; }
.fbar span { position: absolute; left: .5rem; top: 0; line-height: 1.25rem; font-size: .8rem; font-weight: 600; color: var(--ink); }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .4rem; vertical-align: 0; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: .75rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: 1rem; }
.col { background: #eef1f6; border-radius: var(--radius); padding: .6rem; display: flex; flex-direction: column; gap: .5rem; min-height: 8rem; }
.col-head { display: flex; flex-direction: column; padding: 0 .1rem .2rem; }
.col-head span { color: var(--muted); font-size: .78rem; }
.kcard { display: block; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line-2); border-radius: 8px; padding: .5rem .6rem; color: var(--ink); box-shadow: var(--shadow); }
.kcard:hover { text-decoration: none; border-color: var(--accent); }
.kcard b.clip { max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
.late { color: var(--err); font-weight: 600; }
.okt { color: var(--ok); font-weight: 600; }
.scroll-y { max-height: 70vh; overflow: auto; }
.scroll-y th { z-index: 1; }
table.leads td { white-space: normal; max-width: 18rem; }
.pager { display: inline-flex; gap: .5rem; align-items: center; }
.brand { font-weight: 700; letter-spacing: .01em; }
.col-body { display: flex; flex-direction: column; gap: .5rem; max-height: 72vh; overflow-y: auto; padding-right: .15rem; }
details.stale summary { cursor: pointer; font-size: .8rem; color: var(--ink-2); padding: .3rem .2rem; }
details.stale[open] { display: flex; flex-direction: column; gap: .5rem; }
