/* ==========================================================================
   Texas Wing Group 3 Intranet — design system and application styles.

   Visual direction: an operational console rather than a corporate portal.
   A dark navy command rail against a light working canvas, hairline rules
   instead of drop shadows, squared 3px corners, uppercase tracked labels,
   tabular figures in every data table, and status carried by a left accent
   bar rather than decorative colour. Restrained Civil Air Patrol-inspired
   palette; no official CAP emblems or seals are reproduced.

   Everything is driven by custom properties in :root so the palette,
   spacing scale, type scale, radii and breakpoints can be retuned in one
   place.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */
:root {
  /* Brand — deep navy through medium blue */
  --navy-900: #08182a;
  --navy-800: #0a1c30;
  --navy-700: #10293f;
  --navy-600: #16385a;
  --navy-500: #1d4874;
  --blue-700: #1a558f;
  --blue-600: #2168ab;
  --blue-500: #2e7cc4;
  --blue-200: #b9d5ee;
  --blue-100: #e2eef9;
  --blue-050: #f1f7fc;

  /* Signal colours */
  --gold-700: #8a5d06;
  --gold-600: #a9740d;
  --gold-100: #fbf1d8;
  --red-700: #8f1d1d;
  --red-600: #a92626;
  --red-100: #fae9e9;
  --green-700: #11603f;
  --green-600: #17754e;
  --green-100: #e3f2ea;
  --violet-600: #5b4a9e;
  --violet-100: #eeebf8;

  /* Neutrals */
  --ink-900: #0e1724;
  --ink-700: #2c3a4d;
  --ink-500: #52627a;
  --ink-400: #6d7c93;
  --ink-300: #93a0b3;
  --line: #dce2ea;
  --line-strong: #c3ccd9;
  --canvas: #f2f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;

  /* Semantic aliases (re-pointed by the dark theme) */
  --bg: var(--canvas);
  --fg: var(--ink-900);
  --fg-muted: var(--ink-500);
  --fg-subtle: var(--ink-400);
  --panel-bg: var(--surface);
  --panel-alt: var(--surface-2);
  --border: var(--line);
  --border-strong: var(--line-strong);
  --accent: var(--blue-600);
  --accent-fg: #ffffff;
  --rail-bg: var(--navy-800);
  --rail-fg: #d7e2ee;
  --rail-fg-dim: #8ba3bd;
  --rail-active: var(--navy-600);
  --rail-line: #1b3550;
  --focus: #3b8ee0;

  /* Typography */
  --font-ui:
    "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-head: var(--font-ui);
  --font-mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;

  --fs-xxs: 0.6875rem; /* 11px — micro labels */
  --fs-xs: 0.75rem; /* 12px */
  --fs-sm: 0.8125rem; /* 13px */
  --fs-base: 0.9375rem; /* 15px */
  --fs-md: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.125rem;

  --lh-tight: 1.2;
  --lh-snug: 1.35;
  --lh-base: 1.55;

  --track-caps: 0.08em; /* uppercase label tracking */
  --track-wide: 0.03em;

  /* Spacing scale */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.25rem;
  --s-6: 1.5rem;
  --s-8: 2rem;
  --s-10: 2.5rem;
  --s-12: 3rem;

  /* Radii — deliberately tight; this is an instrument panel, not a card game */
  --r-sm: 2px;
  --r-md: 3px;
  --r-lg: 5px;
  --r-pill: 999px;

  /* Elevation — used sparingly, only for floating layers */
  --shadow-pop: 0 6px 24px rgb(8 24 42 / 18%);
  --shadow-modal: 0 18px 48px rgb(8 24 42 / 28%);

  /* Layout metrics */
  --rail-w: 244px;
  --rail-w-collapsed: 62px;
  --topbar-h: 62px;
  --bottomnav-h: 56px;
  --content-max: 1360px;

  /* Breakpoints (documented for JS; media queries must inline the values) */
  --bp-sm: 560px;
  --bp-md: 860px;
  --bp-lg: 1080px;
  --bp-xl: 1400px;

  --transition: 140ms ease;
}

/*
 * Tell the browser which theme is in force so its own widgets — scrollbars,
 * date pickers, select menus, form controls — match. Without this a member who
 * forces light while their operating system is dark keeps dark scrollbars, and
 * the mismatch is very visible against a light page.
 */
