/* ==========================================================================
   Telangar — shell additions for T-041 (panel/static/css/shell.css)

   components.css is Mary's file and T-041 must not modify it. Everything the
   health page needs beyond it lives here, additive only, after it in the
   cascade: the mobile drawer open state, the stale bar, the three-state theme
   switch, the Runner card stack and the queue ring value arc.

   Consumes tokens.css only. Logical properties only (RTL-first, LTR-ready).
   ========================================================================== */

/* ---------- Icon sizes components.css does not declare ---------- */
/* .i and .i.sm are in components.css; .lg has a token but no rule. */
.tl svg.i.lg { width: var(--icon-lg); height: var(--icon-lg); }

/* The sprite itself must never take part in layout. */
#tl-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- Runner cards stacked in one grid column ---------- */
.cardstack { display: flex; flex-direction: column; gap: var(--section-gap); min-width: 0; }

/* ---------- Queue ring: the value arc ----------
   The background circle is .bg in components.css; the arc length comes from
   stroke-dasharray, computed in health_view.queue_rings. */
.ring .val { stroke: var(--primary); transition: stroke-dasharray var(--dur) var(--ease); }
.ring .num { position: relative; font-variant-numeric: tabular-nums; }

/* ---------- Sidebar foot: who is signed in, and the theme ---------- */
.whoami { padding-inline: var(--space-3); }
.whoami dd { text-align: start; overflow-wrap: anywhere; }
.logout { width: 100%; }

