* { box-sizing: border-box; }
html {
  /* Дизайн лише світлий — без цього iOS у тёмному режимі підставляє системний
     БІЛИЙ колір тексту кнопкам без явно заданого color (напр. .role-btn), і на
     білому фоні кнопки текст стає невидимим ("порожні блоки" на телефоні). */
  color-scheme: light;
}
html, body {
  overscroll-behavior-y: contain;
  /* Без этого Safari/iPadOS считает быстрый повторный тап (например, дважды по
     степперу +/-) жестом "приблизить экран". touch-action:manipulation убирает
     именно двойной тап-зум, пинч-зум пальцами при этом остаётся доступным. */
  touch-action: manipulation;
}
body {
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  background: #f4f5f7;
  color: #1f2430;
  font-size: 16px;
  line-height: 1.5;
}
header.topbar {
  background: #1f2430;
  color: #fff;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-left: calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
header.topbar h1 { font-size: 18px; margin: 0; }
.logo-greco { font-family: 'Inter', -apple-system, sans-serif; font-weight: 900; }
.app-name { opacity: 0.75; font-weight: 400; }
.cycle-badge {
  background: rgba(255,255,255,0.15); color: #fff; font-weight: 700;
  padding: 3px 10px; border-radius: 8px; font-size: 15px; vertical-align: middle;
}
header.topbar nav a {
  color: #fff;
  text-decoration: none;
  margin-left: 16px;
  font-size: 16px;
  opacity: 0.85;
}
header.topbar nav a:hover { opacity: 1; }
header.topbar form { display: inline; margin-left: 16px; }
header.topbar button.link-btn {
  background: none; border: none; color: #fff; opacity: 0.85; cursor: pointer; font-size: 16px;
}

main {
  padding: 16px; max-width: 1000px; margin: 0 auto;
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
}

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tab-btn {
  padding: 12px 18px;
  border: 1px solid #d0d4dc;
  background: #fff;
  color: #1f2430;
  border-radius: 10px;
  font-size: 17px;
  cursor: pointer;
}
.tab-btn.active { background: #2d5bff; color: #fff; border-color: #2d5bff; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* METRO C&C — фирменные синий/жёлтый */
.tab-btn.metro-brand { background: #0055a4; color: #ffd200; border-color: #0055a4; font-weight: 700; }
.tab-btn.metro-brand.active { background: #003d7a; color: #ffd200; border-color: #003d7a; }

.category { background: #fff; border-radius: 12px; margin-bottom: 12px; overflow: hidden; border: 1px solid #e2e5ea; scroll-margin-top: 84px; }
.category-header {
  padding: 14px 16px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  background: #eef1f8;
}
.category-body { padding: 6px 16px 12px; display: none; }
.category-body.open { display: block; }
.cat-count { color: #2d5bff; font-weight: 700; }

/* Повар — на широком экране (iPad и шире) вместо аккордеона слева закреплённая
   панель категорий: тап сразу прокручивает к нужной, все категории раскрыты
   и видны сразу, не нужно листать/сворачивать по одной. На телефоне панель
   скрыта, поведение остаётся прежним — аккордеон со сворачиванием. */
.category-nav { display: none; }
@media (min-width: 900px) {
  .category-layout { display: flex; align-items: flex-start; gap: 20px; }
  .category-nav {
    display: flex; flex-direction: column; gap: 2px; flex: 0 0 200px;
    position: sticky; top: 16px; background: #fff; border: 1px solid #e2e5ea;
    border-radius: 12px; padding: 8px; max-height: calc(100vh - 32px); overflow-y: auto;
  }
  .category-nav-item {
    text-align: left; padding: 10px 12px; border-radius: 8px; border: none;
    background: transparent; font-size: 15px; cursor: pointer; color: #1f2430;
  }
  .category-nav-item:hover { background: #eef1f8; color: #2d5bff; }
  .category-content { flex: 1; min-width: 0; }
  /* На широком экране категории всегда раскрыты — панель слева заменяет ручное
     сворачивание/разворачивание, стрелку-индикатор прячем как не нужную. */
  .category-layout .category-body { display: block !important; }
  .category-layout .category-header { cursor: default; }
  .category-layout .category-header > span:last-child { display: none; }
}

.row .unit { color: #767c8c; font-size: 15px; margin-left: 6px; }

/* Повар — карточки позиций сеткой (степпер −/+ вместо клавиатуры, явная подсветка
   заполненных карточек). Фиксировано 3 в ряд на широком экране (крупнее на 50%,
   удобнее нажимать), меньше колонок на узких экранах, чтобы не схлопывались поля. */
.item-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 700px) {
  .item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 420px) {
  .item-grid { grid-template-columns: 1fr; }
}
.item-card {
  background: #fff; border: 1px solid #e2e5ea; border-radius: 12px;
  padding: 12px 15px; display: flex; flex-direction: column; gap: 8px;
}
.item-card.filled { background: #eef9ef; border-color: #7dbf8e; }
.item-card-name { font-size: 21px; font-weight: 500; }
.item-card-meta { color: #767c8c; font-size: 15px; margin-top: -4px; }
.item-card-stock { color: #8a6d1f; background: #fdf4e3; font-size: 13px; font-weight: 600; padding: 2px 8px; border-radius: 6px; align-self: flex-start; margin-top: -2px; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper-btn {
  width: 42px; height: 42px; flex: 0 0 auto; border-radius: 10px; border: 1px solid #ccd1db;
  background: #fff; font-size: 24px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: #1f2430;
}
.stepper-btn:active { background: #eef1f8; border-color: #2d5bff; }
.stepper-input-wrap { position: relative; flex: 1 1 0; min-width: 60px; }
.stepper-input-wrap input[type=number] {
  width: 100%; text-align: center; font-size: 22px; font-weight: 600;
  padding: 9px 34px 9px 6px; border: 1px solid #ccd1db; border-radius: 10px;
}
.stepper-unit {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-size: 15px; font-weight: 700; color: #767c8c; pointer-events: none;
}

/* Переключатель КГ/ШТ у повара — для кг-позиций, где повар не знает вес заранее
   (например, "2 головки сиру"): вводит количество штук, закупщик потом сам зважить. */
.unit-toggle { display: flex; gap: 6px; align-self: flex-start; }
.unit-toggle-btn {
  padding: 4px 10px; font-size: 13px; font-weight: 700; border-radius: 7px;
  border: 1px solid #ccd1db; background: #fff; color: #767c8c; cursor: pointer;
}
.unit-toggle-btn.active { border-color: #2d5bff; background: #eef1f8; color: #2d5bff; }

.selected-count { font-size: 15px; font-weight: 600; color: #1f2430; margin-bottom: 10px; text-align: center; }

/* Закупщик — строка позиции: 2 строки на позицию (инфо + поля ввода), чтобы на экране
   помещалось сразу несколько позиций — закупка обычно большая, длинный список неудобно
   листать, если под каждую позицию уходит полэкрана. Поля всё ещё крупные для ввода. */
.pi-row {
  font-family: inherit; display: flex; flex-direction: column; gap: 8px;
  background: #fff; border: 1px solid #e4e6eb; border-radius: 12px; padding: 10px 14px;
  margin-bottom: 8px; box-shadow: 0 1px 2px rgba(16,24,40,0.04);
}
/* Заповнена позиция (вага+сума+спосіб оплати) — зелена, щоб закупщик бачив
   прогрес одразу по списку, не гортаючи вгору до "Заповнено: X із Y". */
.pi-row.filled { background: #eef9ef; border-color: #7dbf8e; }
/* Не пройшла перевірку перед проведенням (напр. забув спосіб оплати) — червона
   рамка + прокрутка до першої такої позиції, див. initMissingHighlight в app.js. */
.pi-row.missing-highlight { border-color: #d64545; box-shadow: 0 0 0 2px rgba(214,69,69,0.25); }
.pi-line1 { display: flex; align-items: center; gap: 8px; }
.pi-name {
  flex: 1 1 auto; min-width: 0; font-size: 15px; font-weight: 600; color: #101828;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pi-plan-badge {
  background: #4f46e5; color: #fff; font-size: 13px; font-weight: 700;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap; flex: 0 0 auto;
}
.pi-mismatch {
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 6px;
  white-space: nowrap; flex: 0 0 auto;
}
.pi-mismatch.neutral { color: #667085; background: #f9fafb; border: 1px solid #e4e6eb; }
.pi-mismatch.warn { color: #b54708; background: #fffaeb; border: 1px solid #fedf89; }
.pi-total {
  margin-left: auto; font-size: 16px; font-weight: 700; color: #101828;
  white-space: nowrap; flex: 0 0 auto;
}

.pi-line2 { display: flex; align-items: center; gap: 8px; }
.pi-field {
  display: flex; align-items: center; border: 2px solid #d0d5dd; border-radius: 9px;
  height: 48px; overflow: hidden; flex: 1 1 0; min-width: 0;
}
.pi-field:focus-within { border-color: #4f46e5; }
.pi-field input {
  width: 0; flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  text-align: center; font-size: 19px; font-weight: 700; color: #101828; padding: 0 4px;
}
.pi-field.pi-field-price input { text-align: left; padding-left: 10px; }
.pi-field-unit {
  padding: 0 8px; font-size: 13px; font-weight: 600; color: #667085; border-left: 2px solid #e4e6eb;
  height: 100%; display: flex; align-items: center; white-space: nowrap;
}
.pi-unit-price { font-size: 12px; color: #667085; margin-top: -2px; }
.price-trend { font-weight: 700; margin-left: 4px; }
.price-trend.price-up { color: #d64545; }
.price-trend.price-down { color: #1a8a4a; }
.price-trend.price-flat { color: #9aa1b0; }

.pi-payment { display: flex; gap: 6px; flex: 0 0 auto; }
.pi-pay-btn {
  position: relative; width: 48px; height: 48px; display: flex; align-items: center;
  justify-content: center; font-size: 21px; border-radius: 9px; border: 2px solid #d0d5dd;
  background: #fff; cursor: pointer;
}
.pi-pay-btn input { position: absolute; opacity: 0; width: 0; height: 0; }
.pi-pay-btn:has(input:checked) { border-color: #4f46e5; background: #eef2ff; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.autosave-status { text-align: center; font-size: 14px; color: #8a90a0; min-height: 20px; padding-top: 8px; }
.autosave-status.saved { color: #1a8a4a; }
.autosave-status.error { color: #a02020; }

@media (max-width: 480px) {
  main { padding: 10px; }
}

.actions { margin-top: 20px; display: flex; gap: 10px; }
.actions-sticky {
  position: sticky; bottom: 0; background: #f4f5f7;
  padding: 12px 0 calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid #e2e5ea; margin-top: 20px; z-index: 5;
  flex-direction: column; align-items: stretch;
}
button.primary, input[type=submit].primary {
  background: #2d5bff; color: #fff; border: none; padding: 14px 22px;
  border-radius: 10px; font-size: 16px; cursor: pointer;
}
button.secondary, a.secondary {
  background: #fff; border: 1px solid #ccd1db; padding: 14px 22px;
  border-radius: 10px; font-size: 16px; cursor: pointer; color: #2d3340;
}
button.danger { background: #d64545; color: #fff; border: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; }

/* Плаваюча (sticky) — залишається на екрані під час скролу довгого списку,
   не треба щоразу гортати назад нагору, щоб знайти позицію пошуком. На
   екрані закупщика top підлаштовується під висоту .sticky-summary над нею
   (див. initStickySearchOffset в app.js) — інакше вони наклались би одна на одну. */
.search-box {
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: #f4f5f7;
  padding: env(safe-area-inset-top) 0 8px;
}
.search-box input {
  width: 100%; padding: 14px; font-size: 16px; border: 1px solid #ccd1db; border-radius: 10px;
}
/* Без окремого position:relative — .search-box вже завжди має position:sticky
   (той самий елемент), яка сама по собі є контекстом позиціонування для
   абсолютно позиціонованої іконки нижче. Дублюючий relative тут раніше
   вигравав за порядком у файлі й ламав sticky (однакова специфічність). */
.search-box-icon .search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: #9aa1b0; pointer-events: none;
}
.search-box-icon input { padding-left: 44px; }

.vendor-group { margin-bottom: 28px; }
.vendor-group h2 { font-size: 19px; margin-bottom: 10px; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 16px; }
.alert.error { background: #fde5e5; color: #a02020; }
.alert.info { background: #e5f2ff; color: #1a4d99; }
.alert.success { background: #e2f7e9; color: #1a8a4a; }

/* Закупщик — баланс + прогресс заполнения закреплены сверху одним блоком: пока
   листаешь длинный список, видно и текущий баланс, и сколько ещё не заповнено,
   без скролла обратно наверх. safe-area-inset-top играет роль только когда сайт
   открыт с домашнего экрана (standalone) — в обычном Safari-табе он равен 0. */
.sticky-summary {
  position: sticky; top: 0; z-index: 6; margin-bottom: 16px;
  padding-top: env(safe-area-inset-top);
}
.balance-bar {
  background: #1f2430; color: #fff; padding: 12px 16px; border-radius: 10px 10px 0 0;
  font-size: 16px; display: flex; align-items: center;
  gap: 6px; flex-wrap: wrap;
}
.progress-line {
  background: #16a34a; color: #fff; font-size: 14px; font-weight: 700;
  padding: 8px 16px; border-radius: 0 0 10px 10px;
}

table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; }
table th, table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #eef0f4; font-size: 15px; }
table th { background: #eef1f8; }

/* Власне модальне підтвердження ("Так"/"Ні") замість системного confirm() —
   для дій на кшталт видалення позиції, де хочеться показати саме назву й
   контрольовані кнопки, а не стандартний браузерний діалог. */
.confirm-overlay {
  display: none; position: fixed; inset: 0; background: rgba(31,36,48,0.55);
  align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.confirm-overlay.open { display: flex; }
.confirm-dialog { background: #fff; border-radius: 14px; padding: 24px; max-width: 360px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,0.25); }
.confirm-dialog p { font-size: 16px; margin: 0 0 20px; color: #1f2430; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }
.confirm-actions button { padding: 10px 20px; }

.login-wrap { max-width: 360px; margin: 80px auto; background: #fff; padding: 28px; border-radius: 14px; }
.login-wrap h1 { font-size: 20px; margin-bottom: 20px; text-align: center; }
.login-wrap input { width: 100%; padding: 12px; margin-bottom: 12px; font-size: 16px; border: 1px solid #ccd1db; border-radius: 8px; }

.role-picker { display: flex; flex-direction: column; gap: 12px; }
.role-btn {
  width: 100%; padding: 20px; font-size: 18px; font-weight: 700;
  border: 2px solid #ccd1db; border-radius: 12px; background: #fff; color: #1f2430; cursor: pointer;
}
.role-btn:active { background: #eef1f8; border-color: #2d5bff; color: #2d5bff; }

.admin-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.section { background: #fff; padding: 16px; border-radius: 12px; margin-bottom: 20px; }
.section h2 { margin-top: 0; font-size: 18px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.inline-form input, .inline-form select { padding: 10px; border: 1px solid #ccd1db; border-radius: 8px; font-size: 15px; }
