:root {
  color-scheme: light;
  --bg: #f4f7f4;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2f9e44;
  --primary-soft: #eafbf0;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 14px;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Плавное масштабирование шрифта под ширину экрана (пользователь, 2026-10-03: «чем меньше
     разрешение, тем мельче шрифт и фреймы, чтобы всё влезало без прокруток») — clamp() даёт
     непрерывную зависимость от ширины вместо скачков на фиксированных брейкпоинтах. */
  font-size: clamp(13px, 1.05vw + 10.5px, 16px);
  line-height: 1.4;
  padding-bottom: 72px;
}

img { max-width: 100%; }
[hidden] { display: none !important; }

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

.app-shell {
  min-height: 100vh;
}

.sidebar {
  display: none;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 18px;
  font-weight: 700;
  font-size: 17px;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 12px;
  flex: 1;
  overflow-y: auto;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.sidebar-nav a:hover { background: var(--bg); }
.sidebar-nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.sidebar-nav .icon { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 16px 12px 4px;
}

/* Сворачиваемая группа пунктов меню (например «Склад») — чтобы не раздувать
   общий список, когда появляется много связанных страниц (2026-10-03). */
.sidebar-group summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}
.sidebar-group summary::-webkit-details-marker { display: none; }
.sidebar-group summary::after {
  content: '▸';
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  transition: transform .15s;
}
.sidebar-group[open] summary::after { transform: rotate(90deg); }
.sidebar-group summary:hover { background: var(--bg); }
.sidebar-subnav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0 4px 32px;
}
.sidebar-subnav a {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.sidebar-subnav a:hover { background: var(--bg); color: var(--text); }
.sidebar-subnav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }

.sidebar-logout {
  padding: 14px 20px 0;
  border-top: 1px solid var(--border);
  margin-top: 10px;
}

.sidebar-logout button {
  width: 100%;
  text-align: left;
  padding: 10px 0;
}

.content-col {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  font-weight: 600;
  font-size: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.topbar form { margin: 0; }
.topbar button.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
}

main {
  padding: clamp(8px, 3vw, 16px);
  max-width: 960px;
  margin: 0 auto;
}

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: clamp(10px, 3vw, 16px);
  border: 1px solid var(--border);
}

.card.wide { grid-column: 1 / -1; }

.card .label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.card .value {
  font-size: clamp(16px, 2.2vw + 11px, 22px);
  font-weight: 700;
}

.ok { color: var(--ok); }
.warn { color: var(--warn); }
.danger { color: var(--danger); }

.quick-actions {
  display: flex;
  gap: clamp(6px, 1.5vw, 10px);
  margin: clamp(10px, 3vw, 16px) 0;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: clamp(8px, 1.8vw, 12px) clamp(12px, 3vw, 18px);
  border-radius: 999px;
  border: none;
  background: var(--primary);
  color: var(--primary-text);
  font-size: clamp(12px, 1vw + 10px, 15px);
  font-weight: 600;
  cursor: pointer;
}

.btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.soon {
  background: var(--surface);
  color: var(--muted);
  border: 1px dashed var(--border);
  cursor: default;
}

table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
th, td { padding: clamp(6px, 1.6vw, 10px) clamp(7px, 1.8vw, 12px); text-align: left; border-bottom: 1px solid var(--border); font-size: clamp(12px, 0.9vw + 10px, 14px); }
th { color: var(--muted); font-weight: 600; font-size: clamp(10px, 0.6vw + 9px, 12px); text-transform: uppercase; }

/* Таблицы с большим числом колонок (операции и т.п.) на узком экране не влезают даже с
   уменьшенным шрифтом — вместо горизонтальной прокрутки всей страницы (пользователь,
   2026-10-03: «появилась горизонтальная прокрутка») строка складывается в блок из подписанных
   пар «подпись: значение», как в карточке. Подпись берётся из data-label на каждом <td>. */
