:root {
  color-scheme: light;
  --page: #f6f6f3; --surface: #fcfcfb; --surface-2: #f0efec; --hover: rgba(11,11,11,.04);
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781; --grid: #e1e0d9; --axis: #c3c2b7;
  --border: rgba(11,11,11,.10); --accent: #2a78d6; --accent-ink: #fff; --accent-soft: #e6f0fc;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --good: #0ca30c; --good-ink: #006300; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b; --crit-ink: #b42323;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --r: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --hover: rgba(255,255,255,.05);
    --ink: #fff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255,255,255,.10); --accent: #3987e5; --accent-soft: #15273d;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-ink: #0ca30c; --crit-ink: #e66767;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --hover: rgba(255,255,255,.05);
  --ink: #fff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255,255,255,.10); --accent: #3987e5; --accent-soft: #15273d;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-ink: #0ca30c; --crit-ink: #e66767;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font-size: 14px; line-height: 1.45; }
body { -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40px; color: var(--muted); }
.num, td.r, .tab-n { font-variant-numeric: tabular-nums; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 24px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login p { margin: 0 0 8px; color: var(--ink-2); }

/* ---------- каркас ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.top-in { max-width: 1320px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; height: 52px; }
.brand { font-weight: 700; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand img { width: 22px; height: 22px; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a { text-decoration: none; color: var(--ink-2); padding: 7px 12px; border-radius: 8px; white-space: nowrap; font-weight: 500; }
nav.tabs a:hover { background: var(--hover); color: var(--ink); }
nav.tabs a.on { background: var(--accent-soft); color: var(--accent); }
.me { display: flex; align-items: center; gap: 8px; color: var(--ink-2); white-space: nowrap; }
main { max-width: 1320px; margin: 0 auto; padding: 16px 16px 80px; }

/* фильтр-полоса */
.scope { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 16px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; cursor: pointer; color: var(--ink-2); font-weight: 500; white-space: nowrap; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 4px 11px; cursor: pointer; color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.chip:hover { border-color: var(--axis); color: var(--ink); }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip .n { opacity: .65; margin-left: 4px; }
.lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.spacer { flex: 1; }

/* ---------- карточки и сетка ---------- */
.grid { display: grid; gap: 12px; }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 12px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .g-2, .g-3 { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; min-width: 0; }
.card h2 { font-size: 15px; margin: 0 0 2px; font-weight: 600; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.card-h { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card-h .spacer + * { font-size: 12.5px; }
.kpi { padding: 14px 16px; }
.kpi .k { color: var(--ink-2); font-size: 12.5px; }
.kpi .v { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -.01em; white-space: nowrap; }
.kpi .d { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.alert .v { color: var(--crit-ink); }
.kpi.click { cursor: pointer; }
.kpi.click:hover { border-color: var(--axis); }
.good { color: var(--good-ink); }
.bad { color: var(--crit-ink); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- таблицы ---------- */
.tbl-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th.r, td.r { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--hover); }
tfoot td { font-weight: 600; border-bottom: 0; }
th.sort { cursor: pointer; user-select: none; }
th.sort:hover { color: var(--ink); }
.person { font-weight: 500; }
.person small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.bar-cell { position: relative; min-width: 90px; }
.bar-cell i { position: absolute; left: 8px; bottom: 4px; height: 3px; border-radius: 2px; background: var(--good); }

/* статусы: всегда точка + подпись */
.st { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 13px; }
.st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.st.new::before { background: var(--axis); }
.st.contacted::before { background: var(--s1); }
.st.promised::before { background: var(--s7); }
.st.schedule::before { background: var(--s3); }
.st.no_answer::before { background: var(--serious); }
.st.problem::before { background: var(--warn); }
.st.escalated::before { background: var(--crit); }
.st.paused::before { background: var(--muted); }
.st.paid::before { background: var(--good); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.tag.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--ink); }
.due-late { color: var(--crit-ink); font-weight: 500; }
.due-today { color: var(--ink); font-weight: 600; }
.mgr { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.mgr i { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* ---------- формы ---------- */
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; }
select.inline { width: auto; padding: 5px 8px; }
.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--axis); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--hover); color: var(--ink); }
.btn.danger { color: var(--crit-ink); }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.err { color: var(--crit-ink); min-height: 1em; }

/* ---------- шторка с карточкой ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; background: rgba(0,0,0,.28); }
.drawer[hidden] { display: none; }
.drawer .panel { width: min(720px, 100%); height: 100%; background: var(--page); overflow-y: auto; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.panel-h { position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; }
.panel-h h2 { margin: 0; font-size: 18px; }
.panel-h .sub { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.panel-b { padding: 16px; display: grid; gap: 12px; }
.money3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.money3 div { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 10px 12px; }
.money3 b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.money3 span { font-size: 12px; color: var(--muted); }
.timeline { display: grid; gap: 0; }
.tl { display: grid; grid-template-columns: 78px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--grid); }
.tl:last-child { border-bottom: 0; }
.tl .when { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tl .what { white-space: pre-wrap; word-break: break-word; }
.tl .meta { font-size: 12px; color: var(--muted); }
.tl.pay .what b { color: var(--good-ink); }
.tl .x { float: right; }
details.fold > summary { cursor: pointer; color: var(--ink-2); font-weight: 500; list-style: none; }
details.fold > summary::before { content: "▸ "; }
details.fold[open] > summary::before { content: "▾ "; }

/* ---------- графики ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridl { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .xh { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
.tip { position: absolute; pointer-events: none; z-index: 5; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 12.5px; min-width: 150px; white-space: nowrap; }
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .l { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip .l span { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tip .l i { width: 8px; height: 8px; border-radius: 2px; }
.tip .l b { font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.legend i.line { height: 2px; border-radius: 1px; width: 14px; }
.hbars { display: grid; gap: 7px; }
.hb { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; gap: 10px; align-items: center; cursor: default; }
.hb.click { cursor: pointer; border-radius: 6px; }
.hb.click:hover { background: var(--hover); }
.hb .name { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb .track { height: 14px; position: relative; }
.hb .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--s1); min-width: 2px; }
.hb .val { font-size: 12.5px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hb .val small { color: var(--muted); margin-left: 6px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* ---------- прочее ---------- */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 80; background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.err { background: var(--crit); color: #fff; }
.note { background: var(--surface-2); border-radius: 9px; padding: 10px 12px; color: var(--ink-2); font-size: 13px; }
.bulk { position: sticky; bottom: 12px; z-index: 10; background: var(--ink); color: var(--surface); border-radius: 12px; padding: 10px 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; box-shadow: var(--shadow); margin-top: 12px; }
.bulk select { width: auto; background: var(--surface); color: var(--ink); }
.more { display: flex; justify-content: center; padding: 14px; }
pre.paste { white-space: pre-wrap; }
@media (max-width: 700px) {
  .top-in { gap: 8px; }
  .brand span { display: none; }
  .me .who { display: none; }
  .kpi .v { font-size: 20px; }
  .money3 b { font-size: 15px; }
  .hide-m { display: none; }
  .hb { grid-template-columns: minmax(90px, 40%) 1fr auto; }
}
@media (forced-colors: active) { .st::before, .mgr i, .legend i { forced-color-adjust: none; } }
