/* Нативная тема Telegram Mini App (§8). Светлая/тёмная через --tg-theme-*.
   Значения приходят из Telegram.WebApp.themeParams; ниже — дефолты-фолбэки. */
:root {
  --accent: #2481CC;              /* акцентный; переопределяется button_color */
  --bg: #EFEFF4;                  /* фон экрана (secondary) */
  --card: #FFFFFF;                /* карточки/списки */
  --header: #FFFFFF;
  --text: #000000;
  --hint: #8E8E93;
  --sep: rgba(60,60,67,0.12);
  --sep-strong: rgba(60,60,67,0.29);
  --chip-bg: rgba(118,118,128,0.12);
  --tabbar: #F7F7F8;
  --on-accent: #FFFFFF;
  --danger: #E5533C;

  /* Цвета статусов экземпляра (§5) — фиксированные, из дизайна */
  --st-in_stock: #1E9E5A;
  --st-reserved: #7A5AF0;
  --st-pending: #E5820A;
  --st-issued: #6E7A8A;
  --st-repair: #E5533C;
  --st-damaged: #E5533C;
  --st-lost: #C1121F;
  --st-written_off: #9AA1AC;
}
:root.dark {
  --bg: #0E1621;
  --card: #17212B;
  --header: #17212B;
  --text: #FFFFFF;
  --hint: #708499;
  --sep: rgba(255,255,255,0.07);
  --sep-strong: rgba(255,255,255,0.18);
  --chip-bg: rgba(255,255,255,0.08);
  --tabbar: #131C26;
  --danger: #E5533C;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'SF Pro Text', 'Segoe UI', system-ui, Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
#app { display: flex; flex-direction: column; min-height: 100%; }

/* Заголовок экрана */
.hdr {
  position: sticky; top: 0; z-index: 10;
  background: var(--header);
  border-bottom: 0.5px solid var(--sep);
  padding: 12px 8px; display: flex; align-items: center; gap: 4px;
  /* Учитываем и вырез экрана, и безопасную зону Telegram (fullscreen) */
  padding-top: calc(12px + env(safe-area-inset-top) + var(--tg-content-top, 0px));
}
.hdr__back { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.hdr__title { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.hdr__title b { font-size: 16px; font-weight: 600; }
.hdr__title span { font-size: 12px; color: var(--hint); }
.hdr__actions { display: flex; gap: 8px; padding-right: 6px; }
.hdr__btn { width: 29px; height: 29px; border-radius: 50%; background: var(--chip-bg);
  display: flex; align-items: center; justify-content: center; font-size: 17px; color: var(--hint); cursor: pointer; }

/* Прокручиваемая область */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-top: 4px; padding-bottom: 24px; }

/* Секции и списки в стиле iOS */
.section-title { font-size: 13px; color: var(--hint); text-transform: uppercase;
  letter-spacing: 0.3px; padding: 16px 16px 8px; }
.list { background: var(--card); border-radius: 14px; margin: 0 16px 16px; overflow: hidden; }
.row { display: flex; align-items: center; min-height: 54px; padding: 9px 16px; gap: 12px; cursor: pointer; }
.row:active { background: var(--chip-bg); }
.row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row__title { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__sub { font-size: 13px; color: var(--hint); }
.sep { height: 0.5px; background: var(--sep); margin-left: 16px; }
.sep--icon { margin-left: 66px; }
.chevron { flex-shrink: 0; }

/* Иконка-код категории (NB/PH/…) */
.code-ic { width: 38px; height: 38px; border-radius: 9px; display: flex; align-items: center;
  justify-content: center; color: #fff; font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 12px; font-weight: 700; letter-spacing: 0.5px; flex-shrink: 0; }

/* Пилюля статуса */
.pill { font-size: 13px; font-weight: 600; padding: 4px 9px; border-radius: 8px; white-space: nowrap; }

/* Достаточный тач-таргет для мелкой кнопки отмены заявки */
[data-cancel] { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }

/* Поиск и фильтры */
.searchbar { padding: 12px 16px 4px; }
.searchbar input { width: 100%; border: 0; outline: 0; background: var(--chip-bg); color: var(--text);
  border-radius: 11px; padding: 10px 12px; font-size: 16px; }
.searchbar input::placeholder { color: var(--hint); }
.filters { display: flex; gap: 8px; padding: 10px 16px 12px; overflow-x: auto; }
.filters::-webkit-scrollbar { display: none; }
.chip { white-space: nowrap; padding: 7px 14px; border-radius: 16px; font-size: 14px; font-weight: 500;
  background: var(--chip-bg); color: var(--text); border: 0; cursor: pointer; }
.chip--on { background: var(--accent); color: var(--on-accent); }

/* Кнопки */
.footer { padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); background: var(--bg);
  position: sticky; bottom: 0; display: flex; flex-direction: column; gap: 8px; }
.btn { height: 50px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 600; border: 0; cursor: pointer; width: 100%; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--secondary { background: var(--chip-bg); color: var(--text); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--ghost { background: transparent; color: var(--accent); font-weight: 500; }
.btn:disabled { opacity: 0.5; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { height: 44px; font-size: 16px; }

/* Таб-бар */
.tabbar { border-top: 0.5px solid var(--sep); background: var(--tabbar); display: flex;
  padding: 8px 0 calc(22px + env(safe-area-inset-bottom)); position: sticky; bottom: 0; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; }
.tab span { font-size: 11px; color: var(--hint); }
.tab--on span { color: var(--accent); }

/* Формы */
.field { padding: 9px 16px 10px; }
.field label { display: block; font-size: 12px; color: var(--hint); margin-bottom: 2px; }
.field input, .field textarea, .field select {
  width: 100%; border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 16px; font-family: inherit; padding: 0; }
textarea {
  width: 100%; border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 16px; font-family: inherit; line-height: 1.45;
  min-height: 92px; resize: none; overflow: hidden; }
.hint-note { font-size: 13px; color: var(--hint); padding: 8px 20px 0; line-height: 1.4; }

/* Плитки-статы (отчёты) */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
.tile { background: var(--card); border-radius: 14px; padding: 16px; }
.tile__val { font-size: 34px; font-weight: 700; line-height: 1; }
.tile__lbl { font-size: 14px; color: var(--hint); margin-top: 6px; }

/* Сетка каталога */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px 16px 20px; }
.gcard { background: var(--card); border-radius: 14px; overflow: hidden; cursor: pointer; }
.gcard__ph { height: 92px; background: repeating-linear-gradient(45deg,
  var(--chip-bg) 0 9px, transparent 9px 18px); display: flex; align-items: center; justify-content: center;
  position: relative; }
.gcard__body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }

/* Пустое состояние, тосты */
.empty { text-align: center; color: var(--hint); padding: 48px 24px; font-size: 15px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(0,0,0,0.82); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: 14px; z-index: 100; max-width: 80%; text-align: center; }
.spinner { width: 26px; height: 26px; border: 2.5px solid var(--sep-strong);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Карточки-контейнеры (очередь/приёмка) */
.card { background: var(--card); border-radius: 14px; padding: 14px 16px; margin: 0 16px 12px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.photo-thumb { width: 84px; height: 84px; border-radius: 12px; object-fit: cover; }
.photo-add { width: 84px; height: 84px; border-radius: 12px; border: 1.5px dashed var(--sep-strong);
  display: flex; align-items: center; justify-content: center; color: var(--accent); font-size: 32px; font-weight: 300; cursor: pointer; }