:root[data-theme="light"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

/* Dark theme — follows the OS by default, overridable with data-theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1420;
    --fg: #e6ecf4;
    --fg-muted: #9daec3;
    --fg-subtle: #7f92a9;
    --panel-bg: #101c2b;
    --panel-alt: #142334;
    --surface-3: #1a2b3e;
    --border: #22364c;
    --border-strong: #2e4763;
    --accent: #4f9be0;
    --rail-bg: #071322;
    --rail-line: #17293d;
    --rail-active: #16385a;
    --blue-100: #16304a;
    --blue-050: #12283e;
    --gold-100: #3a2c0d;
    --red-100: #3a1717;
    --green-100: #103127;
    --violet-100: #251f42;
    --gold-600: #dfa63a;
    --red-600: #e97878;
    --green-600: #5cc79b;
    --blue-600: #6fb2ea;
    --violet-600: #a99ae0;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1420;
  --fg: #e6ecf4;
  --fg-muted: #9daec3;
  --fg-subtle: #7f92a9;
  --panel-bg: #101c2b;
  --panel-alt: #142334;
  --surface-3: #1a2b3e;
  --border: #22364c;
  --border-strong: #2e4763;
  --accent: #4f9be0;
  --rail-bg: #071322;
  --rail-line: #17293d;
  --rail-active: #16385a;
  --blue-100: #16304a;
  --blue-050: #12283e;
  --gold-100: #3a2c0d;
  --red-100: #3a1717;
  --green-100: #103127;
  --violet-100: #251f42;
  --gold-600: #dfa63a;
  --red-600: #e97878;
  --green-600: #5cc79b;
  --blue-600: #6fb2ea;
  --violet-600: #a99ae0;
}

/* --------------------------------------------------------------------------
   2. Reset and base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5 {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 650;
  line-height: var(--lh-tight);
  letter-spacing: -0.005em;
}

p {
  margin: 0 0 var(--s-3);
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-thickness: 2px;
}

img,
svg {
  max-width: 100%;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--s-6) 0;
}

code,
kbd,
pre,
.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection {
  background: var(--blue-200);
  color: var(--ink-900);
}

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

.skip-link {
  position: absolute;
  left: var(--s-2);
  top: -60px;
  z-index: 200;
  background: var(--navy-800);
  color: #fff;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-md);
  text-decoration: none;
  transition: top var(--transition);
}

.skip-link:focus {
  top: var(--s-2);
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sm {
  width: 16px;
  height: 16px;
  stroke-width: 1.8;
}

.icon-lg {
  width: 26px;
  height: 26px;
  stroke-width: 1.5;
}

.noscript {
  max-width: 34rem;
  margin: var(--s-12) auto;
  padding: var(--s-6);
  border: 1px solid var(--border);
  background: var(--panel-bg);
}

/* --------------------------------------------------------------------------
   3. Boot and fatal screens
   -------------------------------------------------------------------------- */
.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--s-5);
  background: var(--navy-800);
  color: #cfdcea;
  z-index: 300;
}

body:not(.is-booting) .boot {
  display: none;
}

.boot-mark {
  width: 72px;
  height: 72px;
  animation: pulse 1.6s ease-in-out infinite;
}

.boot-text {
  font-size: var(--fs-sm);
  letter-spacing: var(--track-wide);
  margin: 0;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.fatal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--s-4);
  background: var(--navy-800);
  z-index: 320;
  overflow: auto;
}

.fatal-card {
  max-width: 44rem;
  background: var(--surface);
  color: var(--ink-900);
  border-top: 4px solid var(--red-600);
  padding: var(--s-8);
  border-radius: var(--r-md);
}

.fatal-title {
  font-size: var(--fs-xl);
  margin-bottom: var(--s-3);
}

.fatal-body {
  color: var(--ink-700);
  font-size: var(--fs-sm);
}

.fatal-code {
  background: var(--surface-3);
  border: 1px solid var(--line);
  padding: var(--s-3);
  overflow-x: auto;
  border-radius: var(--r-md);
  color: var(--ink-900);
}

/* --------------------------------------------------------------------------
   4. Public (unauthenticated) area
   -------------------------------------------------------------------------- */
.public {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.public-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 34%) 1fr;
}

.public-brand {
  background: var(--navy-800);
  background-image: linear-gradient(180deg, var(--navy-800) 0%, var(--navy-900) 100%);
  color: #d6e2ee;
  padding: var(--s-10) var(--s-8);
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  border-right: 1px solid var(--navy-600);
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

/* Group III Texas Wing emblem, supplied by the unit. */
.brand-mark {
  width: 120px;
  height: 120px;
  margin-bottom: var(--s-4);
  object-fit: contain;
}

.brand-eyebrow {
  margin: 0;
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: #8fb0cd;
  font-weight: 600;
}

.brand-title {
  font-size: var(--fs-2xl);
  color: #fff;
  margin: 0;
}

.brand-sub {
  margin: 0;
  color: #a9c1d8;
  font-size: var(--fs-sm);
}

.brand-quote {
  margin: 0;
  padding-left: var(--s-4);
  border-left: 3px solid var(--gold-600);
  font-size: var(--fs-md);
  line-height: var(--lh-snug);
  color: #eaf1f8;
}

.brand-points {
  margin: 0;
  padding-left: 1.1rem;
  color: #a9c1d8;
  font-size: var(--fs-sm);
  display: grid;
  gap: var(--s-2);
}

.brand-foot {
  margin-top: auto;
  font-size: var(--fs-xs);
  color: #7d97b1;
  border-top: 1px solid var(--navy-600);
  padding-top: var(--s-4);
}

.public-panel {
  padding: var(--s-10) var(--s-8);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
}

.pubview {
  width: 100%;
  max-width: 34rem;
}

.pubview[hidden] {
  display: none;
}

.pubview-eyebrow {
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--fg-subtle);
  font-weight: 700;
  margin: 0 0 var(--s-2);
}

.pubview-title {
  font-size: var(--fs-2xl);
  margin-bottom: var(--s-4);
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--border);
}

.pubview-lead {
  color: var(--fg-muted);
  margin-bottom: var(--s-6);
}

.pubview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}

.pubview-note {
  font-size: var(--fs-sm);
}

.pubview-links {
  margin-top: var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-4);
  font-size: var(--fs-sm);
}

.public-footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  justify-content: center;
  padding: var(--s-4);
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
}

@media (max-width: 860px) {
  .public-grid {
    grid-template-columns: 1fr;
  }

  .public-brand {
    padding: var(--s-6) var(--s-5);
    border-right: 0;
    border-bottom: 1px solid var(--navy-600);
  }

  .brand-points,
  .brand-foot {
    display: none;
  }

  .public-panel {
    padding: var(--s-6) var(--s-4);
  }
}

/* --------------------------------------------------------------------------
   5. Forms
   -------------------------------------------------------------------------- */
.form {
  display: grid;
  gap: var(--s-4);
}

.field {
  display: grid;
  gap: var(--s-1);
  min-width: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
}

