/* Оформление в духе консолей Google: светлый нейтральный фон, один синий
   акцент, тонкие границы вместо теней. Цветом отмечаем только смысл —
   рост, падение, статус. */

:root {
  --bg: #f8f9fa;
  --panel: #ffffff;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dadce0;
  --line-soft: #e8eaed;

  --brand: #1a73e8;
  --brand-ink: #1967d2;
  --brand-soft: #e8f0fe;

  --ok: #188038;   --ok-soft: #e6f4ea;
  --warn: #b06000; --warn-soft: #fef7e0;
  --err: #d93025;  --err-soft: #fce8e6;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(60, 64, 67, .15), 0 4px 8px rgba(60, 64, 67, .1);

  /* Палитра графиков: синий ведущий, серый — для плана. */
  --c1: #1a73e8; --c2: #12b5cb; --c3: #e8710a; --c4: #f9ab00;
  --c5: #7cb342; --c6: #9334e6; --c7: #d93025; --c8: #80868b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202124;
    --panel: #292a2d;
    --ink: #e8eaed;
    --muted: #9aa0a6;
    --line: #3c4043;
    --line-soft: #35363a;

    --brand: #8ab4f8;
    --brand-ink: #8ab4f8;
    --brand-soft: #283142;

    --ok: #81c995;   --ok-soft: #1e3325;
    --warn: #fdd663; --warn-soft: #332d1a;
    --err: #f28b82;  --err-soft: #33231f;

    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 8px rgba(0, 0, 0, .3);

    --c1: #8ab4f8; --c2: #4ecde6; --c3: #fa903e; --c4: #fdd663;
    --c5: #a8dab5; --c6: #d7aefb; --c7: #f28b82; --c8: #9aa0a6;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- шапка --- */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar .inner {
  max-width: 1440px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; gap: 4px; min-height: 64px; flex-wrap: wrap;
}
.brand {
  font-size: 18px; font-weight: 400; color: var(--ink);
  margin-right: 22px; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand span { color: var(--brand); }
.nav a {
  display: inline-block; padding: 7px 14px; border-radius: 16px;
  color: var(--muted); font-weight: 500; font-size: 14px;
}
.nav a:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand-ink); }
.spacer { flex: 1; }
.who { font-size: 12px; color: var(--muted); text-align: right; line-height: 1.35; }
.who b { display: block; color: var(--ink); font-size: 14px; font-weight: 500; }

