/* ==========================================================================
   Оболочка приложения: боковая навигация, верхняя панель, рабочая область
   ========================================================================== */

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

/* ---------- Боковая навигация ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--nav-bg);
  color: var(--nav-text);
  overflow-y: auto;
  scrollbar-width: thin;
  z-index: 40;
}

.sidebar__brand {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px;
  align-items: center;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--nav-line);
}
.brand-mark {
  grid-row: span 2;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--brass);
  border-radius: 50%;
  color: var(--brass);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  box-shadow: inset 0 0 0 3px var(--nav-bg), inset 0 0 0 4px var(--brass);
}
.brand-word {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.14em;
  color: var(--nav-text-active);
  line-height: 1.1;
}
.brand-sub { font-size: var(--fs-xs); color: var(--nav-muted); line-height: 1.3; }

.sidebar__tenant {
  margin: 12px 12px 4px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--nav-hover);
  font-size: var(--fs-sm);
  line-height: 1.35;
}
.sidebar__tenant b { display: block; color: var(--nav-text-active); font-weight: 600; }

.nav { padding: 8px 10px 16px; display: flex; flex-direction: column; gap: 2px; }
.nav__group {
  margin: 14px 10px 4px;
  font-size: var(--fs-xs);
  color: var(--nav-muted);
  letter-spacing: 0.04em;
}
.nav__item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--nav-text);
  font-size: var(--fs-md);
  text-decoration: none;
  position: relative;
}
.nav__item:hover { background: var(--nav-hover); color: var(--nav-text-active); text-decoration: none; }
.nav__item.is-active { background: var(--nav-active); color: var(--nav-text-active); font-weight: 500; }
.nav__item.is-active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brass);
}
.nav__item .icon { width: 18px; height: 18px; flex: none; opacity: 0.9; }
.nav__count {
  margin-left: auto;
  min-width: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--nav-active);
  color: var(--nav-text-active);
  font-size: var(--fs-xs);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.nav__item.is-active .nav__count { background: var(--nav-bg); }

.sidebar__role { display: none; margin: 4px 12px 0; }
.sidebar__role label { display: block; font-size: var(--fs-xs); color: var(--nav-muted); margin-bottom: 4px; }
.sidebar__role .select { background: var(--nav-hover); border-color: var(--nav-line); color: var(--nav-text-active); }

.sidebar__foot {
  margin-top: auto;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--nav-line);
  font-size: var(--fs-xs);
  color: var(--nav-muted);
}

/* ---------- Рабочая область ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--topbar-h);
  padding: 8px var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar__menu { display: none; }
.topbar__search {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 1 420px;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: var(--fs-md);
  text-align: left;
}
.topbar__search:hover { border-color: var(--line-strong); }
.topbar__search span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__spacer { flex: 1 1 auto; }
.topbar__role { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-2); }
.topbar__role select { max-width: 200px; }
.topbar__user { display: flex; align-items: center; gap: 10px; padding-left: 6px; }
.topbar__user-name { font-size: var(--fs-sm); line-height: 1.25; }
.topbar__user-name b { display: block; font-weight: 600; color: var(--text); }
.topbar__user-name span { color: var(--text-3); }

.content {
  width: 100%;
  max-width: 1480px;
  padding-inline: var(--gutter);
  padding-block: 24px 112px;
  outline: none;
}

.scrim { display: none; }

/* ---------- Экран без оболочки (вход) ---------- */
.app--bare { grid-template-columns: minmax(0, 1fr); }
.app--bare .sidebar,
.app--bare .topbar,
.app--bare .help-fab { display: none; }
.app--bare .content { max-width: none; padding: 0; }

/* ---------- Адаптив ---------- */
@media (max-width: 1100px) {
  .topbar__user-name, .topbar__role > span { display: none; }
}

@media (max-width: 960px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-2);
    padding-top: env(safe-area-inset-top, 0px);
  }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 35;
  }
  .topbar__menu { display: inline-grid; }
  .topbar__search { flex: 1 1 auto; }
}

@media (max-width: 560px) {
  .topbar { gap: 6px; }
  .topbar__search kbd { display: none; }
  .topbar__role { display: none; }
  .sidebar__role { display: block; }
  .content { padding-block: 16px 104px; }
}
