/* =============================================================================
   FM · Layout — каркас приложения: сайдбар, топбар, страница
   Разметку каркаса генерирует app/core/layout/shell.js — здесь только стили.
   ========================================================================== */

.app {
  display: grid;
  grid-template-columns: var(--fm-sidebar-w) minmax(0, 1fr);
  min-height: 100dvh;
  background: var(--fm-bg);
}

/* --- Сайдбар ----------------------------------------------------------------
   «Диспетчерская»: глубокий петроль, а не чёрный. Свет падает сверху слева —
   оттуда же идёт тёплое пятно вермильона, единственное на всей панели. */

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  background: var(--fm-nav-bg);
  background-image:
    radial-gradient(70% 34% at 12% 0%, rgba(240, 112, 58, .16), transparent 70%),
    radial-gradient(90% 40% at 50% 0%, rgba(30, 98, 115, .5), transparent 65%);
  border-right: 1px solid var(--fm-nav-edge);
  padding: 20px 14px 26px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  z-index: var(--fm-z-sidebar);
}

.sidebar__brand {
  display: flex; align-items: center; gap: 11px;
  padding: 0 6px; text-decoration: none;
}
.sidebar__brand:hover { text-decoration: none; }

/* Марка: петролевая плашка с вермильоновым ромбом внутри — знак FM */
.sidebar__mark {
  width: 32px; height: 32px; border-radius: 10px;
  background: var(--fm-brand-soft); position: relative; flex: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), 0 2px 8px -3px rgba(240, 112, 58, .55);
  transition: transform var(--fm-t-base);
}
.sidebar__brand:hover .sidebar__mark { transform: rotate(-6deg); }
.sidebar__mark::after {
  content: ''; position: absolute; left: 9px; top: 9px;
  width: 14px; height: 14px;
  border: 2px solid var(--fm-accent-bright); border-radius: 3px;
  transform: rotate(45deg);
}
.sidebar__name {
  font-family: var(--fm-font-display); font-weight: 800; font-size: 15px;
  color: var(--fm-nav-text-strong); letter-spacing: var(--fm-tr-title); line-height: 1.2;
}
.sidebar__sub {
  font-family: var(--fm-font-mono); font-size: 10px;
  color: var(--fm-nav-text-mute); letter-spacing: .06em; text-transform: uppercase;
}

.sidebar__user {
  background: var(--fm-nav-bg-2);
  border: 1px solid var(--fm-nav-border);
  border-radius: 11px;
  padding: 10px 11px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
}
.sidebar__user-row { display: flex; align-items: center; gap: 9px; }
.sidebar__avatar {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--fm-brand-soft); border: 1px solid var(--fm-nav-border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--fm-font-mono); font-weight: 600; font-size: 11px;
  color: var(--fm-nav-text-strong); flex: none;
}
.sidebar__user-name {
  font-weight: 600; font-size: 12.5px; color: var(--fm-nav-text-strong);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar__user-role { font-family: var(--fm-font-mono); font-size: 10.5px; color: var(--fm-nav-text-mute); }

/* Демо-переключатель роли. В проде удаляется — роль приходит из JWT.        */
.sidebar__roles { display: flex; gap: 5px; margin-top: 9px; }
.sidebar__role-btn {
  flex: 1; text-align: center; padding: 5px 0;
  font-family: var(--fm-font-mono); font-weight: 600; font-size: 10px; letter-spacing: .04em;
  border: 1px solid var(--fm-nav-border); background: transparent; color: var(--fm-nav-text-mute);
  border-radius: var(--fm-radius-sm);
  transition: border-color var(--fm-t-fast), color var(--fm-t-fast), background var(--fm-t-fast);
}
.sidebar__role-btn:hover { border-color: var(--fm-brand-soft); color: var(--fm-nav-text); }
.sidebar__role-btn[aria-pressed="true"] {
  border-color: var(--fm-brand-soft); background: var(--fm-brand-soft); color: var(--fm-nav-text-strong);
}

.sidebar__nav { display: flex; flex-direction: column; gap: 4px; }

/* Заголовок группы: иконка в своей плашке + подпись + линия до края.
   Линия визуально закрывает предыдущую группу — глазу не нужно мерить
   отступы, чтобы понять, где кончается один раздел и начинается другой. */
.nav-group__title {
  display: flex; align-items: center; gap: 9px; width: 100%;
  border: 0; background: none; cursor: pointer; text-align: left;
  padding: 14px 6px 8px;
  font-family: var(--fm-font-mono); font-weight: 600; font-size: var(--fm-fs-label);
  letter-spacing: var(--fm-tr-label); text-transform: uppercase; color: var(--fm-nav-text-mute);
}
.nav-group__title::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, var(--fm-nav-border), transparent);
}
.nav-group__title .ico {
  width: 24px; height: 24px; padding: 4.5px; flex: none;
  background: rgba(159, 203, 211, .08);
  border: 1px solid var(--fm-nav-border);
  border-radius: 7px;
  color: var(--fm-nav-text);
}
/* У первой группы нет чужого «хвоста» сверху — верхний отступ меньше */
.sidebar__nav > div:first-child .nav-group__title { padding-top: 2px; }

