/* ============================================================
   ALPR-RU — AppShell (sidebar + header)
   Loads after main.css; owns .app-shell/.topbar/.sidebar/.brand__mark/
   .status-pill/.user-pill — the structural chrome layer, deliberately a
   different tone (--nav-bg/--header-bg) from workspace panels so nav,
   workspace and operational content read as three distinct tiers instead
   of one flat wash of dark boxes (a8n.bolder.1).
   See DESIGN.md "Layout" and "Components > Navigation".
   ============================================================ */

:root {
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --header-h: 60px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  transition: grid-template-columns .16s ease;
  background: var(--bg);
}

.app-shell[data-sidebar="collapsed"] {
  grid-template-columns: var(--sidebar-w-collapsed) 1fr;
}

/* ---------- Sidebar ---------- */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--sp-4) var(--sp-3);
  background: var(--nav-bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 0 var(--sp-1) var(--sp-4);
  margin-bottom: var(--sp-2);
  border-bottom: 1px solid var(--border-2);
}

.sidebar__brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}

/* a8n.bolder.1: the mark is the one place the accent is allowed to be
   loud — everywhere else it stays restrained per DESIGN.md's Signal
   Discipline Rule. */
.brand__mark {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--r-xs);
  background: linear-gradient(155deg, var(--accent), var(--accent-2));
  color: #ffffff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .02em;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent);
}

.sidebar__brand-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__mobile-close {
  display: none;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: var(--sp-1);
}

.sidebar__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 42px;
  padding: 0 var(--sp-3) 0 calc(var(--sp-3) + 3px);
  border-radius: var(--r-sm);
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  transition: background .12s ease, color .12s ease;
}

.sidebar__link-icon {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--muted);
  transition: color .12s ease;
}

.sidebar__link-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar__link:hover .sidebar__link-icon {
  color: var(--text);
}

.sidebar__link:focus-visible,
.sidebar__collapse:focus-visible,
.sidebar__mobile-close:focus-visible,
.sidebar__brand:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* a8n.bolder.1: active state is a left accent bar + filled label + tinted
   icon — three redundant signals, not just a soft background tint, so it
   reads instantly even at a glance (and never relies on color alone). */
.sidebar__link--active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 700;
}

.sidebar__link--active::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.sidebar__link--active .sidebar__link-icon {
  color: var(--accent);
}

.sidebar__collapse {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  height: 36px;
  margin-top: var(--sp-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}

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

.sidebar__collapse-icon {
  transition: transform .16s ease;
}

.app-shell[data-sidebar="collapsed"] .sidebar__collapse-icon {
  transform: rotate(180deg);
}

/* Collapsed: icon rail only. Label text is visually hidden but the link's
   `title` attribute still exposes it as a native tooltip, and the label
   stays in the DOM for screen readers instead of being removed. */
.app-shell[data-sidebar="collapsed"] .sidebar__brand-text,
.app-shell[data-sidebar="collapsed"] .sidebar__link-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app-shell[data-sidebar="collapsed"] .sidebar__link {
  justify-content: center;
  padding: 0;
}

.app-shell[data-sidebar="collapsed"] .sidebar__link--active::before {
  left: -10px;
}

.app-shell[data-sidebar="collapsed"] .sidebar__top {
  justify-content: center;
}

.app-shell[data-sidebar="collapsed"] .sidebar__mobile-close {
  display: none;
}

/* ---------- Header ---------- */

.app-shell__main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  min-height: var(--header-h);
  padding: 0 var(--sp-6);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

/* a8n.cleanup.1: the header used to repeat the current page's title as its
   own <h1>, duplicating pageHead()'s heading in the page content below.
   The header no longer renders a title at all — pageHead()'s <h1> is the
   single semantic heading per page; the header stays for navigation
   (mobile hamburger), connection state and account actions only. */
.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-left: auto;
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar__divider {
  width: 1px;
  height: 22px;
  background: var(--border);
}

.account-cluster {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* status-pill / user-pill: shell-only chrome, restyled bolder than the
   generic .chip so system state and identity read at a glance without
   fighting each other for weight. */
.status-pill,
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.status-pill.is-online i {
  background: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent);
}

.status-pill.is-error i {
  background: var(--red);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 22%, transparent);
}

.user-pill {
  background: var(--surface-2);
  color: var(--text);
}

.user-pill::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(155deg, var(--accent), var(--accent-2));
  flex-shrink: 0;
}

.sidebar__mobile-open {
  display: none;
}

/* ---------- Mobile drawer ---------- */

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-mobile-backdrop);
  background: rgba(5, 9, 16, .55);
}

.sidebar-backdrop[hidden] {
  display: none;
}

@media (max-width: 960px) {
  .app-shell,
  .app-shell[data-sidebar="collapsed"] {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 25% 0 0;
    z-index: var(--z-mobile-sidebar);
    width: auto;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: var(--shadow);
  }

  .app-shell[data-mobile-nav="open"] .sidebar {
    transform: translateX(0);
  }

  /* Mobile drawer is always shown expanded, regardless of the desktop
     collapse preference — the two behaviors are independent. */
  .app-shell[data-sidebar="collapsed"] .sidebar__brand-text,
  .app-shell[data-sidebar="collapsed"] .sidebar__link-text {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  .app-shell[data-mobile-nav="open"] .sidebar__link {
    justify-content: flex-start;
    padding: 0 var(--sp-3) 0 calc(var(--sp-3) + 3px);
  }

  .sidebar__collapse {
    display: none;
  }

  .sidebar__mobile-close {
    display: inline-flex;
  }

  .sidebar__mobile-open {
    display: inline-flex;
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 0 var(--sp-3);
    gap: var(--sp-2);
  }
}

@media (max-width: 460px) {
  .topbar__divider {
    display: none;
  }

  .account-cluster .user-pill {
    padding: 0 8px;
  }
}
