/* =====================================================================
   Каркас: .app-layout = сайдбар | рабочая область.
   Рабочая область: шапка 64px → полоса вкладок → контент на всю оставшуюся ширину и высоту.
   ===================================================================== */

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  transition: grid-template-columns var(--dur-base) var(--ease-out);
}

.app-layout.sidebar-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ---------- Сайдбар ---------- */
.sidebar {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  background: var(--bg-elevated);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border-right: 1px solid var(--glass-border);
  z-index: var(--z-sidebar);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: none;
  height: var(--topbar-h);
  padding: 0 var(--sp-5);
  border-bottom: 1px solid var(--glass-border);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  background: var(--accent-gradient);
  color: var(--on-accent);
  font-weight: var(--fw-bold);
  font-size: var(--fs-lg);
  box-shadow: var(--glow-md);
}

.brand-name { font-weight: var(--fw-bold); letter-spacing: .01em; white-space: nowrap; font-size: var(--fs-lg); }
.brand-sub { color: var(--text-faint); font-size: var(--fs-xs); white-space: nowrap; }

.nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-2) var(--sp-3) var(--sp-4);
}

.nav-section {
  padding: var(--sp-5) var(--sp-3) var(--sp-2);
  color: var(--text-faint);
  font-size: 10.5px;
  font-weight: var(--fw-bold);
  letter-spacing: .1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  height: 38px;
  padding: 0 var(--sp-3);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  text-align: left;
  white-space: nowrap;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}

.nav-item:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.nav-item.active {
  background: linear-gradient(90deg, rgba(0, 102, 255, .22), rgba(0, 198, 255, .06));
  border-color: var(--glass-border);
  color: var(--text);
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -13px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: var(--r-pill);
  background: var(--accent-gradient);
  box-shadow: var(--glow-md);
}

.nav-item.active .icon { color: var(--accent-2); filter: drop-shadow(0 0 6px rgba(0, 198, 255, .6)); }
.nav-item:disabled { opacity: .45; cursor: default; }
.nav-label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }

.nav-badge {
  min-width: 22px;
  padding: 0 7px;
  border-radius: var(--r-pill);
  background: var(--accent-gradient);
  color: var(--on-accent);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  line-height: 20px;
  text-align: center;
  box-shadow: var(--glow-md);
}

.nav-step {
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-faint);
  font-size: 10px;
  line-height: 18px;
}

.sidebar-footer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-3);
  border-top: 1px solid var(--glass-border);
}

.profile {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  padding: var(--sp-2);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--text);
  text-align: left;
  min-width: 0;
}

.profile:hover { background: var(--surface-2); border-color: var(--glass-border); }
.profile-meta { min-width: 0; flex: 1 1 auto; }
.profile-role { color: var(--text-on-surface-accent); font-size: var(--fs-xs); font-weight: var(--fw-semibold); }

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--on-accent);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  box-shadow: var(--glow-sm);
}

.sidebar-collapsed .brand-text,
.sidebar-collapsed .nav-label,
.sidebar-collapsed .nav-section,
.sidebar-collapsed .profile-meta,
.sidebar-collapsed .nav-badge,
.sidebar-collapsed .nav-step { display: none; }

.sidebar-collapsed .nav-item { justify-content: center; padding: 0; }
.sidebar-collapsed .brand { justify-content: center; padding: 0; }
.sidebar-collapsed .profile { justify-content: center; }
.sidebar-collapsed .nav-item.active::before { left: -11px; }

/* ---------- Рабочая область ---------- */
.workspace {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: none;
  height: var(--topbar-h);
  padding: 0 var(--content-pad);
  background: var(--bg-elevated);
  backdrop-filter: blur(var(--blur));
  -webkit-backdrop-filter: blur(var(--blur));
  border-bottom: 1px solid var(--glass-border);
}

.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; flex: none; }

.global-search { position: relative; flex: 1 1 auto; max-width: 620px; min-width: 0; }

.global-search .input {
  height: 42px;
  padding-left: 42px;
  padding-right: 64px;
  border-radius: var(--r-md);
  background: var(--surface);
  border-color: var(--glass-border);
}

.global-search > .icon { position: absolute; left: 14px; top: 12px; color: var(--accent-2); pointer-events: none; }
.global-search kbd { position: absolute; right: 10px; top: 11px; }

.tabs-bar {
  display: flex;
  align-items: flex-end;
  flex: none;
  height: var(--tabsbar-h);
  padding: 0 var(--content-pad);
  border-bottom: 1px solid var(--glass-border);
  background: color-mix(in srgb, var(--bg) 60%, transparent);
}

.content-area {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.page[hidden] { display: none; }

.page-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-4) var(--content-pad);
  border-bottom: 1px solid var(--glass-border);
}