.themeset {
  display: flex; gap: 2px; padding: 3px;
  border-radius: var(--radius-sm); background: var(--surface-2);
}
[data-surface="tonal"] .themeset { border-radius: var(--radius-pill); }
.themeset .icon-btn { width: auto; height: 36px; flex: 1; border-radius: var(--radius-xs); }
.themeset .icon-btn[aria-pressed="true"] {
  background: var(--card); color: var(--foreground);
  box-shadow: 0 1px 2px color-mix(in srgb, #000 12%, transparent);
}
@media (pointer: coarse) {
  /* 44x44 minimum touch target; tokens.css already does this for controls. */
  .themeset .icon-btn { height: 44px; }
}

/* ---------- Mobile drawer ----------
   Under 900px components.css sets .sidebar { display: none } and shows
   .topbar. The menu button sets data-drawer="open" on .shell (the Alpine
   `drawer` component in panel.js), and only then does the sidebar come back
   as an overlay from the inline-start edge. Above 900px data-drawer is
   ignored: the sidebar is simply there. */
.drawer-backdrop {
  display: none; position: fixed; inset: 0; border: 0; padding: 0;
  background: color-mix(in srgb, #000 45%, transparent);
  z-index: calc(var(--z-drawer) - 1);
}

@container tl (max-width: 900px) {
  .shell[data-drawer="open"] .sidebar {
    display: flex; position: fixed;
    inset-block: 0; inset-inline-start: 0;
    width: min(300px, 86vw); max-width: 100vw;
    z-index: var(--z-drawer);
    overflow-y: auto;
    box-shadow: 0 0 40px color-mix(in srgb, #000 28%, transparent);
  }
  .shell[data-drawer="open"] .drawer-backdrop { display: block; }
}

/* ---------- Stale bar: the dashboard's own silent failure ----------
   Sits directly under the alert bar, above everything else, and is `hidden`
   until panel.js has seen two consecutive poll failures. */
.stale_bar {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) var(--space-10); min-height: 60px;
  background: var(--warning-soft); color: var(--warning-fg);
  border-block-end: 1px solid color-mix(in srgb, var(--warning) 35%, transparent);
}
.stale_bar[hidden] { display: none; }
.stale_bar .alert-icon {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--warning); color: #231800;
}
.stale_bar strong { color: var(--foreground); font-weight: var(--weight-semibold); }
.stale_bar .alert-meta { color: var(--muted-foreground); font-size: var(--text-sm); }
.stale_bar .spacer { flex: 1; }

@container tl (max-width: 900px) {
  .stale_bar { flex-wrap: wrap; padding: var(--space-4); align-items: flex-start; }
  .stale_bar .spacer { display: none; }
  .stale_bar .btn { flex: 1 1 100%; }
}

/* ---------- Alert bar wrapper ----------
   Always in the DOM so htmx has something to poll; it must add nothing of its
   own when there is no alert inside it. */
.alertslot { display: contents; }

/* ---------- T-123 Shafaq: aurora background (§3) ----------
   Four soft blobs behind everything, built from pseudo-elements so no template
   changes: two on <body>, two on the page container. Fixed, so they sit still
   while content scrolls; z-index -1 keeps them under every card. Colours are
   tokens; strength is --aurora-opacity (light 0.15, dark 0.6). */
/* The body is its own stacking context, so the blobs (z-index -1) paint above
   its background instead of behind it; no default margin around the aurora. */
body.tl { margin: 0; min-height: 100vh; isolation: isolate; }
.tl .shell { min-height: 100vh; }

@keyframes tl-aurora {
  to { transform: translate(calc(-60px * var(--dir)), 36px) scale(1.08); }
}
body.tl:not(.bare)::before,
body.tl:not(.bare)::after,
.tl .shell::before,
.tl .shell::after {
  content: ""; position: fixed; z-index: -1; pointer-events: none;
  inline-size: 560px; block-size: 440px; border-radius: 50%;
  opacity: var(--aurora-opacity);
  filter: blur(120px);
  animation: tl-aurora 22s ease-in-out infinite alternate;
}
body.tl:not(.bare)::before { background: var(--aurora-1); inset-block-start: -140px; inset-inline-end: -60px; animation-delay: -3s; }
body.tl:not(.bare)::after { background: var(--aurora-2); inset-block-start: 34vh; inset-inline-start: 30vw;
  inline-size: 620px; block-size: 480px; filter: blur(130px); animation-delay: -9s; }
.tl .shell::before { background: var(--aurora-3); inset-block-end: -170px; inset-inline-end: 8vw;
  inline-size: 520px; block-size: 420px; filter: blur(110px); animation-delay: -15s; }
.tl .shell::after { background: var(--aurora-1); inset-block-start: -120px; inset-inline-start: 6vw;
  inline-size: 540px; block-size: 430px; animation-delay: -20s; }
@media (prefers-reduced-motion: reduce) {
  body.tl:not(.bare)::before,
body.tl:not(.bare)::after,
.tl .shell::before,
.tl .shell::after { animation: none; }
}

/* ==========================================================================
   T-124 Shafaq shell: floating glass rail, collapsible to icons (§7)
   ========================================================================== */
.tl { --rail-open: 264px; --rail-closed: 92px; --rail-gap: 16px; --rail-radius: 30px;
  --rail-active: var(--primary); --rail-active-fg: var(--primary-foreground); }
.tl:not(.app):not(.bare) { --rail-open: 248px; --rail-radius: 28px;
  --rail-active: var(--admin-ink); --rail-active-fg: var(--admin-ink-foreground); }

.tl .shell {
  grid-template-columns: calc(var(--rail-open) + var(--rail-gap)) minmax(0, 1fr);
  transition: grid-template-columns var(--dur-lift) var(--ease-soft);
}
.tl .sidebar {
  position: sticky; inset-block-start: var(--rail-gap);
  block-size: calc(100vh - 2 * var(--rail-gap));
  margin-block: var(--rail-gap); margin-inline-start: var(--rail-gap);
  padding: var(--space-5) 12px var(--space-4);
  gap: var(--space-5);
  border: 1px solid var(--glass-border); border-radius: var(--rail-radius);
  background: var(--glass-fill);
  -webkit-backdrop-filter: blur(32px) saturate(180%);
  backdrop-filter: blur(32px) saturate(180%);
  box-shadow: var(--glass-shadow);
  overflow: visible; align-self: start;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tl .sidebar { background: var(--sidebar); }
}
.tl .sidebar .brand { padding-inline: 19px 8px; white-space: nowrap; overflow: hidden; flex: none; block-size: 30px; }
/* Fixed sizes: the open rail's taller footer must not squeeze the items, or
   the icons would shift vertically between open and collapsed. */
.tl .sidebar .nav-caption, .tl .sidebar .nav-item { flex: none; }

/* Labels come and go; icons never move: fixed start padding on every item. */
.tl .brand-name, .tl .nav-label {
  display: inline-block; max-inline-size: 180px; overflow: hidden; white-space: nowrap;
  transition: max-inline-size var(--dur-lift) var(--ease-soft), opacity 300ms var(--ease-soft) 140ms;
}

.tl .nav-list { position: relative; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; overflow-x: hidden; min-block-size: 0; flex: 1 1 auto; }
.tl .nav-caption { block-size: 28px; display: flex; align-items: center; margin: 0; padding-inline: 25px;
  font-size: 12px; font-weight: var(--weight-bold); white-space: nowrap; overflow: hidden; }
.tl .nav-item {
  position: relative; z-index: 1;
  block-size: 46px; padding-inline: 25px 12px; gap: var(--space-3);
  border-radius: 16px; color: var(--sidebar-foreground); white-space: nowrap;
  transition: background var(--dur-soft) var(--ease-soft), color var(--dur-soft) var(--ease-soft),
    box-shadow var(--dur-soft) var(--ease-soft);
}
.tl .nav-item:hover { text-decoration: none; }
.tl .nav-item svg.i { transition: transform var(--dur-soft) var(--ease-soft); }
.tl .nav-item:hover svg.i, .tl .nav-item:focus-visible svg.i { transform: scale(1.15); }
.tl .nav-item[aria-current="page"] {
  background: var(--rail-active); color: var(--rail-active-fg);
  box-shadow: 0 14px 26px -14px var(--rail-active);
}
.tl .nav-item .count { margin-inline-start: auto; min-inline-size: 22px; block-size: 22px; border-radius: var(--radius-pill); }

/* The following highlight: one glass layer behind the items, moved by panel.js
   (custom properties set on the list; no style attribute in the template). */
.tl .nav-glow {
  position: absolute; inset-inline: 0; inset-block-start: 0; z-index: 0;
  block-size: var(--glow-h, 46px); border-radius: 16px;
  background: var(--surface-2); border: 1px solid var(--glass-border);
  transform: translateY(var(--glow-y, 0)); opacity: 0; pointer-events: none;
  transition: transform 500ms var(--ease-soft), opacity 300ms var(--ease-soft);
}
.tl .nav-list[data-glow="on"] .nav-glow { opacity: 1; }
.tl .nav-list[data-glow-snap] .nav-glow { transition: none; }

/* Round collapse button on the rail's inline-end edge; 44px hit area. */
.tl .nav-collapse {
  display: grid; place-items: center; position: absolute; z-index: 2;
  inset-block-start: 30px; inset-inline-end: -17px;
  inline-size: 34px; block-size: 34px; padding: 0; border-radius: 50%;
  border: 1px solid var(--glass-border); background: var(--card); color: var(--foreground);
  box-shadow: var(--glass-shadow); cursor: pointer;
}
.tl .nav-collapse::before { content: ""; position: absolute; inset: -5px; border-radius: 50%; }
.tl .nav-collapse-icon { display: grid; place-items: center; transition: transform var(--dur-lift) var(--ease-soft); }

.tl .sidebar-foot { gap: var(--space-3); }
.tl .themeset { border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--glass-border); }
.tl .themeset .icon-btn { border-radius: var(--radius-pill); transition: background var(--dur-soft) var(--ease-soft); }
.tl .themeset .icon-btn[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary-strong); box-shadow: none; }

