:root {
  --bg: #fafafb;
  --surface: #ffffff;
  --line: #ECECEF;
  --text: #1b1d22;
  --muted: #6b7280;
  --blue: #007aff;
  --success: #16a34a;
  --success-bg: #e7f7ec;
  --warning: #d97706;
  --warning-bg: #fdf3e3;
  --danger: #dc2626;
  --danger-bg: #fde8e8;
  --neutral-bg: #f0f0f3;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --font: -apple-system, "SF Pro Display", "SF Pro Text", Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html {
  background: var(--bg);
  color-scheme: light;
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
/* Apple-типографика: гасим дефолтный «жирный» вес strong/заголовков по всей панели */
strong, b { font-weight: 600; }
h2, h3 { font-weight: 600; letter-spacing: -.018em; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px 14px;
}
.brand {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .04em;
  padding: 0 10px 22px;
}
.nav { display: grid; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
}
.nav-item span {
  width: 18px;
  text-align: center;
  color: inherit;
}
.nav-item.active {
  background: #f1f7ff;
  color: var(--blue);
}
.sidebar-bottom { margin-top: auto; }

.page {
  margin-left: 220px;
  min-height: 100vh;
  padding: 32px;
}
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -.022em;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  padding: 8px 14px;
  min-height: 36px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary.small {
  min-height: 32px;
  padding: 6px 12px;
  font-size: 13px;
}
.btn-primary.danger { background: var(--danger); }
.testmode-banner {
  margin-bottom: 16px;
  border: 1px solid #f0b25b;
  border-left: 4px solid var(--danger);
  border-radius: 10px;
  background: var(--warning-bg);
  color: var(--danger);
  padding: 12px 14px;
  font-weight: 700;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-row.narrow { grid-template-columns: repeat(3, minmax(0, 180px)); }
.kpi { padding: 18px 18px 16px; }
.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 32px;
  line-height: 1;
  font-weight: 500;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.table th {
  text-align: left;
  padding: 13px 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  border-bottom: 1px solid var(--line);
}
.table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.num, .table td.num { font-variant-numeric: tabular-nums; }
.muted {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -.005em;
  white-space: nowrap;
}
.pill-success { color: var(--success); background: var(--success-bg); }
.pill-warning { color: var(--warning); background: var(--warning-bg); }
.pill-danger { color: var(--danger); background: var(--danger-bg); }
.pill-neutral { color: var(--muted); background: var(--neutral-bg); }
.pill-accent { color: var(--blue); background: #eef6ff; }

.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  margin-bottom: 24px;
}
.section-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
}
.section-title.compact {
  padding: 16px 16px 0;
  margin-bottom: 12px;
}
.settings-action {
  padding: 0 16px 16px;
}
.fleet-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.fleet-cell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  min-height: 100px;
  display: grid;
  gap: 12px;
  align-content: space-between;
  justify-items: start;
}
.fleet-user {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fleet-sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}
.side-card { padding-bottom: 12px; }
.alert-counts {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
}
.list { display: grid; }
.list-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.list-row span {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.head-details {
  position: relative;
}
.head-details > summary {
  list-style: none;
}
.head-details > summary::-webkit-details-marker { display: none; }
.dropdown-form {
  position: absolute;
  right: 0;
  top: 44px;
  width: 320px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 10;
  display: grid;
  gap: 10px;
}
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
input, select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 7px 10px;
}
.check {
  grid-template-columns: auto 1fr;
  align-items: center;
}
.check input { width: auto; min-height: auto; }

.assign-inline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.assign-inline select {
  width: auto;
  max-width: 150px;
  min-width: 116px;
  min-height: 32px;
  padding: 5px 9px;
  font-size: 13px;
}
.assign-inline .btn-primary {
  flex: 0 0 auto;
}