/* --- вкладки второго уровня --- */
.tabbar { background: var(--panel); border-bottom: 1px solid var(--line); }
.tabbar .inner {
  max-width: 1440px; margin: 0 auto; padding: 0 24px;
  display: flex; gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tabbar a {
  padding: 13px 16px 10px; font-size: 14px; font-weight: 500;
  color: var(--muted); white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.tabbar a:hover { color: var(--ink); text-decoration: none; }
.tabbar a.active { color: var(--brand-ink); border-bottom-color: var(--brand); }

/* --- карточки показателей раздела --- */
.metric-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.metric-grid > .metric-chart { grid-column: 1 / -1; margin-bottom: 0; }
.metric {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px 14px;
  display: flex; flex-direction: column; min-width: 0;
}
.metric.pending { border-style: dashed; background: transparent; }
.metric .name {
  display: flex; gap: 8px; font-size: 13px; font-weight: 500;
  line-height: 1.35; color: var(--ink); min-height: 36px;
}
.metric .value {
  font-size: 28px; font-weight: 400; margin: 14px 0 auto;
  font-variant-numeric: tabular-nums; letter-spacing: -.5px;
}
.metric .value small { font-size: 14px; color: var(--muted); margin-left: 5px; }
.metric.pending .value { font-size: 22px; color: var(--muted); }
.metric .foot { color: var(--muted); font-size: 12px; margin-top: 8px; }
.metric .foot.period { margin-top: 3px; opacity: .8; }

/* Цвет строки исходной таблицы: зелёная или жёлтая. */
.mark {
  width: 8px; height: 8px; border-radius: 50%;
  flex: 0 0 auto; margin-top: 6px; display: inline-block;
}
.mark.green { background: var(--ok); }
.mark.yellow { background: var(--c4); }
.card-head h2 .mark { margin: 0 8px 0 0; vertical-align: 1px; }
.legend-dots {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted);
}
.legend-dots .mark { margin: 0 6px 0 0; vertical-align: 0; }

/* --- каркас --- */
.wrap { max-width: 1440px; margin: 0 auto; padding: 24px 24px 72px; }
.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
h1 { font-size: 22px; font-weight: 400; margin: 0 0 4px; letter-spacing: 0; }
h2 { font-size: 16px; font-weight: 500; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 13px; margin: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card > h2 { display: flex; align-items: center; gap: 8px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.card-head h2 { margin: 0; }
.section-head {
  display: flex; align-items: baseline; gap: 12px;
  flex-wrap: wrap; margin: 28px 0 14px;
}
.section-head h2 { margin: 0; font-size: 18px; font-weight: 400; }
.section-head .sub { font-size: 13px; }
.section-head .spacer { flex: 1; }

/* --- карточки показателей --- */
.kpis {
  display: grid; gap: 16px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}
.kpi {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px;
}
.kpi .label {
  color: var(--muted); font-size: 12px; font-weight: 500;
  letter-spacing: .2px; margin-bottom: 10px;
}
.kpi .value {
  font-size: 26px; font-weight: 400; color: var(--ink);
  letter-spacing: -.4px; font-variant-numeric: tabular-nums;
}
.kpi .value.big { font-size: 32px; }
.kpi .value small {
  font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 5px;
  letter-spacing: 0;
}
.kpi .plan, .kpi .foot { color: var(--muted); font-size: 12px; margin-top: 10px; }
.kpi .plan b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 13px; font-weight: 500; margin-top: 10px; }
.kpi .delta .plan { display: inline; margin: 0; }

.up { color: var(--ok); }
.down { color: var(--err); }
.over { color: var(--warn); }
.flat { color: var(--muted); }
td.up, td.down, td.over, td.flat { font-variant-numeric: tabular-nums; }

.bar {
  height: 4px; border-radius: 2px; background: var(--line-soft);
  margin-top: 12px; overflow: hidden;
}
.bar > i { display: block; height: 100%; border-radius: 2px; background: var(--brand); }
.bar > i.done { background: var(--ok); }
.bar > i.near { background: var(--brand); }
.bar > i.short { background: var(--warn); }

/* --- таблицы --- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 10px 14px; text-align: left; }
th {
  background: var(--panel); color: var(--muted);
  font-weight: 500; font-size: 12px; letter-spacing: .2px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; white-space: nowrap;
}
td { border-bottom: 1px solid var(--line-soft); }
tbody tr:hover { background: var(--bg); }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }
.tot-row td { background: var(--bg); font-weight: 500; border-top: 1px solid var(--line); }
.tot-row:hover td { background: var(--bg); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* --- формы --- */
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
label.field { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
label.field span { display: block; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], input[type=date],
select, textarea {
  width: 100%; padding: 9px 12px; font: inherit; font-size: 14px;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
}
textarea { min-height: 64px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

.btn {
  display: inline-block; padding: 8px 16px; font: inherit; font-size: 14px;
  font-weight: 500; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn.danger { color: var(--err); }
.btn.danger:hover { background: var(--err-soft); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --- чипы: фильтры и переключатели --- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 5px 12px; border-radius: 16px; border: 1px solid var(--line);
  font-size: 13px; font-weight: 500; color: var(--muted); background: var(--panel);
}
.chip:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.chip.active {
  background: var(--brand-soft); border-color: transparent; color: var(--brand-ink);
}
button.chip { cursor: pointer; font-family: inherit; line-height: 1.4; }
.chip.active:hover { background: var(--brand-soft); color: var(--brand-ink); }

/* --- бейджи и сообщения --- */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 12px; font-weight: 500;
  background: var(--bg); color: var(--muted); border: 1px solid transparent;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.brand { background: var(--brand-soft); color: var(--brand-ink); }
.badge.neutral { background: var(--bg); color: var(--muted); border-color: var(--line); }

.flash {
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 14px;
  font-size: 14px; border: 1px solid transparent;
}
.flash.success { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--err-soft); color: var(--err); }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* --- вход --- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-box { width: 100%; max-width: 380px; }
.login-box .card { padding: 32px; box-shadow: var(--shadow); }
.login-box h1 { text-align: center; margin-bottom: 24px; }

/* --- графики --- */
.chart-grid { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
.chart-grid > .card { min-width: 0; }
@media (max-width: 900px) { .chart-grid { grid-template-columns: 1fr; } }
.chart { width: 100%; height: 280px; display: block; }
/* Главный график крупнее остальных: на нём читают отклонения. */
.chart.tall { height: 400px; }
@media (max-width: 700px) { .chart.tall { height: 300px; } }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .grid-line { stroke: var(--line-soft); stroke-width: 1; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
/* Черта-ориентир на графике отклонений. */
.chart .limit-line { stroke: var(--err); stroke-width: 1.5; stroke-dasharray: 6 4; }
/* Подпись черты ложится поверх столбцов — обводим цветом фона, чтобы читалась. */
.chart .limit-text {
  fill: var(--err); font-size: 11px; font-weight: 500;
  stroke: var(--panel); stroke-width: 3px; paint-order: stroke;
}
.legend {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); margin-top: 12px;
}
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 6px; }
.legend b { color: var(--ink); font-weight: 500; }

/* --- выбор периода календарём --- */
.range-card { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 14px 20px; }
.rangebox { position: relative; }
.rangebox form { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.range-btn { font-variant-numeric: tabular-nums; font-weight: 500; }
.range-btn.active { border-color: var(--brand); color: var(--brand-ink); background: var(--brand-soft); }
.range-pop {
  position: absolute; z-index: 30; top: calc(100% + 8px); left: 0;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.range-cals { display: flex; gap: 24px; }
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 10px; font-size: 14px;
}
.cal-head b { font-weight: 500; }
.cal-nav {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 0; background: transparent; color: var(--muted);
  font-size: 16px; line-height: 1;
}
.cal-nav:hover { background: var(--bg); color: var(--ink); }
/* Ширина сетки фиксирована: иначе всплывающее окно сжимает её до нечитаемого. */
.cal { flex: 0 0 auto; }
.cal-grid { border-collapse: collapse; table-layout: fixed; width: 252px; font-size: 13px; }
.cal-grid th {
  width: 36px; padding: 6px 0; border: 0; background: transparent;
  position: static; text-align: center; letter-spacing: 0;
  font-size: 11px; font-weight: 500; color: var(--muted);
}
.cal-grid td { padding: 0; border: 0; text-align: center; }
.cal-grid tbody tr:hover { background: transparent; }
.cal-grid td[data-day] {
  width: 36px; height: 32px; cursor: pointer; border-radius: 16px;
  font-variant-numeric: tabular-nums;
}
.cal-grid td[data-day]:hover { background: var(--bg); }
.cal-grid td.today { font-weight: 700; color: var(--brand); }
.cal-grid td.in { background: var(--brand-soft); border-radius: 0; color: var(--brand-ink); }
.cal-grid td.pick { background: var(--brand); color: #fff; font-weight: 500; }
/* День вне загруженных данных: виден, но выбрать нельзя. */
.cal-grid td.off { width: 36px; height: 32px; color: var(--muted); opacity: .35; }
.range-foot {
  display: flex; align-items: center; gap: 8px; margin-top: 14px;
  padding-top: 12px; border-top: 1px solid var(--line-soft);
  font-size: 13px; color: var(--muted);
}
.range-label { font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 700px) {
  .range-cals { flex-direction: column; }
  .range-foot { flex-wrap: wrap; }
}

/* --- сетка ячеек Excel --- */
.sheet-wrap { overflow: auto; max-height: 460px; border: 1px solid var(--line); border-radius: var(--radius); }
table.sheet { font-size: 12.5px; border-collapse: separate; border-spacing: 0; }
table.sheet th, table.sheet td { border: 1px solid var(--line-soft); padding: 5px 8px; white-space: nowrap; }
table.sheet th {
  background: var(--bg); text-align: center; cursor: pointer;
  position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--line);
}
table.sheet th.rowhead { position: sticky; left: 0; z-index: 1; top: auto; }
table.sheet td { cursor: pointer; max-width: 190px; overflow: hidden; text-overflow: ellipsis; }
table.sheet td:hover { background: var(--brand-soft); outline: 2px solid var(--brand); }
table.sheet td.picked { background: var(--brand); color: #fff; }
table.sheet td.merged { color: var(--muted); font-style: italic; }

/* --- мелочи --- */
.filters { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.filters label.field { min-width: 150px; flex: 0 1 auto; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.stack { display: grid; gap: 10px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.updated { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); display: inline-block; }

/* --- подсказка на графиках --- */
.chart-tip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px 12px; font-size: 13px; color: var(--ink);
  min-width: 160px; max-width: 300px;
}
.chart-tip .tip-head { font-weight: 500; margin-bottom: 6px; }
.chart-tip .tip-row {
  display: flex; align-items: center; gap: 8px;
  line-height: 1.85; white-space: nowrap;
}
.chart-tip .tip-row i { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; }
.chart-tip .tip-row span { color: var(--muted); }
.chart-tip .tip-row b {
  margin-left: auto; font-weight: 500; font-variant-numeric: tabular-nums;
}
.chart-tip .tip-sum {
  border-top: 1px solid var(--line-soft); margin-top: 6px; padding-top: 6px;
}
.chart .hover-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hover-band { fill: var(--brand); opacity: .08; }
.chart .hover-dot { stroke: var(--panel); stroke-width: 2; }
.chart .slice-on { opacity: .78; }

/* --- выбор доступных вкладок в карточке пользователя --- */
.tabpick { display: flex; gap: 24px; flex-wrap: wrap; }
.tabpick-group { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.tabpick-group > b {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; margin-bottom: 2px;
}
.tabpick label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; cursor: pointer; line-height: 1.5;
}
.tabpick label:hover span { color: var(--brand-ink); }
.tabpick input { cursor: pointer; margin: 0; }
/* Административные вкладки показаны, но недоступны: так видно, что они есть
   и почему их нельзя выдать галочкой. */
.tabpick-group.locked label { cursor: not-allowed; color: var(--muted); }
.tabpick-group.locked label:hover span { color: var(--muted); }

tr.subrow > td { border-top: 0; padding-top: 0; }
tr.subrow details { margin: 0 0 6px; }
tr.subrow summary {
  cursor: pointer; font-size: 12px; color: var(--muted);
  padding: 4px 0; list-style-position: inside;
}
tr.subrow summary:hover { color: var(--brand-ink); }
tr.subrow details[open] summary { margin-bottom: 10px; }
tr.subrow details[open] { padding-bottom: 8px; }

/* --- «Обзор» в две колонки: слева производство, справа персонал --- */
/* Обзор идёт сверху вниз в одну колонку: сначала производство, под ним —
   рапорт по персоналу. Раньше рапорт стоял сбоку, и обеим частям не хватало
   ширины: таблица по площадкам жалась, а графики влезали только по одному. */
.overview-cols {
  display: grid; gap: 16px; align-items: start;
  grid-template-columns: minmax(0, 1fr);
}
.overview-cols > .ov-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.ov-col > * { margin: 0; }

/* --- галочки выбора рядов под графиком --- */
.series-pick {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  padding: 10px 0 2px; border-top: 1px solid var(--line); margin-top: 10px;
}
.series-pick label {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted); cursor: pointer;
}
.series-pick label:hover span { color: var(--ink); }
.series-pick input { margin: 0; cursor: pointer; }
.series-pick i {
  width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none;
}

/* --- таблица персонала по площадкам на «Обзоре» --- */
.staff-board td.num, .staff-board th.num { text-align: right; }
.staff-board th:first-child, .staff-board td:first-child { text-align: left; }
/* Первый столбец — сумма по всем площадкам, выделяем его как итог. */
.staff-board th:nth-child(2), .staff-board td:nth-child(2) {
  border-right: 1px solid var(--line); font-weight: 600;
}
/* Три верхние строки — итоги численности, они же на графике ниже. */
.staff-board tr.headline td { font-weight: 600; }
.staff-board tr.headline:last-of-type td { border-bottom: 1px solid var(--line); }

/* Галочка внутри поля формы (например, «сводный разрез»). */
.inline-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.inline-check input { margin: 0; cursor: pointer; }
.inline-check span { font-size: 13px; color: var(--ink); }