.page-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: var(--content-pad);
}

.page-body.flush { padding: 0; overflow: hidden; display: flex; flex-direction: column; }

.page-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  padding: var(--sp-2) var(--content-pad);
  border-top: 1px solid var(--glass-border);
  background: var(--bg-elevated);
  backdrop-filter: blur(var(--blur));
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

/* ---------- Телефон ---------- */
.bottombar,
.sidebar-scrim { display: none; }

@media (max-width: 1100px) {
  :root { --content-pad: 16px; }
  .topbar .hide-narrow { display: none; }
}

@media (max-width: 767px) {
  .app-layout,
  .app-layout.sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease-out);
    box-shadow: var(--shadow-lg);
    background: var(--surface-solid);
  }

  .app-layout.sidebar-open .sidebar { transform: none; }

  .app-layout.sidebar-open .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: calc(var(--z-sidebar) - 1);
  }

  .sidebar-collapsed .brand-text,
  .sidebar-collapsed .nav-label,
  .sidebar-collapsed .nav-section,
  .sidebar-collapsed .profile-meta { display: initial; }

  .workspace { grid-column: 1; padding-bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom)); }
  .topbar { gap: var(--sp-2); padding: 0 var(--sp-3); }
  .topbar .hide-mobile, .global-search kbd { display: none; }
  .global-search .input { padding-right: 12px; }
  .tabs-bar { padding: 0 var(--sp-2); }

  .bottombar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-elevated);
    backdrop-filter: blur(var(--blur));
    border-top: 1px solid var(--glass-border);
    z-index: var(--z-sticky);
  }

  .bottombar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: 100%;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: var(--fs-xs);
  }

  .bottombar-item.active { color: var(--accent-2); }

  .fab {
    justify-self: center;
    display: grid;
    place-items: center;
    width: var(--fab-size);
    height: var(--fab-size);
    margin-top: calc(var(--fab-size) / -2.4);
    border: 0;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: var(--on-accent);
    box-shadow: var(--glow-lg);
  }

  .fab .icon { width: 28px; height: 28px; }
}

/* Профиль в шапке — только на телефоне, где нет бокового меню. */
.topbar .show-mobile { display: none; }
.avatar.avatar-sm { width: 30px; height: 30px; font-size: 11px; }
@media (max-width: 767px) {
  .topbar .show-mobile { display: inline-grid; }
  .sidebar, .sidebar-scrim { display: none; }
}

/* Вкладки раздела (компьютер): инструменты выбранного раздела меню со счётчиками. */
.section-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: none;
  min-height: 46px;
  padding: 6px var(--content-pad);
  border-bottom: 1px solid var(--glass-border);
  background: color-mix(in srgb, var(--bg-elevated) 70%, transparent);
  backdrop-filter: blur(var(--blur));
}
.section-bar.hidden { display: none; }
.section-tabs { display: flex; gap: 4px; min-width: 0; flex: 0 1 auto; overflow-x: auto; scrollbar-width: none; }
.section-tabs:empty { display: none; }
/* Открытые карточки и документы — справа в том же ряду, без отдельной полосы вкладок. */
.section-bar .tabs-bar { flex: 1 1 0; justify-content: flex-end; min-width: 120px; height: auto; margin-left: auto;
  padding: 0; border: 0; background: none; backdrop-filter: none; }
.section-bar .tabs-bar.hidden { display: none; }
.section-bar .tabs-bar .tabstrip { flex: 0 1 auto; }
.section-tabs:empty + .tabs-bar { justify-content: flex-start; margin-left: 0; }
.section-tabs::-webkit-scrollbar { display: none; }
.section-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  height: 32px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.section-tab:hover { background: var(--surface-2); color: var(--text); }
.section-tab[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--text);
  box-shadow: var(--glow-sm);
}
.section-tab[aria-selected="true"] .icon { color: var(--accent-2); }
.section-badge {
  min-width: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--accent-gradient);
  color: var(--on-accent);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  line-height: 18px;
  text-align: center;
}
.section-badge.hidden { display: none; }
.sidebar-collapsed .nav-item .nav-badge { position: absolute; top: 2px; right: 2px; min-width: 16px; padding: 0 4px; line-height: 16px; font-size: 10px; }
@media (max-width: 767px) {
  .section-bar { display: none !important; }
}

@media (min-width: 768px) {
  .dup-tabs { display: none; }
}
/* Карточки и документы в ряду раздела — такие же «пилюли», как вкладки инструментов. */
.section-bar .tab { height: 32px; border: 1px dashed var(--glass-border); border-radius: var(--r-pill); }
.section-bar .tab.active { border-style: solid; border-color: var(--accent-border); background: var(--accent-soft); }
.section-bar .tab.active::after, .section-bar .tab.active::before { display: none; }