@media (max-width: 560px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg);
}

.req {
  color: var(--red-600);
  font-weight: 700;
}

.opt {
  color: var(--fg-subtle);
  font-weight: 400;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="search"],
select,
textarea {
  width: 100%;
  font: inherit;
  font-size: var(--fs-base);
  color: var(--fg);
  background: var(--panel-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 0.5rem 0.625rem;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
}

textarea {
  resize: vertical;
  min-height: 4.5rem;
  line-height: var(--lh-base);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 16px) calc(50% + 2px),
    calc(100% - 11px) calc(50% + 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2rem;
}

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: var(--fg-subtle);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--surface-3);
  color: var(--fg-subtle);
  cursor: not-allowed;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--red-600);
}

.field-hint {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
}

.field-error {
  margin: 0;
  font-size: var(--fs-xs);
  color: var(--red-600);
  font-weight: 600;
  min-height: 0;
}

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

.check {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--s-2);
  align-items: start;
  font-weight: 400;
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  cursor: pointer;
}

.check input[type="checkbox"],
.check input[type="radio"] {
  width: 1rem;
  height: 1rem;
  margin-top: 0.2rem;
  accent-color: var(--accent);
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  cursor: pointer;
}

.check-list {
  display: grid;
  gap: var(--s-2);
  max-height: 15rem;
  overflow-y: auto;
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--panel-alt);
}

.password-field {
  position: relative;
  display: flex;
}

.password-field input {
  padding-right: 4.25rem;
}

.pw-toggle {
  position: absolute;
  right: 4px;
  top: 4px;
  bottom: 4px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  padding: 0 var(--s-2);
  cursor: pointer;
  border-radius: var(--r-sm);
}

.pw-toggle:hover {
  background: var(--surface-3);
}

.form-msg {
  margin: 0;
  font-size: var(--fs-sm);
  min-height: 0;
}

.form-msg:empty {
  display: none;
}

.form-msg.is-error {
  color: var(--red-600);
  font-weight: 600;
}

.form-msg.is-ok {
  color: var(--green-600);
  font-weight: 600;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  align-items: center;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  margin: 0;
}

legend {
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  font-weight: 700;
  color: var(--fg-subtle);
  padding: 0 var(--s-2);
}

/* --------------------------------------------------------------------------
   6. Buttons
   -------------------------------------------------------------------------- */
.btn {
  --btn-bg: transparent;
  --btn-fg: var(--fg);
  --btn-border: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.2;
  padding: 0.5rem 0.875rem;
  min-height: 36px;
  border: 1px solid var(--btn-border);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background var(--transition),
    border-color var(--transition),
    color var(--transition);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  --btn-bg: var(--navy-600);
  --btn-fg: #fff;
  --btn-border: var(--navy-600);
}

.btn-primary:hover:not(:disabled) {
  --btn-bg: var(--navy-500);
  --btn-border: var(--navy-500);
}

.btn-outline {
  --btn-border: var(--border-strong);
  --btn-bg: var(--panel-bg);
}

.btn-outline:hover:not(:disabled) {
  --btn-bg: var(--surface-3);
  --btn-border: var(--fg-subtle);
}

.btn-ghost {
  --btn-fg: var(--fg-muted);
}

.btn-ghost:hover:not(:disabled) {
  --btn-bg: var(--surface-3);
  --btn-fg: var(--fg);
}

.btn-danger {
  --btn-bg: var(--red-600);
  --btn-fg: #fff;
  --btn-border: var(--red-600);
}

.btn-danger:hover:not(:disabled) {
  --btn-bg: var(--red-700);
  --btn-border: var(--red-700);
}

.btn-danger-outline {
  --btn-fg: var(--red-600);
  --btn-border: color-mix(in srgb, var(--red-600) 45%, transparent);
}

.btn-danger-outline:hover:not(:disabled) {
  --btn-bg: var(--red-100);
}

.btn-sm {
  font-size: var(--fs-xs);
  padding: 0.3125rem 0.5625rem;
  min-height: 30px;
}

.btn-lg {
  font-size: var(--fs-base);
  padding: 0.625rem 1.25rem;
  min-height: 44px;
}

.btn-block {
  width: 100%;
}

.btn.is-busy {
  position: relative;
  color: transparent !important;
}

.btn.is-busy::after {
  content: "";
  position: absolute;
  width: 15px;
  height: 15px;
  border: 2px solid currentcolor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--btn-fg);
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  position: relative;
  padding: 0;
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--fg);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

/* --------------------------------------------------------------------------
   7. Application shell
   -------------------------------------------------------------------------- */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
  grid-template-areas:
    "rail topbar"
    "rail main"
    "rail foot";
  transition: grid-template-columns var(--transition);
}

body.nav-collapsed .app {
  grid-template-columns: var(--rail-w-collapsed) minmax(0, 1fr);
}

/* --- Command rail --- */
.rail {
  grid-area: rail;
  background: var(--rail-bg);
  color: var(--rail-fg);
  border-right: 1px solid var(--rail-line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4);
  border-bottom: 1px solid var(--rail-line);
  min-height: var(--topbar-h);
}

.rail-mark {
  width: 34px;
  height: 34px;
  flex: none;
  object-fit: contain;
}

.rail-id {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rail-id-top {
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--rail-fg-dim);
  font-weight: 600;
}

.rail-id-main {
  font-size: var(--fs-sm);
  font-weight: 650;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-close {
  display: none;
  margin-left: auto;
  color: var(--rail-fg-dim);
}

.rail-nav {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s-3) 0 var(--s-4);
  scrollbar-width: thin;
}

