/*
 * shell.css — Stage 12.0.83
 * App-shell layout: sidebar (left, fixed) + topbar (sticky) + main content area.
 * Подключается в base.html после tokens.css и components.css.
 *
 * Mobile breakpoint 768px: sidebar collapses в off-canvas drawer
 * с overlay; hamburger button в topbar открывает.
 */

/* ── App shell grid ───────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────── */
.app-sidebar {
  grid-area: sidebar;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 30;
}
.app-sidebar__brand {
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.app-sidebar__logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-strong) 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.18) inset,
              0 6px 14px -4px rgba(0, 134, 209, 0.35);
  flex-shrink: 0;
}
.app-sidebar__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.2;
}
.app-sidebar__subtitle {
  font-size: 11px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-top: 2px;
}

.app-sidebar__nav {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  overflow-y: auto;
}
.app-sidebar__section {
  margin-top: var(--space-4);
}
.app-sidebar__section:first-child { margin-top: 0; }
.app-sidebar__section-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.app-sidebar__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 10px 8px var(--space-3);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: background var(--duration-fast, 120ms) ease,
              color var(--duration-fast, 120ms) ease;
  margin-bottom: 2px;
}
.app-sidebar__link:hover {
  background: var(--color-surface-soft);
  color: var(--color-text-primary);
}
.app-sidebar__link--active {
  background: var(--color-primary-soft);
  color: var(--color-primary-strong);
  font-weight: 600;
}
.app-sidebar__link--active .app-sidebar__link-icon {
  color: var(--color-primary);
}
.app-sidebar__link-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--color-text-muted);
}
.app-sidebar__link-label {
  flex: 1;
  min-width: 0;
}
.app-sidebar__link-counter {
  background: var(--color-surface-soft);
  color: var(--color-text-secondary);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 18px;
  text-align: center;
}
.app-sidebar__link-counter--accent {
  background: var(--color-primary-soft);
  color: var(--color-primary-strong);
}
.app-sidebar__link-counter--warn {
  background: var(--color-warning-soft);
  color: var(--color-warning-text);
}
.app-sidebar__link-counter--danger {
  background: var(--color-danger-soft);
  color: var(--color-danger-text);
}

.app-sidebar__subnav {
  margin-left: 32px;
  padding-left: var(--space-2);
  border-left: 1px solid var(--color-border);
}
.app-sidebar__subnav .app-sidebar__link {
  font-size: 12.5px;
  padding-top: 6px;
  padding-bottom: 6px;
}

.app-sidebar__footer {
  padding: var(--space-3);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-surface);
  position: sticky;
  bottom: 0;
}
.app-sidebar__avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary-soft), color-mix(in oklab, var(--color-primary-soft) 60%, var(--color-surface)));
  color: var(--color-primary-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
  flex-shrink: 0;
  border: 1px solid color-mix(in oklab, var(--color-primary) 18%, transparent);
}
.app-sidebar__user {
  flex: 1;
  min-width: 0;
}
.app-sidebar__user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-sidebar__user-role {
  font-size: 11px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.app-sidebar__logout {
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  transition: background var(--duration-fast, 120ms) ease, color var(--duration-fast, 120ms) ease;
}
.app-sidebar__logout:hover {
  color: var(--color-danger);
  background: var(--color-danger-soft);
}

/* ── Topbar ───────────────────────────────────────────────────────── */
.app-topbar {
  grid-area: topbar;
  background: color-mix(in oklab, var(--color-surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  position: sticky;
  top: 0;
  z-index: 20;
  gap: var(--space-4);
}
.app-topbar__menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-secondary);
  border: 0;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.app-topbar__menu-btn:hover {
  background: var(--color-surface-soft);
}
.app-topbar__breadcrumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  color: var(--color-text-secondary);
}
.app-topbar__breadcrumbs a {
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color var(--duration-fast, 120ms) ease;
}
.app-topbar__breadcrumbs a:hover { color: var(--color-text-primary); }
.app-topbar__breadcrumb-sep {
  color: var(--color-text-muted);
  font-size: 12px;
  user-select: none;
}
.app-topbar__breadcrumb-current {
  color: var(--color-text-primary);
  font-weight: 600;
  letter-spacing: -0.005em;
}
.app-topbar__search {
  width: 320px;
  max-width: 30vw;
  position: relative;
}
.app-topbar__search input {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-3) 0 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-soft);
  font-size: 13px;
  color: var(--color-text-primary);
  font-family: inherit;
}
.app-topbar__search input::placeholder {
  color: var(--color-text-muted);
}
.app-topbar__search input:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.app-topbar__search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
  width: 14px;
  height: 14px;
}
.app-topbar__marketplace {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}
.app-topbar__marketplace-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.app-topbar__marketplace-select {
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 6px var(--space-2);
  font-size: 13px;
  font-family: inherit;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.app-topbar__marketplace-select:hover {
  border-color: var(--color-border-strong);
}
.app-topbar__marketplace-select:focus-visible {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.app-topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.app-topbar__icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-secondary);
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.app-topbar__icon-btn:hover {
  background: var(--color-surface-soft);
  color: var(--color-text-primary);
}
.app-topbar__icon-btn-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-danger);
}

/* ── Main content area ────────────────────────────────────────────── */
.app-main {
  grid-area: main;
  padding: var(--space-8);
  overflow-x: auto;
}
.app-main__inner {
  max-width: 1400px;
  margin: 0 auto;
}
.page-header {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.page-header--flush {
  border-bottom: 0;
  padding-bottom: 0;
  margin-bottom: var(--space-6);
}
.page-header__title {
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.022em;
  line-height: 1.2;
  margin: 0;
}
.page-header__subtitle {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-top: 6px;
  line-height: 1.5;
  max-width: 65ch;
}
.page-header__actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

/* ── Mobile drawer ────────────────────────────────────────────────── */
.app-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 30, 0.45);
  z-index: 25;
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 40;
    box-shadow: var(--shadow-xl);
  }
  .app-sidebar.is-open {
    transform: translateX(0);
  }
  .app-sidebar-overlay.is-open {
    display: block;
  }
  .app-topbar__menu-btn {
    display: inline-flex;
  }
  .app-topbar__search {
    display: none;
  }
  .app-main {
    padding: var(--space-4);
  }
}

/* ── Lucide icon helper ───────────────────────────────────────────── */
.lucide {
  width: 16px;
  height: 16px;
  stroke-width: 1.75;
  flex-shrink: 0;
}
.lucide--lg { width: 20px; height: 20px; }
.lucide--xl { width: 24px; height: 24px; }
