/* ============================================================
   Калькулятор ивентов — стили. Mobile-first.
   Цветовое кодирование: цена (net) — тёмная, себестоимость — янтарная,
   прибыль — зелёная, убыток — красный, акцент бренда — глубокий бирюзовый.
   ============================================================ */

:root {
  --bg: #EBEEF0;
  --surface: #FFFFFF;
  --surface-2: #F4F6F7;
  --ink: #15191D;
  --muted: #6B7680;
  --border: #DDE2E6;
  --accent: #0B6E75;       /* бирюзовый — бренд/акцент/итог */
  --accent-ink: #FFFFFF;
  --accent-soft: #E1F0F0;
  --cost: #B45309;         /* себестоимость — янтарь */
  --profit: #15803D;       /* прибыль — зелёный */
  --loss: #B91C1C;         /* убыток — красный */
  --danger: #B91C1C;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(21,25,29,.06), 0 4px 16px rgba(21,25,29,.06);
  --shadow-lg: 0 8px 40px rgba(21,25,29,.18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --header-h: 56px;
  --search-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 16px; }

/* ---------- базовые кнопки ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 600;
  font-size: 15px;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--primary:hover { background: #0a5f66; }
.btn--ghost { background: transparent; border-style: dashed; color: var(--accent); }
.btn--ghost:hover { background: var(--accent-soft); }
.btn--sm { padding: 6px 10px; font-size: 13px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============================================================
   Экран входа
   ============================================================ */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(11,110,117,.10), transparent 60%),
    var(--bg);
}
.login__card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 24px;
  text-align: center;
}
.login__brand {
  font-weight: 800;
  letter-spacing: .28em;
  color: var(--accent);
  font-size: 15px;
  margin-bottom: 6px;
}
.login__title { font-size: 20px; margin: 0 0 22px; font-weight: 700; }
.login__input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  background: var(--surface-2);
}
.login__input:focus { background: var(--surface); }
.login__btn { width: 100%; padding: 13px; font-size: 16px; }
.login__error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 12px 0 0; }

/* ============================================================
   Шапка
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header__brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.app-header__logo { font-weight: 800; letter-spacing: .2em; color: var(--accent); font-size: 15px; }
.app-header__title {
  font-size: 14px; color: var(--muted); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-header__actions { display: flex; align-items: center; gap: 6px; }
.lang {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 7px 8px;
  font-size: 13px;
  color: var(--ink);
}
.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 17px; color: var(--ink);
}
.icon-btn:hover { background: var(--surface-2); }

/* ============================================================
   Sticky поиск
   ============================================================ */
.search {
  position: sticky;
  top: var(--header-h);
  z-index: 25;
  background: var(--bg);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.search__input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* ============================================================
   Раскладка
   ============================================================ */
.layout { padding: 12px 14px 96px; }
.layout__catalog { min-width: 0; }

/* ---------- Категории ---------- */
.cat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.cat__header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: var(--surface);
  border: none;
  text-align: left;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}
.cat__header:hover { background: var(--surface-2); }
.cat__chevron { color: var(--muted); font-size: 12px; width: 12px; }
.cat__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat__count {
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: var(--surface-2); border-radius: 999px; padding: 2px 9px;
}
.cat__hide { border: none; background: transparent; font-size: 16px; padding: 2px 4px; opacity: .55; }
.cat__hide:hover { opacity: 1; }
.cat__body { border-top: 1px solid var(--border); }

