:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --ink: #191a1c;
  --muted: #6c6f74;
  --line: #e1e1dc;
  --accent: #e8b800;        /* фирменный жёлтый — акцент, кнопки */
  --accent-ink: #191a1c;
  --ok: #157f3d;  --ok-bg: #e7f4ec;
  --warn: #c2410c; --warn-bg: #fcebdd; /* оранжевый: не сливается с брендовым жёлтым */
  --bad: #b42323; --bad-bg: #fbe9e9;
  --row-total: #f1f1ea;
  --box-sh: 0 1px 2px rgba(25,26,28,.07);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131312; --surface: #1c1c1b; --ink: #ededea; --muted: #9c9c94;
    --line: #34342f; --accent: #ffd21e; --accent-ink: #131312;
    --ok: #4cc272; --ok-bg: #16311f;
    --warn: #ffa043; --warn-bg: #35270f;
    --bad: #ff6b6b; --bad-bg: #3a1a1a;
    --row-total: #232322; --box-sh: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Шапка ---------- */
header {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
}
.hrow { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.brand { font-weight: 700; letter-spacing: .01em; margin-right: 4px; }
.brand small { color: var(--muted); font-weight: 400; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; padding: 7px 13px; cursor: pointer; color: var(--muted);
  border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.ctl { display: inline-flex; align-items: center; gap: 6px; }
.ctl label { color: var(--muted); font-size: 13px; }
input[type=date], select, input[type=text], input[type=number] {
  background: var(--surface); border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 8px; min-height: 34px;
}
select:disabled, input:disabled { opacity: .45; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }
.btn {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600;
}
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.pill { font-size: 12px; border-radius: 99px; padding: 2px 9px; }
.net-on  { color: var(--ok); }
.net-off { color: var(--bad); font-weight: 600; }

/* ---------- Фирменная чёрная шапка (ЦА: чёрный + жёлтый) ---------- */
header { background: #17181a; border-bottom: 2px solid #f2c200; }
header .brand { color: #ffffff; }
header .brand small { color: #8e8f89; }
header .ctl label { color: #b9bab2; }
header .hint, header #queue { color: #8e8f89; }
header .seg { border-color: #3a3b36; }
header .seg button { color: #b9bab2; border-right-color: #3a3b36; }
header .seg button.on { background: #f2c200; color: #17181a; }
header input[type=date], header input[type=text], header input[type=number], header select {
  background: #242527; border-color: #3a3b36; color: #ededea; color-scheme: dark;
}
header input[type=date] { min-width: 128px; cursor: pointer; }
header input[type=date]::-webkit-calendar-picker-indicator { filter: invert(.85); cursor: pointer; opacity: .9; }
header .btn { background: #f2c200; color: #17181a; }
header .btn.secondary { background: transparent; color: #f2c200; border-color: #caa400; }
header .net-on { color: #4cc272; }
header .net-off { color: #ff6b6b; }

/* ---------- Контент ---------- */
main { padding: 14px; max-width: 1280px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--box-sh); }
.card + .card { margin-top: 14px; }
.card h2 { font-size: 16px; margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card h2 .sp { flex: 1; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- Таблица ---------- */
.twrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 14px; text-align: right; white-space: nowrap; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
td:first-child, th:first-child {
  text-align: left; position: sticky; left: 0; background: var(--surface);
  max-width: 190px; overflow: hidden; text-overflow: ellipsis; padding-left: 16px;
}
th:last-child, td:last-child { padding-right: 16px; }
table.wk th.day, table.wk td.day { min-width: 122px; }
table.wk th.wknd, table.wk td.wknd { min-width: 92px; background: var(--row-total); }
/* Группы KPI внедрения */
th.grp-head { text-align: center; font-size: 12px; letter-spacing: .02em; border-bottom: 0; padding-bottom: 2px; }
.sep { border-left: 2px solid var(--line); }
tr.row-off td { opacity: .55; }
tr.row-off td:first-child { opacity: .7; }
/* Маркетинг: всё по центру, умеренно ужатые ячейки — строка-источник в один экран */
table.mkv th, table.mkv td { text-align: center; padding: 7px 8px; }
table.mkv td:first-child, table.mkv th:first-child { text-align: left; padding-left: 14px; max-width: 150px; }
table.mkv td.num { min-width: 0; }
table.mkv td.edit input { width: 72px; text-align: center; padding: 4px 5px; }
table.mkv .st { min-width: 44px; padding: 2px 6px; }
@media (max-width: 900px) {
  table.mkv th, table.mkv td { padding: 6px 6px; }
  table.mkv td.edit input { width: 62px; }
}

/* Мультивыбор источников (маркетинг) */
.msel { position: absolute; top: calc(100% + 6px); left: 0; z-index: 60; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); padding: 8px 4px; min-width: 240px; max-height: 320px; overflow: auto; }
.msel-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; cursor: pointer; white-space: nowrap; border-radius: 6px; }
.msel-row:hover { background: var(--row-total); }
/* Таблица задач: центрирование */
table.tcen th, table.tcen td.tc { text-align: center; }
table.tcen td.tc.edit input { width: 64px; text-align: center; margin: 0 auto; display: inline-block; }
table.tcen td.tc input:disabled { background: var(--row-total); border-style: solid; opacity: .55; }
tr.total td { background: var(--row-total); font-weight: 700; position: relative; }
tr.total td:first-child { background: var(--row-total); }
td.num { min-width: 86px; }
td.edit input {
  width: 96px; text-align: right; border: 1px dashed var(--line); background: transparent;
  border-radius: 6px; padding: 4px 6px;
}
td.edit input:focus { border-style: solid; border-color: var(--accent); outline: none; background: var(--surface); }
.st { display: inline-block; min-width: 56px; text-align: center; border-radius: 6px; padding: 2px 7px; font-weight: 700; }
.st.ok   { color: var(--ok);   background: var(--ok-bg); }
.st.warn { color: var(--warn); background: var(--warn-bg); }
.st.bad  { color: var(--bad);  background: var(--bad-bg); }
.st.na   { color: var(--muted); background: transparent; font-weight: 400; }
.neg { color: var(--bad); font-weight: 600; }
.pos { color: var(--ok); font-weight: 600; }
.wk-sub { display: grid; grid-template-columns: auto auto; gap: 2px 12px; font-size: 13px; justify-content: center; }
.wk-sub .l { color: var(--muted); text-align: right; }
.offday { color: var(--muted); }
.approx { color: var(--muted); font-size: 11px; }

/* ---------- Комментарии и задачи ---------- */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; align-items: stretch; }
.two > .card { margin-top: 0; display: flex; flex-direction: column; }
.two > .card .list { flex: 1; }
@media (max-width: 860px) { .two { grid-template-columns: 1fr; } }
.list { padding: 8px 14px 12px; }
.item { display: flex; gap: 8px; align-items: flex-start; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.item:last-child { border-bottom: 0; }
.item .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.item .txt { flex: 1; }
.item.done .txt { text-decoration: line-through; color: var(--muted); }
.carry { color: var(--warn); font-size: 12px; font-weight: 600; }
.addrow { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.addrow input[type=text] { flex: 1; min-width: 160px; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; font-size: 15px; }
.icon-btn:hover { color: var(--bad); }
.empty { color: var(--muted); padding: 14px; }

/* ---------- Оверлеи ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,18,20,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.panel { background: var(--surface); border-radius: 12px; padding: 18px; width: 100%; max-width: 420px; }
.panel h3 { margin: 0 0 10px; }
.panel .row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.panel .row > * { flex: 1; min-width: 140px; }
.panel .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.emp-list { max-height: 260px; overflow: auto; margin-top: 10px; border-top: 1px solid var(--line); }
.emp-list .item { align-items: center; }

@media (max-width: 700px) {
  header { padding-left: 10px; padding-right: 10px; }
  main { padding: 10px 8px; }
  th, td { padding: 8px 11px; }
  td:first-child, th:first-child { padding-left: 12px; max-width: 150px; }
  th:last-child, td:last-child { padding-right: 12px; }
  table.wk th.day, table.wk td.day { min-width: 112px; }
  table.wk th.wknd, table.wk td.wknd { min-width: 84px; }
  td.edit input { width: 82px; }
}