.nav-group-label {
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--rail-fg-dim);
  font-weight: 700;
  padding: var(--s-4) var(--s-4) var(--s-2);
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0.5rem var(--s-4);
  color: var(--rail-fg);
  text-decoration: none;
  font-size: var(--fs-sm);
  border-left: 3px solid transparent;
  white-space: nowrap;
  position: relative;
}

.nav-item:hover {
  background: rgb(255 255 255 / 6%);
  color: #fff;
}

.nav-item.is-active {
  background: var(--rail-active);
  border-left-color: var(--gold-600);
  color: #fff;
  font-weight: 650;
}

.nav-item .icon {
  color: #8fb0cd;
}

.nav-item.is-active .icon,
.nav-item:hover .icon {
  color: #fff;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-badge {
  margin-left: auto;
  background: var(--red-600);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
}

.nav-badge.is-muted {
  background: var(--navy-500);
}

.rail-foot {
  border-top: 1px solid var(--rail-line);
  padding: var(--s-3) var(--s-4);
}

.rail-disclaimer {
  margin: 0;
  font-size: var(--fs-xxs);
  line-height: 1.4;
  color: var(--rail-fg-dim);
}

body.nav-collapsed .rail-id,
body.nav-collapsed .nav-label,
body.nav-collapsed .nav-group-label,
body.nav-collapsed .rail-disclaimer,
body.nav-collapsed .nav-badge {
  display: none;
}

body.nav-collapsed .nav-item {
  justify-content: center;
  padding-inline: 0;
}

body.nav-collapsed .rail-head {
  justify-content: center;
  padding-inline: var(--s-2);
}

.rail-scrim {
  display: none;
}

/* --- Top bar --- */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 0 var(--s-5);
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-menu {
  margin-left: calc(var(--s-2) * -1);
}

.topbar-titles {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--fg-subtle);
  font-weight: 600;
}

.crumbs:empty {
  display: none;
}

.crumbs a {
  color: inherit;
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.crumb-sep {
  opacity: 0.5;
}

.page-title {
  font-size: var(--fs-lg);
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--s-1);
}

.pip {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--r-pill);
  background: var(--navy-500);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  font-variant-numeric: tabular-nums;
}

.pip-alert {
  background: var(--red-600);
}

.account-btn {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  padding: var(--s-1) var(--s-2);
  cursor: pointer;
  color: var(--fg);
  font: inherit;
  max-width: 220px;
}

.account-btn:hover {
  background: var(--surface-3);
}

.avatar {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: var(--r-md);
  background: var(--navy-600);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.avatar-lg {
  width: 64px;
  height: 64px;
  font-size: var(--fs-lg);
}

.account-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  line-height: 1.25;
}

.account-name {
  font-size: var(--fs-sm);
  font-weight: 650;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-role {
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--fg-subtle);
  font-weight: 600;
}

@media (max-width: 860px) {
  .account-meta {
    display: none;
  }
}

/* --- Main / footer --- */
.main {
  grid-area: main;
  padding: var(--s-6) var(--s-6) var(--s-10);
  min-width: 0;
}

.outlet {
  max-width: var(--content-max);
  margin: 0 auto;
}

.app-banners {
  max-width: var(--content-max);
  margin: 0 auto var(--s-4);
  display: grid;
  gap: var(--s-3);
}

.app-banners:empty {
  display: none;
}

.appfoot {
  grid-area: foot;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-5);
  align-items: center;
  padding: var(--s-3) var(--s-6);
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
}

.foot-note {
  margin-left: auto;
}

.bottomnav {
  display: none;
}

@media (max-width: 1080px) {
  .main {
    padding: var(--s-5) var(--s-4) var(--s-8);
  }
}

/* Mobile: rail becomes an off-canvas drawer, bottom nav appears. */
@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "main"
      "foot";
  }

  .rail {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 300px);
    z-index: 90;
    transform: translateX(-102%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow-modal);
  }

  body.nav-open .rail {
    transform: none;
  }

  .rail-close {
    display: inline-grid;
  }

  .rail-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgb(6 16 28 / 55%);
    z-index: 80;
  }

  .rail-scrim[hidden] {
    display: none;
  }

  body.nav-collapsed .rail-id,
  body.nav-collapsed .nav-label,
  body.nav-collapsed .nav-group-label,
  body.nav-collapsed .nav-badge,
  body.nav-collapsed .rail-disclaimer {
    display: revert;
  }

  body.nav-collapsed .nav-item {
    justify-content: flex-start;
    padding-inline: var(--s-4);
  }

  .main {
    padding-bottom: calc(var(--bottomnav-h) + var(--s-8));
  }

  .appfoot {
    padding-bottom: calc(var(--bottomnav-h) + var(--s-3));
  }

  .foot-note {
    margin-left: 0;
  }

  .bottomnav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--bottomnav-h);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--rail-bg);
    border-top: 1px solid var(--rail-line);
    z-index: 60;
  }

  .bottomnav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--rail-fg-dim);
    text-decoration: none;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    position: relative;
  }

  .bottomnav a.is-active {
    color: #fff;
  }

  .bottomnav a.is-active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 22%;
    right: 22%;
    height: 2px;
    background: var(--gold-600);
  }

  .bottomnav .nav-badge {
    position: absolute;
    top: 4px;
    right: 50%;
    margin-right: -20px;
    margin-left: 0;
  }
}

/* --------------------------------------------------------------------------
   8. Panels, page furniture
   -------------------------------------------------------------------------- */
.view-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--s-5);
}

.view-intro {
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  max-width: 62ch;
  margin: 0;
}

.view-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: var(--s-5);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  background: var(--panel-alt);
  min-height: 46px;
}

.panel-title {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  font-weight: 700;
  color: var(--fg-muted);
  margin: 0;
}