@media (max-width: 640px) {
  table.table-stack thead { display: none; }
  table.table-stack, table.table-stack tbody, table.table-stack tr, table.table-stack td {
    display: block;
    width: 100%;
  }
  table.table-stack tr { padding: 8px 0; border-bottom: 1px solid var(--border); }
  table.table-stack td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 4px clamp(7px, 1.8vw, 12px);
    border-bottom: none;
    text-align: right;
  }
  table.table-stack td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: clamp(10px, 0.6vw + 9px, 12px);
    text-transform: uppercase;
    text-align: left;
    flex-shrink: 0;
  }
  /* Ячейка действий (кнопка "Изменить" + разворачиваемая форма) — своя подпись не нужна,
     и форма внутри должна оставаться обычным блоком, а не ещё одной строкой flex. */
  table.table-stack td.col-actions { display: block; text-align: left; }
  table.table-stack td.col-actions::before { content: none; }
}

.section-title { font-size: clamp(14px, 1vw + 12px, 16px); font-weight: 700; margin: clamp(14px, 3vw, 24px) 0 clamp(6px, 1.5vw, 10px); }

.empty { color: var(--muted); padding: clamp(14px, 4vw, 24px); text-align: center; background: var(--surface); border-radius: var(--radius); }

.form-grid { display: flex; flex-direction: column; gap: clamp(6px, 1.8vw, 10px); background: var(--surface); padding: clamp(10px, 3vw, 16px); border-radius: var(--radius); border: 1px solid var(--border); }
.form-grid label { font-size: clamp(11px, 0.8vw + 9px, 13px); color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.form-grid input, .form-grid select, .form-grid textarea {
  font-size: 16px;
  padding: clamp(7px, 1.8vw, 10px) clamp(9px, 2vw, 12px);
  border-radius: 10px;
  border: 1px solid var(--border);
  font-family: inherit;
}

/* Компактный однострочный блок фильтров (как в Эльбе) — в отличие от .form-grid, поля идут
   в ряд без подписей сверху, оборачиваются на узких экранах, а не растягиваются на всю
   высоту (пользователь, 2026-10-03: «в 1 строку, не на пол экрана»). */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(6px, 1.5vw, 8px);
  margin: clamp(6px, 1.5vw, 10px) 0;
}
.filter-bar input, .filter-bar select {
  font-size: clamp(12px, 0.9vw + 10px, 14px);
  padding: clamp(6px, 1.5vw, 8px) clamp(8px, 2vw, 10px);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
  flex: 1 1 140px;
}
.filter-bar .btn { flex: 0 0 auto; }

/* Выпадающий список прямо в строке документа — меняет статус без перехода на страницу
   документа (пользователь, 2026-10-03, по образцу Эльбы: «действия выпадающим списком
   сбоку»). Оформлен как компактный тег, не как обычный input. */
.status-select {
  font-size: clamp(10px, 0.7vw + 9px, 12px);
  padding: 2px clamp(4px, 1vw, 8px);
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f3f4f6;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
}
.status-select.ok { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.inline-status-form { display: inline-block; margin: 0; }

.login-wrap {
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  padding: 32px 24px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 340px;
}

.error { color: var(--danger); font-size: 14px; margin-top: 8px; }

.tag { display: inline-block; padding: 2px clamp(4px, 1vw, 8px); border-radius: 999px; font-size: clamp(10px, 0.7vw + 9px, 12px); background: #eef2ff; color: var(--primary); }
.tag.muted { background: #f3f4f6; color: var(--muted); }
.tag.warn { background: #fef3c7; color: var(--warn); }
.tag.danger { background: #fee2e2; color: var(--danger); }

.progress { background: #e5e7eb; border-radius: 999px; height: 10px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; }
.progress-bar.warn { background: var(--warn); }
.progress-bar.danger { background: var(--danger); }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 20;
}

.bottom-nav a {
  flex: 1;
  text-align: center;
  padding: 10px 4px 8px;
  font-size: 11px;
  color: var(--muted);
}

.bottom-nav a.active { color: var(--primary); font-weight: 600; }
.bottom-nav .icon { display: block; font-size: 20px; margin-bottom: 2px; }

.more-list { display: flex; flex-direction: column; gap: 8px; }
.more-list a {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
  font-weight: 500;
}

@media (min-width: 769px) {
  body { padding-bottom: 0; }
  .bottom-nav { display: none; }
  main { padding: 24px 32px; }

  .app-shell { display: flex; }
  .sidebar {
    display: flex;
    flex-direction: column;
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 0;
    position: sticky;
    top: 0;
    height: 100vh;
  }
  .content-col { flex: 1; }
  .topbar-logout { display: none; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
}