.nav-group__items { display: flex; flex-direction: column; gap: 1px; }
.nav-section { margin: 18px 6px 2px; padding-bottom: 6px; border-bottom: 1px solid var(--fm-nav-border);
  font: 700 10px/1 var(--fm-font-mono); letter-spacing: .18em; text-transform: uppercase; color: var(--fm-accent); }
.nav-section:first-child { margin-top: 0; }
.nav-group__title { padding: 9px 6px 6px; }
.nav-group__title::after { display: none; }
.nav-group__label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-group__chev { margin-left: auto; display: inline-flex; transition: transform .18s ease; color: var(--fm-nav-text-mute); }
.nav-group[data-open="true"] .nav-group__chev { transform: rotate(90deg); }
.nav-group__title:hover .nav-group__label { color: var(--fm-nav-text); }

/* Пункты с отступом под подпись группы: дерево читается без линий */
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px 7px 8px; margin-left: 25px;
  border-radius: var(--fm-radius-sm);
  font-size: 13px; color: var(--fm-nav-text); text-decoration: none;
  transition: background var(--fm-t-fast), color var(--fm-t-fast), transform var(--fm-t-fast);
}
.nav-item:hover {
  color: var(--fm-nav-text-strong); background: rgba(255, 255, 255, .06);
  text-decoration: none; transform: translateX(2px);
}
/* Вертикальная кромка слева: у активного пункта она вермильоновая */
.nav-item__bar {
  width: 2.5px; height: 15px; margin-left: -8px; border-radius: 2px;
  background: transparent; flex: none;
  transition: background var(--fm-t-fast), height var(--fm-t-fast);
}
.nav-item__label { line-height: 1.3; min-width: 0; }
.nav-item__num {
  font-family: var(--fm-font-mono); font-weight: 500; font-size: var(--fm-fs-label);
  color: var(--fm-nav-text-mute); flex: none; margin-left: auto;
}
.nav-item[aria-current="page"] {
  font-weight: 600; color: var(--fm-nav-text-strong); background: var(--fm-nav-active-bg);
  transform: none;
}
.nav-item[aria-current="page"] .nav-item__bar { background: var(--fm-accent-bright); height: 19px; }
.nav-item[aria-current="page"] .nav-item__num { color: var(--fm-nav-text); }

.sidebar__foot {
  margin-top: auto; padding: 13px 8px 0;
  border-top: 1px solid var(--fm-nav-border);
  display: flex; justify-content: space-between;
  font-family: var(--fm-font-mono); font-size: 10.5px; color: var(--fm-nav-text-mute);
}

/* --- Топбар ---------------------------------------------------------------- */

.app__main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: color-mix(in srgb, var(--fm-bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--fm-border);
  padding: 0 var(--fm-page-x);
  position: sticky; top: 0; z-index: var(--fm-z-topbar);
}
.topbar__row { display: flex; align-items: center; gap: 14px; height: var(--fm-topbar-h); }

.topbar__burger {
  display: none; width: 34px; height: 34px; flex: none;
  border: 1px solid var(--fm-border); background: var(--fm-surface);
  border-radius: var(--fm-radius); align-items: center; justify-content: center;
}
.topbar__burger span, .topbar__burger span::before, .topbar__burger span::after {
  content: ''; display: block; width: 15px; height: 1.5px;
  background: var(--fm-text-2); border-radius: 2px; position: relative;
  transition: transform var(--fm-t-base);
}
.topbar__burger span::before { position: absolute; top: -5px; }
.topbar__burger span::after  { position: absolute; top:  5px; }
/* Три полосы складываются в крест, а не просто исчезают */
.app[data-nav="open"] .topbar__burger span { background: transparent; }
.app[data-nav="open"] .topbar__burger span::before { transform: translateY(5px) rotate(45deg); }
.app[data-nav="open"] .topbar__burger span::after  { transform: translateY(-5px) rotate(-45deg); }

