/* ============================================================
   StarLeads KB — сетка приложения: header, sidebar, main
   ============================================================ */

body {
  display: flex;
  flex-direction: column;
}

/* ---------- Шапка ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--header-h);
  padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
  margin-left: auto;
}

.sidebar-toggle {
  display: none;
}

/* ---------- Бренд ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  transition: background var(--transition);
}

.brand:hover {
  background: var(--surface-3);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  color: var(--primary-contrast);
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 55%, var(--accent)));
  border-radius: 9px;
  box-shadow: var(--shadow-sm);
}

.brand-mark .icon {
  width: 18px;
  height: 18px;
  stroke-width: 1.6;
}

.brand-name {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-tag {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* ---------- Иконка-кнопка ---------- */
.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--text-2);
  border-radius: var(--radius-md);
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-3);
}

/* Переключатель темы: показываем иконку текущей темы */
.theme-toggle .icon-moon,
[data-theme='dark'] .theme-toggle .icon-sun {
  display: none;
}

[data-theme='dark'] .theme-toggle .icon-moon {
  display: block;
}

/* ---------- Тело приложения ---------- */
.app-body {
  display: flex;
  align-items: flex-start;
  flex: 1;
  min-height: 0;
}

/* ---------- Сайдбар ---------- */
.sidebar {
  position: sticky;
  top: var(--header-h);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  flex: none;
  padding: 18px 14px 20px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.nav-group-label {
  padding: 0 10px;
  margin-bottom: 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

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

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
}

.sidebar-backdrop {
  display: none;
}

/* ---------- Основная область ---------- */
.main {
  flex: 1;
  min-width: 0;
  padding: 28px clamp(16px, 3vw, 40px) 72px;
}

.main:focus {
  outline: none;
}

.page {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ---------- Адаптив ---------- */
@media (max-width: 960px) {
  .sidebar-toggle {
    display: grid;
  }

  .brand-tag {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    z-index: var(--z-sidebar);
    transform: translateX(-102%);
    width: min(320px, 86vw);
    height: calc(100dvh - var(--header-h));
    box-shadow: var(--shadow-lg);
    transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
    visibility: hidden;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    visibility: visible;
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: var(--header-h) 0 0 0;
    z-index: calc(var(--z-sidebar) - 1);
    background: var(--overlay);
    animation: fade-in 180ms ease;
  }

  .main {
    padding-top: 22px;
  }
}

@media (max-width: 640px) {
  .brand-name {
    display: none;
  }

  .app-header {
    gap: 8px;
    padding: 0 10px;
  }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