.panel-actions {
  margin-left: auto;
  display: flex;
  gap: var(--s-2);
  align-items: center;
  flex-wrap: wrap;
}

.panel-body {
  padding: var(--s-4);
}

.panel-body-flush {
  padding: 0;
}

.panel-foot {
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--border);
  background: var(--panel-alt);
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
}

.section-label {
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  font-weight: 700;
  color: var(--fg-subtle);
  margin: 0 0 var(--s-2);
}

.grid {
  display: grid;
  gap: var(--s-5);
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
}

.grid-4 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
}

.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: var(--s-5);
  align-items: start;
}

@media (max-width: 1080px) {
  .dash-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.stack {
  display: grid;
  gap: var(--s-3);
}

.stack-lg {
  display: grid;
  gap: var(--s-5);
}

.inline {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}

.spacer {
  flex: 1;
}

.muted {
  color: var(--fg-muted);
}

.subtle {
  color: var(--fg-subtle);
  font-size: var(--fs-xs);
}

.nums {
  font-variant-numeric: tabular-nums;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Metric tiles --- */
.metric {
  border: 1px solid var(--border);
  border-left: 3px solid var(--navy-600);
  border-radius: var(--r-md);
  background: var(--panel-bg);
  padding: var(--s-4);
  display: grid;
  gap: var(--s-1);
}

.metric-label {
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  font-weight: 700;
  color: var(--fg-subtle);
}

.metric-value {
  font-size: var(--fs-2xl);
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.metric-note {
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
}

.metric.is-warn {
  border-left-color: var(--gold-600);
}

.metric.is-danger {
  border-left-color: var(--red-600);
}

.metric.is-ok {
  border-left-color: var(--green-600);
}

/* --- List rows (records) --- */
.rows {
  display: flex;
  flex-direction: column;
}

.row {
  display: flex;
  gap: var(--s-4);
  align-items: flex-start;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  text-decoration: none;
  color: inherit;
}

.row:last-child {
  border-bottom: 0;
}

.row:hover {
  background: var(--panel-alt);
}

.row-main {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.row-title {
  font-weight: 650;
  font-size: var(--fs-base);
  color: var(--fg);
}

.row-sub {
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1) var(--s-3);
}

.row-body {
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  margin-top: var(--s-1);
}

.row-aside {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.row.is-urgent {
  border-left-color: var(--red-600);
}

.row.is-important {
  border-left-color: var(--gold-600);
}

.row.is-unread {
  background: var(--blue-050);
}

.row.is-pinned {
  border-left-color: var(--navy-600);
}

@media (max-width: 560px) {
  .row {
    flex-direction: column;
    gap: var(--s-2);
  }

  .row-aside {
    justify-content: flex-start;
  }
}

/* --- Tags / badges --- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xxs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  padding: 2px 7px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-3);
  color: var(--fg-muted);
  white-space: nowrap;
}

.tag-blue {
  background: var(--blue-100);
  border-color: color-mix(in srgb, var(--blue-600) 35%, transparent);
  color: var(--blue-700);
}

.tag-gold {
  background: var(--gold-100);
  border-color: color-mix(in srgb, var(--gold-600) 40%, transparent);
  color: var(--gold-700);
}

.tag-red {
  background: var(--red-100);
  border-color: color-mix(in srgb, var(--red-600) 40%, transparent);
  color: var(--red-700);
}

.tag-green {
  background: var(--green-100);
  border-color: color-mix(in srgb, var(--green-600) 40%, transparent);
  color: var(--green-700);
}

.tag-violet {
  background: var(--violet-100);
  border-color: color-mix(in srgb, var(--violet-600) 40%, transparent);
  color: var(--violet-600);
}

:root[data-theme="dark"] .tag-blue,
:root[data-theme="dark"] .tag-gold,
:root[data-theme="dark"] .tag-red,
:root[data-theme="dark"] .tag-green {
  color: #fff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tag-blue,
  :root:not([data-theme="light"]) .tag-gold,
  :root:not([data-theme="light"]) .tag-red,
  :root:not([data-theme="light"]) .tag-green {
    color: #fff;
  }
}

/* --- Notices / banners --- */
.notice {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--border);
  border-left: 3px solid var(--navy-600);
  border-radius: var(--r-md);
  background: var(--panel-bg);
  font-size: var(--fs-sm);
}

.notice-info {
  border-left-color: var(--blue-600);
  background: var(--blue-050);
}

.notice-warn {
  border-left-color: var(--gold-600);
  background: var(--gold-100);
}

.notice-danger {
  border-left-color: var(--red-600);
  background: var(--red-100);
}

.notice-ok {
  border-left-color: var(--green-600);
  background: var(--green-100);
}

.notice-body {
  flex: 1;
  min-width: 0;
}

.notice-actions {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
  margin-top: var(--s-2);
}

/* --- Empty / loading states --- */
.empty {
  padding: var(--s-8) var(--s-4);
  text-align: center;
  color: var(--fg-subtle);
  display: grid;
  gap: var(--s-2);
  justify-items: center;
}

.empty-title {
  font-weight: 650;
  color: var(--fg-muted);
  font-size: var(--fs-base);
}

.empty .icon {
  color: var(--border-strong);
}

.skeleton {
  display: grid;
  gap: var(--s-3);
  padding: var(--s-4);
}

.skeleton-line {
  height: 12px;
  border-radius: var(--r-sm);
  background: linear-gradient(
    90deg,
    var(--surface-3) 25%,
    color-mix(in srgb, var(--surface-3) 55%, var(--panel-bg)) 50%,
    var(--surface-3) 75%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-line:nth-child(2n) {
  width: 78%;
}

.skeleton-line:nth-child(3n) {
  width: 55%;
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

.spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid currentcolor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  vertical-align: -2px;
}

.load-state {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--fg-subtle);
  font-size: var(--fs-sm);
  padding: var(--s-6);
  justify-content: center;
}

/* --------------------------------------------------------------------------
   9. Tables (responsive: become cards below 720px)
   -------------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}

.table caption {
  text-align: left;
  padding: var(--s-2) var(--s-4);
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
}

.table th {
  text-align: left;
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  font-weight: 700;
  color: var(--fg-subtle);
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
  background: var(--panel-alt);
  position: sticky;
  top: 0;
}

.table td {
  padding: var(--s-3);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table tbody tr:hover {
  background: var(--panel-alt);
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table .num {
  text-align: right;
}

.table .actions-cell {
  white-space: nowrap;
  text-align: right;
}

.table-sort {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  font-weight: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.table-sort[aria-sort="ascending"]::after {
  content: "▲";
  font-size: 0.5rem;
}

.table-sort[aria-sort="descending"]::after {
  content: "▼";
  font-size: 0.5rem;
}

@media (max-width: 720px) {
  .table--cards thead {
    display: none;
  }

  .table--cards,
  .table--cards tbody,
  .table--cards tr,
  .table--cards td {
    display: block;
    width: 100%;
  }

  .table--cards tr {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: var(--s-3);
    background: var(--panel-bg);
    padding: var(--s-2);
  }

  .table--cards td {
    border-bottom: 1px dashed var(--border);
    padding: var(--s-2);
    display: grid;
    grid-template-columns: 40% 1fr;
    gap: var(--s-3);
  }

  .table--cards td:last-child {
    border-bottom: 0;
  }

  .table--cards td::before {
    content: attr(data-label);
    font-size: var(--fs-xxs);
    text-transform: uppercase;
    letter-spacing: var(--track-caps);
    font-weight: 700;
    color: var(--fg-subtle);
  }

  .table--cards td:empty {
    display: none;
  }

  .table--cards .actions-cell {
    text-align: left;
  }
}

/* --- Definition lists --- */
.summary-list,
.detail-list {
  display: grid;
  grid-template-columns: minmax(9rem, auto) 1fr;
  gap: var(--s-2) var(--s-4);
  margin: 0;
  font-size: var(--fs-sm);
}

.summary-list dt,
.detail-list dt {
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  font-weight: 700;
  color: var(--fg-subtle);
  padding-top: 2px;
}

.summary-list dd,
.detail-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 560px) {
  .summary-list,
  .detail-list {
    grid-template-columns: 1fr;
    gap: var(--s-1);
  }

  .summary-list dd,
  .detail-list dd {
    margin-bottom: var(--s-2);
  }
}

/* --------------------------------------------------------------------------
   10. Toolbars, filters, tabs, pagination
   -------------------------------------------------------------------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  align-items: center;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  background: var(--panel-alt);
}

.toolbar .field {
  gap: 0;
}

.toolbar input[type="search"],
.toolbar input[type="text"],
.toolbar select {
  min-height: 34px;
  padding-block: 0.3125rem;
  font-size: var(--fs-sm);
}

.toolbar-search {
  flex: 1 1 15rem;
  min-width: 10rem;
}

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  border: 0;
  background: none;
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg-muted);
  padding: var(--s-3) var(--s-4);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab:hover {
  color: var(--fg);
  background: var(--panel-alt);
}

.tab[aria-selected="true"] {
  color: var(--fg);
  border-bottom-color: var(--navy-600);
}

.tab-count {
  display: inline-block;
  margin-left: 6px;
  font-size: var(--fs-xxs);
  background: var(--surface-3);
  border-radius: var(--r-pill);
  padding: 1px 6px;
  font-variant-numeric: tabular-nums;
}

.pager {
  display: flex;
  gap: var(--s-2);
  align-items: center;
  justify-content: center;
  padding: var(--s-3);
  font-size: var(--fs-sm);
  color: var(--fg-muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-pill);
  padding: 2px 10px;
  font-size: var(--fs-xs);
  background: var(--panel-bg);
  color: var(--fg-muted);
  cursor: pointer;
  font-weight: 600;
}

.chip[aria-pressed="true"] {
  background: var(--navy-600);
  border-color: var(--navy-600);
  color: #fff;
}

/* --------------------------------------------------------------------------
   11. Popovers, modals, toasts, search overlay
   -------------------------------------------------------------------------- */
.popover-wrap {
  position: relative;
}

.popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: min(92vw, 320px);
  max-height: min(70vh, 480px);
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  z-index: 70;
}

.popover-wide {
  width: min(94vw, 400px);
}

.popover-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  font-weight: 700;
  color: var(--fg-subtle);
  position: sticky;
  top: 0;
  background: var(--panel-alt);
}

.popover-item {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  width: 100%;
  text-align: left;
  background: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  font: inherit;
  cursor: pointer;
}

.popover-item:hover {
  background: var(--panel-alt);
}

.popover-item.is-unread {
  background: var(--blue-050);
}

.popover-item-title {
  font-size: var(--fs-sm);
  font-weight: 650;
}

.popover-item-body {
  font-size: var(--fs-xs);
  color: var(--fg-muted);
}

.popover-item-time {
  font-size: var(--fs-xxs);
  color: var(--fg-subtle);
}

.popover-foot {
  padding: var(--s-2) var(--s-3);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--s-2);
  justify-content: space-between;
  position: sticky;
  bottom: 0;
  background: var(--panel-alt);
}

