/*
  Стиль: спокойное меню слева (минимализм) + карточки и понятные кнопки.
  Основные устройства: iPad 13" (80% времени) и ноутбук 13".
  - Текст компактный (15px), чтобы на экран помещалось больше строк.
  - Поля ввода — 16px: при меньшем шрифте Safari на iPad увеличивает страницу при нажатии.
  - Кнопки не ниже 44px — удобно попадать пальцем.
*/
:root {
  --bg: #f6f6f3;
  --sidebar: #efede6;
  --card: #ffffff;
  --text: #2c2c2a;
  --muted: #6f6e68;
  --line: #e2e0d8;
  --line-strong: #c9c6bb;

  --primary: #0f6e56;
  --primary-dark: #0b5644;
  --primary-soft: #e1f5ee;
  --ok: #0f6e56;
  --ok-bg: #e1f5ee;
  --warn: #854f0b;
  --warn-bg: #faeeda;
  --bad: #a32d2d;
  --bad-bg: #fcebeb;
  --info-bg: #e6f1fb;
  --info: #0c447c;

  --radius: 12px;
  --radius-sm: 10px;
  --control-h: 44px;
  --sidebar-w: 215px;
}

* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.45;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 1rem; }
h2 { font-size: 1.2rem; font-weight: 600; margin: 1.5rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Каркас: меню слева ---------- */
body.with-sidebar { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--sidebar); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: .85rem .6rem;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 .5rem .6rem; }
.brand { font-size: 1.3rem; font-weight: 700; color: var(--text); text-decoration: none; }
.menu-toggle { display: none; }
.sidebar-nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .6rem; min-height: 40px;
  padding: .45rem .65rem; border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-size: 1rem;
}
.sidebar-nav a:hover { background: rgba(0,0,0,.05); }
.sidebar-nav a.active { background: var(--card); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }
.sidebar-nav .ico { width: 1.5rem; text-align: center; font-size: 1.1rem; }
.nav-section { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: .85rem .65rem .25rem; }
.sidebar-user { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .6rem .5rem 0; border-top: 1px solid var(--line); margin-top: .85rem; }

.page { flex: 1; min-width: 0; max-width: 1440px; margin: 0 auto; padding: 1.25rem 1.5rem 3rem; }

