:root {
  --bg: #F3F5F8; --surface: #FFFFFF; --sunk: #EBEFF4; --ink: #121826; --ink2: #2B3444; --muted: #5A6475;
  --line: #DCE2EA; --accent: #2255D4; --accent-ink: #1A43A8; --accent-soft: #E6EDFC;
  --good: #12805C; --good-soft: #E2F3EB; --warn: #9A6208; --warn-soft: #FBF0DA; --bad: #BF3A2D; --bad-soft: #FBE6E2;
  --radius: 14px; --font: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px;
  line-height: 1.45; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-ink); }
.num, td.n, .kpi b { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* header */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent; }
.top.scrolled { border-bottom-color: var(--line); }
.top-title { flex: 1; min-width: 0; display: grid; }
.top-title b { font-size: 18px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.top-title span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; font-size: 17px; cursor: pointer; flex: none; }
.icon-btn:active { transform: scale(.96); }
.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding: 4px 12px calc(84px + var(--safe-bottom)); display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
main > *, .card > *, .list > * { min-width: 0; max-width: 100%; }
main:focus { outline: none; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(8px + var(--safe-bottom)); }
.tabs a { display: grid; justify-items: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11px;
  font-weight: 500; position: relative; padding: 2px 0; }
.tabs a svg { width: 22px; height: 22px; }
.tabs a.on { color: var(--accent-ink); font-weight: 600; }
.tabs em { position: absolute; top: -2px; left: calc(50% + 6px); min-width: 16px; height: 16px; border-radius: 8px;
  background: var(--bad); color: #fff; font-style: normal; font-size: 10px; font-weight: 700; display: grid;
  place-items: center; padding: 0 4px; }