.presence-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  font-size: var(--fs-sm);
  border-bottom: 1px solid var(--border);
}

.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-600);
  flex: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgb(7 18 30 / 55%);
  display: grid;
  padding: var(--s-4);
  overflow-y: auto;
}

.overlay[hidden] {
  display: none;
}

.modal {
  background: var(--panel-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-modal);
  width: min(100%, 40rem);
  margin: auto;
  max-height: calc(100vh - var(--s-8));
  display: flex;
  flex-direction: column;
}

.modal-wide {
  width: min(100%, 60rem);
}

.modal-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: var(--fs-md);
  font-weight: 650;
  margin: 0;
}

.modal-body {
  padding: var(--s-5);
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--border);
  background: var(--panel-alt);
  flex-wrap: wrap;
}

.toast-root {
  position: fixed;
  right: var(--s-4);
  bottom: var(--s-4);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  max-width: min(92vw, 24rem);
}

.toast {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: var(--s-3) var(--s-4);
  background: var(--navy-800);
  color: #eaf1f8;
  border-radius: var(--r-md);
  border-left: 3px solid var(--blue-500);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-sm);
  animation: toast-in 160ms ease;
}

.toast-ok {
  border-left-color: var(--green-600);
}

.toast-error {
  border-left-color: var(--red-600);
}

