/* App shell: sidebar/nav, command palette, slide-over drawer, the status
 * pill system, and bare page-level element defaults. Ported from what used
 * to be templates/base.html's inline <style> block — same rules, rewritten
 * against static/css/tokens.css instead of hardcoded hex.
 */

* {
  box-sizing: border-box;
}
/* `hidden` must beat a component's own `display` (e.g. `.btn` is inline-flex,
   `.modal-overlay` is flex) — the wizard toggles steps and buttons with it. */
[hidden] {
  display: none !important;
}
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  min-height: 100vh;
}
a {
  color: var(--color-accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
/* A link sitting inside running text needs a non-colour cue (WCAG 1.4.1) —
   underline it. Links used as nav / buttons / cards aren't in text blocks
   and keep the clean look. */
p a,
li a:not(.btn),
td a:not(.btn) {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
h1,
h2,
h3,
h4 {
  font-weight: 600;
  line-height: var(--leading-tight);
  letter-spacing: -0.011em;
  text-wrap: balance;
}
h1 {
  font-size: var(--text-xl);
  margin: 0 0 0.35rem;
}
h2 {
  font-size: var(--text-lg);
  margin: 0 0 0.35rem;
}
h3 {
  font-size: var(--text-md);
  margin: 2rem 0 0.5rem;
}
h4 {
  font-size: var(--text-sm);
  margin: 0 0 0.35rem;
}
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}
th,
td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--color-border-hairline);
  font-size: var(--text-sm);
}

/* Keyboard focus — one visible ring everywhere, tuned per-component below
   where a control needs something tighter. Mouse clicks don't trigger it
   (:focus-visible, not :focus). */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Skip past the sidebar to content — first focusable element on every page
   (templates/base.html). Off-screen until focused. */
.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 200;
  background: var(--color-bg-raised);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.9rem;
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: var(--shadow-popover);
  transform: translateY(-150%);
  transition: transform var(--dur-fast) var(--ease);
}
.skip-link:focus-visible {
  transform: translateY(0);
  text-decoration: none;
}

/* Global reduced-motion — components keep their own local guards too. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* One color system for every status shown anywhere — see
   runner/templatetags/pills.py for the status -> bucket mapping. */
.pill {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill-green {
  background: var(--color-green-bg);
  color: var(--color-green);
}
.pill-red {
  background: var(--color-red-bg);
  color: var(--color-red);
}
.pill-amber {
  background: var(--color-amber-bg);
  color: var(--color-amber);
}
.pill-gray {
  background: var(--color-gray-bg);
  color: var(--color-gray);
}
.pill-blue {
  background: var(--color-blue-bg);
  color: var(--color-blue);
}
.pill-blue[data-pulse] {
  animation: pill-pulse 1.6s ease-in-out infinite;
}
@keyframes pill-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Square icon-only button — top bar, close controls, GitHub link. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--color-bg-hover);
  color: var(--color-text);
  text-decoration: none;
}

/* Sidebar */
#sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border-hairline);
  display: flex;
  flex-direction: column;
  padding: 0.9rem 0.7rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}
#sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.3rem 0.5rem 1rem;
  color: var(--color-text);
}
#sidebar .brand:hover { text-decoration: none; }
#sidebar .brand-mark { flex-shrink: 0; }
#sidebar .brand-name {
  font-weight: 680;
  font-size: var(--text-md);
  letter-spacing: -0.01em;
  line-height: 1.15;
}
#sidebar .brand-name span {
  display: block;
  font-weight: 500;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-dim);
}
#switcher {
  margin-bottom: 1rem;
}
#switcher select {
  width: 100%;
  background: var(--color-bg-raised);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.5rem;
  font-family: inherit;
  font-size: var(--text-sm);
}
#sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
#sidebar nav a,
#sidebar nav .nav-locked,
#sidebar nav .soon {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
}
#sidebar nav a svg,
#sidebar nav .nav-locked svg,
#sidebar nav .soon svg {
  flex-shrink: 0;
  opacity: 0.75;
}
#sidebar nav a:hover {
  background: var(--color-bg-hover);
  text-decoration: none;
}
#sidebar nav a.active {
  background: var(--color-bg-active);
  color: var(--color-accent);
  font-weight: 600;
}
#sidebar nav a.active svg { opacity: 1; }
#sidebar nav .nav-locked,
#sidebar nav .soon {
  color: var(--color-text-dim);
  cursor: default;
}
#sidebar nav .nav-locked svg,
#sidebar nav .soon svg {
  opacity: 0.45;
}
#sidebar nav .soon .badge {
  margin-left: auto;
  font-size: var(--text-xs);
  text-transform: uppercase;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.05rem 0.3rem;
}
#sidebar .footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border-hairline);
  font-size: 0.78rem;
  color: var(--color-text-muted);
}
#sidebar .footer .who-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0 -0.4rem 0.4rem;
  padding: 0.35rem 0.4rem;
  min-width: 0;
  border-radius: var(--radius-sm);
  color: inherit;
  text-decoration: none;
  transition: background 0.1s ease;
}
#sidebar .footer .who-row:hover { background: var(--color-bg-active); }
#sidebar .footer .who-row[aria-current="page"] { background: var(--color-bg-active); }
/* .avatar itself is a shared component (components.css); the sidebar only
   needs it not to shrink in the flex row. */
#sidebar .footer .who {
  color: var(--color-text);
  line-height: 1.3;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}
