/* Application shell: sidebar, top bar, mobile tab bar, public header. */

.brand { display: inline-flex; align-items: center; gap: var(--s3); color: inherit; text-decoration: none; min-width: 0; min-height: var(--control); }
.brand:hover { color: inherit; }
.brand-mark { display: inline-flex; flex: none; }
.brand-mark svg { width: 2.25rem; height: 2.25rem; }
.brand-name { font: 600 1.1rem/1.2 var(--font-display); letter-spacing: -0.005em; }

.app {
  --side: var(--sidebar); display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh;
  background: linear-gradient(90deg, var(--navy-900) var(--side), transparent var(--side)); transition: grid-template-columns var(--t) var(--ease);
}

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

.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh; z-index: 30;
  display: flex; flex-direction: column; gap: var(--s5); padding: var(--s4) var(--s3);
  background: var(--navy-900); color: var(--on-dark-2);
}
.sidebar .brand { color: var(--on-dark); padding: 0 var(--s2); }
.sidebar :focus-visible { outline-color: var(--teal-300); }
.side-nav { flex: 1; overflow-y: auto; overflow-x: clip; display: flex; flex-direction: column; gap: var(--s5); }
.side-group > p { margin: 0 0 var(--s1); padding: 0 var(--s3); font-size: var(--fs-xs); font-weight: 600; color: var(--on-dark-3); }
.side-group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.side-link {
  position: relative; display: flex; align-items: center; gap: var(--s3); min-height: 2.6rem; padding: 0 var(--s3); border-radius: var(--r-sm);
  color: var(--on-dark-2); text-decoration: none; font-weight: 500; font-size: var(--fs-base); white-space: nowrap;
  transition: background-color var(--t-fast), color var(--t-fast);
}
.side-link .icon { width: 1.2rem; height: 1.2rem; }
.side-link:hover { background: rgb(148 163 184 / 0.12); color: #fff; }
.side-link[aria-current] { background: rgb(16 185 129 / 0.24); color: #fff; font-weight: 600; box-shadow: inset 0 0 0 1px rgb(165 180 252 / 0.22); }
.side-link[aria-current] .icon { color: var(--teal-300); }
.side-link[aria-current]::after { content: ''; position: absolute; left: calc(var(--s3) * -1); top: 0.6rem; bottom: 0.6rem; width: 3px; border-radius: 0 3px 3px 0; background: var(--teal-300); }

.side-foot { display: flex; flex-direction: column; gap: var(--s2); border-top: 1px solid var(--line-dark); padding-top: var(--s3); }
.side-user { display: flex; align-items: center; gap: var(--s3); padding: var(--s2); border-radius: var(--r-md); color: var(--on-dark); text-decoration: none; min-width: 0; }
a.side-user:hover { background: rgb(148 163 184 / 0.12); color: #fff; }
.side-user > span:last-child { min-width: 0; }
.side-user strong, .side-user small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user strong { font-size: var(--fs-sm); }
.side-user small { font-size: var(--fs-xs); color: var(--on-dark-3); }
.side-collapse { display: flex; align-items: center; gap: var(--s3); min-height: 2.4rem; padding: 0 var(--s3); border: 0; border-radius: var(--r-sm); background: none; color: var(--on-dark-3); font: 500 var(--fs-sm) var(--font-sans); cursor: pointer; white-space: nowrap; }
.side-collapse:hover { background: rgb(148 163 184 / 0.12); color: #fff; }
.side-collapse .icon { width: 1.2rem; height: 1.2rem; transition: transform var(--t) var(--ease); }

/* Top bar -------------------------------------------------------------------- */

.app-body { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 25; display: flex; align-items: center; gap: var(--s4); min-height: var(--topbar); padding: var(--s2) var(--gutter);
  background: rgb(255 255 255 / 0.94); border-bottom: 1px solid var(--border);
}
@supports (backdrop-filter: blur(8px)) { .topbar { background: rgb(255 255 255 / 0.86); backdrop-filter: blur(8px); } }
.topbar .brand { display: none; }
.crumbs { min-width: 0; margin-right: auto; }
.crumbs ol { display: flex; align-items: center; gap: var(--s2); list-style: none; padding: 0; margin: 0; font-size: var(--fs-sm); font-weight: 500; color: var(--text-3); white-space: nowrap; }
.crumbs li { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.crumbs li + li::before { content: '/'; color: var(--border-strong); }
.crumbs a { color: var(--text-2); text-decoration: none; min-height: 1.75rem; display: inline-flex; align-items: center; }
.crumbs a:hover { color: var(--accent-700); text-decoration: underline; }
.crumbs [aria-current] { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.crumbs li:last-child { overflow: hidden; }

.search { position: relative; display: flex; align-items: center; margin: 0; width: min(21rem, 32vw); flex: none; }
.search > .icon { position: absolute; left: 0.75rem; color: var(--text-3); pointer-events: none; }
.search input[type='search'] { min-height: 2.5rem; padding: 0.4rem 2.4rem 0.4rem 2.35rem; font-size: var(--fs-sm); background: var(--surface-2); border-color: var(--border-strong); }
.search input[type='search']:focus-visible { border-color: var(--accent-600); background: var(--surface); }
.search kbd { position: absolute; right: 0.55rem; font-size: var(--fs-xs); border: 1px solid var(--border-strong); border-radius: var(--r-xs); padding: 0 0.4rem; color: var(--text-3); background: var(--surface); pointer-events: none; }
.search input:focus ~ kbd { display: none; }
.topbar-actions { display: flex; align-items: center; gap: var(--s2); }
.profile > summary { display: flex; align-items: center; gap: var(--s1); padding: var(--s1); border-radius: var(--r-md); min-height: var(--control); }
.profile > summary:hover, .profile[open] > summary { background: var(--surface-3); }
.profile > summary > .icon { color: var(--text-3); }
.topbar .mobile-search, .topbar .admin-menu { display: none; }

.main { flex: 1; width: 100%; max-width: 82rem; margin-inline: auto; padding: var(--s6) var(--gutter) var(--s9); min-width: 0; }
.app-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s2) var(--s5); padding: var(--s4) var(--gutter) var(--s5); border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-3); }
.app-footer p { margin: 0; }
.app-footer nav { display: flex; flex-wrap: wrap; gap: var(--s5); }
.app-footer a { color: var(--text-2); text-decoration: none; min-height: 1.5rem; }
.app-footer a:hover { text-decoration: underline; }

.tab-bar { display: none; }
.mobile-only { display: none !important; }

/* Page header ---------------------------------------------------------------- */

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: var(--s4) var(--s6); margin-bottom: var(--s6); }
.page-head-text { display: flex; align-items: center; gap: var(--s4); min-width: 0; }
.page-head-text > div { min-width: 0; }
.page-head h1 { margin: 0; overflow-wrap: anywhere; }
.page-head .lede { margin: var(--s1) 0 0; overflow-wrap: anywhere; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s3); }

/* Public (signed-out) frame --------------------------------------------------- */

.wrap { width: 100%; max-width: 76rem; margin-inline: auto; padding-inline: var(--gutter); }

/* Narrow rail: chosen by the user on wide screens, automatic on tablets. ------ */

@media (min-width: 68.01rem) {
  .nav-collapsed .app { --side: var(--rail); }
  .nav-collapsed .sidebar { padding-inline: var(--s3); }
  .nav-collapsed .sidebar .brand-name, .nav-collapsed .side-group > p, .nav-collapsed .side-label, .nav-collapsed .side-user > span:last-child {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .nav-collapsed .side-nav { overflow: visible; }
  .nav-collapsed .side-group + .side-group { border-top: 1px solid var(--line-dark); padding-top: var(--s4); }
  .nav-collapsed .side-link, .nav-collapsed .side-collapse, .nav-collapsed .side-user, .nav-collapsed .sidebar .brand { justify-content: center; padding-inline: 0; }
  .nav-collapsed .side-collapse .icon { transform: rotate(180deg); }
  .nav-collapsed .side-link:hover .side-label, .nav-collapsed .side-link:focus-visible .side-label {
    position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%); width: auto; height: auto; clip-path: none; z-index: 60;
    background: var(--navy-700); color: #fff; padding: 0.35rem 0.6rem; border-radius: var(--r-xs); font-size: var(--fs-xs); box-shadow: var(--e2);
  }
}

@media (max-width: 68rem) and (min-width: 52.01rem) {
  .app { --side: var(--rail); }
  .sidebar .brand-name, .side-group > p, .side-label, .side-user > span:last-child {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .side-collapse { display: none; }
  .side-nav { overflow: visible; }
  .side-group + .side-group { border-top: 1px solid var(--line-dark); padding-top: var(--s4); }
  .side-link, .side-user, .sidebar .brand { justify-content: center; padding-inline: 0; }
  .side-link:hover .side-label, .side-link:focus-visible .side-label {
    position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%); width: auto; height: auto; clip-path: none; z-index: 60;
    background: var(--navy-700); color: #fff; padding: 0.35rem 0.6rem; border-radius: var(--r-xs); font-size: var(--fs-xs); box-shadow: var(--e2);
  }
}

/* Short screens: let the whole rail scroll rather than clipping it. */
@media (max-height: 40rem) and (min-width: 52.01rem) {
  .sidebar { overflow-y: auto; gap: var(--s3); }
  .side-nav { flex: none; overflow: visible; }
}

/* Phones --------------------------------------------------------------------- */

@media (max-width: 52rem) {
  .app { grid-template-columns: minmax(0, 1fr); background: none; }
  .sidebar { display: none; }
  .topbar { gap: var(--s2); }
  .topbar .brand { display: inline-flex; color: var(--text); margin-right: auto; }
  .topbar .brand-name { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
  .crumbs, .topbar .search { display: none; }
  .topbar .mobile-search { display: inline-grid; }
  .topbar .admin-menu { display: inline-block; }
  .admin-menu .menu-panel { max-height: calc(100dvh - var(--topbar) - 1rem); overflow-y: auto; width: 16rem; }
  .admin-menu .menu-panel p { margin: var(--s3) var(--s3) var(--s1); font-size: var(--fs-xs); font-weight: 600; color: var(--text-3); }
  .admin-menu .menu-panel a[aria-current] { background: var(--accent-50); color: var(--accent-800); font-weight: 600; }
  .main { padding-top: var(--s5); }
  .mobile-only { display: block !important; }
  .has-tab-bar { padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
  .tab-bar {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; z-index: 40; inset: auto 0 0 0;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -6px 18px -12px rgb(15 23 42 / 0.25);
  }
  .tab-bar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem; min-height: var(--tabbar); color: var(--text-3); text-decoration: none; font-size: 0.6875rem; font-weight: 600; }
  .tab-bar .icon { width: 1.35rem; height: 1.35rem; }
  .tab-bar a[aria-current] { color: var(--accent-700); }
  .tab-bar a[aria-current]::before { content: ''; position: absolute; top: 0; width: 2.25rem; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent-600); }
}

@media (max-width: 24rem) {
  .shell-admin .topbar .brand-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}

@media (max-width: 36rem) {
}

@media print {
  .sidebar, .topbar, .tab-bar, .app-footer, .public-bar, .toast { display: none !important; }
  .app { display: block; background: none; }
  body { background: #fff; padding: 0; }
}
