/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/*
 * ── Design tokens ─────────────────────────────────────────────
 * All tokens live in css/parts/tokens.css (loaded before this file):
 * colors, typography (display/body/mono), spacing, bevels, shadows,
 * and both themes — dark "Night console" (:root) and light
 * "Day clinical" (:root[data-theme="light"]). Consume vars only.
 */

html { height: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  min-height: 100%;
  color: var(--text-primary);
  line-height: var(--leading-body);
  display: flex; flex-direction: column;
  transition: background-color var(--dur), color var(--dur);
}

body.modal-open {
  overflow: hidden;
}

main#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

/* ── Layout ────────────────────────────────────────────────── */
/*
 * GOTCHA: body { display:flex; flex-direction:column } + margin: 0 auto
 * on a child collapses its width — always pair with width: 100%.
 *
 * GOTCHA: External images (YouTube ggpht, Gravatar, etc.) may block loading
 * when the Referer header points to localhost or an unknown origin. Fix:
 * 1. Add <meta name="referrer" content="no-referrer"> in <head> (global)
 * 2. Or add referrerpolicy="no-referrer" on each <img> tag
 */
.container {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-6);
  flex: 1;
}

/* Vertical rhythm: use inside .container or nested regions */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}
.stack--tight { gap: var(--space-4); }
.stack--loose { gap: var(--space-8); }
.mt-4 { margin-top: var(--space-4); }

/* Page section: title row + body (replaces “card everything” for grouping) */
.section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.section__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
}
.section__titles {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}
.section__title {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-primary);
}
.section__lead {
  font-size: var(--text-sm);
  color: var(--text-muted);
  line-height: 1.45;
  max-width: 52ch;
}
.section__lead code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
  color: var(--text-secondary);
}
.stack > .card { margin-bottom: 0; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* ── Header ────────────────────────────────────────────────── */
/* Themed via --header-* tokens: deep navy + azure sweep in Night console,
   white + hairline azure in Day clinical. A 1px azure underline + dotted
   seam echo the console tabs in both. */
.header-bar {
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--accent);
  box-shadow: 0 1px 0 0 var(--accent-soft), 0 6px 22px -10px var(--scrim);
  padding: 0 var(--space-6);
  height: 68px;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky-header);
  display: flex;
  align-items: center;
}
/* Dotted seam beneath the header — the same NieR signature as the tab divider. */
.header-bar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -7px; height: 6px;
  background-image: radial-gradient(circle, var(--accent) 1px, transparent 1.2px);
  background-size: 16px 6px; background-position: 0 2px;
  opacity: .35; pointer-events: none;
}

/* Scroll progress indicator — thin azure line at the very top of the viewport. */
.scroll-progress {
  position: fixed; top: 0; left: 0; height: 2px; z-index: 1000;
  background: linear-gradient(90deg, var(--accent), var(--accent-bright));
  box-shadow: 0 0 8px var(--accent-glow);
  width: 0%; transition: width 0.1s linear;
}

