/* Shell: grouped sidebar, top bar, page header, related strip and search (portal/web/nav.py, templates/base.html, static/shell.js).
   Loaded after style.css, so these rules override its older sidebar and top-bar rules. */
:root { --sidebar-w: 256px; --rail-w: 64px; --topbar-h: 56px; }
.sidebar { overflow: hidden; z-index: 40; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 10px 16px; }
.sidebar-head .sidebar-brand { padding: 0; gap: 10px; min-width: 0; }
.sidebar-head .sidebar-brand .mark { width: 32px; height: 32px; }
.rail-toggle, .topbar-btn, .nav-chev { display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--color-text-muted); cursor: pointer; border-radius: 8px; }
.rail-toggle { width: 32px; height: 32px; }
.rail-toggle:hover, .topbar-btn:hover, .nav-chev:hover { background: var(--color-surface); color: var(--color-text); }
.rail-toggle .icon, .topbar-btn .icon { width: 18px; height: 18px; }
.sidebar > .nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 10px 12px; gap: 0; scrollbar-width: thin; }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-group + .nav-group { margin-top: 10px; }
.nav-group-label { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--color-text-faint); padding: 8px 12px 4px; }
.nav-row { display: flex; align-items: center; gap: 2px; }
.nav-row .nav-item { flex: 1; min-width: 0; }
.nav-item { padding: 7px 12px; gap: 10px; font-size: 13.5px; }
.nav-item .nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.in { color: var(--color-primary-dark); font-weight: 700; }
.nav-chev { width: 28px; height: 28px; flex-shrink: 0; }
.nav-chev .icon { width: 14px; height: 14px; transition: transform var(--dur-fast) var(--ease-out); }
.nav-mod.open > .nav-row .nav-chev .icon { transform: rotate(90deg); }
.nav-mod > .nav-sub { display: none; }
.nav-mod.open > .nav-sub { display: flex; }
.nav-sub { margin: 1px 0 6px 21px; padding-left: 8px; gap: 1px; }
.nav-item.subitem { padding: 5px 12px; font-size: 13px; font-weight: 500; }
.nav-item.subitem.active { font-weight: 700; }
.nav-item.subitem .icon { width: 14px; height: 14px; }
.nav-rule { height: 1px; background: var(--color-border); margin: 4px 12px; }
.nav-badge { position: static; margin-left: auto; }
.nav-badge[data-badge] { background: var(--sparkle-orange); }
.sidebar > .nav.nav-admin { flex: 0 0 auto; border-top: 1px solid var(--color-border); padding: 6px 10px 10px; gap: 0; max-height: 45vh; overflow-y: auto; }
.nav-group-toggle { display: flex; align-items: center; justify-content: space-between; width: 100%; border: 0; background: transparent; cursor: pointer; border-radius: 8px; }
.nav-group-toggle:hover { color: var(--color-text); background: var(--color-surface); }
.nav-group-toggle .icon { width: 12px; height: 12px; transition: transform var(--dur-fast) var(--ease-out); }
.nav-admin.open .nav-group-toggle .icon { transform: rotate(90deg); }
.nav-admin:not(.open) #admin-mods { display: none; }
.nav-admin #admin-mods { display: flex; flex-direction: column; gap: 1px; }

/* rail: icons only */
.app-shell.rail .sidebar { width: var(--rail-w); }
.app-shell.rail .main { margin-left: var(--rail-w); }
.app-shell.rail .brand-words, .app-shell.rail .nav-label, .app-shell.rail .nav-chev, .app-shell.rail .nav-sub, .app-shell.rail .nav-group-label:not(.nav-group-toggle),
.app-shell.rail .nav-row .nav-badge { display: none !important; }
.app-shell.rail .sidebar-head { flex-direction: column; gap: 8px; padding: 14px 0 8px; }
.app-shell.rail .nav-item { justify-content: center; padding: 8px 0; }
.app-shell.rail .nav-group + .nav-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--color-border); }
.app-shell.rail .nav-group-toggle { justify-content: center; font-size: 0; padding: 6px 0; }
.app-shell.rail .nav-group-toggle .icon { width: 14px; height: 14px; }