.toast-warn {
  border-left-color: var(--gold-600);
}

.toast-close {
  background: none;
  border: 0;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  padding: 0;
  margin-left: auto;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (max-width: 860px) {
  .toast-root {
    left: var(--s-3);
    right: var(--s-3);
    bottom: calc(var(--bottomnav-h) + var(--s-3));
    max-width: none;
  }
}

/* --- Search overlay --- */
.search-dialog {
  width: min(100%, 44rem);
  margin: 8vh auto auto;
  background: var(--panel-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
  max-height: 76vh;
  display: flex;
  flex-direction: column;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  color: var(--fg-subtle);
}

.search-input-wrap input {
  border: 0;
  padding: 0;
  font-size: var(--fs-md);
  background: transparent;
}

.search-input-wrap input:focus {
  box-shadow: none;
}

.search-results {
  overflow-y: auto;
  padding: var(--s-2) 0;
}

.search-group-label {
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  font-weight: 700;
  color: var(--fg-subtle);
  padding: var(--s-3) var(--s-4) var(--s-1);
}

.search-hit {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  font: inherit;
  padding: var(--s-2) var(--s-4);
  cursor: pointer;
  color: inherit;
  text-decoration: none;
}

.search-hit:hover,
.search-hit.is-cursor {
  background: var(--blue-050);
}

.search-hit-title {
  font-weight: 650;
  font-size: var(--fs-sm);
}

.search-hit-sub {
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
}

/* --------------------------------------------------------------------------
   12. Feature-specific pieces
   -------------------------------------------------------------------------- */

/* Calendar month grid */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
}

.cal-dow {
  padding: var(--s-2);
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  font-weight: 700;
  color: var(--fg-subtle);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--panel-alt);
  text-align: center;
}

.cal-cell {
  min-height: 104px;
  padding: var(--s-1);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cal-cell.is-outside {
  background: var(--panel-alt);
  opacity: 0.6;
}

.cal-cell.is-today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.cal-date {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--fg-subtle);
  font-variant-numeric: tabular-nums;
}

.cal-event {
  font-size: var(--fs-xxs);
  padding: 2px 4px;
  border-radius: var(--r-sm);
  background: var(--blue-100);
  color: var(--blue-700);
  border-left: 2px solid var(--blue-600);
  text-align: left;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  cursor: pointer;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  width: 100%;
}

.cal-event.is-cancelled {
  text-decoration: line-through;
  opacity: 0.7;
  border-left-color: var(--red-600);
}

@media (max-width: 720px) {
  .cal-cell {
    min-height: 66px;
  }

  .cal-event {
    font-size: 0.5625rem;
  }
}

/* Directory / people cards */
.person {
  display: flex;
  gap: var(--s-3);
  align-items: center;
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
}

.person:last-child {
  border-bottom: 0;
}

.person-main {
  min-width: 0;
  flex: 1;
}

.person-name {
  font-weight: 650;
}

.person-meta {
  font-size: var(--fs-xs);
  color: var(--fg-subtle);
}

/* Document cards */
.doc-card {
  display: flex;
  gap: var(--s-3);
  align-items: flex-start;
  padding: var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--panel-bg);
}

.doc-ext {
  width: 40px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--fg-muted);
  background: var(--panel-alt);
}

/* Timeline (request thread, audit detail) */
.thread {
  display: grid;
  gap: var(--s-3);
}

.msg {
  border: 1px solid var(--border);
  border-left: 3px solid var(--navy-600);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  background: var(--panel-bg);
}

.msg-internal {
  border-left-color: var(--gold-600);
  background: var(--gold-100);
}

.msg-system {
  border-left-color: var(--border-strong);
  background: var(--panel-alt);
  font-size: var(--fs-sm);
  color: var(--fg-muted);
}

.msg-head {
  display: flex;
  gap: var(--s-2);
  align-items: baseline;
  flex-wrap: wrap;
  margin-bottom: var(--s-1);
}

.msg-author {
  font-weight: 650;
  font-size: var(--fs-sm);
}

.msg-time {
  font-size: var(--fs-xxs);
  color: var(--fg-subtle);
}

.msg-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: var(--fs-sm);
}

/* Tools embed */
.embed-frame {
  width: 100%;
  height: min(72vh, 760px);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--panel-alt);
}

.embed-fallback {
  padding: var(--s-6);
  text-align: center;
}

/* Progress meter (readiness) */
.meter {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  background: var(--navy-600);
}

