/*
 * admin/css/shell.css — the chrome around every page (ui/shell.js, rail.js,
 * switcher.js): the hub top bar, the sign-in card, and the event workspace's
 * dark rail, sticky header, event switcher and phone drawer.
 *
 * Geometry is FrontRow's (read-only): styles/admin/_workspace.scss (rail,
 * header, switcher, drawer, breakpoints), styles/admin/_admin.scss
 * (.admin-shell, .admin-topbar, .login-*, .badge). Spec §3, §6. Every colour
 * is a var() from tokens.css.
 *
 * Breakpoints (spec §6): ≥1200 full rail card · 768–1199 icon rail (88px) ·
 * <768 slide-in drawer · ≤480 two-row header.
 */

/* ── The header block every sticky offset derives from ──────────────────── */
/* Published only in the workspace, where the sticky header exists: 60px
   header + 10px inset on desktop, 60px flush on a phone, two rows (100px) at
   ≤480. base.css sticky tabs and asides read it; scroll-padding keeps
   scrollIntoView() targets (the conflict alert, a focused field) clear of it. */
html[data-admin-shell="workspace"] {
  --admin-header-block: 70px;
  scroll-padding-top: calc(var(--admin-header-block) + 8px);
}

@media (max-width: 767px) {
  html[data-admin-shell="workspace"] { --admin-header-block: 60px; }
}

@media (max-width: 480px) {
  html[data-admin-shell="workspace"] { --admin-header-block: 100px; }
}

#app,
.page-root {
  min-width: 0;
}

/* ── Hub shell: a centred column under a lean top bar ───────────────────── */
.hub-shell {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Wraps rather than overflows on a phone; gap applies to both axes. */
.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.admin-brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.035em;
  word-spacing: 0.1em;
  line-height: 1.2;
  color: var(--text);
  text-decoration: none;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* The toggle among full-size 44px buttons: a tonal square like its header twin. */
.admin-topbar .theme-toggle {
  background: var(--surface-hi);
}

.admin-topbar .theme-toggle:hover {
  background: var(--surface);
}

.hub-canvas {
  min-width: 0;
}

/* Phone: the hub cluster wraps under the wordmark; its controls take the
   workspace header's compact 36px geometry (with a 44px hit layer), so the
   two wrapped rows stay light. */
@media (max-width: 560px) {
  .hub-shell {
    gap: 22px;
  }

  .admin-topbar {
    gap: 12px;
  }

  .admin-actions {
    gap: 8px;
  }

  .admin-actions > .btn,
  .admin-actions > .theme-toggle {
    position: relative;
    height: 36px;
    min-height: 36px;
  }

  .admin-actions > .btn {
    padding: 0 12px;
  }

  .admin-actions > .theme-toggle {
    width: 36px;
  }

  .admin-actions > .btn::before,
  .admin-actions > .theme-toggle::before {
    content: '';
    position: absolute;
    inset-block: min(0px, calc((100% - 44px) / 2));
    inset-inline: min(0px, calc((100% - 44px) / 2));
  }
}

/* ── Sign-in ────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-wrap > .page-root {
  width: 100%;
  max-width: 400px;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 36px 32px;
  border-radius: var(--radius-card);
  background: var(--surface);
}

.login-brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -0.035em;
  word-spacing: 0.1em;
  color: var(--text);
}

.login-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.login-heading {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(22px, 4vw, 28px);
  letter-spacing: -0.03em;
  word-spacing: 0.1em;
  line-height: 1.1;
  color: var(--text);
}

.login-sub {
  font-size: 14px;
  color: var(--text-dim);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-form .btn--primary {
  width: 100%;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  white-space: pre-line;
}

.login-error:empty {
  display: none;
}

/* ── Not found ──────────────────────────────────────────────────────────── */
.not-found {
  margin-top: 24px;
}

/* ── Status word (header): colour only — no pill, border or dot ─────────── */
.badge {
  display: inline-flex;
  align-items: center;
  flex: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text-dim);
}

.badge--active { color: var(--success); }
.badge--inactive { color: var(--text-dim); }
.badge--deleted { color: var(--danger); }

/* ── Workspace ──────────────────────────────────────────────────────────── */
/* The rail's footprint is 17.5% of the viewport (card + 10px margins);
   .workspace-main offsets by the same --rail-span. Change both or neither. */
.workspace {
  --rail-span: 17.5%;
  display: flex;
  min-height: 100dvh;
}

/* Rail — fixed, a detached dark card, the same in both themes. */
.workspace-rail {
  /* The rail is dark in both themes, so it names its own focus ink. */
  --focus-ring: var(--rail-active-text);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  width: calc(var(--rail-span) - 20px);
  height: calc(100% - 20px);
  margin: 10px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--rail-bg);
  color: var(--rail-text);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.workspace-rail::-webkit-scrollbar {
  display: none;
}

.rail-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 16px;
}

.rail-logo {
  display: flex;
  align-items: center;
  height: 44px;
  border-radius: 10px;
  color: var(--rail-active-text);
  transition: opacity var(--dur) var(--ease-ui);
}