/* ---------- Карточки и плитки ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .85rem; margin-bottom: 1.5rem; }
.tile {
  display: flex; align-items: center; gap: .85rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; text-decoration: none; color: var(--text); min-height: 88px;
  transition: border-color .15s, transform .05s;
}
.tile:hover { border-color: var(--primary); }
.tile:active { transform: scale(.99); }
.tile .icon {
  flex: 0 0 3rem; height: 3rem; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; background: var(--primary-soft);
}
.tile .text { display: flex; flex-direction: column; gap: .15rem; }
.tile .name { font-size: 1.1rem; font-weight: 600; }
.tile .hint { font-size: .85rem; color: var(--muted); }
.tile-main { border: 2px solid var(--primary); }
.tile-main .icon { background: var(--primary); }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--control-h);
  border: 2px solid var(--primary); background: var(--primary); color: #fff;
  border-radius: var(--radius-sm); padding: .45rem 1.1rem;
  font-size: 1rem; font-weight: 600; font-family: inherit; cursor: pointer;
  text-decoration: none; line-height: 1.2;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn:active { transform: scale(.98); }
.btn-big { min-height: 48px; padding: .6rem 1.6rem; font-size: 1.07rem; }
.btn-small { min-height: 36px; padding: .2rem .75rem; font-size: .9rem; }
.btn-ghost { background: var(--card); color: var(--primary); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--primary-soft); border-color: var(--primary); }
.btn-ok { background: var(--ok); border-color: var(--ok); }
.btn-danger { background: var(--card); color: var(--bad); border-color: #f09595; }
.btn-danger:hover { background: var(--bad-bg); border-color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: 1rem 0; }

/* ---------- Сообщения ---------- */
.alert { padding: .65rem .95rem; border-radius: var(--radius-sm); margin-bottom: .9rem; border: 1px solid transparent; }
.alert-success { background: var(--ok-bg); color: #085041; }
.alert-error { background: var(--bad-bg); color: #791f1f; }
.alert-warning { background: var(--warn-bg); color: #633806; }
.alert-info { background: var(--info-bg); color: var(--info); }

/* ---------- Формы ---------- */
label { display: block; font-weight: 600; margin-bottom: .3rem; }
input[type=text], input[type=number], input[type=date], input[type=password], input:not([type]), select, textarea {
  width: 100%; min-height: var(--control-h);
  font-size: 16px; /* не меньше 16px — иначе iPad увеличивает страницу при нажатии */
  font-family: inherit; padding: .45rem .7rem;
  border: 2px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--text);
}
textarea { min-height: 6rem; }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox] { width: 1.4rem; height: 1.4rem; vertical-align: middle; accent-color: var(--primary); }
.field { margin-bottom: .9rem; }
.errorlist { color: var(--bad); list-style: none; padding: 0; margin: .3rem 0; font-size: .9rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 1.25rem; }
.checkbox-field label { display: inline; font-weight: 400; margin-left: .5rem; }
.helptext { color: var(--muted); font-size: .85rem; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .45rem .75rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #faf9f6; }
tbody tr:hover { background: #fbfaf7; }
td.num, th.num { text-align: right; white-space: nowrap; }
tr.group th { background: var(--sidebar); color: var(--text); font-size: .95rem; text-transform: none; letter-spacing: 0; }
tfoot td { font-weight: 700; background: #faf9f6; border-top: 1px solid var(--line); }
tr.inactive td { color: var(--muted); }
td input, td select { min-height: 40px; padding: .3rem .55rem; }
.lines td { vertical-align: top; }
.lines td, .lines th { padding-left: .4rem; padding-right: .4rem; }
.lines td input[type=text], .lines td input:not([type]) { min-width: 5.5rem; }
.lines td select { min-width: 5.5rem; }
.lines th { white-space: nowrap; }
.item-cell { display: flex; gap: .35rem; align-items: center; }
.item-cell select { flex: 1; min-width: 11rem; }
.item-cell .add-item { white-space: nowrap; padding-left: .55rem; padding-right: .55rem; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem;
  width: min(520px, calc(100vw - 2rem)); color: var(--text); background: var(--card);
}
dialog::backdrop { background: rgba(30, 30, 28, .45); }
.confirm-dialog { width: min(440px, calc(100vw - 2rem)); }
.confirm-text { font-size: 1.1rem; margin: 0 0 1rem; line-height: 1.5; }
.extras-option { display: flex; align-items: center; gap: .6rem; min-height: 44px; font-weight: 600; font-size: 1.05rem; cursor: pointer; }
.extras-option.disabled { color: var(--muted); font-weight: 400; cursor: default; }
.dialog-extra { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: .75rem; }
.dialog-extra form { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .75rem; }
tr.group-inactive th { background: #e7e5de; color: var(--muted); }

/* ---------- Состояния ---------- */
.badge { display: inline-block; padding: .2rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 600; vertical-align: middle; }
.badge-draft { background: var(--warn-bg); color: var(--warn); }
.badge-posted { background: var(--ok-bg); color: var(--ok); }
.badge-cancelled { background: #eceae4; color: var(--muted); text-decoration: line-through; }
.plus { color: var(--ok); font-weight: 600; }
.minus { color: var(--bad); font-weight: 600; }

/* ---------- Вкладки-фильтры ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.tabs a {
  display: inline-flex; align-items: center; min-height: 38px;
  padding: .3rem .95rem; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); color: var(--text); text-decoration: none;
}
.tabs a:hover { border-color: var(--primary); }
.tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* ---------- Цены: поле, которое сохраняется само ---------- */
.price-input { width: 8.5rem !important; text-align: right; font-weight: 600; }
.price-input.saving { border-color: #ef9f27; }
.price-input.saved { border-color: var(--ok); background: var(--ok-bg); }
.price-input.error { border-color: var(--bad); background: var(--bad-bg); }
.price-status { font-size: .85rem; margin-left: .5rem; display: inline-block; }
.price-input.saved + .price-status { color: var(--ok); }
.price-input.error + .price-status { color: var(--bad); }

/* Форма «Новая позиция» на экранах цен */
.add-product-title { font-weight: 600; font-size: 1.05rem; margin-bottom: .75rem; }
.add-row { display: flex; flex-wrap: wrap; gap: 0 .75rem; align-items: flex-end; }
.add-row .field { margin-bottom: .6rem; flex: 1 1 8.5rem; min-width: 0; }
.add-row .add-name { flex: 3 1 16rem; }
.add-row .add-btn { flex: 0 0 auto; }
.row-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; }
.col-no { width: 3rem; padding-right: .25rem !important; }
.name-cell { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.unit-hint { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.icon-btn {
  border: 1px solid transparent; background: transparent; border-radius: 8px; cursor: pointer;
  font-size: 1rem; line-height: 1; padding: .35rem .45rem; opacity: .55;
}
.icon-btn:hover, .icon-btn:focus-visible { opacity: 1; border-color: var(--line-strong); background: var(--card); }
tr:hover .icon-btn { opacity: 1; }
/* На iPad нет наведения мышью — карандаш ✏️ всегда хорошо виден и крупнее под палец. */
@media (hover: none) {
  .icon-btn { opacity: 1; padding: .5rem .6rem; }
  tbody tr:hover { background: transparent; }
}
.item-link { color: inherit; text-decoration: none; }
.item-link:hover { color: var(--primary); text-decoration: underline; }
tr:target td { background: var(--primary-soft); transition: background 1.5s; }

/* ---------- Заявки ---------- */
.tab-disabled { display: inline-flex; align-items: center; min-height: 38px; padding: .3rem .95rem; border-radius: 999px; border: 1px dashed var(--line-strong); color: var(--muted); }
.orders-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; margin-bottom: .75rem; }
.orders-head h1 { margin: 0; }
.date-nav { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.date-nav input[type=date] { width: auto; }
.order-tabs a { gap: .45rem; }
.tab-badge { font-size: .75rem; font-weight: 600; padding: .05rem .45rem; border-radius: 999px; background: var(--ok-bg); color: var(--ok); }
.tabs a.active .tab-badge { background: rgba(255,255,255,.25); color: #fff; }
.tab-badge.empty { background: transparent; color: var(--muted); }
.order-totals { display: flex; flex-wrap: wrap; gap: .5rem 2rem; }
.order-totals div { display: flex; flex-direction: column; }
.order-totals b { font-size: 1.15rem; }
.order-qty { width: 6.5rem !important; text-align: right; font-weight: 600; }
.order-qty.saving { border-color: #ef9f27; }
.order-qty.saved { border-color: var(--ok); }
.order-qty.error { border-color: var(--bad); background: var(--bad-bg); }
.order-row.filled td { background: #f3faf6; }
.order-row.filled .order-qty { background: var(--ok-bg); }
.order-row .row-amount { font-weight: 600; }
.order-group.supplies .group th { background: #e7e5de; }
.checkbox-inline { display: inline-flex; align-items: center; gap: .4rem; font-weight: 400; margin: 0; min-height: 44px; }
.summary-table td, .summary-table th { white-space: nowrap; }
/* Таблица по ширине содержимого: название целиком, остальные колонки — сразу рядом. */
.table-fit { display: inline-block; max-width: 100%; vertical-align: top; }
.table-fit > table { width: auto; }
.order-table .name-cell { flex-wrap: nowrap; white-space: nowrap; }
.order-table td, .order-table th { padding-left: .6rem; padding-right: .6rem; }
.order-table td:nth-child(2) { padding-right: 1.5rem; }
.order-table .row-amount { min-width: 5rem; }

/* Итоги заявки закреплены сверху экрана. */
.order-summary {
  position: sticky; top: 0; z-index: 6;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1.5rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .6rem 1rem; margin-bottom: .75rem;
  box-shadow: 0 6px 12px -10px rgba(0,0,0,.25);
}
.order-totals { gap: .25rem 1.75rem; }
.order-totals b { font-size: 1.1rem; }
.order-summary-actions { display: flex; gap: .5rem; align-items: center; }

/* Не сохранилось (нет связи) — заметно, в закреплённой сводке. */
.save-warning {
  margin-top: .5rem; padding: .45rem .75rem; border-radius: var(--radius-sm);
  background: var(--bad-bg); color: #791f1f; font-weight: 600;
}
.save-warning[hidden] { display: none; }
.past-date a { white-space: nowrap; margin-left: .35rem; }

/* Заявка оптовика: доставка — поле прямо в сводке; особая цена — метка у цены. */
.order-totals .delivery-box .delivery-field { display: flex; align-items: center; }
.order-delivery { width: 5.5rem !important; min-height: 36px; height: 36px; padding: .15rem .5rem; text-align: right; font-weight: 600; }
.order-delivery.saving { border-color: #ef9f27; }
.order-delivery.saved { border-color: var(--ok); }
.order-delivery.error { border-color: var(--bad); background: var(--bad-bg); }
.delivery-field .price-status { font-size: .8rem; color: var(--bad); }
.special-mark {
  display: inline-block; margin-left: .3rem; padding: 0 .35rem; border-radius: 999px;
  font-size: .7rem; font-weight: 600; color: var(--text, #222); background: #fde9c8; vertical-align: 1px;
}
/* Оптовиков ~20 — вкладки компактнее, переносятся на несколько строк. */
.order-tabs.many { flex-wrap: wrap; }
.order-tabs.many a { padding-left: .7rem; padding-right: .7rem; }

/* «Как в прошлый раз» — главный сценарий, когда заявки ещё нет. */
.copy-banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1.5rem;
  background: var(--primary-soft); border: 1px solid #9fe1cb; border-radius: var(--radius);
  padding: .9rem 1.1rem; margin-bottom: .75rem;
}

/* Роллы: таблица «ролл × магазин». */
.rolls-table .roll-name { white-space: nowrap; padding-right: 1.25rem; }
/* Вертикальные названия магазинов и оптовиков — их будет ~20, узкие колонки помещаются. */
.rolls-table th.vertical-head { vertical-align: bottom; text-align: center; padding: .5rem .25rem; text-transform: none; letter-spacing: 0; }
.rolls-table th.vertical-head span {
  writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap;
  display: inline-block; max-height: 12rem; overflow: hidden; text-overflow: ellipsis;
  font-size: .85rem; color: var(--text);
}
.rolls-table td.qty-col { text-align: center; min-width: 2.6rem; padding-left: .3rem; padding-right: .3rem; border-left: 1px solid var(--line); }

/* Для водителей */
.drivers-table td, .drivers-table th { padding: .5rem 1rem; font-size: 1.05rem; }
.drivers-table .handwrite { min-width: 9rem; border-left: 1px solid var(--line); }
.drivers-table tr.subtotal td { font-weight: 600; border-top: 1px solid var(--line-strong); }

/* Две колонки, как на накладной: слева салаты, справа остальное. */
.order-filters { margin-bottom: .75rem; }
.order-columns { display: grid; grid-template-columns: 1fr; gap: .9rem; align-items: start; }
@media (min-width: 1200px) {
  .order-columns { grid-template-columns: max-content max-content; }
}
.order-col { display: block; }
.order-col .order-table { width: 100%; }

/* Компактные строки: ~44px, поле ввода 40px — попасть пальцем по-прежнему легко. */
.order-table td { padding-top: .12rem; padding-bottom: .12rem; }
.order-table .order-qty { min-height: 40px; height: 40px; width: 5.5rem !important; padding: .2rem .5rem; }
.order-table .qty-cell { white-space: nowrap; }
.order-table .price-status { font-size: .8rem; margin-left: .35rem; }
.order-table .price-status:empty { display: none; }

.filters { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; margin-bottom: 1.25rem; }
.filters .field { margin: 0; min-width: 220px; }

.summary { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.5rem; margin: 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 600; }

details.card summary { cursor: pointer; font-size: 1.05rem; }

.login-box { max-width: 420px; margin: 12vh auto; }
.show-mobile { display: none; }

/* ---------- Телефон и узкий экран: меню сворачивается наверх ---------- */
@media (max-width: 900px) {
  html { font-size: 15px; }
  body.with-sidebar { display: block; }
  .sidebar {
    position: sticky; top: 0; z-index: 10; width: 100%; height: auto;
    flex-direction: column; padding: .6rem 1rem; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .sidebar-head { padding: 0; }
  .menu-toggle {
    display: inline-flex; align-items: center; min-height: 2.6rem;
    font: inherit; font-weight: 600; padding: .3rem 1rem;
    border: 2px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--card); color: var(--text);
  }
  .sidebar-nav, .sidebar-user { display: none; }
  .sidebar.open .sidebar-nav, .sidebar.open .sidebar-user { display: flex; }
  .sidebar.open .sidebar-nav { padding-top: .5rem; }
  .page { padding: 1.25rem 1rem 3rem; }
  .btn-big { width: 100%; }
  .tiles { grid-template-columns: 1fr; }
  .hide-mobile { display: none; }
  .order-summary { top: 58px; } /* под свёрнутым меню */
  .add-row .add-btn { flex: 1 1 100%; }
  .add-row .add-btn .btn { width: 100%; }
  .show-mobile { display: block; }
  th, td { padding: .45rem .6rem; }
  .price-input { width: 7.5rem !important; }
  .price-status { display: block; margin: .25rem 0 0; }
}