.header-logo { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.header-logo-img {
  height: 36px; width: auto; flex-shrink: 0;
  filter: var(--header-logo-filter);
  transition: transform 0.3s var(--ease-snap);
  display: block;
}
.header-logo-img:hover { transform: scale(1.14) rotate(-9deg); }

.header-title-link { text-decoration: none; color: inherit; }
.header-logo h1 { font-size: 1.2em; font-weight: 600; color: var(--header-text); letter-spacing: .5px; }
.header-subtitle { font-size: .82em; color: var(--header-text-dim); font-weight: 500; margin-top: 3px; }

/* ── Nav & Auth ────────────────────────────────────────────── */
/*
 * THREE PATTERNS:
 *   A) No nav, no auth → margin-left: auto on .header-home
 *   B) Auth only       → margin-left: auto on .auth-toggle, margin-left: 8px on .header-home
 *   C) Nav + auth      → margin-left: auto on <nav>, margin-left: 5px on .header-home
 */
nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header-home {
  display: flex; align-items: center; justify-content: center;
  min-width: var(--control-height);
  min-height: var(--control-height);
  padding: var(--space-2);
  color: var(--header-text-dim); text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color var(--dur), background var(--dur);
  flex-shrink: 0;
}
.header-home:hover { color: var(--header-text); background: var(--header-hover); }
.header-home svg { width: 34px; height: 34px; display: block; }

/* Notification bell + theme toggle: sit left of the home icon in the right cluster. */
.header-bell,
.header-theme {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-width: var(--control-height);
  min-height: var(--control-height);
  padding: var(--space-2);
  color: var(--header-text-dim); background: transparent;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer; transition: color var(--dur), background var(--dur);
  flex-shrink: 0;
}
.header-bell { margin-left: auto; }
.header-bell:hover,
.header-theme:hover { color: var(--header-text); background: var(--header-hover); }
.header-bell svg { width: 28px; height: 28px; display: block; }
.header-theme svg { width: 24px; height: 24px; display: block; }
.header-bell__dot {
  position: absolute; top: 10px; right: 10px;
  width: 8px; height: 8px;
  background: var(--danger); border-radius: 50%;
  box-shadow: 0 0 8px var(--danger);
  opacity: 0; transform: scale(0);
  transition: opacity var(--dur), transform var(--dur);
}
.header-bell__dot.is-visible { opacity: 1; transform: scale(1); }

/* Mobile-only quick-menu trigger. Hidden on wide screens; appears when the
   hold-Esc shortcut is impractical on touch/narrow viewports. */
.header-menu {
  display: none; align-items: center; justify-content: center;
  margin-left: 8px;
  min-width: var(--control-height);
  min-height: var(--control-height);
  padding: var(--space-2);
  color: var(--header-text-dim); background: transparent;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  cursor: pointer; transition: color var(--dur), background var(--dur);
  flex-shrink: 0;
}
.header-menu:hover { color: var(--header-text); background: var(--header-hover); }
.header-menu svg { width: 28px; height: 28px; display: block; }

@media (max-width: 760px) {
  .header-menu { display: inline-flex; }
  /* Prevent iOS from zooming into form fields on focus. */
  input, textarea, select, [type="search"] { font-size: 1rem; }
}

/* ── Buttons (canonical) ─────────────────────────────────────
 * Use .btn + a variant. Aliases: .nav-link = toolbar ghost; .auth-* map below.
 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  transition:
    background-color var(--dur),
    color var(--dur),
    border-color var(--dur),
    box-shadow var(--dur),
    transform var(--dur-fast);
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}
.btn--sm {
  min-height: var(--control-height-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}
.btn--block { width: 100%; }
.btn--icon {
  min-width: var(--control-height);
  padding: 0;
}
.btn--primary {
  background: var(--accent);
  color: var(--ink-on-accent);
  font-weight: 700;
  border-color: transparent;
}
.btn--primary:hover { background: var(--accent-bright); }
.btn--secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn--secondary:hover {
  background: var(--surface-3);
  border-color: var(--accent);
}
.btn--ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn--ghost:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--accent);
}
.btn--danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}
.btn--danger:hover { background: var(--danger-hover); }

/* Toolbar ghost (header nav) — same as .btn.btn--ghost.btn--sm */
.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background-color var(--dur), color var(--dur), border-color var(--dur);
}
.nav-link:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--accent);
}

.auth-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: var(--control-height);
  min-height: var(--control-height);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  transition: background-color var(--dur), color var(--dur), border-color var(--dur);
}
.auth-toggle:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--accent);
}
.auth-toggle svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: block;
}
.auth-toggle.logged-in { color: var(--accent); }
.auth-toggle.logged-in svg circle:nth-of-type(2) {
  fill: currentColor;
  stroke: none;
}

/* ── Sheet (inline panel under header) — not a modal ─────────
 * Use for auth, filters, compact forms. No backdrop; page scrolls.
 * For blocking overlays use .modal below.
 */
.auth-panel {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-subtle);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}
.auth-panel.open { max-height: 300px; }
.auth-panel-inner {
  padding: var(--space-6);
  max-width: 400px;
  margin: 0 auto;
}
.auth-tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.auth-tab {
  flex: 1;
  min-height: var(--control-height-sm);
  padding: 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background-color var(--dur), color var(--dur), border-color var(--dur);
}
.auth-tab.active {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.auth-form input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: inherit;
}
.auth-submit {
  width: 100%;
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--ink-on-accent);
  font-family: inherit;
  font-weight: 700;
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background-color var(--dur);
}
.auth-submit:hover { background: var(--accent-bright); }
#authUser {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.auth-username {
  color: var(--text-primary);
  font-weight: 600;
}
.auth-logout {
  min-height: var(--control-height-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background-color var(--dur), color var(--dur), border-color var(--dur);
}
.auth-logout:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}
.auth-divider {
  height: 1px;
  background: var(--border-subtle);
}