/* Collapsed rail: only above 900px; below that the sidebar is the drawer. */
@container tl (min-width: 901px) {
  [data-nav="collapsed"] .tl .shell { grid-template-columns: calc(var(--rail-closed) + var(--rail-gap)) minmax(0, 1fr); }
  [data-nav="collapsed"] .tl .brand-name,
  [data-nav="collapsed"] .tl .nav-label { max-inline-size: 0; opacity: 0; transition-delay: 0ms; }
  [data-nav="collapsed"] .tl .nav-collapse-icon { transform: rotate(180deg); }
  [data-nav="collapsed"] .tl .nav-caption { font-size: 0; }
  [data-nav="collapsed"] .tl .nav-caption::before { content: ""; inline-size: 18px; block-size: 2px; border-radius: 2px; background: var(--border); }
  [data-nav="collapsed"] .tl .nav-item .count {
    position: absolute; inset-block-start: 6px; inset-inline-start: 36px;
    min-inline-size: 17px; block-size: 17px; padding-inline: 4px; font-size: 10px; margin: 0;
  }
  [data-nav="collapsed"] .tl .whoami { display: none; }
  [data-nav="collapsed"] .tl .sidebar-foot .themeset { flex-direction: column; border-radius: 22px; }
  [data-nav="collapsed"] .tl .sidebar-foot .themeset .icon-btn { flex: none; block-size: 36px; }
  [data-nav="collapsed"] .tl .logout { padding-inline: 0; }
}