/* top bar: portal-wide things only */
.topbar { height: var(--topbar-h); min-height: var(--topbar-h); padding: 0 20px 0 24px; gap: 12px; justify-content: flex-start; }
.drawer-toggle { display: none; width: 34px; height: 34px; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--color-text-muted); min-width: 0; white-space: nowrap; overflow: hidden; }
.crumbs a { color: var(--color-text-muted); font-weight: 600; text-decoration: none; }
.crumbs a:hover { color: var(--color-text); text-decoration: underline; }
.crumbs [aria-current=page] { color: var(--color-text); font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.crumb-sep { color: var(--color-text-faint); }
.search-trigger { margin-left: auto; display: flex; align-items: center; gap: 8px; width: min(380px, 32vw); height: 34px; padding: 0 8px 0 10px; border: 1px solid var(--color-border);
  border-radius: 10px; background: var(--color-bg); color: var(--color-text-faint); font: inherit; font-size: 12.5px; cursor: pointer; flex-shrink: 1; min-width: 0; }
.search-trigger:hover { border-color: var(--ink-20); color: var(--color-text-muted); }
.search-trigger .icon { width: 15px; height: 15px; flex-shrink: 0; }
.search-ph { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-trigger kbd { font: 600 10.5px var(--font-data); border: 1px solid var(--color-border); border-radius: 5px; padding: 1px 5px; color: var(--color-text-muted); background: var(--color-surface); }
.topbar-tools { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.topbar-btn { width: 34px; height: 34px; position: relative; }
.tb-count { position: absolute; top: 2px; right: 1px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--sparkle-orange); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; }
.env-badge { font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; padding: 4px 9px; border-radius: 6px; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn); white-space: nowrap; }
.env-badge.crit { background: var(--crit-bg); color: var(--crit-ink); border-color: var(--crit); text-transform: none; letter-spacing: 0; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 11px; border: 1px solid var(--color-border); border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--color-text-muted); text-decoration: none; white-space: nowrap; }
.status-pill:hover { text-decoration: none; border-color: var(--ink-20); color: var(--color-text); }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-20); }
.status-pill[data-tone=good] .dot { background: var(--good); }
.status-pill[data-tone=warn] { color: var(--warn-ink); }
.status-pill[data-tone=warn] .dot { background: var(--warn); }
.status-pill[data-tone=crit] { color: var(--crit-ink); border-color: var(--crit); background: var(--crit-bg); }
.status-pill[data-tone=crit] .dot { background: var(--crit); }
.tb-menu { position: relative; }
.tb-pop { position: absolute; right: 0; top: calc(100% + 8px); width: 320px; max-height: 70vh; overflow-y: auto; background: var(--color-bg); border: 1px solid var(--color-border);
  border-radius: 12px; box-shadow: var(--shadow-lg); padding: 8px; z-index: 50; display: flex; flex-direction: column; gap: 2px; }
.tb-pop[hidden] { display: none; }
.tb-pop a, .tb-pop .linkish { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--color-text); font-size: 13px; font-weight: 600; text-decoration: none; }
.tb-pop a:hover, .tb-pop .linkish:hover { background: var(--color-surface); text-decoration: none; }
.tb-pop .linkish { border: 0; background: transparent; width: 100%; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; text-align: left; }
.tb-pop .linkish .icon { width: 15px; height: 15px; }
.tb-pop form { margin: 0; }
.tb-pop-h { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-faint); padding: 6px 10px 4px; }
.tb-pop .muted.small { padding: 6px 10px; margin: 0; }
.tb-pop a.inbox-item { flex-direction: column; align-items: flex-start; gap: 1px; font-weight: 500; }
.inbox-item .src { font-size: 11px; font-weight: 700; color: var(--color-primary-dark); }
.inbox-item.sev-critical .src { color: var(--red-700); } .inbox-item.sev-warning .src { color: var(--warn-ink); }
.tb-user .who { display: flex; flex-direction: column; gap: 1px; padding: 8px 10px 10px; border-bottom: 1px solid var(--color-border); margin-bottom: 4px; font-size: 12px; line-height: 1.4; }
.tb-user .who strong { font-size: 13px; word-break: break-all; }
.theme-pick { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px 8px; font-size: 13px; font-weight: 600; }
.theme-seg { display: inline-flex; padding: 2px; border-radius: 999px; background: var(--color-surface-alt); }
.theme-seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 600; color: var(--color-text-muted); cursor: pointer; }
.theme-seg button:hover { color: var(--color-text); }
.theme-seg button[aria-checked="true"] { background: var(--color-bg); color: var(--color-text); box-shadow: var(--shadow-xs); }
.avatar { width: 32px; height: 32px; border-radius: 50%; border: 0; background: var(--color-primary-tint); color: var(--color-primary-dark); font: 800 13px var(--font-sans); cursor: pointer; margin-left: 4px; }
.avatar:hover { box-shadow: 0 0 0 2px var(--color-primary); }

