:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #edf4ff;
  --line: #d8e2f0;
  --line-strong: #b7c6da;
  --text: #171717;
  --muted: #657084;
  --accent: #0b328f;
  --accent-strong: #06266f;
  --accent-soft: #e8f0ff;
  --info: #15aeea;
  --info-strong: #008fd1;
  --info-soft: #e6f7ff;
  --danger: #b83b35;
  --danger-soft: #fdebea;
  --warning: #8a5a00;
  --warning-soft: #fff4d8;
  --shadow: 0 14px 38px rgba(11, 50, 143, 0.09);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--info);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f9fbff;
  color: #1b2f66;
  font: 0.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 30px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin: 26px 0 12px;
  font-size: 19px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  color: var(--text);
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--info));
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-title {
  display: block;
  font-weight: 760;
  line-height: 1.15;
}

.brand-subtitle {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 4px;
}

.nav-item {
  display: flex;
  min-height: 38px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 8px;
  color: #17233a;
  font-weight: 650;
}

.nav-item:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding: 12px 8px 0;
  border-top: 1px solid var(--line);
}

.user-pill {
  overflow: hidden;
  color: var(--muted);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-content {
  min-width: 0;
  padding: 28px 30px 44px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.page-note,
.muted {
  color: var(--muted);
  font-size: 0.92em;
}

.surface {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.stack {
  display: grid;
  gap: 18px;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  margin-bottom: 18px;
}

.toolbar form,
.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f7faff;
  color: #21345c;
  font-weight: 760;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #f8fbff;
}

tr.inactive td {
  color: #8b96a1;
  background: #fafbfc;
}

.cell-actions {
  min-width: 260px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

form {
  margin: 0;
}

.form-stack {
  display: grid;
  gap: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: #1f2c44;
  font-size: 13px;
  font-weight: 700;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="file"],
select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input[type="file"] {
  padding: 7px;
}

input:focus,
select:focus {
  outline: 3px solid rgba(21, 174, 234, 0.22);
  border-color: var(--info);
}

.input-xs {
  max-width: 78px;
}

.input-sm {
  max-width: 130px;
}

.input-md {
  max-width: 280px;
}

.input-lg {
  max-width: 540px;
}

.button,
button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 760;
  white-space: nowrap;
}

.button:hover,
button:hover {
  background: var(--accent-strong);
}

.button-secondary,
button.secondary {
  border-color: var(--line-strong);
  background: #fff;
  color: #1f2c44;
}

.button-secondary:hover,
button.secondary:hover {
  background: #f4f8ff;
}

.button-danger,
button.danger {
  background: var(--danger);
}

.button-danger:hover,
button.danger:hover {
  background: #96302b;
}

.button-ghost,
button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.button-ghost:hover,
button.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-secondary,
.btn-link,
.btn-danger-sm {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 7px 11px;
  border-radius: 7px;
  font-weight: 760;
  text-decoration: none;
}

.btn-secondary {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #1f2c44;
}

.btn-link {
  border: 1px solid var(--line-strong);
  background: var(--info-soft);
  color: var(--accent);
}

.btn-danger-sm {
  min-height: 34px;
  padding: 7px 11px;
  background: var(--danger);
}

.btn-secondary:hover,
.btn-link:hover {
  background: #f4f8ff;
  text-decoration: none;
}

.btn-danger-sm:hover {
  background: #96302b;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 26px 0 12px;
}

.section-header h2 {
  margin: 0;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.settings-card {
  display: grid;
  gap: 6px;
  min-height: 138px;
  padding: 18px;
  color: var(--text);
  text-decoration: none;
}

.settings-card:hover {
  border-color: var(--line-strong);
  background: #f8fbff;
  text-decoration: none;
}

.settings-card strong {
  font-size: 18px;
}

.settings-card span:last-child {
  color: var(--muted);
  font-size: 14px;
}

.settings-kicker {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.flash,
.alert {
  padding: 11px 13px;
  border: 1px solid #b9dcff;
  border-radius: var(--radius);
  margin: 0 0 16px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.alert-error {
  border-color: #f0b8b5;
  background: var(--danger-soft);
  color: var(--danger);
}

.alert-warning {
  border-color: #efd08b;
  background: var(--warning-soft);
  color: var(--warning);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--info-soft);
  color: #064e8a;
  font-size: 12px;
  font-weight: 760;
}

.status-ok {
  color: var(--accent-strong);
  font-weight: 760;
}

.status-muted {
  color: var(--muted);
  font-weight: 650;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-card {
  padding: 16px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.metric-value {
  display: block;
  margin-top: 8px;
  font-size: 27px;
  line-height: 1.1;
  font-weight: 800;
}

.metric-hint {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.chart-panel {
  padding: 16px;
}

.chart-panel canvas {
  width: 100%;
  max-height: 430px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}

.summary-card {
  padding: 14px;
}

.manager-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.8fr);
  gap: 14px;
  margin: 18px 0;
  align-items: start;
}

.compact-table {
  box-shadow: none;
}

.compact-table table {
  min-width: 680px;
}

.status-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.person-list {
  display: grid;
  gap: 7px;
  padding-left: 18px;
  margin: 0;
}

.report-text {
  margin: 0;
  white-space: pre-wrap;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(21, 174, 234, 0.10), rgba(11, 50, 143, 0.08)),
    var(--bg);
}

.login-panel {
  width: min(100%, 420px);
  padding: 28px;
}

.login-panel h1 {
  margin: 20px 0 18px;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    gap: 12px;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar-footer {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .main-content {
    padding: 20px 14px 32px;
  }

  .page-header,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  .nav-list {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .metrics-grid,
  .summary-grid,
  .manager-grid,
  .status-columns {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Enhancements (best-practice, additive): keyboard focus,
   reduced motion, dark theme, print. Pure CSS — без JS и
   веб-шрифтов, нулевая стоимость в рантайме.
   ============================================================ */

/* Клавиатурный фокус виден только при навигации с клавиатуры
   (не при клике мышью) — чище и доступнее. */
a:focus-visible,
button:focus-visible,
.button:focus-visible,
.nav-item:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(21, 174, 234, 0.45);
  outline-offset: 2px;
}

/* Лёгкие переходы для интерактивных элементов (ощущение отзывчивости
   без «тормозов»). Полностью отключаются при reduced-motion. */
a,
button,
.button,
.nav-item,
tbody tr:hover td,
input,
select {
  transition: background-color 0.12s ease, border-color 0.12s ease,
    color 0.12s ease, outline-color 0.12s ease;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Тёмная тема: переопределяем переменные + точечно «захардкоженные»
   светлые места, чтобы тема была цельной, а не наполовину светлой. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1620;
    --surface: #161f2c;
    --surface-2: #1e2a3a;
    --line: #283749;
    --line-strong: #3a4c63;
    --text: #e6edf6;
    --muted: #97a4b6;
    --accent: #4f8cf7;
    --accent-strong: #7aa9ff;
    --accent-soft: #1a2740;
    --info: #38bdf0;
    --info-strong: #63cdf5;
    --info-soft: #122c44;
    --danger: #f0726a;
    --danger-soft: #3a1d1c;
    --warning: #e3ad44;
    --warning-soft: #382c12;
    --shadow: 0 14px 38px rgba(0, 0, 0, 0.45);
  }

  .sidebar {
    background: var(--surface);
  }

  .nav-item {
    color: var(--text);
  }

  code {
    background: #0f1a28;
    color: #a8c6ef;
    border-color: var(--line);
  }

  th {
    background: #1a2636;
    color: #c5d3e8;
  }

  tbody tr:hover td {
    background: #1b2a3c;
  }

  tr.inactive td {
    color: var(--muted);
    background: #131c27;
  }

  label {
    color: #cdd8e8;
  }

  input[type="text"],
  input[type="number"],
  input[type="password"],
  input[type="date"],
  input[type="file"],
  select {
    background: #0f1a28;
    color: var(--text);
  }

  .button-secondary,
  button.secondary {
    background: var(--surface-2);
    color: var(--text);
  }

  .badge {
    color: #cfe6ff;
  }

  .settings-card:hover {
    background: #1b2a3c;
  }
}

/* Печать сводных отчётов (кейс руководителя): только контент,
   без сайдбара/теней, чёрный текст на белом. */
@media print {
  .sidebar,
  .toolbar,
  .row-actions,
  form button {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .main-content {
    padding: 0;
  }

  .surface,
  .table-wrap {
    box-shadow: none;
    border-color: #ccc;
  }

  body {
    background: #fff;
    color: #000;
  }
}

/* ── W2: кабинет сотрудника / форма отчёта ──────────────────── */
.nav-section {
  display: block;
  margin: 14px 12px 4px;
  font-size: 11px;
  font-weight: 760;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 760;
  text-decoration: none;
}
.button-link:hover { background: var(--accent-strong); color: #fff; }

.slot-pill,
.kpi-card .kpi-unit {
  color: var(--muted);
}
.slot-pill {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
}
.slot-pill b { color: var(--text); }

.report-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 18px;
  align-items: start;
}
.report-form { display: grid; gap: 18px; }
.cf-row { display: flex; gap: 18px; flex-wrap: wrap; }
.cf-row label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

.report-table th { font-size: 12px; }
.report-table td { vertical-align: middle; }
.report-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.score-card {
  position: sticky;
  top: 18px;
  padding: 18px;
  text-align: center;
  display: grid;
  gap: 10px;
}
.score-total {
  font-size: 40px;
  font-weight: 820;
  color: var(--accent);
  line-height: 1;
}
.score-unit { font-size: 16px; color: var(--muted); font-weight: 600; }
.score-split {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.score-split b { color: var(--text); }
.score-details {
  margin: 4px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
  list-style: none;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-card { padding: 16px 18px; display: grid; gap: 2px; }
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi-value { font-size: 30px; font-weight: 820; color: var(--accent); }
.kpi-unit { font-size: 12px; }

@media (max-width: 880px) {
  .report-layout { grid-template-columns: 1fr; }
  .score-card { position: static; }
}

/* ── W2: степпер −/+ и строки продуктов (мобильно-дружелюбно) ── */
.product-list { display: grid; gap: 8px; }
.product-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 190px;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.product-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.product-info strong { font-size: 15px; }
.product-info .muted { font-size: 12px; }

.stepper {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.step-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.step-btn:hover { background: var(--accent-soft); }
.step-btn:active { background: var(--accent); color: #fff; }
/* Селектор повышенной специфичности: перебивает общее
   input[type="number"]{width:100%}, иначе поле растягивается на всю строку. */
.stepper input.step-input {
  width: 64px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-radius: 0;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  background: var(--surface);
  color: var(--text);
  -moz-appearance: textfield;
  appearance: textfield;
}
.step-input::-webkit-outer-spin-button,
.step-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.product-row input.amount-input {
  width: 100%;
  min-height: 44px;
}

/* ── Вечерний отчёт: тройные поля план/мес/день ────────────── */
.daily-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}
.daily-row .triple {
  display: flex;
  gap: 6px;
  justify-self: end;
}
.daily-row .amount-triple { grid-column: 1 / -1; justify-self: stretch; margin-top: 2px; }
.daily-row .amount-triple .triple-input { flex: 1; width: auto; text-align: left; }
.triple input.triple-input {
  width: 72px;
  min-height: 40px;
  padding: 6px 8px;
  text-align: center;
  -moz-appearance: textfield;
  appearance: textfield;
}
.triple input.triple-input::-webkit-outer-spin-button,
.triple input.triple-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.subtotal-row { background: var(--surface-2); }

@media (max-width: 880px) {
  .daily-row { grid-template-columns: 1fr; }
  .daily-row .product-info { grid-column: 1; }
  .daily-row .triple { grid-column: 1; justify-self: stretch; }
  .daily-row .triple .triple-input { flex: 1; width: auto; }
}

/* ── Копируемый отчёт для беседы ───────────────────────────── */
.copy-report { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.copy-report-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.copy-report-text {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}
.copy-btn { white-space: nowrap; }

@media (max-width: 880px) {
  /* Карточка продукта: название слева, компактный степпер справа,
     поле суммы (если есть) — отдельной строкой во всю ширину. */
  .product-row {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px 12px;
  }
  .product-info { grid-column: 1; }
  .stepper { grid-column: 2; justify-self: end; }
  .amount-input { grid-column: 1 / -1; width: 100%; }
}

/* ── W2: планы и прогресс ──────────────────────────────────── */
.derived { align-self: end; color: var(--muted); font-size: 14px; padding-bottom: 8px; }
.derived b { color: var(--accent); }

.progress-bar {
  height: 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
  margin-bottom: 18px;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .3s ease;
}
.kpi-value small { font-size: 16px; font-weight: 700; }