@container tl (max-width: 900px) {
  .tl .shell { grid-template-columns: minmax(0, 1fr); }
  .tl .nav-collapse { display: none; }
  .tl .sidebar { position: static; block-size: auto; margin: 0; }
  .tl .shell[data-drawer="open"] .sidebar {
    inset-block: 12px; inset-inline-start: 12px; block-size: auto;
    border-radius: 28px; padding-inline: 12px;
  }
}

/* T-176 / Shafaq 12.1: a parent item with a submenu (a native <details>). The
   parent takes the filled active look when one of its children is current; a
   child takes the soft one. Icons never move between open and collapsed. */
.tl .nav-group > summary { list-style: none; cursor: pointer; }
.tl .nav-group > summary::-webkit-details-marker { display: none; }
.tl .nav-parent[data-active="true"] {
  background: var(--rail-active); color: var(--rail-active-fg);
  box-shadow: 0 14px 26px -14px var(--rail-active);
}
.tl .nav-chevron { margin-inline-start: auto; display: inline-flex; transition: transform 600ms var(--ease-soft); }
.tl .nav-group[open] > summary .nav-chevron { transform: rotate(-90deg); }
.tl .nav-sub {
  list-style: none; margin: 4px 0 4px; padding: 0;
  padding-inline-start: 12px; margin-inline-start: 25px;
  border-inline-start: 2px solid var(--sidebar-border);
  display: grid; gap: 2px;
}
@media (prefers-reduced-motion: no-preference) {
  .tl .nav-group[open] .nav-sub > li { animation: nav-sub-in 600ms var(--ease-soft) backwards; }
  .tl .nav-group[open] .nav-sub > li:nth-child(2) { animation-delay: 40ms; }
  .tl .nav-group[open] .nav-sub > li:nth-child(3) { animation-delay: 80ms; }
  .tl .nav-group[open] .nav-sub > li:nth-child(4) { animation-delay: 120ms; }
}
@keyframes nav-sub-in { from { opacity: 0; transform: translateY(-4px); } }
.tl .nav-child { min-block-size: 44px; border-radius: 14px; font-size: 14px; }
.tl .nav-child[aria-current="page"] {
  background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); box-shadow: none;
}
@container tl (min-width: 901px) {
  [data-nav="collapsed"] .tl .nav-sub { margin-inline-start: 0; padding-inline-start: 0; border-inline-start: 0;
    border-block: 2px solid var(--sidebar-border); padding-block: 4px; }
  [data-nav="collapsed"] .tl .nav-chevron { display: none; }
}

/* Alert and stale bars: soft status surface under the glass language (§8). */
.tl .alertbar, .tl .stale_bar {
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  backdrop-filter: blur(24px) saturate(160%);
}

@media (prefers-reduced-motion: reduce) {
  .tl .shell, .tl .brand-name, .tl .nav-label, .tl .nav-item, .tl .nav-item svg.i,
  .tl .nav-glow, .tl .nav-collapse-icon, .tl .themeset .icon-btn, .tl .nav-chevron { transition: none; }
}