/* building blocks */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  display: grid; gap: 8px; min-width: 0; }
.card.flat { border: 0; background: transparent; padding: 0; }
.card.click { cursor: pointer; }
.card.click:active { background: #FAFBFD; }
.sev-bad { box-shadow: inset 3px 0 0 var(--bad); }
.sev-warn { box-shadow: inset 3px 0 0 var(--warn); }
.sev-good { box-shadow: inset 3px 0 0 var(--good); }
.sev-info { box-shadow: inset 3px 0 0 var(--accent); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.row > * { min-width: 0; }
.row > .pill, .row > .btn, .row > .switch, .row > .chip, .row > .btns { flex: none; }
.row > b.ellipsis, .row > .ellipsis { flex: 1 1 auto; }
.card, .bubble { overflow-wrap: anywhere; }
.stack { display: grid; gap: 6px; }
.lbl { font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.h2 { font-size: 16px; font-weight: 700; margin: 6px 2px -2px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.h2 a, .h2 button { font-size: 13px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title { font-weight: 600; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .9em; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 1px; }
.chips::-webkit-scrollbar { display: none; }
.chips.more, .tbl-wrap.more { -webkit-mask-image: linear-gradient(to right, #000 85%, transparent);
  mask-image: linear-gradient(to right, #000 85%, transparent); }
.chip { flex: none; font-size: 13px; min-height: 36px; padding: 0 13px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--line); color: var(--ink2); cursor: pointer; white-space: nowrap; display: inline-flex;
  align-items: center; gap: 6px; transition: background-color .15s ease, color .15s ease, border-color .15s ease; }
.chip .cnt { font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
  display: inline-grid; place-items: center; background: var(--sunk); color: var(--ink2); }
.chip.on .cnt { background: rgba(255,255,255,.25); color: #fff; }
.chip .cnt.bad { background: var(--bad-soft); color: var(--bad); }
button:focus-visible, a:focus-visible, .chip:focus-visible, .card.click:focus-visible, input:focus-visible,
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.soft { background: var(--sunk); border-color: transparent; }
.chip:active { transform: scale(.97); }

.pill { display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 600; border-radius: 999px;
  padding: 2px 8px; white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.acc { background: var(--accent-soft); color: var(--accent-ink); }
.pill.gray { background: var(--sunk); color: var(--muted); }
.up { color: var(--good); } .down { color: var(--bad); }

.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kpis.kpis4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px; min-width: 0; }
.kpi small { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi b { display: block; font-size: 18px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.kpi i { font-style: normal; font-size: 12px; font-weight: 600; }
.kpi .sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn { border: 0; border-radius: 12px; padding: 11px 14px; font-weight: 600; font-size: 14px; cursor: pointer;
  background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.ghost { background: var(--accent-soft); color: var(--accent-ink); }
.btn.line { background: var(--surface); color: var(--ink2); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.good { background: var(--good); }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns .btn { flex: 1 1 auto; }

input.inp, select.inp, textarea.inp { width: 100%; border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 10px 12px; outline: none; }
input.inp:focus, select.inp:focus, textarea.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* table */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
table.t { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.t th, .t td { padding: 8px 9px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.t th { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  background: #F8FAFC; position: sticky; top: 0; cursor: pointer; user-select: none; }
.t th.on { color: var(--accent-ink); }
.t th:first-child, .t td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface);
  max-width: 44vw; overflow: hidden; text-overflow: ellipsis; z-index: 1; }
.t th:first-child { background: #F8FAFC; z-index: 2; }
.t tr:last-child td { border-bottom: 0; }
.t tr.total td { font-weight: 700; background: #FAFBFD; }
.t td .raw { display: block; font-size: 11px; color: var(--muted); }
.t tr.click { cursor: pointer; }

/* bars and charts */
.bar { height: 6px; border-radius: 3px; background: var(--sunk); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.bad > i { background: var(--bad); } .bar.good > i { background: var(--good); } .bar.dim > i { background: #AFC2EE; }
svg.spark { width: 100%; height: 64px; display: block; }
.chart-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

/* hero and metric grids */
.hero { gap: 6px; }
.hero .big { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.hero .main { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.hero .sub { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--ink2); }
.hero .sub b { font-weight: 600; font-variant-numeric: tabular-nums; }
.mgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px 8px; }
.bundle, .offer { container-type: inline-size; }
@container (max-width: 300px) { .mgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.mgrid .m { display: grid; gap: 1px; min-width: 0; }
.mgrid .m small { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mgrid .m b { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mgrid .m i { font-style: normal; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mgrid .m b { overflow: hidden; text-overflow: ellipsis; }
.offer.hl { background: var(--accent-soft); border-radius: 12px; padding: 10px; margin: 0 -4px; }
.sec-title { font-size: 12px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600;
  margin: 4px 2px -4px; }
.onboard { background: var(--accent-soft); border-color: transparent; }
.onboard ol { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13.5px; color: var(--ink2); }
.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar .inp { flex: 1; min-width: 0; }
.select-chip { flex: none; }
/* people */
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ava { width: 36px; height: 36px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700;
  font-size: 14px; color: var(--accent-ink); background: var(--accent-soft); }
.ava.warn { background: var(--warn-soft); color: var(--warn); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.link-box { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; background: var(--sunk);
  border-radius: 10px; padding: 10px 12px; overflow-wrap: anywhere; user-select: all; }
.me-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--accent-soft);
  color: var(--accent-ink); font-weight: 700; font-size: 14px; cursor: pointer; flex: none; }

/* lists */
.list { display: grid; gap: 8px; }
.bundle .metrics { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--ink2); }
.bundle .metrics b { font-weight: 600; }

/* offers editor */
.offer { display: grid; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.offer:first-of-type { border-top: 0; }
.verdicts { display: flex; flex-wrap: wrap; gap: 4px; }
.share-ed { display: grid; grid-template-columns: 1fr 64px 44px; gap: 8px; align-items: center; }
.share-ed input[type=range] { width: 100%; accent-color: var(--accent); }
.share-ed input.pct { text-align: right; padding: 7px 8px; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 13px; background: var(--line); transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%;
  background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.sum { font-weight: 700; } .sum.bad { color: var(--bad); } .sum.good { color: var(--good); }

/* chat */
.chat { display: grid; gap: 10px; }
.bubble { border-radius: 14px; padding: 9px 12px; max-width: 92%; font-size: 14.5px; line-height: 1.45;
  overflow-wrap: anywhere; }
.bubble.me { background: var(--accent); color: #fff; justify-self: end; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.bubble.ai { background: var(--surface); border: 1px solid var(--line); justify-self: start; border-bottom-left-radius: 4px;
  white-space: pre-wrap; }
.bubble.ai code { background: var(--sunk); padding: 1px 4px; border-radius: 4px; font-size: .92em; }
.bubble.ai .attach { margin-top: 8px; display: grid; gap: 6px; white-space: normal; }
.thinking { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13px; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { position: fixed; left: 0; right: 0; bottom: calc(62px + var(--safe-bottom)); z-index: 25; padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(8px); display: flex; gap: 8px;
  align-items: flex-end; border-top: 1px solid var(--line); }
.composer textarea.inp { flex: 1; resize: none; height: 44px; min-height: 44px; max-height: 112px; padding: 11px 16px;
  line-height: 20px; border-radius: 22px; overflow-y: auto; }
.composer .btn { flex: none; width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 17px; }
.chat-end { height: var(--composer-h, 76px); }
.attach .reps { display: flex; flex-wrap: wrap; gap: 6px; }
.attach .reps .btn { flex: 0 1 auto; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: inline-block; }
.suggest { display: grid; gap: 8px; }
.suggest button { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; cursor: pointer; }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(18, 24, 38, .35); }
.sheet-body { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 14px 14px calc(18px + var(--safe-bottom)); display: grid; gap: 12px;
  animation: up .18s ease-out; }
.sheet-body::before { content: ""; width: 40px; height: 4px; border-radius: 2px; background: var(--line); justify-self: center; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(76px + var(--safe-bottom)); z-index: 60;
  background: var(--ink); color: #fff; border-radius: 12px; padding: 11px 14px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(18,24,38,.25); }
.toast.bad { background: var(--bad); } .toast.good { background: var(--good); }
.toast.act { cursor: pointer; font-weight: 600; }
body.with-composer .toast { bottom: calc(70px + var(--composer-h, 76px) + var(--safe-bottom)); }
.tabs em.dot { min-width: 9px; width: 9px; height: 9px; padding: 0; left: calc(50% + 8px); top: 0; background: var(--accent); animation: blink 1.4s infinite; }

.empty { text-align: center; color: var(--muted); padding: 28px 12px; display: grid; gap: 8px; justify-items: center; }
.skel { background: linear-gradient(90deg, var(--sunk), #F6F8FB, var(--sunk)); background-size: 200% 100%;
  animation: sk 1.2s infinite; border-radius: 12px; min-height: 64px; }
@keyframes sk { to { background-position: -200% 0; } }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; }
.banner.info { background: var(--accent-soft); color: var(--accent-ink); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.preset { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; cursor: pointer;
  display: grid; gap: 2px; text-align: left; }
.preset b { font-size: 14px; } .preset span { font-size: 12px; color: var(--muted); }
.diff-line { font-size: 13px; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 14px; align-items: center; }
details summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--accent-ink); }
@media (min-width: 720px) {
  main { padding-left: 20px; padding-right: 20px; }
  .kpis, .kpis.kpis4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .list.cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