/* ---------- Позиция каталога ---------- */
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: none; }
.item__info { flex: 1; min-width: 0; }
.item__name { font-weight: 600; font-size: 15px; margin-bottom: 3px; }
.item__meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }
.item__price {
  color: var(--ink); font-weight: 600;
  border: 1px dashed transparent; background: transparent;
  padding: 1px 4px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.item__price:hover { border-color: var(--accent); }
.item__price-input {
  width: 90px; padding: 3px 6px;
  border: 1px solid var(--accent); border-radius: 6px; color: var(--ink); font-weight: 600;
}
.item__cost {
  color: var(--cost); font-weight: 600;
  border: 1px dashed transparent; background: transparent;
  padding: 1px 4px; border-radius: 6px; font-size: 13px;
}
.item__cost:hover { border-color: var(--cost); }
.item__cost-input {
  width: 90px; padding: 3px 6px;
  border: 1px solid var(--cost); border-radius: 6px; color: var(--cost); font-weight: 600;
}
.btn--add {
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn--add:hover { background: var(--accent-soft); }
.btn--add-active { background: var(--accent); color: var(--accent-ink); }

/* действия в строке товара (кнопка добавления + удаление для ручных блюд) */
.item__actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.item__del {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.item__del:hover { border-color: var(--loss); background: var(--surface-2); }
.item__del:disabled { opacity: .5; cursor: default; }
.item--manual .item__name::after {
  content: '•';
  color: var(--accent);
  margin-left: 6px;
}

/* сообщение об ошибке в модалке */
.modal__error { color: var(--loss); font-size: 13px; font-weight: 600; margin: 0 0 10px; }
.empty__detail { font-size: 12px; color: var(--muted); word-break: break-word; margin: 0 0 12px; }

/* ============================================================
   Панель заказа (список + итоги)
   ============================================================ */
.layout__order {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.order__head {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 16px; margin-bottom: 10px;
}
.order__close { display: none; border: none; background: transparent; font-size: 26px; line-height: 1; color: var(--muted); }

/* ---------- Строка списка ---------- */
.cart { display: flex; flex-direction: column; gap: 8px; }
.line {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface-2);
}
.line__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.line__name { font-weight: 600; font-size: 14px; min-width: 0; }
.line__tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 4px; padding: 1px 5px; margin-left: 6px; vertical-align: middle;
}
.line__remove { border: none; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; padding: 0 4px; flex-shrink: 0; }
.line__remove:hover { color: var(--danger); }

.line__grid { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; align-items: end; }
.line__cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.line__label { font-size: 11px; color: var(--muted); }
.line__val { font-weight: 600; font-size: 14px; }
.line__cost-input {
  width: 100%; padding: 5px 7px;
  border: 1px solid var(--cost); border-radius: 6px; color: var(--cost); font-weight: 600; font-size: 14px;
}

.qty { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.qty__btn { border: none; background: transparent; width: 30px; height: 32px; font-size: 18px; color: var(--accent); }
.qty__btn:hover { background: var(--accent-soft); }
.qty__input { width: 42px; height: 32px; border: none; border-left: 1px solid var(--border); border-right: 1px solid var(--border); text-align: center; font-weight: 600; -moz-appearance: textfield; }
.qty__input::-webkit-outer-spin-button, .qty__input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.line__sums { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: 13px; font-weight: 600; }
.line__sum--sale { color: var(--ink); }
.line__sum--cost { color: var(--cost); }

.manual-add { width: 100%; margin: 10px 0 4px; }

/* ---------- Скидка ---------- */
.discount { margin: 12px 0 8px; }
.discount__label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.discount__controls { display: flex; gap: 8px; }
.discount__input { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.discount__types { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.discount__type { border: none; background: var(--surface); padding: 0 14px; font-weight: 700; color: var(--muted); }
.discount__type.is-active { background: var(--accent); color: var(--accent-ink); }

/* ---------- Итоги ---------- */
.totals { margin-top: 10px; }
.sum-rows { border-top: 1px solid var(--border); padding-top: 10px; }
.sum-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 14px; }
.sum-row__label { color: var(--muted); }
.sum-row__value { font-weight: 600; font-variant-numeric: tabular-nums; }
.sum-row--discount .sum-row__value { color: var(--loss); }
.sum-row--grand { margin-top: 6px; padding-top: 10px; border-top: 2px solid var(--ink); }
.sum-row--grand .sum-row__label { color: var(--ink); font-weight: 700; font-size: 15px; }
.sum-row--grand .sum-row__value { color: var(--accent); font-weight: 800; font-size: 22px; }

.financials { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.sum-row--muted .sum-row__value { color: var(--cost); }
.sum-row--profit .sum-row__value { color: var(--profit); font-weight: 700; }
.sum-row--loss .sum-row__value { color: var(--loss); font-weight: 700; }

/* ============================================================
   Панель категорий (настройки)
   ============================================================ */
.settings {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.settings__title { margin: 0 0 10px; font-size: 15px; }
.settings__list { display: flex; flex-direction: column; gap: 6px; }
.hidden-cat { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius-sm); }
.hidden-cat__name { font-weight: 600; font-size: 14px; }

/* ============================================================
   Пустые состояния
   ============================================================ */
.empty { padding: 26px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.empty--cart { padding: 18px 8px; }
.empty--error { color: var(--ink); }
.empty--error p { margin: 0 0 12px; }

/* ============================================================
   Модалка
   ============================================================ */
.modal__overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(21,25,29,.45);
  display: grid; place-items: center; padding: 20px;
  overflow-y: auto;
}
.modal__card {
  width: 100%; max-width: 380px;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 20px;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
}
.modal__title { margin: 0 0 16px; font-size: 18px; }
.modal__field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 12px; flex: 1; }
.modal__input { padding: 11px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink); }
.modal__input:focus { background: var(--surface); }
.modal__row { display: flex; gap: 12px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ============================================================
   Мобильная нижняя панель + выезжающий список
   ============================================================ */
.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(21,25,29,.08);
}
.mobile-bar__info { display: flex; flex-direction: column; min-width: 0; }
.mobile-bar__label { font-size: 11px; color: var(--muted); font-weight: 600; }
.mobile-bar__total { font-size: 20px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.mobile-bar__btn { border: none; background: var(--accent); color: var(--accent-ink); border-radius: var(--radius-sm); padding: 12px 20px; font-weight: 700; font-size: 15px; }

/* ============================================================
   Десктоп
   ============================================================ */
@media (min-width: 900px) {
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 18px;
    padding: 16px 22px 40px;
    max-width: 1200px;
    margin: 0 auto;
  }
  .layout__order {
    position: sticky;
    top: calc(var(--header-h) + var(--search-h) + 16px);
    align-self: start;
    max-height: calc(100vh - var(--header-h) - var(--search-h) - 40px);
    overflow-y: auto;
  }
  .app-header { padding: 0 22px; }
  .app-header__title { font-size: 15px; }
  .search { padding: 12px 22px; }
  .mobile-bar { display: none; }
  .order__close { display: none; }
}

/* ---------- Мобильный выезжающий список (до 900px) ---------- */
@media (max-width: 899px) {
  .layout__order {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 50;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 82vh;
    overflow-y: auto;
    transform: translateY(110%);
    transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  #app-root.order-open .layout__order { transform: translateY(0); }
  .order__close { display: block; }
  #app-root.order-open .mobile-bar { box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ===== Экран администратора ===== */
.login__toggle {
  margin-top: 12px; border: none; background: transparent;
  color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.admin { padding: 12px 14px 40px; }
.admin__hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; line-height: 1.4; }
.admin__status { font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 12px; }
.admin__list { display: flex; flex-direction: column; gap: 10px; }
.admin-cat__header {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 12px 14px; border: none; background: var(--surface-2);
  cursor: pointer; text-align: left;
}
.admin-cat__body { display: flex; flex-direction: column; }
.admin-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.admin-item:last-child { border-bottom: none; }
.admin-item__info { flex: 1; min-width: 0; }
.admin-item__name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-item__meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.admin-item.is-hidden { opacity: .5; }
.admin-item__toggle {
  flex-shrink: 0; border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); border-radius: var(--radius-sm); padding: 7px 12px;
  font-weight: 600; font-size: 13px; cursor: pointer;
}
.admin-item__toggle.is-hidden { border-color: var(--accent); color: var(--accent); }
.admin-item__toggle:disabled { opacity: .5; cursor: default; }

/* ===== Вложенное дерево категорий (каталог и админка) ===== */
.tree-cat__header {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 11px 14px; border: none; border-top: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; text-align: left;
  font: inherit; color: var(--ink);
}
.tree-cat__header:first-child { border-top: none; }
.tree-cat__header .cat__name { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-cat__header .cat__count { color: var(--muted); font-size: 12px; font-weight: 600; flex-shrink: 0; }
.tree-cat__header .cat__chevron { color: var(--muted); width: 12px; flex-shrink: 0; }
.tree-cat__body { display: block; }

/* ===== Вложенное дерево категорий (каталог и админка) ===== */
.tree-cat__header {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 11px 14px; border: none; background: var(--surface-2);
  cursor: pointer; text-align: left; border-bottom: 1px solid var(--border);
}
.tree-cat__header .cat__count { margin-left: 4px; }
.tree-cat__body { display: flex; flex-direction: column; }
.tree-cat__bulk {
  margin-left: auto; flex-shrink: 0;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); border-radius: var(--radius-sm); padding: 5px 10px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.tree-cat__bulk.is-hidden { border-color: var(--accent); color: var(--accent); }
.tree-cat__bulk:disabled { opacity: .5; cursor: default; }

/* ===== Выгрузка сметы ===== */
.exports { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.exports__title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 8px; }
.exports__btns { display: flex; gap: 8px; }
.export-btn { flex: 1; padding: 11px 12px; border-radius: var(--radius-sm); font-weight: 700; font-size: 14px; cursor: pointer; border: 1px solid var(--accent); line-height: 1.2; }
.export-btn--client { background: var(--accent); color: #fff; }
.export-btn--internal { background: var(--surface); color: var(--accent); }

/* Кнопка обновления снимка из Syrve (админка) */
.admin__refresh { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.admin__refresh-btn { padding: 9px 14px; font-size: 14px; }
.admin__refresh-status { font-size: 13px; color: var(--profit); font-weight: 600; }
.admin__refresh-status.is-error { color: var(--loss); }
