/* Панель врача — оформление.
   Спокойные цвета, крупный шрифт, всё читается с ноутбука и с телефона. */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dfe4ec;
  --border-strong: #c3ccdb;
  --text: #1d2735;
  --text-muted: #66748a;
  --accent: #2f6bd8;
  --accent-dark: #24539f;
  --accent-soft: #e8f0fd;
  --danger: #c8372d;
  --danger-soft: #fdeceb;
  --success: #1f7a4d;
  --success-soft: #e7f6ee;
  --warning: #9a6600;
  --warning-soft: #fdf3dd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 32, 51, .06), 0 4px 14px rgba(20, 32, 51, .06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

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

/* ---------- Шапка ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { font-weight: 650; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }

.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }

.nav a {
  padding: 7px 13px;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-dark); }

.user-menu { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.user-menu .logout { color: var(--text-muted); }

/* ---------- Страница ---------- */

.page { max-width: 1080px; margin: 0 auto; padding: 26px 24px 80px; }
.page.narrow { max-width: 620px; }
.page.wide { max-width: 1320px; }

h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: -.2px; }
h2 { font-size: 19px; margin: 30px 0 12px; }
h3 { font-size: 16px; margin: 22px 0 8px; }

.subtitle { color: var(--text-muted); margin: 0 0 22px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.breadcrumbs { font-size: 14px; color: var(--text-muted); margin-bottom: 10px; }
.breadcrumbs a { color: var(--text-muted); }

/* ---------- Карточки ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 15px;
  font-weight: 650;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-hint { color: var(--text-muted); font-size: 14px; margin: -6px 0 14px; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }

/* ---------- Показатели ---------- */

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.metric-value { font-size: 28px; font-weight: 660; letter-spacing: -.5px; }
.metric-label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ---------- Формы ---------- */

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

label { display: block; font-size: 14px; font-weight: 550; margin-bottom: 5px; }
.label-hint { font-weight: 400; color: var(--text-muted); font-size: 13px; }

input[type=text], input[type=password], input[type=number], input[type=url],
input[type=email], input[type=date], input[type=time], input[type=search],
select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

input:focus, select:focus, textarea:focus, .editor:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { min-height: 100px; resize: vertical; line-height: 1.5; }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 180px; }
.row-tight { gap: 8px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-weight: 400;
  font-size: 15px;
  cursor: pointer;
  padding: 5px 0;
}
.check input { margin: 3px 0 0; width: 17px; height: 17px; flex: none; cursor: pointer; }
.check-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-danger { color: var(--danger); border-color: #eec4c1; background: var(--danger-soft); }
.btn-danger:hover { background: #f9dedb; }

.btn-small { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn-icon { padding: 5px 9px; font-size: 14px; line-height: 1; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Плашки ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: var(--success-soft); color: var(--success); }
.badge-draft { background: #eef0f4; color: var(--text-muted); }
.badge-error { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--accent-soft); color: var(--accent-dark); }

/* ---------- Сообщения ---------- */

.flash-stack { margin-bottom: 18px; display: grid; gap: 8px; }

.flash {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 15px;
}
.flash-success { background: var(--success-soft); border-color: #bfe3d0; color: var(--success); }
.flash-error { background: var(--danger-soft); border-color: #eec4c1; color: var(--danger); }
.flash-close {
  border: 0; background: none; cursor: pointer; font-size: 20px;
  line-height: 1; color: inherit; opacity: .5; padding: 0;
}
.flash-close:hover { opacity: 1; }

.notice {
  padding: 13px 16px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 14.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.notice-error { background: var(--danger-soft); border-color: #eec4c1; color: var(--danger); }
.notice-warn { background: var(--warning-soft); border-color: #eddcb0; color: var(--warning); }

.empty {
  text-align: center;
  padding: 46px 20px;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ---------- Таблицы ---------- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
/* Заголовки обычным регистром: КАПС на русском читается заметно хуже
   латиницы, а слова вроде «ОБОШЁЛСЯ В» в нём выглядят криком. */
th { font-size: 13px; font-weight: 600; color: var(--text-muted); letter-spacing: 0; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Дерево сценария ---------- */

.tree {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 14px;
  line-height: 1.9;
  overflow-x: auto;
  white-space: nowrap;
}
.tree-row { display: block; }
.tree-prefix { color: var(--border-strong); user-select: none; white-space: pre; }
.tree-q { color: var(--text); font-weight: 600; }
.tree-a { color: var(--text-muted); }
.tree-r { color: var(--success); }
.tree-missing { color: var(--danger); font-weight: 600; }
.tree-repeat { color: var(--text-muted); font-style: italic; }

/* ---------- Список файлов ---------- */

.media-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }

.media-item {
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: var(--surface);
}
.media-thumb {
  display: block;
  width: 100%;
  height: 130px;
  object-fit: cover;
  background: var(--bg);
}
.media-file {
  display: flex; align-items: center; justify-content: center;
  height: 130px; background: var(--bg); font-size: 34px;
}
.media-body { padding: 9px 11px; }
.media-name { font-size: 12.5px; color: var(--text-muted); word-break: break-all; }
.media-actions { display: flex; gap: 5px; padding: 0 11px 11px; }

/* ---------- Редактор текста ---------- */

.editor-wrap { border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }

.editor-toolbar {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  padding: 6px 7px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.editor-toolbar button {
  min-width: 32px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.editor-toolbar button:hover { background: var(--surface); border-color: var(--border); }
.editor-toolbar .sep { width: 1px; background: var(--border); margin: 4px 5px; }

.editor {
  min-height: 220px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 14px 16px;
  font-size: 15.5px;
  line-height: 1.6;
}
.editor:empty::before { content: attr(data-placeholder); color: var(--text-muted); }
.editor h2 { font-size: 19px; margin: 18px 0 8px; }
.editor h3 { font-size: 16.5px; margin: 15px 0 6px; }
.editor p { margin: 0 0 11px; }
.editor ul, .editor ol { margin: 0 0 11px; padding-left: 26px; }
.editor li { margin-bottom: 4px; }
.editor blockquote {
  margin: 0 0 11px; padding: 6px 14px;
  border-left: 3px solid var(--border-strong); color: var(--text-muted);
}

/* ---------- График ---------- */

.chart { display: flex; align-items: flex-end; gap: 3px; height: 130px; padding-top: 10px; }
.chart-bar { flex: 1; min-width: 4px; background: var(--accent); border-radius: 3px 3px 0 0; opacity: .85; }
.chart-bar:hover { opacity: 1; }
.chart-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; margin-bottom: 9px; }
.bar-track { background: var(--bg); border-radius: 5px; height: 9px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 5px; }

/* ---------- Мелочи ---------- */

.muted { color: var(--text-muted); }
.small { font-size: 13.5px; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 18px; }
.mb { margin-bottom: 18px; }
.right { text-align: right; }
.divider { height: 1px; background: var(--border); margin: 22px 0; border: 0; }
.inline-form { display: inline; }

/* ---------- Вход ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card { width: 100%; max-width: 380px; }
.login-logo { text-align: center; font-size: 42px; margin-bottom: 10px; }

/* ---------- Телефон ---------- */

@media (max-width: 720px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .nav {
    order: 3; width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }

  .page { padding: 16px 12px 40px; }
  h1 { font-size: 21px; }
  h2 { font-size: 18px; }
  .card { padding: 14px; }
  .metric-value { font-size: 22px; }
  .subtitle { margin-bottom: 16px; }

  /* Поля в одну колонку: на узком экране два поля рядом нечитаемы */
  .row > * { flex: 1 1 100%; min-width: 0; }

  /* Пальцем нужно попадать: минимальная высота нажимаемых элементов */
  .btn { min-height: 44px; padding: 11px 16px; }
  .btn-small { min-height: 36px; padding: 8px 12px; }
  .btn-icon { min-width: 40px; min-height: 40px; }
  input[type=text], input[type=password], input[type=number],
  input[type=url], input[type=email], input[type=date], input[type=time],
  input[type=search], select, textarea {
    padding: 11px 12px;
    /* 16px и больше — иначе Safari на iPhone приближает страницу при фокусе */
    font-size: 16px;
  }
  .check input { width: 22px; height: 22px; }

  /* Главная кнопка формы остаётся на виду, пока карточка на экране */
  .card form > .btn-primary[type=submit],
  form > .btn-primary[type=submit] {
    position: sticky;
    bottom: 10px;
    width: 100%;
    box-shadow: 0 4px 14px rgba(20, 32, 51, .18);
    z-index: 5;
  }

  /* Дерево: вместо псевдографики с прокруткой вбок — отступы и перенос */
  .tree { white-space: normal; font-size: 14.5px; line-height: 1.6; }
  .tree-prefix { display: none; }
  .tree-row {
    display: block;
    padding: 5px 0 5px calc(var(--depth, 0) * 9px + 10px);
    border-left: 2px solid var(--border);
    margin-left: 2px;
  }

  .media-list { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .chart { height: 100px; }
}

/* Совсем узкие экраны */
@media (max-width: 400px) {
  .page { padding: 14px 10px 40px; }
  .card { padding: 12px; }
  .btn-group { gap: 6px; }
  .badge { font-size: 11.5px; padding: 3px 7px; }
}

/* ---------- Подсказки на страницах и гайд ---------- */

/* Ссылка на гайд в верхнем меню — чуть в стороне от рабочих разделов */
.nav .guide-link { margin-left: auto; }

/* Свёрнутая подсказка над содержимым страницы */
.hint {
  background: var(--accent-soft);
  border: 1px solid #cfe0fa;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}
.hint > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent-dark);
  list-style: none;
  user-select: none;
}
.hint > summary::-webkit-details-marker { display: none; }
.hint > summary::after {
  content: "▾";
  float: right;
  transition: transform .15s;
}
.hint[open] > summary::after { transform: rotate(180deg); }
.hint-body { margin-top: 8px; font-size: 15px; }
.hint-body p { margin: 6px 0; }
.hint-body ul, .hint-body ol { margin: 6px 0; padding-left: 22px; }
.hint-body li { margin: 3px 0; }
.hint-more { margin-top: 10px !important; font-size: 14px; }

/* Страница гайда */
.guide-h {
  margin: 28px 0 10px;
  padding-top: 8px;
  font-size: 21px;
  scroll-margin-top: 76px;   /* чтобы якорь не уезжал под шапку */
}
.guide-toc ol { margin: 0; padding-left: 22px; }
.guide-toc li { margin: 5px 0; }
.guide-steps { margin: 10px 0; padding-left: 22px; }
.guide-steps li { margin: 7px 0; }
.guide-term {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.guide-term:first-of-type { border-top: none; }
.guide-term-name { font-weight: 600; }
.guide-term code, .card code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 14px;
}

@media (max-width: 640px) {
  .guide-term { grid-template-columns: 1fr; gap: 2px; }
  .nav .guide-link { margin-left: 0; }
}

/* ==========================================================================
   ТЕЛЕФОН — основной способ работы, а не «уменьшенный компьютер»

   Врач работает с панелью только с телефона. Поэтому здесь не косметика,
   а другая раскладка: таблицы разворачиваются в карточки, палец попадает
   в кнопки, вертикальное место экономится везде, где можно.
   ========================================================================== */

/* Длинный адрес или ссылка не должны распирать страницу вбок */
body { overflow-wrap: break-word; }

@media (max-width: 720px) {

  /* --- Шапка ------------------------------------------------------------
     Прилипшая шапка съедала бы около сотни точек по высоте постоянно —
     на телефоне это дороже, чем удобство перехода между разделами. */
  .topbar { position: static; }

  /* Меню на свою строку. Одного width: 100% мало: базовое .nav { flex: 1 }
     задаёт flex-basis: 0, и в раскладке flex он сильнее ширины. Меню
     ужималось в остаток строки (около 85px), все разделы уходили
     в прокрутку — человек видел один пункт и не догадывался об остальных. */
  .nav { flex: 0 0 100%; width: 100%; padding-bottom: 2px; }
  .nav a { padding: 9px 13px; min-height: 40px; display: flex; align-items: center; }
  .nav::after { content: ""; flex: 0 0 4px; }
  .nav .guide-link { margin-left: 0; }

  /* --- Заголовок страницы ----------------------------------------------- */
  .page-head { gap: 10px; margin-bottom: 16px; }
  .page-head > a.btn,
  .page-head > div > a.btn { width: 100%; text-align: center; }
  .breadcrumbs { font-size: 13px; }

  /* --- Строки формы раскладываются в столбик -----------------------------
     В шаблонах ширина колонок задана прямо в разметке (style="flex:2"),
     а такие правила сильнее обычных. Без !important поля остаются в ряд
     и последнее уезжает за край экрана. */
  .row > *,
  .row-tight > * { flex: 1 1 100% !important; width: auto !important; min-width: 0; }

  /* --- Кнопка сохранения --------------------------------------------------
     Висит над формой, чтобы не искать её внизу длинной страницы. Значит
     под формой нужен запас: иначе она накрывает последнее поле. */
  /* Запас снизу, чтобы липкая кнопка не накрывала последнее поле.
     Без :has(): его понимают не все телефоны, а промах тут дорогой. */
  .page { padding-bottom: 96px; }
  form > .btn-primary[type=submit] { margin-bottom: 8px; }
  .card form > .btn-primary[type=submit],
  form > .btn-primary[type=submit] { bottom: 12px; font-size: 16px; min-height: 48px; }

  /* --- Редактор текста ----------------------------------------------------
     Здесь врач проводит больше всего времени. Панель переносится на две
     строки, а не прокручивается вбок: видно сразу все возможности. */
  .editor-toolbar { gap: 4px; padding: 7px; }
  .editor-toolbar button { min-width: 42px; height: 42px; font-size: 16px; }
  .editor-toolbar .sep { margin: 6px 3px; }
  .editor {
    min-height: 300px;
    max-height: 65vh;
    font-size: 16px;   /* меньше 16px — Safari приближает страницу */
    padding: 12px 13px;
  }

  /* --- Файлы --------------------------------------------------------------
     Две колонки превращали миниатюры в марки. Одна колонка — зато видно,
     что на картинке, и подпись помещается целиком. */
  .media-list { grid-template-columns: 1fr; gap: 12px; }
  .media-thumb { height: 190px; object-fit: contain; padding: 6px; }
  .media-body { padding: 10px 11px 0; }
  .media-body input[type=text] { flex: 1; min-width: 0; font-size: 16px !important; }
  .media-actions { padding: 10px 11px 11px; }
  .media-actions .btn-icon { flex: 1; min-height: 42px; }

  /* Системная кнопка выбора файла мелкая и прижата к краю */
  input[type=file] {
    width: 100%;
    padding: 10px;
    border: 1px dashed var(--border-strong);
    border-radius: 8px;
    background: var(--bg);
    font-size: 15px;
  }

  /* --- Показатели и прочее ------------------------------------------------ */
  .grid { gap: 12px; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .metric { padding: 12px; }
  .metric-value { font-size: 20px; }
  .metric-label { font-size: 12.5px; }
  .hint { padding: 9px 12px; }
  .hint-body { font-size: 15px; }
  .guide-h { font-size: 19px; scroll-margin-top: 12px; }
  .guide-term { grid-template-columns: 1fr; gap: 2px; }
  .btn-group { flex-wrap: wrap; }
  .btn-group .btn { flex: 1 1 auto; }
  .card-title { flex-wrap: wrap; gap: 6px; }
  .bar-row { grid-template-columns: 1fr; gap: 3px; }
}

/* Совсем узкие экраны: старые и компактные телефоны */
@media (max-width: 380px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .editor-toolbar button { min-width: 40px; height: 40px; }
}

/* ============================================================
   Плитки показателей на сводке
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat {
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e3e6ea);
  border-radius: 10px;
  padding: 14px 16px;
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
}

.stat-label {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-muted, #6b7280);
}

.right { text-align: right; }

/* ============================================================
   Раскладка форм и таблиц
   ============================================================ */
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
.checkbox input { width: auto; margin: 0; }

/* Итоговая строка таблицы */
.row-total td {
  border-top: 2px solid var(--border, #e3e6ea);
  background: var(--surface-muted, #f7f8fa);
}

details summary { cursor: pointer; }


/* ============================================================
   Боковое меню. На десктопе слева, на телефоне — выезжает
   по бургеру. Ширина фиксированная: содержимое не прыгает
   при переходе между разделами.
   ============================================================ */
:root {
  --sidebar-width: 240px;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--surface, #fff);
  border-right: 1px solid var(--border, #e3e6ea);
  z-index: 40;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.25;
  color: var(--text, #1f2430);
  text-decoration: none;
  border-bottom: 1px solid var(--border, #e3e6ea);
}
.sidebar .brand .icon { flex: none; }

.sidebar .nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 10px;
  flex: 1;
}

.sidebar .nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-muted, #6b7280);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.sidebar .nav a:hover { background: var(--surface-muted, #f2f4f7); color: var(--text, #1f2430); }
.sidebar .nav a.active {
  background: var(--accent-soft, #e8f0fe);
  color: var(--accent-dark, #1a56c4);
  font-weight: 500;
}

.nav-divider {
  height: 1px;
  background: var(--border, #e3e6ea);
  margin: 10px 12px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border, #e3e6ea);
}
.sidebar-footer .user-link {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted, #6b7280);
  text-decoration: none;
}
.sidebar-footer .user-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-footer .user-link:hover { background: var(--surface-muted, #f2f4f7); }
.sidebar-footer .logout {
  display: flex;
  padding: 7px;
  border-radius: 8px;
  color: var(--text-muted, #6b7280);
}
.sidebar-footer .logout:hover { background: var(--danger-soft, #fdeceb); color: var(--danger, #c0392b); }

.icon { width: 18px; height: 18px; flex: none; }

/* Контент сдвигается вправо на ширину меню */
.page {
  margin-left: var(--sidebar-width);
  padding: 28px 32px 60px;
  max-width: 1180px;
}
.page-plain { margin-left: 0; }

.burger,
.sidebar-backdrop { display: none; }

/* ------------------------------------------------------------
   Телефон и планшет: меню прячется, открывается бургером
   ------------------------------------------------------------ */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .12);
  }
  .sidebar.open { transform: translateX(0); }

  .page { margin-left: 0; padding: 64px 16px 48px; }

  .burger {
    display: flex;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 50;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border, #e3e6ea);
    border-radius: 9px;
    background: var(--surface, #fff);
    color: var(--text, #1f2430);
    cursor: pointer;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(15, 20, 30, .35);
  }
  .sidebar-backdrop.show { display: block; }
}

/* ============================================================
   Сегменты участников
   ============================================================ */
.segment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}

.segment {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--border, #e3e6ea);
  border-radius: 10px;
  background: var(--surface, #fff);
  text-decoration: none;
  color: inherit;
}
.segment:hover { border-color: var(--accent, #2f6fe4); }
.segment.active {
  border-color: var(--accent, #2f6fe4);
  background: var(--accent-soft, #e8f0fe);
}
.segment-count { font-size: 22px; font-weight: 600; line-height: 1.1; }
.segment-title { font-size: 13px; color: var(--text-muted, #6b7280); }
.segment.active .segment-title { color: var(--accent-dark, #1a56c4); }

/* Плитка-ссылка на сводке */
a.stat { text-decoration: none; color: inherit; display: block; }
a.stat:hover { border-color: var(--accent, #2f6fe4); }

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 14px;
}
.filter-row input[type="text"] { flex: 1; min-width: 200px; }
.filter-row select { width: auto; min-width: 160px; }

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.btn .icon { width: 15px; height: 15px; vertical-align: -2px; }


/* ============================================================
   Дата и время. Браузерные поля по умолчанию выпадают из
   оформления: своя рамка, свой шрифт, крошечная иконка календаря.
   Приводим к общему виду и делаем кликабельной всю область,
   а не только значок справа.
   ============================================================ */
input[type=date],
input[type=time] {
  max-width: 220px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

/* Подложку под значок не ставим: в Chrome он рисуется фоновой
   картинкой, и любой background поверх просто закрывает иконку. */
input[type=date]::-webkit-calendar-picker-indicator,
input[type=time]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: .6;
  transition: opacity .15s;
}
input[type=date]:hover::-webkit-calendar-picker-indicator,
input[type=time]:hover::-webkit-calendar-picker-indicator {
  opacity: 1;
}

input[type=date]::-webkit-datetime-edit,
input[type=time]::-webkit-datetime-edit { padding: 0; }

/* Подпись под парой дат: «с … по …» читается как одно поле */
.date-range {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.date-range .field { margin: 0; }
.date-range .dash {
  padding-bottom: 10px;
  color: var(--text-muted, #6b7280);
}

/* ============================================================
   Таблицы панели: рамка, шапка, читаемые строки.
   Базовый стиль давал только нижнюю границу — списки
   расползались и выглядели как набор строк без структуры.
   ============================================================ */
/* Рамка и скругление живут на обёртке, а не на самой таблице:
   свойство overflow для табличных элементов спецификацией не определено,
   и браузер начинает считать ширину колонок по-своему — шапка съезжает
   относительно строк. */
.table-wrap {
  border: 1px solid var(--border, #e3e6ea);
  border-radius: 10px;
  overflow-x: auto;
  background: var(--surface, #fff);
  margin-bottom: 18px;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  /* Раскладка по содержимому.
     Здесь раньше стояло table-layout: fixed — и это ломало все таблицы
     сразу. При фиксированной раскладке браузер делит ширину ПОРОВНУ
     между колонками, у которых не задана ширина явно. В результате
     колонка с числом «5» получала столько же места, сколько колонка
     с именем и датой: заголовок прижимался влево, число — вправо,
     а между ними зияла пустота в половину экрана.
     Раскладка по содержимому даёт колонкам ровно столько, сколько им
     нужно. Заголовок и значение оказываются рядом, потому что колонка
     не шире их обоих. */
  table-layout: auto;
  /* Ниже этого таблица не сжимается — обёртка начинает прокручиваться.
     Значение подобрано так, чтобы на телефоне читались первые две
     колонки: сжимать их до нечитаемости хуже, чем прокручивать. */
  min-width: 560px;
  border-collapse: collapse;
  font-size: 14px;
  background: var(--surface, #fff);
}

.table thead th {
  background: var(--surface-muted, #f7f8fa);
  border-bottom: 1px solid var(--border, #e3e6ea);
  padding: 11px 14px;
  font-size: 12px;
  text-align: left;
  /* Заголовок не переносится: при раскладке по содержимому он сам
     задаёт колонке ширину, и колонка получается ровно такой, чтобы
     и заголовок, и значения читались целиком. */
  white-space: nowrap;
}

/* Числовые заголовки — вправе, к своим числам.
   Правило выше задаёт text-align: left всем заголовкам и стоит ПОЗЖЕ
   общего th.num, поэтому перебивало его: заголовок «Запросов» жался
   влево, а число под ним уходило вправо. Порядок в файле решает. */
.table thead th.num,
.table tbody td.num { text-align: right; }

.table tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft, #eef0f3);
  vertical-align: top;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-muted, #f7f8fa); }

/* Числовые колонки — моноширинные цифры, чтобы разряды совпадали */
.table .right,
.table th.right { text-align: right; font-variant-numeric: tabular-nums; }

/* Вторая строка ячейки: username, id, пояснение */
.table .small { font-size: 12.5px; line-height: 1.45; }
.table code {
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-muted, #f2f4f7);
}


@media (max-width: 700px) {
  .table { font-size: 13px; }
  .table thead th,
  .table tbody td { padding: 9px 10px; }
}

/* Плитки сегментов и сводки — это карточки, а не ссылки в тексте:
   подчёркивание при наведении здесь выглядит как ошибка вёрстки */
.segment,
.segment:hover,
a.stat,
a.stat:hover { text-decoration: none; }

/* Протокол розыгрыша и карточки победителей */
.winner-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft, #eef0f3);
}
.winner-row:last-child { border-bottom: 0; }
.winner-main { background: var(--success-soft, #e9f7ef); border-radius: 8px; padding: 12px; }
.stage-card.stage-empty { opacity: .72; }

/* ============================================================
   Поля ввода внутри таблиц.
   Без этого input держит собственную ширину, ячейка растягивается
   под него, и содержимое перестаёт стоять под своим заголовком.
   ============================================================ */
.table td input[type=text],
.table td input[type=number],
.table td input[type=time],
.table td input[type=date],
.table td select,
.table td textarea {
  width: 100%;
  min-width: 0;
  margin: 0;
  box-sizing: border-box;
}

/* Ячейки с элементами управления выравниваем по центру строки,
   иначе кнопка висит выше текста соседней колонки */
.table td:has(input),
.table td:has(select),
.table td:has(button) { vertical-align: middle; }

/* Ширины колонок задаются только через <col> — см. ниже.
   Классы на ячейках оставляем лишь для выравнивания и переносов. */
.table .col-actions { white-space: nowrap; }

.table td.col-actions form { display: inline-block; margin-left: 4px; }
.table td.col-actions form:first-child { margin-left: 0; }

/* Формы прямо в строке таблицы: элементы в один ряд, без переносов */
.table .filter-row {
  margin: 8px 0 0;
  gap: 6px;
  flex-wrap: nowrap;
}
.table .filter-row input[type=text] { min-width: 120px; }

/* ============================================================
   Модальное подтверждение опасных действий
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 20, 30, .45);
}

.modal {
  width: 100%;
  max-width: 460px;
  background: var(--surface, #fff);
  border-radius: 12px;
  padding: 22px 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.modal h3 { margin: 0 0 10px; font-size: 17px; }
.modal p { margin: 0 0 12px; line-height: 1.5; }
.modal input { margin-bottom: 4px; }
.modal-danger { border-top: 3px solid var(--danger, #c0392b); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ============================================================
   Подсказка по разметке рядом с полями текста
   ============================================================ */
.format-hint {
  margin-top: 8px;
  border: 1px solid var(--border, #e3e6ea);
  border-radius: 8px;
  background: var(--surface-muted, #f7f8fa);
}
.format-hint > summary {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted, #6b7280);
  user-select: none;
}
.format-hint[open] > summary { border-bottom: 1px solid var(--border, #e3e6ea); }
.format-hint-body { padding: 12px; }
.format-hint-body p:last-child { margin-bottom: 0; }

.format-table { width: auto; font-size: 13px; margin-bottom: 10px; }
.format-table td { padding: 3px 14px 3px 0; border: 0; }
.format-table code { font-size: 12px; }

.stage-card { position: relative; }

/* ============================================================
   Боковая справка
   ============================================================ */
.help-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent, #2f6fe4);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(47, 111, 228, .35);
}
.help-fab:hover { filter: brightness(1.07); }
.help-fab .icon { width: 22px; height: 22px; }

.help-backdrop {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: none;
  background: rgba(15, 20, 30, .3);
}
.help-backdrop.show { display: block; }

.help-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  width: 420px;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  background: var(--surface, #fff);
  border-left: 1px solid var(--border, #e3e6ea);
  box-shadow: -8px 0 40px rgba(0, 0, 0, .12);
  transform: translateX(100%);
  transition: transform .22s ease;
}
.help-drawer.open { transform: translateX(0); }

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border, #e3e6ea);
  font-size: 15px;
}
.help-close {
  border: 0;
  background: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted, #6b7280);
  padding: 0 4px;
}
.help-close:hover { color: var(--text, #1f2430); }

.help-search { padding: 12px 18px; border-bottom: 1px solid var(--border, #e3e6ea); }
.help-search input { width: 100%; margin: 0; }

.help-body { flex: 1; overflow-y: auto; padding: 6px 18px 30px; }

.help-section-title {
  margin: 16px 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--text-muted, #6b7280);
}

.help-topic { border-bottom: 1px solid var(--border-soft, #eef0f3); }
.help-topic > summary {
  padding: 10px 0;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  user-select: none;
}
.help-topic > summary:hover { color: var(--accent, #2f6fe4); }
.help-topic-body { padding: 0 0 14px; font-size: 13.5px; line-height: 1.6; }
.help-topic-body p { margin: 0 0 10px; }
.help-topic-body ul,
.help-topic-body ol { margin: 0 0 10px; padding-left: 20px; }
.help-topic-body li { margin-bottom: 5px; }
.help-topic-body code {
  font-size: 12px;
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--surface-muted, #f2f4f7);
}

.help-table { width: 100%; font-size: 13px; margin-bottom: 10px; }
.help-table td {
  padding: 4px 10px 4px 0;
  border: 0;
  border-bottom: 1px solid var(--border-soft, #eef0f3);
  vertical-align: top;
}

.help-danger {
  padding: 9px 11px;
  border-radius: 7px;
  background: var(--danger-soft, #fdeceb);
  color: var(--danger, #c0392b);
}

.help-empty { padding: 20px 0; color: var(--text-muted, #6b7280); font-size: 13.5px; }

@media (max-width: 560px) {
  .help-drawer { width: 100vw; }
  .help-fab { right: 14px; bottom: 14px; }
}

/* ============================================================
   Раскладка колонок.

   Доли задаются через <col> прямо в таблице, а table-layout: fixed
   заставляет браузер их соблюдать. Сумма долей может не давать ровно
   100% — браузер разложит их пропорционально, пропорции сохранятся.
   ============================================================ */
.table th,
.table td {
  /* Длинный ник или ссылка переносятся внутри своей колонки,
     а не выталкивают соседнюю */
  overflow-wrap: anywhere;
  word-break: break-word;
}

.table col.w-name { width: 26%; }
.table col.w-wide { width: 30%; }
.table col.w-ticket { width: 11%; }
.table col.w-status { width: 14%; }
.table col.w-source { width: 13%; }
.table col.w-date { width: 12%; }
.table col.w-num { width: 8%; }
.table col.w-text { width: 20%; }
.table col.w-actions { width: 14%; }
.table col.w-icon { width: 8%; }

/* Таблица «свойство → значение» на карточке участника и в протоколе.
   Это не список: колонок две, доли ей не нужны, а min-width заставил бы
   узкую карточку прокручиваться вбок на пустом месте. */
.table-facts {
  table-layout: auto;
  min-width: 0;
}
.help-foot {
  border-top: 1px solid var(--border, #e3e6ea);
  padding: 12px 16px;
  font-size: 13px;
  background: var(--surface-muted, #f7f8fa);
}

/* Несколько иконок-действий в одной ячейке — в ряд и по правому краю */
.row-actions {
  display: inline-flex;
  flex-wrap: wrap;      /* на узком экране вторая иконка уходит вниз, а не за край */
  gap: 6px;
  justify-content: flex-end;
}

.readonly-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 11px 14px;
  border: 1px solid var(--border, #e3e6ea);
  border-radius: 10px;
  background: var(--surface-muted, #f7f8fa);
  color: var(--text-muted, #6b7280);
  font-size: 13.5px;
}
.readonly-note .icon { flex: 0 0 auto; width: 17px; height: 17px; }

/* Режим наблюдателя: выключенная кнопка не должна выглядеть нажимаемой */
body.readonly button:disabled,
body.readonly input:disabled,
body.readonly select:disabled,
body.readonly textarea:disabled { cursor: not-allowed; }

/* ============================================================
   Переключатель состояния в таблице.

   Заменил пару «бейдж + кнопка во всю колонку»: свойство описывалось
   дважды, а подпись «Сделать необязательным» не влезала и переносилась
   в две строки. Тумблер показывает текущее состояние и меняет его одним
   нажатием — это одна сущность, а не две.
   ============================================================ */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  color: var(--text-muted, #6b7280);
  text-align: left;
}
.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--border, #d7dbe0);
  transition: background .15s ease;
}
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .3);
  transition: transform .15s ease;
}
.switch-on .switch-track { background: var(--success, #16a34a); }
.switch-on .switch-knob { transform: translateX(14px); }
.switch-on .switch-text { color: var(--text, #111827); font-weight: 600; }
.switch:hover:not(:disabled) .switch-track { filter: brightness(.95); }
.switch:focus-visible { outline: 2px solid var(--primary, #2563eb); outline-offset: 3px; border-radius: 4px; }
.switch:disabled { cursor: not-allowed; opacity: .5; }

/* ============================================================
   Кнопка-иконка: одно действие без подписи.
   Занимает место одной иконки вместо кнопки с текстом — в колонке
   действий это разница между аккуратным столбцом и кашей.
   ============================================================ */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border, #e3e6ea);
  border-radius: 8px;
  background: var(--surface, #fff);
  color: var(--text-muted, #6b7280);
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.btn-icon .icon { width: 16px; height: 16px; }
.btn-icon:hover { background: var(--surface-muted, #f7f8fa); color: var(--text, #111827); }
.btn-icon:focus-visible { outline: 2px solid var(--primary, #2563eb); outline-offset: 2px; }
.btn-icon-danger:hover {
  background: var(--danger-soft, #fdeaea);
  border-color: var(--danger, #dc2626);
  color: var(--danger, #dc2626);
}
.btn-icon:disabled { opacity: .45; cursor: not-allowed; }

/* Содержимое ячейки не выходит за свою колонку.

   При фиксированной раскладке колонка не расширяется под контент — значит
   всё, что шире, обязано переноситься само. Бейдж «нет прав администратора»
   без этого вылезал на соседнюю колонку и наезжал на её текст. */
.table td .badge {
  white-space: normal;
  max-width: 100%;
}
.table td input,
.table td select,
.table td textarea,
.table td .inline-form {
  max-width: 100%;
}
/* Кнопка с длинной подписью («Сделать необязательным») переносит текст,
   а не вылезает из колонки — расширить её колонка уже не может. */
.table td .btn {
  white-space: normal;
  max-width: 100%;
  text-align: center;
}
.table td .inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
/* В колонке действий кнопки прижаты к правому краю — там же, где заголовок.
   display у самой ячейки менять нельзя: table-cell — часть табличной
   раскладки, и flex вместо него рассыпает всю строку. Поэтому выравниваем
   через text-align ячейки и inline-flex внутри неё. */
.table td.right .inline-form { display: inline-flex; justify-content: flex-end; }

.table-facts td:first-child {
  width: 42%;
  color: var(--text-muted, #6b7280);
}

/* ============================================================
   Мобильная шапка.
   Раньше бургер висел поверх содержимого и наезжал на название
   в выехавшем меню. Теперь это отдельная полоса: название всегда
   видно, а меню выезжает под ней и ничего не перекрывает.
   ============================================================ */
.mobile-bar { display: none; }

@media (max-width: 900px) {
  .mobile-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 54px;
    padding: 0 12px;
    background: var(--surface, #fff);
    border-bottom: 1px solid var(--border, #e3e6ea);
  }

  .mobile-title {
    font-weight: 600;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .burger {
    display: flex;
    position: static;          /* больше не висит поверх содержимого */
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: none;
    border: 1px solid var(--border, #e3e6ea);
    border-radius: 9px;
    background: var(--surface, #fff);
    color: var(--text, #1f2430);
    cursor: pointer;
  }

  /* Меню выезжает ПОД шапкой, а не поверх неё */
  .sidebar {
    top: 54px;
    width: 270px;
    max-width: 84vw;
  }
  .sidebar .brand { display: none; }   /* название уже есть в шапке */
  .sidebar-backdrop { top: 54px; }

  .page { padding-top: 70px; }

  /* Пальцем попадать проще по крупным целям */
  .sidebar .nav a { padding: 12px 14px; font-size: 15px; }
  .sidebar-footer { padding: 14px 12px; }
}

/* ============================================================
   Резиновость: всё, что на десктопе в строку, на телефоне в столбик
   ============================================================ */
@media (max-width: 700px) {
  h1 { font-size: 22px; }
  h2 { font-size: 17px; }

  .card { padding: 14px; border-radius: 10px; }

  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .stat { padding: 11px 12px; }
  .stat-value { font-size: 20px; }

  .segment-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

  .row-between { flex-direction: column; align-items: stretch; gap: 10px; }
  .row-between .card-actions { justify-content: flex-start; }

  .filter-row { flex-direction: column; align-items: stretch; }
  .filter-row input,
  .filter-row select,
  .filter-row .btn { width: 100%; }

  .date-range { flex-direction: column; align-items: stretch; gap: 8px; }
  .date-range .dash { display: none; }
  input[type=date], input[type=time] { max-width: none; }

  /* Кнопки в формах не жмутся в угол, а занимают строку целиком */
  .stack .btn,
  .modal-actions .btn { width: 100%; }
  .modal-actions { flex-direction: column-reverse; }

  .pager { flex-wrap: wrap; }

  /* Поля не должны вызывать зум при фокусе на iOS: там порог 16px */
  input, select, textarea { font-size: 16px; }
}

/* ============================================================
   Победители: карточка вместо строки в ряд
   ============================================================ */
.prize-card { padding: 0; overflow: hidden; }

.prize-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border, #e3e6ea);
  background: var(--surface-muted, #f7f8fa);
}
.prize-head h3 { margin: 0; font-size: 16px; }

.winner {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft, #eef0f3);
}
.winner:last-child { border-bottom: 0; }
.winner-main { background: var(--success-soft, #e9f7ef); }

.winner-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.winner-who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.winner-name { font-weight: 600; }
.winner-state { display: flex; align-items: center; gap: 8px; flex: none; }

.winner-edit { margin-top: 10px; }
.winner-edit > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted, #6b7280);
  user-select: none;
}
.winner-edit > summary:hover { color: var(--accent, #2f6fe4); }

.winner-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-top: 12px;
}
.winner-form .field { margin: 0; min-width: 170px; }
.winner-form .field-grow { flex: 1; min-width: 200px; }
.winner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty-state { text-align: center; color: var(--text-muted, #6b7280); }
.empty-state p { margin-bottom: 12px; }

.text-danger { color: var(--danger, #c0392b); }

@media (max-width: 700px) {
  .winner-form { flex-direction: column; align-items: stretch; }
  .winner-form .field,
  .winner-form .field-grow { min-width: 0; width: 100%; }
  .winner-actions .btn { width: 100%; }
  .winner-top { flex-direction: column; }
}

/* ============================================================
   Страница входа
   ============================================================ */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;          /* на телефоне адресная строка съедает vh */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e3e6ea);
  border-radius: 14px;
  padding: 30px 28px 24px;
  box-shadow: 0 10px 40px rgba(20, 30, 50, .07);
  text-align: center;
}

.login-logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--accent-soft, #e8f0fe);
  color: var(--accent, #2f6fe4);
}
.login-logo .icon { width: 26px; height: 26px; }

.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-sub { margin: 0 0 22px; font-size: 13.5px; color: var(--text-muted, #6b7280); }
.login-error { text-align: left; margin-bottom: 16px; }

.login-form { text-align: left; }
.login-form .field { margin-bottom: 14px; }
.login-form label { font-size: 13px; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 44px; }

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text-muted, #9aa1ad);
  cursor: pointer;
}
.password-toggle:hover { background: var(--surface-muted, #f2f4f7); }
.password-toggle.active { color: var(--accent, #2f6fe4); }

.login-submit { width: 100%; margin-top: 4px; padding: 11px; font-size: 15px; }

.login-hint {
  margin: 16px 0 0;
  font-size: 12.5px;
  color: var(--text-muted, #6b7280);
}

.login-footer { margin: 0; }

/* Страница входа без бокового меню — контент не сдвигаем */
.page-plain { margin-left: 0; padding: 0; max-width: none; }

/* Инструкция одной страницей */
.guide-article h3 { margin: 0 0 10px; font-size: 16px; }
.guide-body { font-size: 14px; line-height: 1.65; }
.guide-body p { margin: 0 0 10px; }
.guide-body ul,
.guide-body ol { margin: 0 0 10px; padding-left: 22px; }
.guide-body li { margin-bottom: 6px; }
.guide-body p:last-child,
.guide-body ul:last-child,
.guide-body ol:last-child { margin-bottom: 0; }
.guide-body .help-table { max-width: 620px; }

/* Форма смены пароля и сетка полей */
.password-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.password-form .field { margin: 0; flex: 1; min-width: 160px; }
.password-form .field-button { flex: none; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.grid-2 .field { margin: 0; }

.reset-row td { background: var(--surface-muted, #f7f8fa); }

@media (max-width: 700px) {
  .password-form { flex-direction: column; align-items: stretch; }
  .password-form .field { min-width: 0; }
  .password-form .btn { width: 100%; }
}

/* Ссылка-подсказка рядом с полем текста */
.hint-link {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin: 6px 0 0;
}
.hint-link a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  color: var(--accent, #2f6fe4);
}
.hint-link a:hover { text-decoration: underline; }
.hint-link .icon { width: 15px; height: 15px; }

/* ==========================================================================
   Рецепты и категории
   ========================================================================== */

/* Строка фильтров над списком */
.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 18px;
}
.filters input[type="search"] { flex: 1 1 260px; min-width: 0; }
.filters select { flex: 0 1 200px; }

/* Превью фотографии в списке. Фиксированный размер намеренно:
   без него строки таблицы прыгают по высоте вслед за пропорциями
   снимков, и список читается тяжело. */
.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
  background: var(--bg);
}
.thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--border-strong);
}

/* Фотография в карточке */
.photo-current {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.photo-current img {
  width: 180px;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* ==========================================================================
   Формы
   ========================================================================== */

.field-title {
  display: block;
  font-weight: 550;
  font-size: 14px;
  margin-bottom: 5px;
}
.field-hint {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 5px;
  line-height: 1.45;
}

/* Несколько полей в строку. На телефоне сами встают в столбец —
   поля КБЖУ в четыре колонки на узком экране нечитаемы. */
.field-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.field-row > .field { flex: 1 1 180px; min-width: 0; }

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 22px 0;
}

/* Моноширинный ввод — для состава, где выравнивание по столбцам
   помогает увидеть строку целиком */
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.6;
}

/* Опасное действие отделено от формы и визуально, и по расстоянию:
   кнопка удаления не должна стоять рядом с кнопкой сохранения */
.danger-zone {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 34px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ==========================================================================
   Постраничная навигация и плитки
   ========================================================================== */

.pager-current {
  display: inline-block;
  padding: 5px 11px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.stat-note {
  color: var(--text-muted);
  font-size: 12.5px;
  margin-top: 3px;
}
.stat-warn { border-color: #eddcb0; background: var(--warning-soft); }

.table.compact th,
.table.compact td { padding: 7px 10px; font-size: 14px; }

@media (max-width: 640px) {
  .field-row { gap: 0; }
  .field-row > .field { flex: 1 1 100%; }
  .photo-current { flex-direction: column; }
  .photo-current img { width: 100%; height: auto; max-height: 260px; }
}

/* ==========================================================================
   Список с порядком: категории, тарифы
   ========================================================================== */

/* Добавление одним полем. Всё лишнее — порядок, галочки — спрашивать
   здесь нельзя: человек создаёт категорию, а не заполняет анкету. */
.add-row { display: flex; gap: 10px; align-items: center; }
.add-row input[type="text"] { flex: 1; min-width: 0; }

.order-list { display: grid; gap: 8px; margin-bottom: 16px; }

.order-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.order-item.is-hidden { background: var(--bg); border-style: dashed; }
.order-item.is-hidden .order-name input { color: var(--text-muted); }

.order-arrows { display: flex; flex-direction: column; gap: 2px; }
.arrow {
  width: 26px;
  height: 20px;
  line-height: 1;
  padding: 0;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
}
.arrow:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.arrow:disabled { opacity: .3; cursor: default; }

.order-name { display: flex; gap: 8px; align-items: center; flex: 1; min-width: 0; }
.order-name input { flex: 1; min-width: 0; }

.order-count { flex: 0 0 120px; font-size: 14px; text-align: right; }
.order-actions { display: flex; gap: 6px; align-items: center; }

/* Недоступное действие показываем выключенным, а не прячем: исчезнувшая
   кнопка выглядит как поломка, а выключенная объясняет себя подсказкой. */
.btn-off {
  opacity: .45;
  cursor: not-allowed;
  display: inline-flex;
  align-items: center;
}

@media (max-width: 720px) {
  .order-item { flex-wrap: wrap; }
  .order-name { flex: 1 1 100%; order: 1; }
  .order-arrows { order: 0; flex-direction: row; }
  .order-count { order: 2; flex: 1; text-align: left; }
  .order-actions { order: 3; }
  .add-row { flex-wrap: wrap; }
  .add-row input[type="text"] { flex: 1 1 100%; }
}

/* ==========================================================================
   Тарифы
   ========================================================================== */

/* Карточка тарифа читается сверху вниз: кто это — что правим — что делаем.
   Раньше кнопки стояли сбоку от полей и «Удалить» оказывалось на одной
   линии с ценой; попасть не туда было делом одного промаха мышью. */
.plan-list { display: grid; gap: 14px; margin-bottom: 22px; }

.plan-card {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
/* Снятый с продажи виден, но явно отличается: спрятать его нельзя —
   заказчик должен понимать, что тариф существует и почему не продаётся */
.plan-card.is-hidden { background: var(--bg); border-style: dashed; }

.plan-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.plan-head-gap { flex: 1; }

/* Номер = место в списке у покупателя. Он же объясняет, что двигают стрелки */
.plan-num {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12.5px;
  font-weight: 600;
}
.plan-name { font-size: 15.5px; overflow-wrap: anywhere; }
.plan-card.is-hidden .plan-name { color: var(--text-muted); }

.plan-arrows { display: flex; gap: 4px; }

/* Сетка вместо flex-обёртки: у названия своя доля ширины, у трёх чисел —
   своя, и поля не прыгают при каждом изменении длины заголовка. */
.plan-grid {
  display: grid;
  grid-template-columns: minmax(200px, 2.2fr) 120px 150px 150px;
  gap: 4px 16px;
  align-items: start;
}
.plan-grid > .field { min-width: 0; margin-bottom: 12px; }
.plan-grid > .field-wide { grid-column: 1 / -1; }

.plan-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.plan-foot form { display: inline-flex; }
/* Действия над тарифом целиком — у правого края, подальше от «Сохранить» */
.plan-foot-side { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* В карточке «Добавить тариф» подвал один, разделять нечего */
.card .plan-foot { border-top: 0; padding-top: 4px; }

@media (max-width: 900px) {
  .plan-grid { grid-template-columns: 1fr 1fr; }
  .plan-grid > .field-wide { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .plan-grid { grid-template-columns: 1fr; }
  .plan-foot-side { margin-left: 0; width: 100%; }
}

/* ==========================================================================
   Пользователи, платежи, расход
   ========================================================================== */

/* Сегменты списком-таблетками: их десяток, и выпадающий список
   прятал бы от оператора самое полезное — размеры сегментов */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13.5px;
  color: var(--text);
  text-decoration: none;
}
.chip:hover { border-color: var(--border-strong); }
.chip-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-count { font-weight: 600; opacity: .75; }
.chip-active .chip-count { opacity: .9; }

.plus { color: var(--success); font-weight: 600; }
.minus { color: var(--danger); font-weight: 600; }

/* Анкета показывается как есть, построчно */
pre.plain {
  margin: 0 0 14px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* Столбики расхода по дням. Без библиотек: четырнадцать значений
   не стоят подключения графической библиотеки на каждую страницу. */
.spark {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 130px;
  margin-top: 14px;
}
.spark-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
}
.spark-bar {
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: background .15s;
}
.spark-col:hover .spark-bar { background: var(--accent-dark); }
.spark-label {
  font-size: 10.5px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 5px;
  white-space: nowrap;
  overflow: hidden;
}

.badge-warn { background: var(--warning-soft); color: var(--warning); }

/* ==========================================================================
   График расхода
   ========================================================================== */

.chart { width: 100%; margin-top: 12px; }
.chart svg { width: 100%; height: 220px; display: block; overflow: visible; }

.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { fill: var(--text-muted); font-size: 11px; }
.chart-area { fill: var(--accent); opacity: .10; }
.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.chart-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
/* Область наведения на всю высоту: попасть мышью в кружок радиусом
   четыре пикселя человек не сможет, а в полосу — всегда */
.chart-hit { fill: transparent; }
.chart-hit:hover { fill: var(--accent); opacity: .06; }

/* Ссылки в таблицах не подчёркиваются при наведении — в плотном списке
   подчёркивание дёргает строку и мешает читать */
.table a { text-decoration: none; }
.table a:hover { text-decoration: underline; }

/* ==========================================================================
   Карточка человека: поля «название — значение»
   ========================================================================== */

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px 22px;
}
.fact { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fact > span:first-child { font-size: 12.5px; color: var(--text-muted); }
.fact > b { font-size: 15px; overflow-wrap: anywhere; }
.fact-note { font-size: 12px; color: var(--text-muted); }

/* ==========================================================================
   Метки источников
   ========================================================================== */

/* Ссылка и QR рядом: заказчик приходит сюда за тем, что можно отдать
   блогеру, и оба способа отдать должны быть на виду одновременно. */
.source-share { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }
.source-link { flex: 1 1 320px; min-width: 0; }
.source-link input { width: 100%; font-family: ui-monospace, Menlo, monospace; }

.source-qr {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.source-qr img {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;   /* QR читается только на белом, тема тут ни при чём */
  padding: 8px;
}

/* Воронка: полоса длиной в долю дошедших. Проценты рядом цифрой —
   на коротких полосах разницу между 3% и 6% глазом не поймать. */
.funnel { display: flex; flex-direction: column; gap: 14px; }
.funnel-step { display: flex; flex-direction: column; gap: 5px; }

.funnel-bar-wrap {
  height: 10px;
  background: var(--bg);
  border-radius: 5px;
  overflow: hidden;
}
.funnel-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
  min-width: 3px;
  transition: width .3s ease;
}
/* Последний шаг — деньги, и он должен читаться иначе остальных */
.funnel-step.is-last .funnel-bar { background: var(--success); }
.funnel-step.is-last .funnel-value { color: var(--success); }

.funnel-facts { display: flex; align-items: baseline; gap: 10px; }
.funnel-name { font-weight: 560; flex: 1; min-width: 0; }
.funnel-value { font-size: 19px; font-weight: 660; font-variant-numeric: tabular-nums; }
.funnel-share {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex: 0 0 52px;
  text-align: right;
}
.funnel-hint { font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }

.conv-good { color: var(--success); }
/* Органика в общем списке: строка для сравнения, а не такая же метка */
.row-muted td { background: var(--bg); }

@media (max-width: 720px) {
  .source-share { gap: 16px; }
  .source-qr { margin: 0 auto; }
}
.conv-bad { color: var(--danger); }