.rail-logo:hover {
  opacity: .8;
}

.rail-group {
  display: flex;
  flex-direction: column;
  flex: none;
  margin-bottom: 12px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--rail-group-bg);
}

.rail-hdr {
  margin: 0 0 6px;
  padding: 10px;
  border-radius: 4px;
  background: var(--rail-hdr-bg);
  color: var(--rail-text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rail-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 4px;
  border-radius: 10px;
  background: var(--rail-row-bg);
  color: var(--rail-text);
  text-decoration: none;
  transition: color var(--dur) var(--ease-ui), background var(--dur) var(--ease-ui);
}

.rail-link:hover {
  color: var(--rail-active-text);
  background: var(--rail-hover-bg);
}

.rail-link--active,
.rail-link--active:hover {
  color: var(--rail-active-text);
  background: var(--rail-active-bg);
}

.rail-link:focus-visible,
.rail-logo:focus-visible,
.rail-close:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* A 16px line glyph inside a 34×34 tile, stroke forced to 1px (spec §3.3). */
.rail-icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: var(--rail-icon-bg);
  pointer-events: none;
}

.rail-icon .icon {
  width: 16px;
  height: 16px;
  stroke-width: 1px;
}

.rail-label {
  flex: 1 1 auto;
  min-width: 0;
  padding-top: 2px;
  font-size: 14px;
  font-weight: 300;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

/* Drawer chrome exists only on a phone. */
.workspace-navbtn,
.workspace-scrim,
.rail-close {
  display: none;
}

/* Main column — the rail's full footprint to its left. */
.workspace-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  margin-left: var(--rail-span);
}

/* Header — a sticky floating card (60px + a 10px inset), translucent. */
.workspace-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: calc(100% - 10px);
  min-height: 60px;
  margin-top: 10px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--header-bg);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  backdrop-filter: blur(20px) saturate(140%);
}

.workspace-header-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.workspace-event-name {
  min-width: 0;
  max-width: 220px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.025em;
  word-spacing: 0.1em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--dur) var(--ease-ui);
}

.workspace-event-name:hover {
  opacity: .75;
}

.workspace-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* One geometry for the header's controls (switcher, theme, Sign out): 36px
   tall, borderless, radius 8, with an invisible 44px hit layer. Scoped here so
   the global .btn--ghost / .btn-icon stay untouched elsewhere. */
.workspace-header-actions .event-switcher-trigger,
.workspace-header-actions > .theme-toggle,
.workspace-header-actions > .btn {
  position: relative;
  flex: none;
  height: 36px;
  min-height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
}

.workspace-header-actions .event-switcher-trigger::before,
.workspace-header-actions > .theme-toggle::before,
.workspace-header-actions > .btn::before {
  content: '';
  position: absolute;
  inset-block: min(0px, calc((100% - 44px) / 2));
  inset-inline: min(0px, calc((100% - 44px) / 2));
}

.workspace-header-actions > .theme-toggle {
  width: 36px;
  background: var(--surface-hi);
}

.workspace-header-actions > .theme-toggle .icon {
  width: 18px;
  height: 18px;
}

.workspace-header-actions > .btn {
  padding: 0 12px;
  background: var(--surface-hi);
}

.workspace-header-actions > .theme-toggle:hover,
.workspace-header-actions > .btn:hover {
  background: var(--surface);
}

/* Canvas — the one <main>; below the header (50) and rail (100). */
.workspace-canvas {
  position: relative;
  z-index: 2;
  width: 100%;
  min-width: 0;
  margin: 0 auto 0 0;
  padding: 24px 22px 80px 12px;
}

/* ── Event switcher ─────────────────────────────────────────────────────── */
.event-switcher {
  position: relative;
  min-width: 0;
}

/* The header's one filled control: it reads as the primary. */
.event-switcher-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 160px;
  height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--dur) var(--ease-ui);
}

.event-switcher-trigger:hover {
  filter: brightness(1.25);
}