.meter-fill.is-ok {
  background: var(--green-600);
}

.meter-fill.is-warn {
  background: var(--gold-600);
}

.meter-fill.is-danger {
  background: var(--red-600);
}

/* Body text blocks */
.prose {
  font-size: var(--fs-sm);
  color: var(--fg-muted);
  max-width: 72ch;
}

.prose h3 {
  font-size: var(--fs-base);
  color: var(--fg);
  margin: var(--s-5) 0 var(--s-2);
}

.prose h3:first-child {
  margin-top: 0;
}

.prose ul,
.prose ol {
  padding-left: 1.2rem;
  margin: 0 0 var(--s-3);
  display: grid;
  gap: var(--s-1);
}

.body-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Quick links grid */
.quicklinks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
  gap: var(--s-2);
}

.quicklink {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  text-decoration: none;
  color: var(--fg);
  font-size: var(--fs-sm);
  font-weight: 600;
  background: var(--panel-bg);
}

.quicklink:hover {
  border-color: var(--accent);
  background: var(--blue-050);
}

.quicklink .icon {
  color: var(--fg-subtle);
}

/* Drag-order list (admin widget ordering) */
.order-list {
  display: grid;
  gap: var(--s-2);
}

.order-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--panel-bg);
  font-size: var(--fs-sm);
}

.order-item .btn {
  padding: 2px 6px;
  min-height: 26px;
}

/* --------------------------------------------------------------------------
   13. Utility, motion, print
   -------------------------------------------------------------------------- */
[hidden] {
  display: none !important;
}

.hide-sm {
  display: initial;
}

@media (max-width: 560px) {
  .hide-sm {
    display: none;
  }
}

@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;
  }
}

@media print {
  .rail,
  .topbar,
  .bottomnav,
  .appfoot,
  .toolbar,
  .view-actions,
  .panel-actions,
  .toast-root,
  .overlay,
  .skip-link,
  .rail-scrim {
    display: none !important;
  }

  .app {
    display: block;
  }

  .main {
    padding: 0;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }

  .panel {
    border: 1px solid #999;
    break-inside: avoid;
    margin-bottom: 12pt;
  }

  .panel-head {
    background: #eee;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  .table th {
    background: #eee;
    color: #000;
  }
}

/* High-contrast preference: strengthen every hairline. */
@media (prefers-contrast: more) {
  :root {
    --border: #98a4b4;
    --border-strong: #66748a;
    --fg-muted: #334052;
  }
}

/* --------------------------------------------------------------------------
   Readiness
   -------------------------------------------------------------------------- */

/* One block per readiness dimension inside a roster row. */
.readiness-block {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  align-items: baseline;
  margin-top: 0.5rem;
}

.readiness-block > .section-label {
  flex: 0 0 11rem;
  margin: 0;
}

/* The Education and Training ladder: 1 / 2.1 / 2.2 / 3 / 4 / 5. */
.level-pips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.level-pip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.1rem;
  height: 1.6rem;
  padding: 0 0.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-500);
  background: var(--surface);
}

.level-pip.is-done {
  border-color: transparent;
  color: var(--accent-fg);
  background: var(--accent);
}

@media (max-width: 640px) {
  .readiness-block > .section-label {
    flex-basis: 100%;
  }
}

/* --------------------------------------------------------------------------
   Theme switching
   -------------------------------------------------------------------------- */

/*
 * Cross-fade between the themes rather than snapping.
 *
 * The transition is applied only while the switch is happening, through a class
 * the toggle adds and then removes. Leaving it on permanently would put a
 * transition on every element in the document — which makes ordinary hover and
 * focus states feel sluggish, and costs real time on a long list such as the
 * 461-row readiness roster.
 *
 * `!important` is warranted here: it has to beat the per-component transitions
 * for the duration of the switch, and it is scoped to a class that exists for
 * about a fifth of a second.
 */
:root.theme-switching,
:root.theme-switching *,
:root.theme-switching *::before,
:root.theme-switching *::after {
  transition:
    background-color 200ms ease,
    border-color 200ms ease,
    color 200ms ease,
    fill 200ms ease,
    stroke 200ms ease,
    box-shadow 200ms ease,
    outline-color 200ms ease !important;
  transition-delay: 0s !important;
}

/* A theme change is a colour change, not motion — but somebody who has asked
   for reduced motion has generally asked for less visual churn, so honour it. */
@media (prefers-reduced-motion: reduce) {
  :root.theme-switching,
  :root.theme-switching *,
  :root.theme-switching *::before,
  :root.theme-switching *::after {
    transition: none !important;
  }
}

/* --------------------------------------------------------------------------
   Print
   -------------------------------------------------------------------------- */

/*
 * Commanders take paper to a SAREX, not a spreadsheet. CSV export covers
 * analysis; this covers walking away from a desk with the roster in hand.
 */
@media print {
  .app-rail,
  .app-bar,
  .toolbar,
  .tabs,
  .btn,
  .btn-row,
  .row-actions,
  .form-actions,
  .toast-stack,
  .modal-backdrop {
    display: none !important;
  }

  :root {
    color-scheme: light;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 10pt;
  }

  .app-main,
  .app-shell,
  #outlet {
    display: block;
    margin: 0;
    padding: 0;
    max-width: none;
  }

  .panel {
    border: none;
    box-shadow: none;
    break-inside: avoid;
  }

  /* Keep a member's whole block together rather than splitting them mid-record. */
  .row,
  .doc-card,
  .metric {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .tag,
  .level-pip {
    border: 1px solid #999 !important;
    background: none !important;
    color: #000 !important;
  }

  /* A printed page has no hover, so show link targets that are not obvious. */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 8pt;
    color: #444;
  }
}
