:root {
  --ink: #1a2744;
  --muted: #5b6b86;
  --line: #d7deea;
  --bg: #eef2f7;
  --card: #fff;
  --accent: #1e3a5f;
  --ok: #2c6e4f;
  --bad: #9b3b3b;
  --warn: #9a6b12;
  --plan: #7b8bb3;
  --fact: #1e3a5f;
  --font: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 380px;
  max-width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
}
.login-kicker, .kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.login-card h1, .top h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.login-sub { margin: 6px 0 18px; color: var(--muted); }
.login-card label, .filters > label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.login-card input, .filters input, .filters select, .ms-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}
.login-card input:focus, .filters input:focus, .filters select:focus {
  outline: none;
  border-color: var(--accent);
}
.login-card button, .btn {
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 8px;
}
.login-card button { width: 100%; margin-top: 8px; }
.btn.ghost {
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--line);
}
.login-err { color: var(--bad); font-weight: 600; }

#app { min-height: 100vh; }
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px;
  flex: 0 0 260px;
  background: #13233a;
  color: #e8eef8;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 40;
}
.sidebar-brand .kicker { color: #93a4bf; }
.sidebar-brand strong { font-size: 18px; letter-spacing: -.02em; }
.sidebar-nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  border: 0;
  background: transparent;
  color: #c7d3e6;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 650;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.on { background: #1e3a5f; color: #fff; }
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .45);
  z-index: 35;
}
.main {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 18px 64px;
  width: 100%;
}
.top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.top-left { display: flex; gap: 12px; align-items: flex-start; }
.burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  margin-top: 2px;
}
.burger span {
  display: block;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}
.top-actions { display: flex; gap: 8px; align-items: center; }
.page[hidden] { display: none !important; }
.reconcile-filters .wide { grid-column: 1 / -1; }
.status-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
}
.status-pill.ok { background: #e7f1ec; color: var(--ok); }
.status-pill.plan_mismatch { background: #fdf3e4; color: var(--warn); }
.status-pill.unmatched,
.status-pill.no_bitrix_data,
.status-pill.only_bitrix { background: #f8eaea; color: var(--bad); }
.rec-map { min-width: 200px; display: flex; flex-direction: column; gap: 6px; }
.rec-map select,
.dept-select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  background: #fff;
}
.dept-select { max-width: 280px; }
.rec-map-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn.tiny { padding: 5px 8px; font-size: 12px; }
tr.rec-unmatched td { background: #fff8f8; }
.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: #e7ebf6;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.pill.ok { background: #e7f1ec; color: var(--ok); }
.pill.run { background: #fdf3e4; color: var(--warn); }
.pill.bad { background: #f8eaea; color: var(--bad); }

.filters {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  align-items: end;
}
.filters label, .filters .ms { grid-column: span 2; }
.ms-field { display: flex; flex-direction: column; gap: 6px; }
.ms-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.ms.exclude .ms-label { color: var(--bad); }
.ms-btn.exclude { color: var(--bad); border-color: #e3c8c8; }
.filters .grow { grid-column: span 4; }
.period-presets { grid-column: span 4; display: flex; gap: 6px; flex-wrap: wrap; }
.period-presets button {
  border: 1px solid var(--line);
  background: #f7f9fc;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}
.filter-presets {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: end;
}
.filter-presets label {
  min-width: 220px;
  flex: 1 1 220px;
}
.filter-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sync-opt {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.sync-opt input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.status { min-height: 1.4em; color: var(--muted); margin: 0 0 12px; }

.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpis.ratings-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis.efficiency-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.kpi b { display: block; font-size: 26px; letter-spacing: -.03em; }
.kpi span { color: var(--muted); font-size: 12px; font-weight: 700; }
.kpi.bad b { color: var(--bad); }
.kpi.ok b { color: var(--ok); }
.kpi.warn b { color: var(--warn); }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  color: var(--muted);
}
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 220px) 1fr auto; gap: 10px; align-items: center; }
.bar-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: #edf1f7; border-radius: 999px; overflow: hidden; display: flex; }
.bar-plan { height: 100%; background: var(--plan); }
.bar-fact { height: 100%; background: var(--fact); margin-top: -10px; opacity: .92; }
.bar-pair { position: relative; height: 10px; background: #edf1f7; border-radius: 999px; overflow: hidden; }
.bar-pair i { position: absolute; left: 0; top: 0; bottom: 0; }
.bar-pair .plan { background: #c9d3e6; }
.bar-pair .fact { background: var(--accent); }
.bar-val { font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }

.tbl-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.delta-pos { color: var(--bad); font-weight: 700; }
.delta-neg { color: var(--ok); font-weight: 700; }
.task-link { color: var(--accent); font-weight: 650; text-decoration: none; }
.task-link:hover { text-decoration: underline; }
.tag {
  display: inline-block;
  background: #eef2f7;
  border-radius: 999px;
  padding: 2px 8px;
  margin: 0 4px 4px 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}
.note { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
td .note { margin: 2px 0 0; }

.main-row { cursor: pointer; }
.main-row:hover, .main-row.open { background: #f7f9fc; }
.main-row:focus { outline: 2px solid var(--line); outline-offset: -2px; }
.toggle-cell { width: 28px; padding-right: 0; }
.row-toggle {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  width: 24px;
}
.detail-row td { background: #f7f9fc; padding: 8px 10px 14px 42px; border-bottom: 1px solid var(--line); }
.nested { background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.nested th, .nested td { padding: 7px 9px; }
.nested-empty { margin: 0; color: var(--muted); font-size: 13px; }

.ms { position: relative; }
.ms-btn { width: 100%; text-align: left; background: #fff; font-weight: 650; }
.ms-panel {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 240px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  max-height: 280px;
  overflow: auto;
}
.ms-panel input[type="search"] {
  width: 100%;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
}
.ms-actions {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 8px;
}
.ms-clear {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 4px;
}
.ms-clear:disabled {
  color: var(--muted);
  cursor: default;
  opacity: .55;
}
.ms-clear:not(:disabled):hover { text-decoration: underline; }
.filters .ms-item,
.ms-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 5px 2px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}
.filters .ms-item input[type="checkbox"],
.ms-item input[type="checkbox"] {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}
.ms-item-text { flex: 1 1 auto; line-height: 1.3; }
.mark-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
}
.mark-pill.positive { background: #e7f4ec; color: var(--ok); }
.mark-pill.negative { background: #f8eaea; color: var(--bad); }
.mark-pill.unset { background: #f3f0e7; color: var(--warn); }

@media (max-width: 1100px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,.18);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .burger { display: inline-flex; }
}
@media (max-width: 980px) {
  .filters label, .filters .ms, .filters .grow, .period-presets, .filter-presets { grid-column: span 6; }
  .kpis, .kpis.ratings-kpis, .kpis.efficiency-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bar-row { grid-template-columns: 1fr; }
}
@media print {
  #login-screen, .filters, .top-actions, .tabs, .sidebar, .burger { display: none !important; }
  body { background: #fff; }
  .card, .kpi { break-inside: avoid; }
}