.event-switcher-trigger:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.event-switcher-label {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.event-switcher-chevron {
  flex: none;
  display: flex;
  align-items: center;
  opacity: .6;
}

.event-switcher-chevron .icon {
  width: 16px;
  height: 16px;
  stroke-width: 1.9px;
}

/* One popover surface for the list and its empty / loading note: the glass
   tint laid over an opaque --bg. The header around it is itself a backdrop
   root, so a see-through fill would let page text show through unblurred. */
.event-switcher-list,
.event-switcher-empty {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 200;
  min-width: 180px;
  max-width: min(320px, calc(100vw - 24px));
  border-radius: var(--radius-md);
  background: linear-gradient(var(--glass-bg), var(--glass-bg)), var(--bg);
  box-shadow: var(--popover-shadow);
}

.event-switcher-list {
  max-height: min(60vh, 420px);
  margin: 0;
  padding: 6px;
  list-style: none;
  overflow-y: auto;
}

.event-switcher-option {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background var(--dur) var(--ease-ui);
}

/* Hover and keyboard share one highlight: focus is the selection. */
.event-switcher-option:hover,
.event-switcher-option:focus-visible {
  background: var(--surface-hi);
}

.event-switcher-option:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

@media (pointer: coarse) {
  .event-switcher-option {
    min-height: 44px;
  }
}

.event-switcher-empty {
  padding: 12px;
  font-size: 13px;
  color: var(--text-faint);
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .rail-link,
  .rail-logo,
  .event-switcher-trigger,
  .event-switcher-option,
  .workspace-event-name,
  .workspace-rail,
  .workspace-scrim {
    transition: none;
  }
}

/* ── Tablet: icon-only rail (768–1199px) ────────────────────────────────── */
/* Labels and group titles hide; each link keeps its label as a title tooltip
   (and as its accessible name). */
@media (min-width: 768px) and (max-width: 1199px) {
  .workspace {
    --rail-span: 88px;
  }

  .rail-top {
    justify-content: center;
  }

  .rail-group {
    padding: 6px;
  }

  .rail-link {
    justify-content: center;
    gap: 0;
    padding: 0;
  }

  .rail-label,
  .rail-hdr {
    display: none;
  }

  /* The icon is the only label here: a 1px line at 16px anti-aliases under
     3:1, so the tablet rail draws it at 1.5px. */
  .rail-icon .icon {
    stroke-width: 1.5px;
  }
}

/* ── Phone: slide-in drawer (<768px) ────────────────────────────────────── */
@media (max-width: 767px) {
  .workspace-rail {
    width: 264px;
    height: 100%;
    margin: 0;
    border-radius: 0;
    box-shadow: var(--drawer-shadow);
    transform: translateX(-100%);
    /* Closed = out of the tab order too: visibility flips after the slide. */
    visibility: hidden;
    transition: transform .26s var(--ease), visibility 0s linear .26s;
  }

  .workspace-rail--open {
    transform: translateX(0);
    visibility: visible;
    transition: transform .26s var(--ease), visibility 0s linear 0s;
  }

  /* Comfortable touch rows in the drawer. */
  .rail-link {
    height: 48px;
  }

  /* ☰ — fixed top-left, floating over the header. */
  .workspace-navbtn {
    position: fixed;
    top: 10px;
    left: 12px;
    z-index: 60;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--glass-bg);
    color: var(--text);
    cursor: pointer;
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    backdrop-filter: blur(20px) saturate(140%);
  }

  .workspace-navbtn::before {
    content: '';
    position: absolute;
    inset: -2px;
  }

  .workspace-navbtn .icon {
    width: 22px;
    height: 22px;
    stroke-width: 1.6px;
  }

  .workspace-navbtn:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
  }

  /* X inside the drawer: an outlined ghost on the dark rail. */
  .rail-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--rail-close-border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--rail-close-text);
    cursor: pointer;
  }

  .rail-close::before {
    content: '';
    position: absolute;
    inset-block: -4px;
    inset-inline: -4px;
  }

  .rail-close {
    position: relative;
  }

  .rail-close .icon {
    width: 20px;
    height: 20px;
    stroke-width: 1.6px;
  }

  .workspace-scrim {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: block;
    background: var(--scrim);
    opacity: 0;
    pointer-events: none;
    transition: opacity .26s var(--ease-ui);
  }

  .workspace-scrim--open {
    opacity: 1;
    pointer-events: auto;
  }

  .workspace {
    --rail-span: 0px;
  }

  /* Full width, square, flush; room on the left for ☰. */
  .workspace-header {
    width: 100%;
    margin-top: 0;
    padding: 0 12px 0 60px;
    border-radius: 0;
    gap: 8px;
  }

  .event-switcher-trigger {
    max-width: 112px;
  }

  .workspace-canvas {
    padding: 20px 16px 64px;
  }

  /* Scroll lock while the drawer is open — scoped to the phone so a resize
     can never strand a desktop page unscrollable. */
  body.workspace-nav-open {
    overflow: hidden;
  }
}

/* ── ≤480px: two-row header ─────────────────────────────────────────────── */
/* Row 1: event name + status, then Sign out; row 2: switcher and theme. */
@media (max-width: 480px) {
  .workspace-header {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      'identity identity identity signout'
      'switcher toggle   .        .';
    align-items: center;
    min-height: 100px;
    padding: 10px 12px 10px 60px;
  }

  .workspace-header-identity {
    grid-area: identity;
  }

  .workspace-header-actions {
    display: contents;
  }

  .workspace-header-actions > .event-switcher {
    grid-area: switcher;
    justify-self: start;
    max-width: 100%;
  }

  /* Row 2 gives the switcher room of its own: lift the 112px single-row cap
     (FrontRow caps the pill at 160px; the grid column bounds it here). */
  .event-switcher-trigger {
    max-width: min(240px, 100%);
  }

  .workspace-header-actions > .theme-toggle {
    grid-area: toggle;
    justify-self: start;
  }

  .workspace-header-actions > .workspace-signout {
    grid-area: signout;
    justify-self: end;
  }

  .workspace-event-name {
    max-width: 100%;
  }
}