.crumbs { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1 1 auto; }
.crumbs__module {
  font-family: var(--fm-font-mono); font-weight: 500; font-size: 11px;
  color: var(--fm-text-3); letter-spacing: .05em;
}
.crumbs__dot { width: 4px; height: 4px; border-radius: 1px; transform: rotate(45deg); background: var(--fm-accent-bright); flex: none; }
.crumbs__title {
  font-family: var(--fm-font-display); font-weight: 700; font-size: 15px;
  color: var(--fm-text); letter-spacing: var(--fm-tr-title);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.search-trigger {
  flex: 0 1 230px; min-width: 46px; margin-left: auto;
  display: flex; align-items: center; gap: 9px;
  background: var(--fm-surface); border: 1px solid var(--fm-border);
  border-radius: var(--fm-radius); padding: 8px 11px; overflow: hidden;
  color: var(--fm-text-3); font-size: var(--fm-fs-sm); text-align: left;
  transition: border-color var(--fm-t-fast), background var(--fm-t-fast);
}
.search-trigger:hover { border-color: var(--fm-brand-line); background: var(--fm-brand-tint-2); }
.search-trigger__label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.search-trigger__kbd {
  margin-left: auto; flex: none;
  font-family: var(--fm-font-mono); font-weight: 500; font-size: 10px;
  border: 1px solid var(--fm-border-input); border-radius: 5px; padding: 1px 5px;
  background: var(--fm-surface-subtle);
}

.topbar__actions { display: flex; align-items: center; gap: 9px; flex: none; }

.page {
  padding: 24px var(--fm-page-x) 44px;
  min-width: 0; flex: 1;
  animation: fm-rise 380ms var(--fm-ease-out);
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 20px;
}
.page-head__title { display: flex; align-items: center; gap: 11px; }
/* Ромб перед заголовком — фирменный знак. Он же в марке и в маркерах. */
.page-head__title::before {
  content: ''; width: 10px; height: 10px; background: var(--fm-accent-bright);
  border-radius: 2px; transform: rotate(45deg); flex: none;
}
.page-head h1 {
  font-size: var(--fm-fs-display); line-height: var(--fm-lh-tight);
  letter-spacing: var(--fm-tr-display); max-width: 720px; font-weight: 800;
}
.page-head__lead {
  margin-top: 7px; max-width: 62ch;
  font-size: var(--fm-fs-body); color: var(--fm-text-2);
  line-height: 1.55;
}
.page-head__actions { display: flex; gap: 8px; flex: none; flex-wrap: wrap; }

/* Панель «ТЗ» — контекст экрана из реестра. Снимается флагом в config.js. */
.spec-bar {
  border-top: 1px solid var(--fm-border-soft);
  padding: 13px 0 15px;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px;
}
.spec-bar__k {
  font-family: var(--fm-font-mono); font-weight: 500; font-size: var(--fm-fs-label);
  letter-spacing: var(--fm-tr-label); text-transform: uppercase; color: var(--fm-text-3); margin-bottom: 4px;
}
.spec-bar__k--rule { color: var(--fm-accent-deep); }
.spec-bar__v { font-size: var(--fm-fs-sm); color: var(--fm-text-2); line-height: 1.45; }

/* --- Сетки страницы --------------------------------------------------------- */

.grid            { display: grid; gap: var(--fm-space-5); align-items: start; }
.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--5         { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid--auto      { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid--auto-lg   { grid-template-columns: repeat(auto-fit, minmax(370px, 1fr)); }
.grid--main-side { grid-template-columns: minmax(0, 1fr) 340px; }
.grid--side-main { grid-template-columns: 300px minmax(0, 1fr); }
.grid--tight     { gap: var(--fm-space-3); }

/* Экран директора для телефона — единственная «узкая» компоновка проекта */
.phone-frame {
  width: 100%; max-width: 390px; margin-inline: auto;
  background: var(--fm-nav-bg); border-radius: 30px; padding: 12px;
  box-shadow: var(--fm-shadow-lg);
}
.phone-frame__screen {
  background: var(--fm-bg); border-radius: 20px; overflow: hidden;
  min-height: 620px; display: flex; flex-direction: column;
}
.phone-frame__bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 10px; background: var(--fm-brand); color: #fff;
}
.phone-frame__body { padding: 14px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }

/* --- Адаптив ---------------------------------------------------------------- */

.sidebar__scrim {
  display: none; position: fixed; inset: 0;
  background: rgba(12, 44, 54, .55); backdrop-filter: blur(2px); z-index: 35;
}

@media (max-width: 1280px) {
  .grid--main-side, .grid--side-main { grid-template-columns: minmax(0, 1fr); }
  .grid--5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .spec-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; width: var(--fm-sidebar-w);
    transform: translateX(-100%); transition: transform var(--fm-t-slow);
    box-shadow: var(--fm-shadow-lg);
  }
  .app[data-nav="open"] .sidebar { transform: none; }
  .app[data-nav="open"] .sidebar__scrim { display: block; animation: fm-fade-in 180ms var(--fm-ease); }
  .topbar__burger { display: flex; }
  .grid--4, .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  :root { --fm-page-x: 18px; --fm-fs-display: 23px; }
  /* В шапке на телефоне остаются только навигация, уведомления, язык и профиль.
     Плашка согласований и панель «ТЗ» переезжают в сам экран. */
  .topbar .topbar__pending, .topbar .topbar__spec { display: none; }
  .page-head { flex-direction: column; align-items: stretch; gap: 14px; }
  .page-head__actions { justify-content: flex-start; }
  .grid--2, .grid--3, .grid--4, .grid--5, .grid--auto-lg { grid-template-columns: minmax(0, 1fr); }
  .spec-bar { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .search-trigger { flex: 0 0 auto; }
  .search-trigger__label, .search-trigger__kbd { display: none; }
}

@media (max-width: 480px) {
  :root { --fm-page-x: 14px; }
  .page { padding-bottom: 28px; }
  .crumbs__module, .crumbs__dot { display: none; }
}

/* --- Полоса открытых экранов (как в 1С) ----------------------------------
   Человек держит открытыми выписку, журнал и карточку и ходит между ними.
   Полоса намеренно узкая: это служебная навигация, а не содержимое экрана —
   каждый лишний пиксель здесь отнимается у таблицы, ради которой человек
   и пришёл. */
.tabbar {
  display: flex; align-items: stretch; gap: 2px;
  padding: 0 var(--fm-page-x); background: var(--fm-surface);
  border-bottom: 1px solid var(--fm-border);
  position: sticky; top: var(--fm-topbar-h); z-index: calc(var(--fm-z-topbar) - 1);
  overflow: hidden; min-height: 30px;
}
.tabbar__list { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.tabbar__list::-webkit-scrollbar { display: none; }

.opentab {
  display: inline-flex; align-items: center; gap: 1px; flex: 0 0 auto;
  max-width: 190px; border-bottom: 2px solid transparent;
  padding: 0 2px 0 8px; color: var(--fm-text-muted);
}
.opentab:hover { background: var(--fm-bg-soft); color: var(--fm-text); }
.opentab--active { border-bottom-color: var(--fm-brand); color: var(--fm-text); }
.opentab__link {
  display: block; padding: 6px 2px; font-size: 11.5px; line-height: 1.2; color: inherit;
  text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;
}
.opentab--active .opentab__link { font-weight: 600; }
.opentab__close {
  border: 0; background: none; cursor: pointer; color: var(--fm-text-muted);
  font-size: 13px; line-height: 1; padding: 2px 4px; border-radius: 4px; opacity: 0.5;
}
.opentab:hover .opentab__close, .opentab--active .opentab__close { opacity: 1; }
.opentab__close:hover { background: var(--fm-danger-bg); color: var(--fm-danger-fg); }
.tabbar__all {
  border: 0; background: none; cursor: pointer; color: var(--fm-text-muted);
  font-size: 10.5px; padding: 0 6px; white-space: nowrap; align-self: center;
}
.tabbar__all:hover { color: var(--fm-text); text-decoration: underline; }

@media print { .tabbar { display: none; } }