/* page header (the title and actions each page writes) and the related strip */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 28px 0; }
.page-head h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; margin: 0; }
.page-head .sub, .page-head .topbar-title .subtitle { font-size: 12.5px; font-weight: 500; color: var(--color-text-muted); margin: 4px 0 0; line-height: 1.45; max-width: 80ch; }
.page-head .topbar-title:empty, .page-head .topbar-actions:empty { display: none; }
.page-head .topbar-actions { padding-top: 2px; flex-shrink: 0; display: flex; align-items: center; gap: 14px; }
.related { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 12px 28px 0; font-size: 12px; }
.related-h { font-weight: 700; color: var(--color-text-faint); text-transform: uppercase; letter-spacing: .05em; font-size: 10.5px; margin-right: 2px; }
.related a { padding: 3px 10px; border: 1px solid var(--color-border); border-radius: 999px; color: var(--color-text-muted); font-weight: 600; text-decoration: none; background: var(--color-bg); }
.related a:hover { border-color: var(--color-primary); color: var(--color-primary-dark); text-decoration: none; }
.content { padding-top: 20px; }

/* search */
.search-dialog { position: fixed; inset: 0; background: rgba(20, 35, 59, .32); z-index: 100; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
.search-dialog[hidden] { display: none; }
.search-box { width: min(640px, calc(100vw - 32px)); background: var(--color-bg); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; border: 1px solid var(--color-border); }
.search-in { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--color-border); }
.search-in .icon { width: 18px; height: 18px; color: var(--color-text-faint); flex-shrink: 0; }
.search-in input { flex: 1; border: 0; outline: 0; height: 52px; font: inherit; font-size: 15px; background: transparent; color: var(--color-text); min-width: 0; }
.search-results { list-style: none; margin: 0; padding: 6px; max-height: 52vh; overflow-y: auto; }
.search-item a { display: flex; justify-content: space-between; gap: 12px; padding: 9px 12px; border-radius: 8px; color: var(--color-text); text-decoration: none; font-size: 13.5px; font-weight: 600; }
.search-item.sel a { background: var(--color-primary-tint); color: var(--color-primary-dark); }
.search-item .grp { font-size: 11.5px; font-weight: 600; color: var(--color-text-faint); white-space: nowrap; }
.search-empty { padding: 14px 12px; color: var(--color-text-muted); font-size: 13px; }
.search-foot { margin: 0; padding: 8px 16px 10px; border-top: 1px solid var(--color-border); font-size: 11.5px; color: var(--color-text-faint); }

/* automation controls */
.auto-table td, .auto-table th { vertical-align: top; }
.auto-table .what { color: var(--color-text-muted); font-size: 12px; }

/* narrow screens: the sidebar becomes a drawer */
@media (max-width: 1000px) {
  .sidebar, .app-shell.rail .sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform var(--dur-fast) var(--ease-out); box-shadow: var(--shadow-lg); }
  .app-shell.drawer-open .sidebar { transform: none; }
  .app-shell .main, .app-shell.rail .main { margin-left: 0; }
  .app-shell.rail .brand-words, .app-shell.rail .nav-label, .app-shell.rail .nav-chev { display: revert !important; }
  .app-shell.rail .nav-group-label:not(.nav-group-toggle) { display: block !important; }
  .app-shell.rail .nav-mod.open > .nav-sub { display: flex !important; }
  .app-shell.rail .nav-item { justify-content: flex-start; padding: 7px 12px; }
  .rail-toggle { display: none; }
  .drawer-toggle { display: inline-flex; }
  .sidebar-scrim { position: fixed; inset: 0; background: rgba(20, 35, 59, .32); z-index: 35; }
  .sidebar-scrim[hidden] { display: none; }
  .app-shell { flex-direction: row; }
  .sidebar > .nav { flex-direction: column; flex-wrap: nowrap; overflow-y: auto; }
  .nav-sub { flex-direction: column; flex-wrap: nowrap; margin-left: 21px; padding-left: 8px; border-left: 2px solid var(--ink-10); }
  .search-trigger { width: auto; }
  .crumbs > :not(:last-child) { display: none; }
}
@media (max-width: 700px) {
  .search-ph, .search-trigger kbd, .status-pill .txt, .env-badge.crit, #help-btn { display: none; }
  .search-trigger { margin-left: auto; width: 34px; padding: 0; justify-content: center; border: 0; }
  .status-pill { padding: 0 8px; } .crumbs { flex: 1 1 auto; }
  .topbar { padding: 0 12px; }
  .page-head { padding: 18px 16px 0; flex-direction: column; }
  .related { padding: 10px 16px 0; }
  .content { padding: 16px; }
}
@media print { .topbar, .related, .search-dialog { display: none !important; } }
