/* =============================================================================
   Каркас и типографика административной панели.

   Раскладка: слева навигация, сверху шапка, справа содержимое. На узком экране
   навигация уезжает в шторку, а внизу появляется полоса с четырьмя главными
   разделами — на телефоне мастера в цеху так быстрее, чем открывать меню.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

/* Приложение живёт внутри #app, и ему тоже нужна полная высота: без этой
   строки .app { height: 100% } считает высоту от блока с высотой «auto», то
   есть от содержимого, и на коротком экране тёмная боковая полоса
   заканчивается посередине страницы. */
#app { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs)/1.55 var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; }
h1 { font-size: var(--fs-xl); letter-spacing: -.01em; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p  { margin: 0 0 .7em; }
a  { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Цифры в таблицах должны стоять колонкой — иначе взгляд не сравнивает суммы. */
.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* --- Оболочка ------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: 100%;
  height: 100%;
}

/* --- Навигация ------------------------------------------------------------ */

.nav {
  grid-row: 1;
  display: flex;
  flex-direction: column;
  /* Тёмная в любой теме — см. пояснение в tokens.css. */
  background: var(--nav-bg);
  border-right: 1px solid var(--nav-line);
  overflow: hidden;
}

.nav__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--nav-line);
  flex: 0 0 auto;
  color: #fff;
}

.nav__logo {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--acc), var(--purple));
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 14px;
  flex: 0 0 auto;
}

.nav__title { font-weight: 700; font-size: var(--fs-md); letter-spacing: -.01em; }
.nav__title small { display: block; font-size: var(--fs-xs); font-weight: 500; color: var(--nav-text-2); letter-spacing: 0; }

.nav__scroll { flex: 1 1 auto; overflow-y: auto; padding: 10px 8px 16px; }

.nav__group { margin: 0 0 4px; }
.nav__cap {
  padding: 12px 10px 5px;
  font-size: var(--fs-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--nav-text-2);
}

.nav__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--nav-text);
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
}
.nav__link:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav__link.is-active { background: var(--nav-active); color: #fff; font-weight: 600; }
.nav__link svg { flex: 0 0 auto; opacity: .85; }
.nav__link.is-active svg { opacity: 1; }
.nav__badge {
  margin-left: auto;
  min-width: 20px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--bad); color: #fff;
  font-size: var(--fs-xs); font-weight: 700;
  display: grid; place-items: center;
}
.nav__badge.is-dim { background: var(--surface-3); color: var(--text-2); }

.nav__foot { flex: 0 0 auto; padding: 10px; border-top: 1px solid var(--nav-line); }

/* --- Основная область ---------------------------------------------------- */

.main {
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-h);
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.header__title { font-size: var(--fs-md); font-weight: 650; }
.header__sub { font-size: var(--fs-sm); color: var(--text-3); }
.header__spacer { flex: 1 1 auto; }
/* Селектор нарочно из двух классов: .btn в app.css тоже задаёт display, и при
   равной силе побеждает файл, подключённый позже. Кнопка меню оказалась бы
   видна на большом экране, где меню и так на месте. */
.header .header__burger { display: none; }

.content {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px;
  scroll-behavior: smooth;
}
/* Раздел лежит внутри .view (свой узел на каждую отрисовку — см. router.js),
   поэтому селектор не «> .page», а через потомка. */
.content .page { max-width: 1500px; margin: 0 auto; }

/* --- Сетки --------------------------------------------------------------- */

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row--tight { gap: 6px; }
.row--end { justify-content: flex-end; }
.row--between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }

.grid { display: grid; gap: 12px; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--auto { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid--wide { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.stack { display: grid; gap: 12px; }
.stack--sm { gap: 8px; }
.stack--lg { gap: 18px; }

.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.hidden { display: none !important; }

/* --- Утилиты текста ------------------------------------------------------ */

.t-dim  { color: var(--text-3); }
.t-2    { color: var(--text-2); }
.t-sm   { font-size: var(--fs-sm); }
.t-xs   { font-size: var(--fs-xs); }
.t-lg   { font-size: var(--fs-lg); }
.t-b    { font-weight: 650; }
.t-ok   { color: var(--ok-text); }
.t-bad  { color: var(--bad-text); }
.t-warn { color: var(--warn-text); }
.t-acc  { color: var(--acc-text); }
.t-prod { color: var(--prod-text); }
.t-right{ text-align: right; }
.t-center { text-align: center; }
.t-nowrap { white-space: nowrap; }
.t-cut {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =============================================================================
   Узкий экран.

   760px — не «телефон», а «одна колонка»: сюда попадает и телефон, и половина
   экрана моноблока, если человек открыл рядом накладную.
   ========================================================================== */

@media (max-width: 1100px) {
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--wide { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  :root { --nav-w: 0px; }

  .app { grid-template-columns: 1fr; }

  .nav {
    position: fixed;
    inset: 0 auto 0 0;
    width: 272px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-3);
  }
  .nav.is-open { transform: none; }

  .nav__backdrop {
    position: fixed; inset: 0; z-index: 55;
    background: var(--overlay);
    opacity: 0; pointer-events: none;
    transition: opacity .22s ease;
  }
  .nav__backdrop.is-open { opacity: 1; pointer-events: auto; }

  .header .header__burger { display: inline-flex; }
  .content { padding: 12px; padding-bottom: 76px; }

  .grid--2, .grid--3 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
  /* Chrome для iOS рисует системный шрифт крупнее Safari, а масштаб внутри
     приложения не поменять. Свой кегль на узком экране — единственный способ
     получить одинаковую плотность (в OmborX это уже проверено). */
  :root {
    --fs-xs: 12px;
    --fs-sm: 13px;
    --fs: 14px;
    --fs-md: 15.5px;
    --fs-lg: 18px;
    --fs-xl: 22px;
    --fs-2xl: 27px;
  }
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .grid--4 { grid-template-columns: minmax(0, 1fr); }
}

/* --- Нижняя полоса на узком экране --------------------------------------- */

.tabbar { display: none; }

@media (max-width: 900px) {
  .tabbar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 40;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .tabbar a {
    display: grid;
    place-items: center;
    gap: 2px;
    padding: 7px 2px 6px;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 550;
    text-decoration: none;
  }
  .tabbar a.is-active { color: var(--acc); }
  .tabbar a:hover { text-decoration: none; }
}

/* --- Печать -------------------------------------------------------------- */

@media print {
  .nav, .header, .tabbar, .filterbar, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .content { overflow: visible; padding: 0; }
  .card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
  a { color: #000; text-decoration: none; }
}