.actions { width: 44px; text-align: right; }
.kebab {
  position: relative;
  display: inline-block;
}
.kebab summary {
  list-style: none;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
}
.kebab summary::-webkit-details-marker { display: none; }
.kebab[open] summary { background: var(--neutral-bg); }
.menu {
  position: absolute;
  right: 0;
  top: 36px;
  min-width: 260px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 20;
  text-align: left;
}
.menu-form { display: grid; gap: 10px; }
.menu-button {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.menu-button.danger { color: var(--danger); }
.menu-muted { color: var(--muted); padding: 8px 10px; display: block; }
/* Удаление с подтверждением: «Удалить» раскрывает кнопку «Да, удалить — уверен». */
.confirm > summary { list-style: none; cursor: pointer; }
.confirm > summary::-webkit-details-marker { display: none; }
.confirm[open] > summary { opacity: .55; }
.confirm > form { padding: 4px 0 2px 0; }
.confirm > form .menu-button.danger {
  background: var(--danger);
  color: #fff;
  font-weight: 600;
  text-align: center;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}
.flash {
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.flash-success {
  color: var(--success);
  background: var(--success-bg);
  border-color: #c8ecd3;
}
.flash-error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #f4caca;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(100%, 380px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.login-brand { padding: 0 0 18px; }
.login-card h1 {
  font-size: 24px;
  margin-bottom: 16px;
}
.login-card p { color: var(--muted); margin: 0; }
.form-vertical { display: grid; gap: 14px; }
.alert-section { margin-bottom: 16px; }

/* ── Проверка профилей (reviews): подсказка строкой (не карточкой-«инпутом»), паддинг карточек ── */
.page-hint {
  margin: -10px 0 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  max-width: 72ch;
}
.review-item { padding: 16px; }
.review-item > .page-head { margin-bottom: 12px; }
.review-item .table td { padding-left: 0; padding-right: 0; }

/* ── Мобильный каркас: верхний бар + бургер + off-canvas шторка ── */
.nav-toggle { display: none; }
.topbar { display: none; }
.nav-backdrop { display: none; }

@media (max-width: 980px) {
  /* off-canvas сайдбар уезжает за левый край (translateX) — клипуем, чтобы он
     не раздувал scrollWidth страницы (иначе fixed-topbar с right:0 тянется за вьюпорт) */
  html, body { overflow-x: hidden; }

  /* верхний бар (фиксирован сверху, виден только на мобиле) */
  .topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    position: fixed;
    inset: 0 0 auto 0;
    height: 52px;
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    z-index: 40;
  }
  .topbar-brand { font-size: 17px; font-weight: 600; letter-spacing: .04em; }
  .burger {
    width: 40px; height: 40px;
    margin-left: -6px;
    display: grid; align-content: center; gap: 5px;
    padding: 0 9px;
    border-radius: 10px;
    cursor: pointer;
  }
  .burger span {
    display: block; height: 2px; border-radius: 2px;
    background: var(--text);
    transition: transform .22s ease, opacity .22s ease;
  }

  /* сайдбар → выезжающая слева панель */
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 264px;
    max-width: 82vw;
    height: 100vh;
    padding: 20px 14px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 60;
    overflow-y: auto;
  }
  .nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16,24,40,.36);
    z-index: 50;
  }
  #nav-toggle:checked ~ .sidebar { transform: none; }
  #nav-toggle:checked ~ .nav-backdrop { display: block; }
  #nav-toggle:checked ~ .topbar .burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  #nav-toggle:checked ~ .topbar .burger span:nth-child(2) { opacity: 0; }
  #nav-toggle:checked ~ .topbar .burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .page { margin-left: 0; padding: 68px 16px 24px; }
  .kpi-row, .kpi-row.narrow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-grid { grid-template-columns: 1fr; }
  .fleet-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
  .page-head { align-items: stretch; flex-direction: column; gap: 12px; }
  .page-head .head-details { align-self: flex-start; }

  /* ── Таблица → карточки (источник правды — data-label на <td>) ── */
  .card:has(> .table):not(.review-item) { background: transparent; border: 0; box-shadow: none; border-radius: 0; }
  .table, .table thead, .table tbody, .table tr, .table td { display: block; }
  .table thead { display: none; }
  .table tr {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 4px 14px;
    margin-bottom: 12px;
  }
  .table tbody tr:last-child { margin-bottom: 0; }
  .table td {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    padding: 9px 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    min-width: 0;
    text-align: right;
    overflow-wrap: anywhere;
  }
  .table tr td:last-child { border-bottom: 0; }
  .table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    margin-right: auto;          /* лейбл слева, значение группой справа (без разноса) */
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
  }
  .table td:not([data-label])::before,
  .table td[data-label=""]::before { content: none; }
  .table td .muted { flex-basis: 100%; text-align: right; margin-top: 0; }
  /* пустое состояние (colspan) — обычный центр-блок */
  .table td.empty { display: block; text-align: center; }
  .table td.empty::before { content: none; }
  /* действия (kebab ⋯) — отдельной строкой в правом нижнем углу карточки */
  .table td.actions {
    width: auto;
    justify-content: flex-end;
    padding: 6px 0 2px;
  }
  .table td.actions:empty { display: none; }
  /* ячейка с инлайн-назначением скаута → столбик на всю ширину */
  .table td:has(.assign-inline) { display: block; text-align: left; }
  .table td:has(.assign-inline)::before { display: block; margin-bottom: 8px; }

  /* ── Формы → нижняя шторка (bottom-sheet) ── */
  .head-details > .dropdown-form,
  .kebab > .menu {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    width: 100%;
    min-width: 0;
    max-height: 85vh;
    overflow-y: auto;
    border-left: 0; border-right: 0; border-bottom: 0;
    border-radius: 16px 16px 0 0;
    padding: 16px 16px 24px;
    z-index: 80;
  }
  .add-panel { width: 100%; }
  .menu .dropdown-form { position: static; width: 100%; padding: 0; }

  /* ── Тач-цели ≥44px ── */
  .nav-item { height: 48px; }
  .btn-primary, .btn-primary.small { min-height: 44px; }
  input, select { min-height: 44px; }
  .kebab summary { width: 44px; height: 44px; }
  .assign-inline { width: 100%; }
  .assign-inline select { width: 100%; max-width: none; min-width: 0; min-height: 44px; }
  .assign-inline .btn-primary { width: 100%; }
}

/* ── Добавление: «+» + сегмент-контрол «Вручную / Файлом» (Apple) ── */
.add-trigger { gap: 6px; padding-left: 11px; }
.ico-plus {
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  margin-top: -1px;
}
.add-panel { width: 340px; }
.add-panel .seg-radio { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--neutral-bg);
  border-radius: 9px;
}
.seg-tab {
  margin: 0;
  text-align: center;
  padding: 6px 0;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
#acc-manual:checked ~ .segmented .seg-tab-manual,
#acc-file:checked   ~ .segmented .seg-tab-file,
#px-manual:checked  ~ .segmented .seg-tab-manual,
#px-file:checked    ~ .segmented .seg-tab-file {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16,24,40,.10);
}
.seg-pane { display: none; gap: 10px; }
#acc-manual:checked ~ .pane-manual,
#px-manual:checked  ~ .pane-manual,
#acc-file:checked   ~ .pane-file,
#px-file:checked    ~ .pane-file { display: grid; }

/* файловый дроп */
.file-drop {
  position: relative;
  display: block;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  background: var(--bg);
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.file-drop:hover { border-color: var(--blue); background: #f5f9ff; }
.file-drop input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.file-cue {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.file-ico { font-size: 15px; color: var(--blue); }
.hint { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.hint code {
  background: var(--neutral-bg);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 11px;
  color: var(--text);
}