#sidebar .footer .who > span:first-child,
#sidebar .footer .who .name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#sidebar .footer .who .email {
  display: block;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#sidebar .footer-link {
  display: block;
  color: var(--color-text-muted);
  margin: 0 0 0.6rem;
}
#sidebar .palette-hint { margin: 0; }
#theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  border-radius: var(--radius-md);
  padding: 0.4rem 0.6rem;
  font-family: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  margin-bottom: 0.7rem;
}
#theme-toggle:hover {
  border-color: var(--color-text-dim);
}
/* The docs top bar reuses #theme-toggle as a bare icon button. */
#theme-toggle.icon-btn {
  width: 32px;
  height: 32px;
  border-color: transparent;
  margin: 0;
  padding: 0;
}
#theme-toggle.icon-btn:hover { background: var(--color-bg-hover); }
/* Shows the icon of the mode a click switches *to* — moon while light, sun
   while dark. Covers all three states: an explicit [data-theme], and the
   un-stamped "follow the OS" default via prefers-color-scheme. */
#theme-toggle .icon-sun { display: none; }
#theme-toggle .icon-moon { display: inline-flex; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #theme-toggle .icon-sun { display: inline-flex; }
  :root:not([data-theme="light"]) #theme-toggle .icon-moon { display: none; }
}
:root[data-theme="dark"] #theme-toggle .icon-sun { display: inline-flex; }
:root[data-theme="dark"] #theme-toggle .icon-moon { display: none; }
:root[data-theme="light"] #theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] #theme-toggle .icon-moon { display: inline-flex; }
#sidebar .kbd {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 0.3rem;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* Main column = the top bar + the scrolling content area. */
#main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
#topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 52px;
  padding: 0 1.5rem;
  background: color-mix(in srgb, var(--color-bg) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--color-border-hairline);
}
#topbar-context {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-links {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.topbar-links > a:not(.icon-btn) {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--color-text-muted);
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-md);
}
.topbar-links > a:not(.icon-btn):hover {
  background: var(--color-bg-hover);
  color: var(--color-text);
  text-decoration: none;
}
.topbar-links > a[aria-current="page"] { color: var(--color-accent); }
#sidebar-toggle { display: none; }

#main {
  flex: 1;
  min-width: 0;
  padding: 2.25rem 3rem 4rem;
}
#main .crumb {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  margin-bottom: 0.6rem;
}
#main .crumb a { color: var(--color-text-muted); }
#main .crumb a:hover { color: var(--color-accent); }

/* Tooltip bubble (static/js/tooltip.js) */
.tooltip-bubble {
  position: absolute;
  z-index: 100;
  max-width: 15rem;
  background: var(--color-text);
  color: var(--color-bg-raised);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1.4;
  padding: 0.35rem 0.55rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-popover);
  pointer-events: none;
}

/* Sidebar collapses to an icon-only rail once the viewport can't spare the
   label column — labels/switcher/footer text hide via CSS only. */
@media (max-width: 900px) {
  #sidebar {
    width: 60px;
    padding: 0.9rem 0.45rem;
  }
  #sidebar .brand-name,
  #switcher,
  #sidebar nav a span,
  #sidebar nav .nav-locked span,
  #sidebar nav .soon span:not(.badge),
  #sidebar nav .badge,
  #sidebar .footer .who,
  #sidebar .footer-link,
  #sidebar .palette-hint,
  #theme-toggle span:not(.icon-sun):not(.icon-moon) {
    display: none;
  }
  #sidebar nav a,
  #sidebar nav .nav-locked,
  #sidebar nav .soon {
    justify-content: center;
  }
  #theme-toggle { justify-content: center; }
  #sidebar .footer .who-row { justify-content: center; }
  #main { padding: 2rem 1.5rem 3rem; }
  #topbar { padding: 0 1rem; }
}

/* Below 720px the rail slides fully off-canvas; #sidebar-toggle in the top
   bar (static/js/shell.js) brings it back. */
@media (max-width: 720px) {
  #sidebar-toggle { display: inline-flex; }
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 232px;
    padding: 0.9rem 0.7rem;
    transform: translateX(-105%);
    transition: transform var(--dur-med) var(--ease);
    box-shadow: var(--shadow-modal);
  }
  body.nav-open #sidebar { transform: translateX(0); }
  #sidebar .brand-name,
  #sidebar nav a span,
  #sidebar nav .nav-locked span,
  #sidebar .footer .who,
  #sidebar .footer-link,
  #sidebar .palette-hint { display: revert; }
  #sidebar nav a, #sidebar nav .nav-locked { justify-content: flex-start; }
  #switcher { display: block; }
}

/* Command palette (Cmd/Ctrl+K) */
#palette-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  z-index: 50;
}
#palette-overlay.open {
  display: flex;
}
#palette {
  width: 480px;
  max-width: 90vw;
  background: var(--color-bg-raised);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow-overlay);
}
#palette input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 0.8rem 1rem;
  font-family: inherit;
  font-size: var(--text-md);
}
#palette input:focus-visible {
  outline: none;
  border-bottom-color: var(--color-accent);
  box-shadow: 0 1px 0 0 var(--color-accent);
}
#palette-results {
  max-height: 320px;
  overflow: auto;
}
#palette-results .item {
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
}
#palette-results .item.sel {
  background: var(--color-bg-active);
}
#palette-results .empty {
  padding: 0.8rem 1rem;
  color: var(--color-text-muted);
  font-size: 0.82rem;
}

/* Slide-over drawer, used by runner/job.html for test-case detail */
#drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: 40;
}
#drawer-overlay.open {
  display: block;
}
#drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 90vw;
  background: var(--color-bg-drawer);
  border-left: 1px solid var(--color-border);
  transform: translateX(100%);
  transition: transform 0.18s ease;
  z-index: 41;
  padding: 1.5rem;
  overflow-y: auto;
}
#drawer.open {
  transform: translateX(0);
}
#drawer .close {
  float: right;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 1.1rem;
}
#drawer h3 {
  margin-top: 0;
}
#drawer pre {
  background: var(--color-bg-sunken);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
