/* Сброс, типографика, каркас: левая панель, верхняя полоса (телефон), область содержимого. */

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: calc(100vh / var(--ui-zoom, 1));
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 20px;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--c-accent-fill); }
svg { display: block; }

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Левая панель ---------- */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  padding: 16px;
  background: var(--c-sidebar);
  color: var(--c-sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow-y: auto;
}

.sidebar-brand {
  font-size: var(--fs-brand);
  line-height: 24px;
  font-weight: 600;
  color: var(--c-sidebar-text-active);
  padding: 4px 12px 20px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar-bottom { margin-top: auto; padding-top: 16px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--r-control);
  color: var(--c-sidebar-text);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
}
.nav-item svg { width: 20px; height: 20px; flex: none; }
@media (hover: hover) { .nav-item:hover { background: var(--c-sidebar-hover); } }
.nav-item.is-active {
  background: var(--c-sidebar-active);
  color: var(--c-sidebar-text-active);
}

.sidebar-overlay { display: none; }

/* ---------- Верхняя полоса (только телефон) ---------- */

.topbar { display: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--c-text);
}
.icon-btn svg { width: 20px; height: 20px; }
@media (hover: hover) { .icon-btn:hover { background: var(--c-field); } }

/* ---------- Содержимое ---------- */

/* Область содержимого занимает высоту окна. Таблица прокручивается внутри своей
   рамки (в обе стороны), поэтому шапка таблицы и подписи под ней всегда на виду.
   Если окно совсем низкое — прокручивается сама область содержимого. */
.content {
  margin-left: var(--sidebar-w);
  padding: var(--content-pad);
  min-width: 0;
  max-width: var(--content-max);
  display: flex;
  flex-direction: column;
  height: calc(100vh / var(--ui-zoom, 1));
  height: calc(100dvh / var(--ui-zoom, 1));
  overflow-y: auto;
  overscroll-behavior-x: none; /* без упругого сдвига вбок (тачпад macOS) */
}
.content > * { flex: none; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  font-size: var(--fs-title);
  line-height: 36px;
  font-weight: 600;
}

/* Дополнение шапки перед поиском (renderShell extra): прижато к поиску справа */
.page-head-extra { margin-left: auto; }

/* ---------- Компьютер: меню — полоса сверху на всю ширину ----------
   Название, пункты в ряд и «Выйти» справа; содержимое под полосой на всю ширину окна — таблице достаётся место
   бывшей левой панели. Узкое окно (до 768) и сенсорные экраны — как прежде (правила ниже). */
@media (min-width: 769px) and (hover: hover) {
  .sidebar {
    right: 0; bottom: auto;
    width: auto;
    height: var(--topbar-h);
    padding: 0 16px;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    overflow: visible;
  }
  .sidebar-brand { padding: 0 12px; margin-right: 12px; }
  .sidebar-nav { flex-direction: row; gap: 4px; }
  .sidebar-bottom { margin-top: 0; margin-left: auto; padding-top: 0; }
  .content {
    margin-left: 0;
    margin-top: var(--topbar-h);
    max-width: none;
    height: calc(100vh / var(--ui-zoom, 1) - var(--topbar-h));
    height: calc(100dvh / var(--ui-zoom, 1) - var(--topbar-h));
  }
}

/* ---------- Телефон ---------- */

@media (max-width: 768px) {
  /* Закрытая панель скрыта совсем (visibility), чтобы Tab не уходил в невидимые пункты. */
  .sidebar {
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--t-base) ease, visibility 0s linear var(--t-base);
    z-index: 60;
  }
  .sidebar.is-open { transform: none; visibility: visible; transition-delay: 0s; }

  .sidebar-overlay {
    display: block;
    position: fixed; inset: 0;
    background: var(--c-overlay);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-base) ease;
  }
  .sidebar-overlay.is-open { opacity: 1; pointer-events: auto; }

  .topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--topbar-h);
    padding: 0 8px;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-line);
  }
  .topbar-title {
    flex: 1;
    min-width: 0;
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .content {
    margin-left: 0;
    height: calc(100vh - var(--topbar-h));
    height: calc(100dvh - var(--topbar-h));
  }

  .page-head { margin-bottom: 16px; }
  .page-head .page-title { display: none; }
  .page-head .search { display: none; width: 100%; }
  body.is-search-open .page-head .search { display: flex; }
  .page-head:not(:has(.search)) { display: none; }
  body:not(.is-search-open) .page-head { margin-bottom: 0; }
  /* Дополнение шапки — отдельной строкой над таблицей (под поиском, если он открыт) */
  .content .page-head.has-extra { flex-wrap: wrap; margin-bottom: 12px; }
  .page-head.has-extra .page-head-extra { order: 2; width: 100%; margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Сенсорные экраны (телефон, планшет) ----------
   Страница открывается целиком в ширине 1360 (см. meta viewport в html) и приближается
   пальцами, как обычный сайт. Чтобы ничего не «плавало», вложенной прокрутки нет:
   таблица лежит на странице, двигается сама страница.
   Разделы стоят одной строкой сверху и закреплены у верхнего края экрана: строка остаётся
   на виду и одного размера при любом приближении (её двигает pinTopBar в js/ui.js). */
@media (hover: none) and (min-width: 769px) {
  body { overflow-x: visible; }

  .sidebar {
    position: absolute;
    top: 0; left: 0; bottom: auto;
    width: max-content;
    height: 44px;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    padding: 2px 8px;
    overflow: visible;
    transform-origin: 0 0;
    transition: opacity 120ms ease;
    z-index: 60;
  }
  /* Пока экран двигают или приближают, строка прячется и появляется уже на новом месте. */
  .sidebar.is-moving { opacity: 0; pointer-events: none; }
  .sidebar-brand { display: none; }
  .sidebar-nav { flex-direction: row; gap: 2px; }
  .sidebar-bottom { margin-top: 0; margin-left: 24px; padding-top: 0; }
  .nav-item { padding: 0 12px; gap: 0; }
  /* В закреплённой строке только подписи: без значков пункты крупнее и по ним легче попасть. */
  .nav-item svg { display: none; }

  .content {
    margin-left: 0;
    height: auto;
    overflow: visible;
  }
}
