/* ============================================================
   Qualims — Sidebar (.side-шелл, порт из docs/design/assets/shell.css).
   Дизайн-ревизия: аккордеон из хаб-групп. Тёмная панель в ОБЕИХ темах
   (--sidebar-* в tokens.css). Функциональные расширения (сворачивание,
   мобайл, дропдаун профиля, util-кнопки, бейджи) сохранены поверх шелла.
   JS — static/js/sidebar.js.
   ============================================================ */
:root { --sidebar-w: 250px; --sidebar-cw: 56px; }

.side {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--sidebar-line);
  z-index: 100; overflow: hidden;
  transition: width var(--m-base) var(--ease);
}

/* ── Head: brand + pills ── */
.side-head { padding: 1rem 1.1rem .85rem; flex-shrink: 0; }
.side-brand { display: flex; align-items: center; gap: 9px; }
.side-brand .brand-link { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; text-decoration: none; color: inherit; overflow: hidden; }
.side-brand .brand-logo { height: 20px; flex-shrink: 0; }
.side-brand .brand-mark { width: 26px; height: 26px; flex-shrink: 0; display: block; }
.side-brand .name { font-weight: 700; font-size: 1.05rem; letter-spacing: .01em; color: #fff; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-brand .collapse {
  flex-shrink: 0; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  border-radius: 5px; background: none; border: none; cursor: pointer;
  color: var(--sidebar-ink-2); font-size: .8rem;
  transition: background var(--m-fast), color var(--m-fast);
}
.side-brand .collapse:hover { background: rgba(255,255,255,.08); color: #fff; }

.side-pills { display: flex; gap: 6px; margin-top: 11px; flex-wrap: wrap; }
.pill { font-size: var(--text-2xs); font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 8px; border-radius: var(--r-full); line-height: 1.3; }
.pill-plan { background: rgba(13,148,136,.22); color: #7ff0e2; }
.pill-demo { background: rgba(181,121,15,.28); color: #f3cf8c; }

/* ── Nav ── */
.side-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: .35rem .6rem 1rem; }
.side-nav > * { flex-shrink: 0; }

/* ВНИМАНИЕ: .nav-item — Bootstrap-класс (<li class="nav-item"> в контентных
   .nav-tabs на Профиле/Настройках). Поэтому правила сайдбара заскоуплены на
   .side — иначе sidebar-стиль (display:flex; width:100%) протекал в табы и
   ломал их в вертикальный столбец. */
.side .nav-item {
  position: relative;
  display: flex; align-items: center; gap: 11px; padding: 8px 11px;
  border-radius: var(--r-sm); color: var(--sidebar-ink);
  font-size: var(--text-base); font-weight: 500; cursor: pointer;
  text-decoration: none; background: none; border: none; width: 100%; text-align: left;
  white-space: nowrap; overflow: hidden;
  transition: background var(--m-fast) var(--ease), color var(--m-fast) var(--ease);
}
.side .nav-item i { font-size: 1rem; width: 18px; text-align: center; flex-shrink: 0;
  color: var(--sidebar-ink-2); transition: color var(--m-fast); }
.side .nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.side .nav-item:hover i { color: var(--sidebar-ink); }
.side .nav-item.active { background: var(--sidebar-active-bg); color: #fff; font-weight: 600; }
.side .nav-item.active i { color: var(--accent-strong); }
.side .nav-item.active::before { content: ""; position: absolute; left: -3px; top: 8px; bottom: 8px; width: 3px;
  border-radius: var(--r-full); background: var(--accent); }
.nav-item-help { margin-top: .5rem; }

/* ── Accordion groups ── */
.nav-group { margin-top: .55rem; }
.nav-group-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: var(--text-2xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--sidebar-ink-2); padding: 5px 11px; margin-bottom: 2px; cursor: pointer; user-select: none;
  border-radius: var(--r-sm); transition: color var(--m-fast), background var(--m-fast);
}
.nav-group-label:hover { color: #fff; background: rgba(255,255,255,.04); }
.nav-group-label .chev { font-size: .6rem; transition: transform var(--m-base); flex-shrink: 0; }
.nav-group.collapsed .nav-group-label .chev { transform: rotate(-90deg); }
.nav-group.collapsed .nav-sub { display: none; }
.nav-sub .nav-item { padding-left: 11px; font-weight: 450; }
.nav-sub .nav-item i { font-size: .9rem; }

/* ── Foot ── */
.side-foot { border-top: 1px solid var(--sidebar-line); padding: .4rem .35rem .3rem; flex-shrink: 0; }
.sidebar-util-row { display: flex; align-items: center; gap: .15rem; padding: .1rem .35rem .25rem; }
.sidebar-util-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 6px;
  background: none; border: none; cursor: pointer; position: relative; text-decoration: none;
  color: var(--sidebar-ink-2); font-size: .9rem; flex-shrink: 0;
  transition: background var(--m-fast), color var(--m-fast);
}
.sidebar-util-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-badge {
  position: absolute; top: 1px; right: 1px;
  font-size: .5rem; font-weight: 700; padding: .15em .3em;
  border-radius: var(--r-full); line-height: 1; color: #fff;
}
.sidebar-profile {
  display: flex; align-items: center; gap: .5rem;
  padding: .35rem .6rem; cursor: pointer; border-radius: var(--r-sm);
  transition: background var(--m-fast); min-width: 0;
}
.sidebar-profile:hover { background: rgba(255,255,255,.06); }
.sidebar-userinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.sidebar-username { font-size: var(--text-sm); font-weight: 600; color: #fff;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-userrole { font-size: var(--text-2xs); color: var(--sidebar-ink-2);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-profile-chevron { font-size: .65rem; color: var(--sidebar-ink-2); flex-shrink: 0; }
.sidebar-profile-menu { margin: .25rem .35rem 0; border-radius: var(--r-sm);
  background: rgba(255,255,255,.05); overflow: hidden; }
.sidebar-profile-menu a, .sidebar-profile-menu button {
  display: flex; align-items: center; gap: .5rem; padding: .45rem .75rem; font-size: var(--text-sm);
  color: var(--sidebar-ink); text-decoration: none; background: none; border: none; width: 100%; cursor: pointer;
  transition: background var(--m-fast), color var(--m-fast); white-space: nowrap;
}
.sidebar-profile-menu a:hover, .sidebar-profile-menu button:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-profile-menu .divider { height: 1px; background: var(--sidebar-line); margin: .15rem 0; }

/* ── Collapsed (icon-only): свёрнут по умолчанию + hover-раскрытие ──
   Раскрытие — ОВЕРЛЕЕМ (панель выезжает поверх контента, .sbc остаётся на
   узком отступе — страница не разъезжается). Также раскрываем при фокусе
   внутри (клавиатурная доступность, :focus-within). Пин (sbPinBtn)
   закрепляет панель развёрнутой. Весь блок — только desktop ≥992px:
   на мобиле работает прежний .open-оверлей с полной панелью. */
@media (min-width: 992px) {
  .side.sb-collapsed { width: var(--sidebar-cw); }
  .side.sb-collapsed:hover,
  .side.sb-collapsed:focus-within {
    width: var(--sidebar-w);
    z-index: 300;                                  /* поверх контента */
    box-shadow: 6px 0 24px rgba(0, 0, 0, .22);
    /* лёгкая задержка входа — пролёт курсора мимо панели её не дёргает */
    transition-delay: .12s;
  }

  /* скрытие подписей/панелей — только пока НЕ раскрыт ховером/фокусом */
  .side.sb-collapsed:not(:hover):not(:focus-within) .side-head { padding: 1rem .5rem .85rem; }
  .side.sb-collapsed:not(:hover):not(:focus-within) .brand-link .name,
  .side.sb-collapsed:not(:hover):not(:focus-within) .side-pills,
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-item > span,
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-group-label,
  .side.sb-collapsed:not(:hover):not(:focus-within) .sidebar-userinfo,
  .side.sb-collapsed:not(:hover):not(:focus-within) .sidebar-util-row,
  .side.sb-collapsed:not(:hover):not(:focus-within) .sidebar-profile-chevron,
  .side.sb-collapsed:not(:hover):not(:focus-within) .sidebar-profile-menu,
  /* пин и шеврон в узкой полосе не нужны — появятся при раскрытии */
  .side.sb-collapsed:not(:hover):not(:focus-within) .side-brand .collapse { display: none !important; }
  .side.sb-collapsed:not(:hover):not(:focus-within) .side-brand { justify-content: center; }
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-group { margin-top: .25rem; }
  /* в icon-only иконки групп видимы всегда (аккордеон «не существует») */
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-group.collapsed .nav-sub { display: block; }
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-item { justify-content: center; padding: 8px 0; }
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-sub .nav-item { padding-left: 0; }
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-item.active::before { display: none; }
  .side.sb-collapsed:not(:hover):not(:focus-within) .sidebar-badge { display: none; }
  .side.sb-collapsed:not(:hover):not(:focus-within) .sidebar-profile { justify-content: center; padding: .4rem 0; }
  /* фикс мигания: в icon-only гасим анимации аккордеона (страховка к
     JS-гварду в toggleGroup) */
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-group,
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-sub,
  .side.sb-collapsed:not(:hover):not(:focus-within) .nav-group-label .chev {
    transition: none !important; animation: none !important;
  }
}

/* ── Main content offset ── */
.main-content-offset { margin-left: var(--sidebar-w); min-height: 100vh; transition: margin-left var(--m-base) var(--ease); }
.main-content-offset.sbc { margin-left: var(--sidebar-cw); }

/* ── Mobile ── */
.sidebar-toggle {
  display: none; position: fixed; top: .75rem; left: .75rem; z-index: 200;
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--r-sm); width: 36px; height: 36px;
  align-items: center; justify-content: center; font-size: 1.1rem; cursor: pointer;
}
.sidebar-overlay { display: none; position: fixed; inset: 0; z-index: 99; background: rgba(0,0,0,.35); }
@media (max-width: 991px) {
  .sidebar-toggle { display: flex; }
  .side { transform: translateX(-100%); transition: transform .25s; width: var(--sidebar-w) !important; }
  .side.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.15); }
  .sidebar-overlay.open { display: block; }
  .main-content-offset { margin-left: 0 !important; padding-top: 3rem; }
}
