/*
 * GATE — Military Glass Terminal
 * Canonical production visual contract.
 * One asset. No @import graph. No !important escalation.
 * Visual ownership only; application state, persistence, and event behavior remain external.
 */

/* --------------------------------------------------------------------------
   1. FOUNDATION TOKENS
   -------------------------------------------------------------------------- */
:root {
  color-scheme: dark;

  --mg-bg: #121712;
  --mg-bg-elevated: #1b221c;
  --mg-surface: rgba(35, 44, 36, 0.86);
  --mg-surface-strong: rgba(28, 36, 29, 0.96);
  --mg-surface-soft: rgba(72, 88, 73, 0.52);
  --mg-surface-muted: rgba(112, 132, 113, 0.24);
  --mg-text: #f5f8f4;
  --mg-text-soft: #d8e0d5;
  --mg-text-muted: #a7b2a3;
  --mg-carbon: #161c17;
  --mg-accent: #58b9dd;
  --mg-accent-rgb: 88, 185, 221;
  --mg-accent-deep: #2d7490;
  --mg-ok: #3fd08c;
  --mg-ok-rgb: 63, 208, 140;
  --mg-ok-deep: #21845c;
  --mg-blue: #58b9dd;
  --mg-red: #ff5a54;
  --mg-yellow: #e7c34c;
  --mg-olive: #75835c;
  --mg-border-glass: rgba(216, 232, 211, 0.26);
  --mg-border-soft: rgba(216, 232, 211, 0.16);
  --mg-border-strong: rgba(216, 232, 211, 0.42);
  --mg-line: rgba(88, 185, 221, 0.18);
  --mg-field: rgba(14, 19, 15, 0.72);
  --mg-overlay: rgba(4, 7, 5, 0.68);
  --mg-focus: rgba(88, 185, 221, 0.32);
  --mg-shadow-soft: 0 12px 34px rgba(0, 0, 0, 0.22);
  --mg-shadow-strong: 0 28px 72px rgba(0, 0, 0, 0.40);
  --mg-inset-edge: inset 0 1px 0 rgba(255, 255, 255, 0.11);

  --mg-glass-blur: 14px;
  --mg-glass-saturate: 135%;
  --mg-max-content: 1850px;
  --mg-page-gap: 1.5rem;
  --mg-control-h: 42px;
  --mg-control-h-lg: 46px;
  --mg-radius-xs: 6px;
  --mg-radius-sm: 8px;
  --mg-radius-md: 12px;
  --mg-radius-lg: 16px;
  --mg-radius-xl: 22px;
  --mg-radius-pill: 999px;

  --mg-z-base: 0;
  --mg-z-static: 10;
  --mg-z-shell: 100;
  --mg-z-popover: 500;
  --mg-z-modal: 50000;
  --mg-z-critical: 999999;

  --mg-banner-h: 24px;
  --mg-nav-h: 58px;
  --mg-shell-top: calc(var(--mg-banner-h) + var(--mg-nav-h));
  --mg-spring: transform 160ms cubic-bezier(0.25, 1, 0.5, 1);
  --mg-fade: opacity 140ms ease, background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;

  /* Legacy-compatible aliases consumed by existing markup and controllers. */
  --bg: var(--mg-bg);
  --surface: var(--mg-surface);
  --surface-alt: var(--mg-surface-soft);
  --surface-solid: var(--mg-bg-elevated);
  --text: var(--mg-text);
  --text-soft: var(--mg-text-soft);
  --text-muted: var(--mg-text-muted);
  --border: var(--mg-border-glass);
  --green: var(--mg-ok-deep);
  --green-bright: var(--mg-ok);
  --red: var(--mg-red);
  --red-bright: var(--mg-red);
  --yellow: var(--mg-yellow);
  --yellow-bright: var(--mg-yellow);
  --blue: var(--mg-blue);
  --blue-deep: #2d7490;
  --bg-canvas: var(--mg-bg);
  --bg-card: var(--mg-surface);
  --bg-panel: var(--mg-surface-soft);
  --bg-elevated: var(--mg-bg-elevated);
  --color-text: var(--mg-text);
  --color-text-soft: var(--mg-text-soft);
  --color-text-muted: var(--mg-text-muted);
  --border-muted: var(--mg-border-soft);
  --border-default: var(--mg-border-glass);
  --border-strong: var(--mg-border-strong);
  --gate-glass-bg: var(--mg-surface);
  --gate-glass-bg-soft: var(--mg-surface-soft);
  --gate-glass-bg-strong: var(--mg-surface-strong);
  --gate-glass-border: var(--mg-border-glass);
  --gate-glass-border-strong: var(--mg-border-strong);
  --gate-glass-blur: var(--mg-glass-blur);
  --gate-glass-blur-strong: 20px;
  --gate-glass-edge: var(--mg-inset-edge);
  --gate-shadow-soft: var(--mg-shadow-soft);
  --gate-shadow-strong: var(--mg-shadow-strong);
  --glass-bg: var(--mg-surface);
  --glass-border: var(--mg-border-glass);
  --glass-blur: var(--mg-glass-blur);
  --shadow-soft-unified: var(--mg-shadow-soft);
  --radius-sm: var(--mg-radius-sm);
  --radius-md: var(--mg-radius-md);
  --radius-lg: var(--mg-radius-lg);
  --radius-xl: var(--mg-radius-xl);
  --radius-pill: var(--mg-radius-pill);
  --z-modal-backdrop: var(--mg-z-modal);
  --z-modal-window: var(--mg-z-modal);
  --gate-flag-female-red: #ff4d47;
  --gate-flag-band-green: #59c877;
  --gate-flag-space-force-bluebird: #5bc9f0;
  --gate-dorm-card-pad-y: 0.92rem;
  --gate-dorm-card-pad-x: 1rem;
  --input-matrix-grid: minmax(86px, .92fr) minmax(82px, .86fr) minmax(128px, 1.18fr) minmax(150px, 1.36fr) minmax(110px, .88fr) 58px 74px minmax(104px, .86fr) 36px;
  --input-matrix-gap: clamp(6px, .72vw, 10px);
  --input-matrix-min-width: 1040px;
}

body.theme-light,
.theme-light {
  color-scheme: light;
  --mg-bg: #f1f4f0;
  --mg-bg-elevated: #ffffff;
  --mg-surface: rgba(255, 255, 255, 0.86);
  --mg-surface-strong: rgba(250, 252, 248, 0.97);
  --mg-surface-soft: rgba(231, 236, 227, 0.76);
  --mg-surface-muted: rgba(91, 104, 80, 0.07);
  --mg-text: #182016;
  --mg-text-soft: #40503a;
  --mg-text-muted: #697565;
  --mg-carbon: #182016;
  --mg-accent: #2f6f8a;
  --mg-accent-rgb: 47, 111, 138;
  --mg-accent-deep: #245b73;
  --mg-ok: #12805a;
  --mg-ok-rgb: 18, 128, 90;
  --mg-ok-deep: #0f6247;
  --mg-blue: #3f6f80;
  --mg-red: #9b3e39;
  --mg-yellow: #8a6f24;
  --mg-olive: #68784e;
  --mg-border-glass: rgba(74, 88, 61, 0.24);
  --mg-border-soft: rgba(74, 88, 61, 0.13);
  --mg-border-strong: rgba(74, 88, 61, 0.38);
  --mg-line: rgba(47, 111, 138, 0.12);
  --mg-field: rgba(255, 255, 255, 0.90);
  --mg-overlay: rgba(228, 233, 226, 0.88);
  --mg-focus: rgba(47, 111, 138, 0.20);
  --mg-shadow-soft: 0 10px 28px rgba(43, 53, 36, 0.09);
  --mg-shadow-strong: 0 24px 54px rgba(43, 53, 36, 0.15);
  --mg-inset-edge: inset 0 1px 0 rgba(255, 255, 255, 0.88);
  --gate-flag-female-red: #a94440;
  --gate-flag-band-green: #4e7655;
  --gate-flag-space-force-bluebird: #4b7888;
}

/* --------------------------------------------------------------------------
   2. BASE, RESET, ACCESSIBILITY, AND ANTI-FOUC GEOMETRY
   -------------------------------------------------------------------------- */
html {
  min-height: 100%;
  background: var(--mg-bg);
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: var(--mg-bg);
  color: var(--mg-text);
  font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
[role="button"] {
  -webkit-tap-highlight-color: transparent;
}

button:not(:disabled),
[role="button"]:not([aria-disabled="true"]),
summary,
select {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: .58;
}

.hidden,
[hidden],
.confirm-overlay.hidden,
.gate-processing-context-menu.hidden,
.gate-access-denied-toast.hidden,
.gate-shell-toast.hidden {
  display: none;
}

.font-tabular,
.timer-display,
.gate-dorm-timer,
.metric-value,
.gate-squadron-metric-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.text-muted {
  color: var(--mg-text-muted);
}

body::before {
  content: none;
  display: none;
}

body.gate-app-shell-ready.gate-watermark-page::after {
  content: "";
  position: fixed;
  left: 50vw;
  top: 52vh;
  z-index: var(--mg-z-base);
  width: min(64vw, 980px);
  height: min(64vw, 980px);
  pointer-events: none;
  background: url('/assets/gate_emblem_white.png') center / contain no-repeat;
  opacity: .06;
  filter: grayscale(1);
  transform: translate3d(-50%, -50%, 0);
}

body.theme-light.gate-app-shell-ready.gate-watermark-page::after {
  background-image: url('/assets/gate_emblem_blue.png');
  opacity: .035;
  filter: grayscale(.35) saturate(.55);
}

body.gate-app-shell-ready.gate-watermark-processing::after {
  width: min(56vw, 820px);
  height: min(56vw, 820px);
  opacity: .045;
}

body.theme-light.gate-app-shell-ready.gate-watermark-processing::after {
  opacity: .025;
}

.mg-skeleton-viewport {
  position: relative;
  display: grid;
  min-height: clamp(280px, 52vh, 760px);
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  padding: 1.5rem;
  border: 1px solid var(--mg-border-glass);
  border-radius: var(--mg-radius-xl);
  background: var(--mg-surface-soft);
  contain: layout paint;
  overflow: hidden;
}

.mg-skeleton-viewport::before {
  content: "";
  grid-column: 1 / -1;
  min-height: 88px;
  border-radius: var(--mg-radius-lg);
  background: linear-gradient(90deg, var(--mg-surface-muted), var(--mg-surface-soft), var(--mg-surface-muted));
  background-size: 220% 100%;
  animation: mg-skeleton-scan 1.25s ease-in-out infinite;
}

.mg-skeleton-viewport::after {
  content: "";
  grid-column: 1 / -1;
  min-height: 180px;
  border-radius: var(--mg-radius-lg);
  border: 1px solid var(--mg-border-soft);
  background: var(--mg-surface-muted);
}

@keyframes mg-skeleton-scan {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* --------------------------------------------------------------------------
   3. IMMUTABLE SHELL AND LAYER PIPELINE
   -------------------------------------------------------------------------- */
.security-banner-fixed,
.login-classification {
  position: fixed;
  inset: 0 0 auto;
  z-index: var(--mg-z-shell);
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--mg-banner-h);
  min-height: var(--mg-banner-h);
  padding-inline: max(.75rem, env(safe-area-inset-left), env(safe-area-inset-right));
  overflow: hidden;
  background: #213f24;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .16);
  font-size: .61rem;
  font-weight: 900;
  line-height: 1;
  letter-spacing: .13em;
  text-align: center;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

body.theme-light .security-banner-fixed {
  background: #647253;
  color: #fff;
}

.app-nav,
.app-nav.command-header-bar,
.command-header-bar {
  position: fixed;
  top: var(--mg-banner-h);
  left: 0;
  right: 0;
  z-index: var(--mg-z-shell);
  display: grid;
  grid-template-columns: minmax(120px, 160px) minmax(0, 1fr) max-content;
  grid-template-areas: "brand nav tools";
  align-items: center;
  gap: .6rem;
  height: var(--mg-nav-h);
  min-height: var(--mg-nav-h);
  padding: .5rem max(.75rem, env(safe-area-inset-left), env(safe-area-inset-right));
  border-bottom: 1px solid var(--mg-border-glass);
  background: color-mix(in srgb, var(--mg-bg-elevated) 86%, transparent);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .16);
  backdrop-filter: blur(var(--mg-glass-blur)) saturate(var(--mg-glass-saturate));
  -webkit-backdrop-filter: blur(var(--mg-glass-blur)) saturate(var(--mg-glass-saturate));
}

body.theme-light .app-nav,
body.theme-light .app-nav.command-header-bar,
body.theme-light .command-header-bar {
  background: rgba(248, 251, 247, .92);
  box-shadow: 0 6px 20px rgba(43, 53, 36, .08);
}

.app-nav::before,
.command-header-bar::before {
  content: "GATE";
  grid-area: brand;
  display: flex;
  align-items: center;
  height: 36px;
  color: var(--mg-accent);
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: .16em;
}

body.theme-light .app-nav::before,
body.theme-light .command-header-bar::before {
  color: var(--mg-text);
}

.app-nav .nav-group-left,
.app-nav #main-nav-menu,
.app-nav #nav-links,
.command-header-bar .nav-group-left,
.command-header-bar #main-nav-menu,
.command-header-bar #nav-links {
  grid-area: nav;
  display: flex;
  align-items: center;
  gap: .35rem;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}

.app-nav .nav-group-right,
.command-header-bar .nav-group-right {
  grid-area: tools;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .4rem;
  min-width: 0;
}

#mobile-menu-trigger,
#gate-mobile-nav-sheet,
#gate-mobile-menu-scrim,
.gate-shell-system-panel,
.gate-shell-system-controls {
  display: none;
  visibility: hidden;
  pointer-events: none;
}

.nav-btn,
.gate-component-nav-button,
#role-toggle,
#fullscreen-btn,
#sound-toggle-btn,
#theme-toggle-btn,
#week-group-display {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 36px;
  min-height: 36px;
  padding: 0 .72rem;
  border: 1px solid var(--mg-border-glass);
  border-radius: var(--mg-radius-sm);
  background: var(--mg-surface-muted);
  color: var(--mg-text-soft);
  font-size: .69rem;
  font-weight: 850;
  letter-spacing: .055em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  transition: var(--mg-spring), var(--mg-fade);
}

.nav-btn:hover,
.gate-component-nav-button:hover,
#role-toggle:hover,
#fullscreen-btn:hover,
#sound-toggle-btn:hover,
#theme-toggle-btn:hover {
  border-color: var(--mg-border-strong);
  color: var(--mg-text);
  background: var(--mg-surface-soft);
}

.nav-btn.active,
.nav-btn.current-page,
.gate-component-nav-button.active,
.gate-component-nav-button[aria-current="page"] {
  border-color: color-mix(in srgb, var(--mg-accent) 62%, var(--mg-border-glass));
  background: color-mix(in srgb, var(--mg-accent) 15%, var(--mg-surface));
  color: var(--mg-text);
}

body.theme-light .nav-btn.active,
body.theme-light .nav-btn.current-page,
body.theme-light .gate-component-nav-button.active,
body.theme-light .gate-component-nav-button[aria-current="page"] {
  background: rgba(47, 111, 138, .12);
  color: var(--mg-text);
  box-shadow: none;
}

#week-group-display {
  max-width: 150px;
  overflow: hidden;
  color: var(--mg-text);
  text-overflow: ellipsis;
}

/* --------------------------------------------------------------------------
   4. PAGE FRAME, GLASS PLANES, CONTROLS, TABLES
   -------------------------------------------------------------------------- */
.page {
  position: relative;
  z-index: var(--mg-z-static);
  display: none;
  width: min(100%, var(--mg-max-content));
  min-height: 100vh;
  min-height: 100dvh;
  margin-inline: auto;
  padding: calc(var(--mg-shell-top) + var(--mg-page-gap)) var(--mg-page-gap) var(--mg-page-gap);
}

.page.active {
  display: flex;
  flex-direction: column;
}

body.gate-app-shell-ready .page:not(.active) {
  display: none;
  visibility: hidden;
  pointer-events: none;
}

body.gate-app-shell-ready .page.active {
  visibility: visible;
  pointer-events: auto;
}

.surface,
.metric-card,
.metric-block,
.dorm-card,
.gate-dorm-card,
.proc-card,
.gate-squadron-metric,
.gate-active-buses-block,
.sat-arrivals-board,
.gate-archive-toolbar,
.gate-archive-year,
.gate-archive-month,
.gate-archive-record-card,
#receiving-windows-panel {
  border: 1px solid var(--mg-border-glass);
  background: var(--mg-surface);
  box-shadow: var(--mg-inset-edge), var(--mg-shadow-soft);
  backdrop-filter: blur(var(--mg-glass-blur)) saturate(var(--mg-glass-saturate));
  -webkit-backdrop-filter: blur(var(--mg-glass-blur)) saturate(var(--mg-glass-saturate));
}

.surface,
.metric-card,
.metric-block,
.dorm-card,
.gate-dorm-card,
.proc-card,
.gate-squadron-metric,
.gate-active-buses-block,
.sat-arrivals-board {
  border-radius: var(--mg-radius-lg);
}

body.theme-light .surface,
body.theme-light .metric-card,
body.theme-light .metric-block,
body.theme-light .dorm-card,
body.theme-light .gate-dorm-card,
body.theme-light .proc-card,
body.theme-light .gate-squadron-metric,
body.theme-light .gate-active-buses-block,
body.theme-light .sat-arrivals-board,
body.theme-light .gate-archive-toolbar,
body.theme-light .gate-archive-year,
body.theme-light .gate-archive-month,
body.theme-light .gate-archive-record-card,
body.theme-light #receiving-windows-panel {
  background: rgba(255, 255, 255, .86);
  box-shadow: var(--mg-inset-edge), 0 10px 28px rgba(43, 53, 36, .08);
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: var(--mg-control-h);
  padding: .62rem .8rem;
  border: 1px solid var(--mg-border-glass);
  border-radius: var(--mg-radius-sm);
  outline: 0;
  background: var(--mg-field);
  color: var(--mg-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .045);
  transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

body.theme-light input:not([type="checkbox"]):not([type="radio"]),
body.theme-light select,
body.theme-light textarea {
  background: rgba(255, 255, 255, .94);
  color: var(--mg-text);
  box-shadow: inset 0 1px 0 #fff;
}

textarea {
  resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
summary:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--mg-accent) 72%, #fff);
  outline-offset: 2px;
  border-color: color-mix(in srgb, var(--mg-accent) 52%, var(--mg-border-strong));
  box-shadow: 0 0 0 4px var(--mg-focus);
}

button,
.button,
.btn,
.phase-btn,
.load-btn,
.gate-processing-context-action,
.gate-archive-clear-search,
.login-button {
  transition: var(--mg-spring), var(--mg-fade);
  transform: translate3d(0, 0, 0) scale(1);
  transform-origin: center;
  will-change: transform;
}

button:not(:disabled):active,
.button:active,
.btn:active,
[role="button"]:active {
  transform: translate3d(0, 1px, 0) scale(.972);
}

button:not(:disabled):hover,
[role="button"]:not([aria-disabled="true"]):hover {
  border-color: var(--mg-border-strong);
}

.table-wrap,
.overflow-auto,
.overflow-x-auto {
  scrollbar-gutter: stable;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  color: var(--mg-text);
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--mg-surface-strong);
  color: var(--mg-text-soft);
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .075em;
  text-transform: uppercase;
}

th,
td {
  border-bottom: 1px solid var(--mg-border-soft);
}

tbody tr:hover {
  background: var(--mg-surface-muted);
}

/* --------------------------------------------------------------------------
   5. STATUS BOARD / TELEMETRY
   -------------------------------------------------------------------------- */
#page-board .board-header,
#page-squadron .gate-squadron-metrics {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-areas:
    "metrics metrics metrics metrics"
    "active active active active";
  gap: .75rem;
  margin: 0 0 1rem;
}

#page-board .gate-metrics-container {
  grid-area: metrics;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
  min-width: 0;
}

#page-board .metric-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  min-height: 100px;
  padding: .95rem 1.05rem;
  overflow: hidden;
}

#page-board .metric-card::after {
  content: "";
  position: absolute;
  inset: auto .9rem .6rem;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--mg-line), transparent);
}

#page-board .metric-header {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-width: 0;
}

#page-board .metric-label,
.gate-squadron-metric-label,
.gate-active-buses-label {
  color: var(--mg-text-muted);
  font-size: clamp(.66rem, .72vw, .8rem);
  font-weight: 900;
  letter-spacing: .105em;
  line-height: 1;
  text-transform: uppercase;
}

#page-board .metric-value,
.gate-squadron-metric-value {
  min-width: 0;
  margin-top: .5rem;
  overflow: hidden;
  color: var(--mg-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(1.8rem, 2.4vw, 3rem);
  font-weight: 800;
  letter-spacing: -.045em;
  line-height: .95;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.theme-light #page-board .metric-value,
body.theme-light .gate-squadron-metric-value {
  color: var(--mg-text);
  text-shadow: none;
}

.status-dot,
.led-green {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--mg-ok);
  box-shadow: 0 0 10px rgba(var(--mg-ok-rgb), .38);
}

body.theme-light .status-dot,
body.theme-light .led-green {
  box-shadow: none;
}

#page-board .gate-active-buses-block {
  grid-area: active;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: .85rem;
  min-width: 0;
  padding: .8rem .9rem;
}

#page-board .gate-active-buses-label {
  padding-top: .55rem;
  white-space: nowrap;
}

#page-board #active-buses {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: .55rem;
  min-width: 0;
}

#page-board #active-buses .bus-badge,
#page-board #active-buses .prc-bus-card,
#page-board #active-buses .gate-component-active-bus-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .25rem .55rem;
  flex: 0 1 300px;
  min-width: 250px;
  min-height: 92px;
  padding: .66rem .82rem;
  border: 1px solid var(--mg-border-glass);
  border-radius: var(--mg-radius-sm);
  -webkit-appearance: none;
  appearance: none;
  background: color-mix(in srgb, var(--mg-surface-strong) 88%, transparent);
  color: var(--mg-text);
  text-align: left;
  overflow: hidden;
}

#page-board #active-buses .prc-bus-card-title {
  grid-column: 1 / -1;
  overflow: hidden;
  color: var(--mg-text);
  font-size: .94rem;
  font-weight: 900;
  letter-spacing: .045em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.theme-light #page-board #active-buses .prc-bus-card-title {
  color: var(--mg-text);
}

#page-board #active-buses .prc-bus-card-line {
  color: var(--mg-text-soft);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .035em;
  line-height: 1.15;
}

#page-board #active-buses .prc-bus-card-dept {
  grid-column: 1 / -1;
  padding-top: .34rem;
  border-top: 1px solid var(--mg-border-soft);
  color: var(--mg-text-muted);
  font-size: .64rem;
  font-weight: 900;
  letter-spacing: .075em;
  text-transform: uppercase;
}

body:not(.theme-light) #page-board .metric-card,
body:not(.theme-light) #page-board .gate-active-buses-block,
body:not(.theme-light) #page-board .gate-dorm-card,
body:not(.theme-light) #page-board .dorm-card {
  background: rgba(40, 50, 42, .93);
  border-color: rgba(216, 232, 211, .29);
}

body:not(.theme-light) #page-board #active-buses .bus-badge,
body:not(.theme-light) #page-board #active-buses .prc-bus-card,
body:not(.theme-light) #page-board #active-buses .gate-component-active-bus-card {
  background: rgba(50, 63, 52, .98);
  border-color: rgba(216, 232, 211, .36);
  color: var(--mg-text);
}

/* --------------------------------------------------------------------------
   6. DORM BOARDS / STATUS CARDS
   -------------------------------------------------------------------------- */
#page-board .dorm-dashboard,
#page-squadron .dorm-dashboard,
#page-squadron .gate-squadron-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  min-width: 0;
}

#page-board .dorm-column,
#page-squadron .dorm-column,
#page-board [data-dorm-column],
#page-squadron [data-dorm-column] {
  min-width: 0;
}

#page-board #col-empty,
#page-board #col-open,
#page-board #col-closed,
#page-squadron .gate-squadron-dorm-grid,
#page-squadron [data-dorm-grid] {
  display: grid;
  align-content: start;
  gap: .7rem;
  min-width: 0;
}

#page-board .gate-dorm-card,
#page-board .dorm-card,
#page-squadron .gate-dorm-card,
#page-squadron .dorm-card {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "banner banner"
    "name airman"
    "info location"
    "status status"
    "timer load"
    "progress progress";
  gap: .34rem .65rem;
  min-width: 0;
  min-height: 178px;
  padding: var(--gate-dorm-card-pad-y) var(--gate-dorm-card-pad-x);
  overflow: hidden;
  border-radius: var(--mg-radius-lg);
  transition: var(--mg-spring), var(--mg-fade);
  contain: layout paint;
}

#page-board .gate-dorm-card:not(.gate-dorm-has-banner),
#page-board .dorm-card:not(.gate-dorm-has-banner),
#page-squadron .gate-dorm-card:not(.gate-dorm-has-banner),
#page-squadron .dorm-card:not(.gate-dorm-has-banner) {
  grid-template-areas:
    "name airman"
    "info location"
    "status status"
    "timer load"
    "progress progress";
}

.gate-dorm-top-banner {
  grid-area: banner;
  margin: calc(-1 * var(--gate-dorm-card-pad-y)) calc(-1 * var(--gate-dorm-card-pad-x)) .28rem;
  padding: .34rem .7rem;
  border-bottom: 1px solid var(--mg-border-soft);
  color: #fff;
  font-size: .64rem;
  font-weight: 900;
  letter-spacing: .13em;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
}

.banner-band,
.gate-dorm-top-banner.banner-band {
  background: #315e3a;
}

.banner-space-force,
.gate-dorm-top-banner.banner-space-force {
  background: #2d6179;
}

body.theme-light .banner-band,
body.theme-light .gate-dorm-top-banner.banner-band {
  background: #597160;
}

body.theme-light .banner-space-force,
body.theme-light .gate-dorm-top-banner.banner-space-force {
  background: #5b7781;
}

.gate-dorm-name {
  grid-area: name;
  min-width: 0;
  overflow: hidden;
  color: var(--mg-text);
  font-size: clamp(1.3rem, 1.55vw, 1.85rem);
  font-weight: 900;
  letter-spacing: -.025em;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gate-dorm-airman {
  grid-area: airman;
  min-width: 0;
  overflow: hidden;
  color: var(--mg-text-soft);
  font-size: .66rem;
  font-weight: 850;
  letter-spacing: .06em;
  text-align: right;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.gate-dorm-info {
  grid-area: info;
  min-width: 0;
  overflow: hidden;
  color: var(--mg-text-muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .055em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.gate-auditorium-location {
  grid-area: location;
  justify-self: end;
  align-self: center;
  max-width: 100%;
  overflow: hidden;
  padding: .2rem .4rem;
  border: 1px solid var(--mg-border-soft);
  border-radius: var(--mg-radius-pill);
  color: var(--mg-text-soft);
  font-size: .6rem;
  font-weight: 900;
  letter-spacing: .05em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.gate-dorm-status-wrap {
  grid-area: status;
  min-width: 0;
}

.gate-dorm-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  padding: .28rem .48rem;
  border: 1px solid var(--mg-border-soft);
  border-radius: var(--mg-radius-pill);
  overflow: hidden;
  background: var(--mg-surface-muted);
  color: var(--mg-text-soft);
  font-size: .64rem;
  font-weight: 900;
  letter-spacing: .075em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.gate-dorm-state-open .gate-dorm-status,
.gate-dorm-status[data-state="open"] {
  border-color: rgba(var(--mg-ok-rgb), .30);
  color: var(--mg-ok);
}

body.theme-light .gate-dorm-state-open .gate-dorm-status,
body.theme-light .gate-dorm-status[data-state="open"] {
  color: var(--mg-ok-deep);
}

.gate-dorm-state-closed .gate-dorm-status,
.gate-dorm-status[data-state="closed"] {
  border-color: color-mix(in srgb, var(--mg-red) 32%, transparent);
  color: var(--mg-red);
}

.gate-dorm-timer {
  grid-area: timer;
  align-self: end;
  width: 6.35ch;
  min-width: 6.35ch;
  overflow: hidden;
  color: var(--mg-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(1.2rem, 1.5vw, 1.65rem);
  font-weight: 850;
  letter-spacing: -.045em;
  line-height: 1;
  white-space: nowrap;
}

.gate-empty-timer {
  color: var(--mg-text-muted);
}

.gate-dorm-load {
  grid-area: load;
  align-self: end;
  justify-self: end;
  color: var(--mg-text);
  font-size: clamp(1.05rem, 1.25vw, 1.35rem);
  font-weight: 900;
  letter-spacing: -.02em;
  line-height: 1;
  white-space: nowrap;
}

.gate-dorm-progress {
  grid-area: progress;
  height: 5px;
  margin-top: .2rem;
  overflow: hidden;
  border-radius: var(--mg-radius-pill);
  background: var(--mg-surface-muted);
}

.gate-dorm-progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--mg-ok-deep);
  transition: width 180ms ease;
}

.gate-dorm-card.is-full .gate-dorm-progress-fill,
.dorm-card.is-full .gate-dorm-progress-fill {
  background: var(--mg-ok);
}

.gate-dorm-card.is-over .gate-dorm-progress-fill,
.dorm-card.is-over .gate-dorm-progress-fill {
  background: var(--mg-red);
}

#page-board .gate-dorm-card.border-female,
#page-board .dorm-card.border-female,
#page-board .gate-dorm-card[data-female-dorm="true"],
#page-board .dorm-card[data-female-dorm="true"],
#page-squadron .gate-dorm-card.border-female,
#page-squadron .dorm-card.border-female,
#page-squadron .gate-dorm-card[data-female-dorm="true"],
#page-squadron .dorm-card[data-female-dorm="true"] {
  border-color: color-mix(in srgb, var(--gate-flag-female-red) 82%, var(--mg-border-glass));
  box-shadow: var(--mg-inset-edge), 0 0 0 1px color-mix(in srgb, var(--gate-flag-female-red) 28%, transparent), var(--mg-shadow-soft);
}

body.theme-light #page-board .gate-dorm-card.border-female,
body.theme-light #page-board .dorm-card.border-female,
body.theme-light #page-squadron .gate-dorm-card.border-female,
body.theme-light #page-squadron .dorm-card.border-female {
  box-shadow: var(--mg-inset-edge), 0 0 0 1px rgba(169, 68, 64, .18), var(--mg-shadow-soft);
}

.timer-display,
.gate-dorm-timer {
  animation: none;
}

.timer-display.timer-yellow,
.gate-dorm-timer.timer-yellow {
  color: var(--mg-yellow);
}

.timer-display.timer-red,
.timer-display.timer-flash,
.gate-dorm-timer.timer-red,
.gate-dorm-timer.timer-flash {
  color: var(--mg-red);
  animation: none;
}

/* --------------------------------------------------------------------------
   7. PROCESSING PAGE
   -------------------------------------------------------------------------- */
#page-processing #proc-dorm-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 1rem;
  width: 100%;
  min-width: 0;
}

#page-processing #proc-dorm-grid .proc-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: clamp(170px, 14vw, 220px);
  padding: .95rem 1rem;
  overflow: hidden;
  border-radius: var(--mg-radius-lg);
  contain: layout paint;
  transition: var(--mg-spring), var(--mg-fade);
}

#page-processing #proc-dorm-grid .proc-card:hover,
#page-processing #proc-dorm-grid .proc-card:focus-visible {
  border-color: var(--mg-border-strong);
  transform: translate3d(0, -1px, 0);
}

#page-processing #proc-dorm-grid .proc-card.border-female {
  border-width: 3px;
  border-color: var(--gate-flag-female-red);
  box-shadow: var(--mg-inset-edge), 0 0 20px rgba(255, 77, 71, .22), var(--mg-shadow-soft);
}

body.theme-light #page-processing #proc-dorm-grid .proc-card.border-female {
  box-shadow: var(--mg-inset-edge), 0 0 0 1px rgba(169, 68, 64, .16), var(--mg-shadow-soft);
}

#page-processing .proc-card.border-space-force > .text-xl.font-black.font-tabular::before {
  content: "SPACE FORCE";
  display: inline-flex;
  align-items: center;
  margin-right: .4rem;
  padding: .22rem .4rem;
  border: 1px solid color-mix(in srgb, var(--gate-flag-space-force-bluebird) 44%, transparent);
  border-radius: var(--mg-radius-pill);
  background: color-mix(in srgb, var(--gate-flag-space-force-bluebird) 12%, transparent);
  color: var(--gate-flag-space-force-bluebird);
  font-size: .58rem;
  font-weight: 900;
  letter-spacing: .075em;
  vertical-align: middle;
}

#page-processing .proc-card.border-band > .text-xl.font-black.font-tabular::before {
  content: "BAND";
  display: inline-flex;
  align-items: center;
  margin-right: .4rem;
  padding: .22rem .4rem;
  border: 1px solid color-mix(in srgb, var(--gate-flag-band-green) 44%, transparent);
  border-radius: var(--mg-radius-sm);
  color: var(--gate-flag-band-green);
  font-size: .58rem;
  font-weight: 900;
  letter-spacing: .075em;
  vertical-align: middle;
}

#page-processing .proc-card.border-space-force .gate-dorm-flags {
  display: none;
}

.gate-dorm-flags {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  margin-top: .38rem;
}

.gate-dorm-flag-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: .22rem .4rem;
  border: 1px solid var(--mg-border-soft);
  border-radius: var(--mg-radius-pill);
  font-size: .59rem;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.gate-dorm-flag-chip.flag-band { color: var(--gate-flag-band-green); }
.gate-dorm-flag-chip.flag-space-force { color: var(--gate-flag-space-force-bluebird); }

/* --------------------------------------------------------------------------
   8. INPUT / AIRPORT / SAT ARRIVALS
   -------------------------------------------------------------------------- */
#page-input,
#page-airport,
#page-archives {
  min-width: 0;
}

#page-input > .flex-shrink-0:first-of-type,
#page-airport > .flex-shrink-0:first-of-type {
  padding: 1rem 1.25rem;
}

#receiving-windows-panel {
  width: 100%;
  margin-top: .85rem;
  padding: .85rem;
  border-radius: var(--mg-radius-lg);
}

#receiving-windows-panel input[type="datetime-local"] {
  height: 40px;
  min-height: 40px;
}

#batch-grid-wrapper {
  width: 100%;
  padding: .9rem 1rem 1.05rem;
  overflow-x: auto;
  scrollbar-gutter: stable;
  overscroll-behavior-inline: contain;
}

#batch-grid-wrapper > div {
  width: 100%;
  min-width: max(var(--input-matrix-min-width), 100%);
}

#batch-grid-wrapper > div > div:first-child,
#batch-rows-container > div {
  display: grid;
  grid-template-columns: var(--input-matrix-grid);
  align-items: center;
  column-gap: var(--input-matrix-gap);
  width: 100%;
}

#batch-grid-wrapper > div > div:first-child {
  padding: .52rem .2rem .55rem;
  border-bottom: 1px solid var(--mg-border-glass);
  color: var(--mg-text-muted);
  font-size: .67rem;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

#batch-rows-container > div {
  min-height: 42px;
  padding: .18rem .2rem;
}

#batch-rows-container > div > label {
  min-width: 0;
  justify-self: stretch;
}

#batch-rows-container .batch-band,
#batch-rows-container .batch-space-force {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--mg-accent-deep);
}

#batch-rows-container > div > input:not([type="checkbox"]),
#batch-rows-container > div > select,
#batch-rows-container > div > button[onclick*="clearBatchRow"] {
  height: 36px;
  min-height: 36px;
}

#batch-rows-container > div > button[onclick*="clearBatchRow"] {
  width: 36px;
  min-width: 36px;
}

#page-airport .surface,
#page-input .surface {
  min-width: 0;
}

#airport-bus-log-body,
#page-airport tbody {
  font-variant-numeric: tabular-nums;
}

.sat-arrivals-board {
  margin: 1rem 1.5rem 1.5rem;
  padding: 1rem;
}

.sat-status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: .24rem .48rem;
  border: 1px solid var(--mg-border-soft);
  border-radius: var(--mg-radius-pill);
  color: var(--mg-text-soft);
  font-size: .65rem;
  font-weight: 900;
  letter-spacing: .045em;
  text-transform: uppercase;
}

.sat-status-good { color: var(--mg-accent); }
.sat-status-delayed { color: var(--mg-yellow); }
.sat-status-canceled { color: var(--mg-red); }
.sat-status-blue { color: var(--mg-blue); }
.sat-status-muted { color: var(--mg-text-muted); }
body.theme-light .sat-status-good { color: #405237; }

/* --------------------------------------------------------------------------
   9. ARCHIVE MANAGEMENT
   -------------------------------------------------------------------------- */
#page-archives .gate-archive-manager {
  display: grid;
  gap: .9rem;
}

.gate-archive-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 28rem) auto;
  align-items: center;
  gap: .75rem;
  min-height: 4.6rem;
  padding: .85rem .95rem;
  border-radius: var(--mg-radius-xl);
}

.gate-archive-toolbar-title,
.gate-archive-year-title,
.gate-archive-month-title,
.gate-archive-empty-title {
  color: var(--mg-text);
  font-weight: 900;
  letter-spacing: .09em;
  line-height: 1.08;
  text-transform: uppercase;
}

.gate-archive-toolbar-copy,
.gate-archive-record-meta,
.gate-archive-empty-copy {
  color: var(--mg-text-muted);
}

.gate-archive-search-wrap {
  display: grid;
  gap: .3rem;
  min-width: 0;
}

.gate-archive-search-label {
  color: var(--mg-text-soft);
  font-size: .63rem;
  font-weight: 900;
  letter-spacing: .11em;
  text-transform: uppercase;
}

#gate-archive-search {
  min-height: 41px;
}

.gate-archive-clear-search {
  align-self: end;
  min-height: 41px;
  padding: 0 .9rem;
  border: 1px solid var(--mg-border-glass);
  border-radius: var(--mg-radius-pill);
  background: var(--mg-surface-muted);
  color: var(--mg-text-soft);
  font-size: .67rem;
  font-weight: 900;
  letter-spacing: .075em;
  text-transform: uppercase;
}

.gate-archive-empty {
  display: grid;
  place-items: center;
  min-height: 14rem;
  padding: 2rem;
  border: 1px dashed var(--mg-border-glass);
  border-radius: var(--mg-radius-xl);
  background: var(--mg-surface-muted);
  text-align: center;
}

.gate-archive-year,
.gate-archive-month {
  overflow: hidden;
  border-radius: var(--mg-radius-xl);
}

.gate-archive-month {
  border-radius: var(--mg-radius-lg);
}

.gate-archive-year > summary,
.gate-archive-month > summary {
  list-style: none;
  user-select: none;
}

.gate-archive-year > summary::-webkit-details-marker,
.gate-archive-month > summary::-webkit-details-marker {
  display: none;
}

.gate-archive-year > summary,
.gate-archive-month > summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem;
  padding: .78rem .9rem;
}

.gate-archive-year > summary {
  min-height: 4rem;
  border-bottom: 1px solid var(--mg-border-soft);
}

.gate-archive-month > summary {
  min-height: 3.3rem;
}

.gate-archive-month[open] > summary {
  border-bottom: 1px solid var(--mg-border-soft);
  background: var(--mg-surface-muted);
}

.gate-archive-year-title-row,
.gate-archive-month-title-row {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  min-width: 0;
}

.gate-archive-disclosure {
  display: inline-grid;
  place-items: center;
  width: 1.45rem;
  height: 1.45rem;
  flex: 0 0 auto;
  border: 1px solid var(--mg-border-glass);
  border-radius: 50%;
  background: var(--mg-surface-muted);
  color: var(--mg-text-soft);
  font-size: .72rem;
  transition: transform 140ms cubic-bezier(.25, 1, .5, 1), border-color 140ms ease;
}

.gate-archive-year[open] > summary .gate-archive-disclosure,
.gate-archive-month[open] > summary .gate-archive-disclosure {
  transform: rotate(90deg);
  border-color: color-mix(in srgb, var(--mg-accent) 44%, var(--mg-border-glass));
}

.gate-archive-year-count,
.gate-archive-month-count {
  color: var(--mg-text-soft);
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-align: right;
  text-transform: uppercase;
}

.gate-archive-year-body {
  display: grid;
  gap: .72rem;
  padding: .82rem;
}

.gate-archive-record-list {
  display: grid;
  gap: .55rem;
  padding: .78rem .82rem .82rem;
}

.gate-archive-record-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .75rem;
  min-height: 4.25rem;
  padding: .78rem .85rem;
  border-radius: var(--mg-radius-md);
  color: var(--mg-text);
  text-align: left;
}

.gate-archive-record-card:hover,
.gate-archive-record-card:focus-visible {
  background: var(--mg-surface-soft);
}

.gate-archive-record-title,
.gate-archive-record-meta {
  display: block;
}

.gate-archive-record-title {
  font-size: .92rem;
  font-weight: 900;
  letter-spacing: .055em;
}

.gate-archive-record-meta {
  margin-top: .18rem;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.gate-archive-record-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .35rem;
}

.gate-archive-stat-pill {
  padding: .26rem .46rem;
  border: 1px solid var(--mg-border-soft);
  border-radius: var(--mg-radius-pill);
  color: var(--mg-text-soft);
  font-size: .61rem;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   10. MODALS, DRAWERS, CONTEXT MENUS, ALERTS
   -------------------------------------------------------------------------- */
body.gate-modal-open {
  overflow: hidden;
}

.confirm-overlay,
#confirm-dialog,
#dorm-modal,
#dorm-edit-modal,
#archive-edit-modal,
#airport-bus-edit-modal,
#bus-arrival-confirm-modal,
#init-success-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--mg-z-modal);
  align-items: center;
  justify-content: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--mg-overlay);
  backdrop-filter: blur(8px) saturate(112%);
  -webkit-backdrop-filter: blur(8px) saturate(112%);
}

.confirm-overlay:not(.hidden),
#confirm-dialog:not(.hidden),
#dorm-modal:not(.hidden),
#dorm-edit-modal:not(.hidden),
#archive-edit-modal:not(.hidden),
#airport-bus-edit-modal:not(.hidden),
#bus-arrival-confirm-modal:not(.hidden),
#init-success-overlay:not(.hidden) {
  display: flex;
}

.modal-content,
.confirm-overlay > .modal-content,
#confirm-dialog > .surface,
#confirm-dialog > div {
  position: relative;
  z-index: var(--mg-z-modal);
  display: flex;
  flex-direction: column;
  width: min(94vw, 760px);
  max-width: 100%;
  max-height: calc(100dvh - 2rem);
  min-width: 0;
  padding: 1rem;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--mg-border-strong);
  border-radius: var(--mg-radius-xl);
  background: var(--mg-surface-strong);
  color: var(--mg-text);
  box-shadow: var(--mg-inset-edge), var(--mg-shadow-strong);
  backdrop-filter: blur(20px) saturate(125%);
  -webkit-backdrop-filter: blur(20px) saturate(125%);
  scrollbar-gutter: stable;
}

body.theme-light .modal-content,
body.theme-light .confirm-overlay > .modal-content,
body.theme-light #confirm-dialog > .surface,
body.theme-light #confirm-dialog > div {
  background: rgba(249, 251, 247, .98);
  box-shadow: var(--mg-inset-edge), 0 24px 54px rgba(43, 53, 36, .16);
}

.modal-content > .flex.justify-between.items-center.mb-4 {
  position: sticky;
  top: 0;
  z-index: 2;
  margin-bottom: .85rem;
  padding: .72rem .78rem;
  border: 1px solid var(--mg-border-soft);
  border-radius: var(--mg-radius-lg);
  background: color-mix(in srgb, var(--mg-surface-strong) 94%, transparent);
  backdrop-filter: blur(var(--mg-glass-blur));
  -webkit-backdrop-filter: blur(var(--mg-glass-blur));
}

.modal-content input,
.modal-content select {
  min-height: var(--mg-control-h);
}

.modal-content button {
  min-width: 0;
  min-height: 40px;
}

.modal-content textarea {
  max-height: 34dvh;
}

.gate-edit-record-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .6rem;
}

.gate-edit-record-grid input,
#modal-airman-input,
#modal-auditorium-input,
#edit-assigned-airman,
#edit-auditorium-location {
  text-transform: uppercase;
}

.gate-airman-location-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 78px;
  align-items: end;
  gap: .55rem;
}

/* Processing workspace: canonical desktop geometry. */
#dorm-modal .gate-processing-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(250px, .7fr);
  grid-template-areas:
    "header header"
    "meta meta"
    "assignment assignment"
    "phase load"
    "footer footer";
  gap: .75rem;
  width: min(calc(100vw - 2rem), 940px);
  max-width: 940px;
  max-height: calc(100dvh - 1rem);
  padding: .9rem;
}

#dorm-modal .gate-processing-workspace__header { grid-area: header; }
#dorm-modal .gate-processing-workspace__meta { grid-area: meta; }
#dorm-modal .gate-processing-workspace__assignment { grid-area: assignment; }
#dorm-modal .gate-processing-workspace__phase { grid-area: phase; }
#dorm-modal .gate-processing-workspace__load { grid-area: load; }
#dorm-modal .gate-processing-workspace__footer { grid-area: footer; }

#dorm-modal #modal-phase-section,
#dorm-modal #modal-load-section,
#dorm-modal .gate-processing-workspace__assignment {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: .75rem;
  overflow: hidden;
  border: 1px solid var(--mg-border-soft);
  border-radius: var(--mg-radius-lg);
  background: var(--mg-surface-muted);
}

#dorm-modal #modal-phase-section[style*="display: none"] + #modal-load-section,
#dorm-modal #modal-phase-section[style*="display:none"] + #modal-load-section {
  grid-column: 1 / -1;
  width: min(100%, 38rem);
  max-width: 38rem;
  justify-self: center;
}

#dorm-modal #modal-phase-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
}

#dorm-modal .phase-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  padding: .7rem .75rem;
  border: 1px solid var(--mg-border-glass);
  border-radius: var(--mg-radius-md);
  background: var(--mg-surface-soft);
  color: var(--mg-text);
  font-size: .78rem;
  font-weight: 900;
  letter-spacing: .035em;
  text-align: center;
}

#dorm-modal .phase-btn.selected {
  border-color: color-mix(in srgb, var(--mg-accent) 48%, var(--mg-border-glass));
  background: color-mix(in srgb, var(--mg-accent) 13%, var(--mg-surface));
  color: var(--mg-accent);
}

body.theme-light #dorm-modal .phase-btn.selected {
  color: #34452d;
}

#dorm-modal #modal-load-section > .flex.items-center.justify-center.gap-4 {
  display: grid;
  grid-template-columns: repeat(2, minmax(2.25rem, .58fr)) minmax(4.75rem, 1.45fr) repeat(2, minmax(2.25rem, .58fr));
  align-items: center;
  justify-content: stretch;
  gap: .38rem;
  width: 100%;
  max-width: 100%;
  margin: 0 0 .55rem;
}

#dorm-modal #modal-load-section > .flex.items-center.justify-center.gap-4 > * {
  min-width: 0;
  max-width: 100%;
}

#dorm-modal .load-btn {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: .35rem;
  white-space: nowrap;
}

#dorm-modal #modal-load-input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-align: center;
}

#dorm-modal #modal-load-section > .flex.gap-2.justify-center {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
  width: 100%;
}

#dorm-modal #modal-load-section > .flex.gap-2.justify-center > button,
#dorm-modal #modal-action-section > button {
  width: 100%;
  min-width: 0;
}

#dorm-modal #modal-action-section {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .55rem;
  padding-top: .15rem;
}

#dorm-edit-modal .gate-processing-edit-workspace,
#archive-edit-modal .modal-content {
  width: min(calc(100vw - 2rem), 880px);
  max-width: 880px;
}

#archive-edit-modal .modal-content {
  width: min(94vw, 980px);
  max-width: 980px;
}

#dorm-edit-form,
.gate-processing-edit-workspace__form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .7rem;
}

#dorm-edit-form > .flex.gap-2.pt-3,
.gate-processing-edit-workspace__footer,
#dorm-edit-form .prc-dorm-edit-actions {
  grid-column: 1 / -1;
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .5rem;
  padding: .7rem 0 .1rem;
  background: var(--mg-surface-strong);
}

#dorm-edit-form > .space-y-4,
#dorm-edit-form > .gate-edit-record-grid,
#dorm-edit-form > [id="gate-edit-assignment-fields"] {
  grid-column: 1 / -1;
}

#dorm-edit-form .prc-dorm-edit-actions > button,
#reopen-dorm-btn {
  min-width: 88px;
  min-height: 38px;
  padding: .5rem .7rem;
  border-radius: var(--mg-radius-sm);
}

#reopen-dorm-btn {
  border: 1px solid color-mix(in srgb, var(--mg-blue) 48%, var(--mg-border-glass));
  background: color-mix(in srgb, var(--mg-blue) 18%, var(--mg-surface));
  color: var(--mg-text);
}

#archive-edit-modal textarea {
  min-height: 10rem;
}

.gate-processing-context-menu,
#gate-processing-context-menu,
#gate-airport-bus-context-menu {
  position: fixed;
  z-index: var(--mg-z-popover);
  width: min(86vw, 280px);
  padding: .42rem;
  border: 1px solid var(--mg-border-strong);
  border-radius: var(--mg-radius-lg);
  background: var(--mg-surface-strong);
  color: var(--mg-text);
  box-shadow: var(--mg-shadow-strong);
  backdrop-filter: blur(18px) saturate(125%);
  -webkit-backdrop-filter: blur(18px) saturate(125%);
}

.gate-processing-context-title {
  padding: .42rem .52rem .5rem;
  border-bottom: 1px solid var(--mg-border-soft);
  color: var(--mg-text);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .075em;
  text-transform: uppercase;
}

.gate-processing-context-subtitle {
  display: block;
  margin-top: .22rem;
  color: var(--mg-text-muted);
  font-size: .58rem;
  letter-spacing: .06em;
}

.gate-processing-context-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .7rem;
  width: 100%;
  margin-top: .32rem;
  padding: .58rem .62rem;
  border: 1px solid transparent;
  border-radius: var(--mg-radius-md);
  background: transparent;
  color: var(--mg-text);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .055em;
  text-align: left;
  text-transform: uppercase;
}

.gate-processing-context-action:hover,
.gate-processing-context-action:focus-visible {
  border-color: var(--mg-border-strong);
  background: var(--mg-surface-soft);
}

.gate-processing-context-action.danger:hover,
.gate-processing-context-action.danger:focus-visible {
  border-color: color-mix(in srgb, var(--mg-red) 48%, transparent);
  background: color-mix(in srgb, var(--mg-red) 12%, transparent);
}

.gate-access-denied-toast,
.gate-shell-toast,
.gate-critical-alert {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: var(--mg-z-critical);
  transform: translateX(-50%);
  max-width: min(92vw, 440px);
  padding: .72rem .92rem;
  border: 1px solid color-mix(in srgb, var(--mg-red) 55%, transparent);
  border-radius: var(--mg-radius-pill);
  background: color-mix(in srgb, #5d1717 88%, transparent);
  color: #fff;
  box-shadow: var(--mg-shadow-strong);
  font-size: .76rem;
  font-weight: 900;
  letter-spacing: .055em;
  text-align: center;
  text-transform: uppercase;
}

body.gate-airman-role #page-airport,
body.gate-airman-role #page-input,
body.gate-airman-role #page-archives,
body.gate-airman-role #closeout-btn,
body.gate-airman-role #airport-bus-edit-modal,
body.gate-airman-role #dorm-edit-modal,
body.gate-airman-role #archive-edit-modal,
body.gate-airman-role #gate-processing-context-menu {
  display: none;
}

/* --------------------------------------------------------------------------
   11. SQUADRON BOARD
   -------------------------------------------------------------------------- */
#page-squadron .gate-squadron-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
}

#page-squadron .gate-squadron-metric {
  min-height: 96px;
  padding: .9rem 1rem;
}

#page-squadron .gate-squadron-metric-value {
  margin-top: .45rem;
}

#page-squadron .timer-display.timer-yellow,
#page-squadron .timer-display.timer-red,
#page-squadron .timer-display.timer-flash {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 6.35ch;
  max-width: 100%;
  min-height: 1.28em;
  padding: .18em .36em .16em;
  line-height: 1;
  letter-spacing: -.045em;
  white-space: nowrap;
  vertical-align: middle;
}

/* --------------------------------------------------------------------------
   12. LOGIN PORTAL
   -------------------------------------------------------------------------- */
html:has(body.login-page),
body.login-page {
  min-height: 100dvh;
  width: 100%;
}

body.login-page {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  padding: calc(var(--mg-banner-h) + max(1.5rem, env(safe-area-inset-top))) 1rem max(1.5rem, env(safe-area-inset-bottom));
  background:
    linear-gradient(rgba(var(--mg-accent-rgb), .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--mg-accent-rgb), .035) 1px, transparent 1px),
    radial-gradient(circle at 50% 24%, rgba(var(--mg-accent-rgb), .08), transparent 36%),
    var(--mg-bg);
  background-size: 24px 24px, 24px 24px, auto, auto;
}

body.login-page::before {
  inset: 0;
  z-index: var(--mg-z-base);
  background-image: url('/assets/gate_emblem_white.png');
  background-repeat: no-repeat;
  background-position: center 54%;
  background-size: min(58vw, 900px) auto;
  opacity: .075;
  filter: grayscale(1);
}

.login-shell {
  position: relative;
  z-index: var(--mg-z-static);
  width: min(100%, 520px);
  max-width: 520px;
}

.login-card,
.login-card-surface {
  position: relative;
  display: grid;
  gap: 1rem;
  width: 100%;
  padding: clamp(1.4rem, 4vw, 2.1rem);
  overflow: hidden;
  border: 1px solid var(--mg-border-strong);
  border-radius: var(--mg-radius-xl);
  background: var(--mg-surface-strong);
  color: var(--mg-text);
  box-shadow: var(--mg-inset-edge), var(--mg-shadow-strong);
  backdrop-filter: blur(20px) saturate(125%);
  -webkit-backdrop-filter: blur(20px) saturate(125%);
}

.login-brand-stack {
  display: grid;
  justify-items: center;
  gap: .5rem;
  text-align: center;
}

.login-brand-mark {
  width: min(184px, 46vw);
  height: 46px;
  background: url('/assets/gate_emblem_white.png') center / contain no-repeat;
  opacity: .78;
}

.login-command-kicker,
.login-footer-note {
  margin: 0;
  color: var(--mg-text-muted);
  font-size: .65rem;
  font-weight: 900;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.login-title {
  margin: 0;
  color: var(--mg-accent);
  font-size: clamp(3.4rem, 13vw, 5.15rem);
  font-weight: 900;
  line-height: .88;
  letter-spacing: -.075em;
}

.login-system-name {
  max-width: 360px;
  margin: 0;
  color: var(--mg-text-soft);
  font-size: clamp(.82rem, 2.2vw, .98rem);
  font-weight: 900;
  letter-spacing: .086em;
  line-height: 1.16;
  text-transform: uppercase;
}

.login-identity-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .65rem;
  width: 100%;
  margin-top: .45rem;
  padding: .5rem .65rem;
  border: 1px solid var(--mg-border-soft);
  border-radius: var(--mg-radius-pill);
  background: var(--mg-surface-muted);
}

.login-identity-strip span {
  min-width: 0;
  overflow: hidden;
  color: var(--mg-text-muted);
  font-size: .58rem;
  font-weight: 900;
  letter-spacing: .09em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.login-identity-strip span:last-child {
  padding-left: .65rem;
  border-left: 1px solid var(--mg-border-soft);
  color: var(--mg-text-soft);
}

.login-form {
  display: grid;
  gap: .85rem;
}

.login-field {
  display: grid;
  gap: .42rem;
}

.login-form label {
  color: var(--mg-text-muted);
  font-size: .67rem;
  font-weight: 900;
  letter-spacing: .105em;
  text-transform: uppercase;
}

.login-form input {
  min-height: 46px;
}

.login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  border: 1px solid color-mix(in srgb, var(--mg-accent) 42%, var(--mg-border-glass));
  border-radius: var(--mg-radius-sm);
  background: color-mix(in srgb, var(--mg-accent-deep) 78%, #132413);
  color: #fff;
  font-size: .77rem;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.login-footer-note {
  text-align: center;
}

#login-message {
  min-height: 22px;
}

/* --------------------------------------------------------------------------
   13. FULLSCREEN COMMAND BOARD
   -------------------------------------------------------------------------- */
body.fullscreen-board,
body.gate-fullscreen-board-active {
  overflow: hidden;
}

body.fullscreen-board .app-nav,
body.fullscreen-board .command-header-bar,
body.fullscreen-board #gate-mobile-menu-scrim,
body.fullscreen-board #gate-mobile-nav-sheet,
body.gate-fullscreen-board-active .app-nav,
body.gate-fullscreen-board-active .command-header-bar,
body.gate-fullscreen-board-active #gate-mobile-menu-scrim,
body.gate-fullscreen-board-active #gate-mobile-nav-sheet {
  display: none;
}

body.fullscreen-board #page-board,
body.fullscreen-board #page-board.active,
body.gate-fullscreen-board-active #page-board,
body.gate-fullscreen-board-active #page-board.active {
  position: fixed;
  inset: var(--mg-banner-h) 0 0;
  z-index: var(--mg-z-static);
  display: flex;
  flex-direction: column;
  width: 100vw;
  max-width: none;
  min-height: 0;
  max-height: none;
  margin: 0;
  padding: .65rem;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

body.fullscreen-board #page-board .board-header,
body.gate-fullscreen-board-active #page-board .board-header {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-areas:
    "metrics metrics metrics metrics"
    "active active active active";
  gap: .65rem;
  margin: 0 0 .65rem;
}

body.fullscreen-board #page-board .gate-metrics-container,
body.gate-fullscreen-board-active #page-board .gate-metrics-container {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .65rem;
}

body.fullscreen-board #page-board .metric-card,
body.gate-fullscreen-board-active #page-board .metric-card {
  min-height: clamp(88px, 11vh, 126px);
  background: var(--mg-bg-elevated);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

body.fullscreen-board #page-board .metric-value,
body.gate-fullscreen-board-active #page-board .metric-value {
  font-size: clamp(2.2rem, 3.15vw, 4.3rem);
}

body.fullscreen-board #page-board .gate-active-buses-block,
body.gate-fullscreen-board-active #page-board .gate-active-buses-block {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  min-height: 94px;
  background: var(--mg-bg-elevated);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

body.fullscreen-board #page-board #active-buses,
body.gate-fullscreen-board-active #page-board #active-buses {
  display: flex;
  flex-flow: row wrap;
  align-items: stretch;
  align-content: flex-start;
  justify-content: flex-start;
  gap: .6rem;
  width: 100%;
  overflow: visible;
}

body.fullscreen-board #page-board #active-buses .prc-bus-card,
body.fullscreen-board #page-board #active-buses .gate-component-active-bus-card,
body.gate-fullscreen-board-active #page-board #active-buses .prc-bus-card,
body.gate-fullscreen-board-active #page-board #active-buses .gate-component-active-bus-card {
  flex: 0 0 clamp(280px, 17vw, 320px);
  width: clamp(280px, 17vw, 320px);
  max-width: clamp(280px, 17vw, 320px);
}

/* --------------------------------------------------------------------------
   14. RESPONSIVE MATRIX
   -------------------------------------------------------------------------- */
@media (min-width: 1850px) {
  .page:not(#page-board),
  body:not(.fullscreen-board):not(.gate-fullscreen-board-active) #page-board,
  #page-squadron {
    width: min(100%, var(--mg-max-content));
    margin-inline: auto;
  }
}

@media (min-width: 1200px) {
  #page-board .dorm-dashboard,
  #page-squadron .dorm-dashboard,
  #page-squadron .gate-squadron-board,
  #page-processing #proc-dorm-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 768px) and (max-width: 1199px) {
  :root {
    --mg-page-gap: 1rem;
  }

  .app-nav,
  .app-nav.command-header-bar,
  .command-header-bar {
    grid-template-columns: 112px minmax(0, 1fr) max-content;
    gap: .4rem;
    padding-inline: .6rem;
  }

  .nav-btn,
  .gate-component-nav-button,
  #role-toggle,
  #fullscreen-btn,
  #sound-toggle-btn,
  #theme-toggle-btn,
  #week-group-display {
    padding-inline: .5rem;
    font-size: .64rem;
  }

  #page-board .gate-metrics-container,
  #page-squadron .gate-squadron-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #page-board .dorm-dashboard,
  #page-squadron .dorm-dashboard,
  #page-squadron .gate-squadron-board,
  #page-processing #proc-dorm-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #page-board .dorm-column,
  #page-squadron .dorm-column,
  #page-airport .surface,
  #page-input .surface,
  #page-processing .surface,
  #page-archives .gate-archive-manager {
    min-height: 0;
    max-height: calc(100dvh - var(--mg-shell-top) - 2rem);
    overflow-y: auto;
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
  }

  #dorm-modal.confirm-overlay:not(.hidden) {
    align-items: flex-start;
    padding-top: max(.75rem, env(safe-area-inset-top));
  }

  #dorm-modal .gate-processing-workspace {
    width: min(720px, calc(100vw - 2rem));
    max-width: calc(100vw - 2rem);
    max-height: calc(100dvh - 1.5rem);
    overflow-y: auto;
    scrollbar-gutter: stable;
  }

  #dorm-modal .gate-processing-workspace__header,
  #dorm-modal .gate-processing-workspace__footer {
    position: sticky;
    z-index: 2;
    background: var(--mg-surface-strong);
  }

  #dorm-modal .gate-processing-workspace__header { top: 0; }
  #dorm-modal .gate-processing-workspace__footer { bottom: 0; }

  .gate-archive-toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(14rem, 24rem);
  }

  .gate-archive-clear-search {
    grid-column: 2;
    justify-self: end;
  }
}

@media (max-width: 767px), (pointer: coarse) and (max-width: 1024px) and (max-height: 560px) {
  :root {
    --mg-banner-h: 28px;
    --mg-nav-h: 60px;
    --mg-page-gap: .75rem;
    --mg-control-h: 44px;
  }

  body.gate-app-shell-ready.gate-watermark-page::after {
    top: 58vh;
    width: min(86vw, 520px);
    height: min(86vw, 520px);
    opacity: .018;
  }

  body.theme-light.gate-app-shell-ready.gate-watermark-page::after {
    opacity: .014;
  }

  .security-banner-fixed {
    font-size: clamp(.58rem, 2.4vw, .69rem);
  }

  .app-nav,
  .app-nav.command-header-bar,
  .command-header-bar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "week menu";
    height: var(--mg-nav-h);
    min-height: var(--mg-nav-h);
    padding: .5rem max(.75rem, env(safe-area-inset-left), env(safe-area-inset-right));
    overflow: visible;
  }

  .app-nav::before,
  .command-header-bar::before {
    display: none;
  }

  .app-nav .nav-group-right,
  .command-header-bar .nav-group-right {
    display: contents;
  }

  #week-group-display {
    grid-area: week;
    justify-content: flex-start;
    width: 100%;
    max-width: 100%;
    height: 44px;
    padding-inline: .75rem;
  }

  #mobile-menu-trigger {
    grid-area: menu;
    display: inline-flex;
    width: clamp(92px, 27vw, 116px);
    min-width: clamp(92px, 27vw, 116px);
    height: 44px;
    visibility: visible;
    pointer-events: auto;
  }

  #gate-mobile-menu-scrim {
    position: fixed;
    inset: var(--mg-shell-top) 0 0;
    z-index: var(--mg-z-popover);
    background: rgba(2, 5, 2, .58);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  body.gate-mobile-drawer-open #gate-mobile-menu-scrim {
    display: block;
    visibility: visible;
    pointer-events: auto;
  }

  body.gate-app-shell-ready #main-nav-menu,
  body.gate-app-shell-ready #nav-links,
  body.gate-app-shell-ready .nav-group-left {
    display: none;
    visibility: hidden;
    pointer-events: none;
  }

  body.gate-app-shell-ready #gate-mobile-nav-sheet {
    position: fixed;
    top: calc(var(--mg-shell-top) + .5rem);
    left: max(.75rem, env(safe-area-inset-left));
    right: max(.75rem, env(safe-area-inset-right));
    z-index: var(--mg-z-modal);
    isolation: isolate;
    transform: translate3d(0, 0, 0);
    touch-action: manipulation;
    display: none;
    grid-template-columns: minmax(0, 1fr);
    gap: .6rem;
    max-height: calc(100dvh - var(--mg-shell-top) - 1.5rem - env(safe-area-inset-bottom));
    padding: .7rem;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: stable;
    border: 1px solid var(--mg-border-strong);
    border-radius: var(--mg-radius-lg);
    background: var(--mg-surface-strong);
    box-shadow: var(--mg-shadow-strong);
    backdrop-filter: blur(18px) saturate(125%);
    -webkit-backdrop-filter: blur(18px) saturate(125%);
    visibility: hidden;
    pointer-events: none;
  }

  body.gate-app-shell-ready.gate-mobile-drawer-open #gate-mobile-nav-sheet,
  body.gate-app-shell-ready #gate-mobile-nav-sheet.gate-mobile-sheet-open {
    display: grid;
    visibility: visible;
    pointer-events: auto;
  }

  body.gate-app-shell-ready #gate-mobile-nav-sheet .gate-mobile-sheet-title,
  body.gate-app-shell-ready #gate-mobile-nav-sheet .gate-shell-system-label {
    color: var(--mg-text-muted);
    font-size: .66rem;
    font-weight: 900;
    letter-spacing: .12em;
    text-transform: uppercase;
  }

  body.gate-app-shell-ready #gate-mobile-nav-sheet .gate-mobile-sheet-routes,
  body.gate-app-shell-ready #gate-mobile-nav-sheet .gate-shell-system-controls,
  body.gate-app-shell-ready #gate-mobile-nav-sheet .gate-mobile-sheet-system {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: .5rem;
    width: 100%;
    min-width: 0;
  }

  body.gate-app-shell-ready #gate-mobile-nav-sheet .gate-mobile-sheet-system {
    margin-top: .2rem;
    padding-top: .65rem;
    border-top: 1px solid var(--mg-border-soft);
  }

  body.gate-app-shell-ready #gate-mobile-nav-sheet .nav-btn,
  body.gate-app-shell-ready #gate-mobile-nav-sheet .gate-component-nav-button,
  body.gate-app-shell-ready #gate-mobile-nav-sheet button {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 0 .9rem;
    text-align: left;
  }

  .page,
  body.gate-app-shell-ready .page.active {
    width: 100%;
    max-width: 100vw;
    padding: calc(var(--mg-shell-top) + .75rem) .75rem .75rem;
    overflow-x: hidden;
  }

  #page-board .board-header,
  #page-board .gate-metrics-container,
  #page-squadron .gate-squadron-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #page-board .gate-metrics-container .local-card {
    grid-column: auto;
  }

  #page-board .metric-card,
  #page-squadron .gate-squadron-metric {
    min-height: 84px;
    padding: .75rem;
  }

  #page-board .metric-value,
  .gate-squadron-metric-value {
    font-size: clamp(1.65rem, 8vw, 2.35rem);
  }

  #page-board .gate-active-buses-block {
    grid-template-columns: 1fr;
    gap: .5rem;
  }

  #page-board .gate-active-buses-label {
    padding-top: 0;
  }

  #page-board #active-buses .bus-badge,
  #page-board #active-buses .prc-bus-card,
  #page-board #active-buses .gate-component-active-bus-card {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }

  #page-board .dorm-dashboard,
  #page-squadron .dorm-dashboard,
  #page-squadron .gate-squadron-board,
  #page-processing #proc-dorm-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: .7rem;
  }

  #page-board .gate-dorm-card,
  #page-board .dorm-card,
  #page-squadron .gate-dorm-card,
  #page-squadron .dorm-card,
  #page-processing #proc-dorm-grid .proc-card {
    min-height: 0;
    padding: .8rem;
    border-radius: var(--mg-radius-md);
  }

  #page-board .gate-dorm-card,
  #page-board .dorm-card,
  #page-squadron .gate-dorm-card,
  #page-squadron .dorm-card {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .gate-dorm-top-banner {
    margin: -.8rem -.8rem .25rem;
  }

  #page-input > .flex-shrink-0:first-of-type,
  #page-airport > .flex-shrink-0:first-of-type {
    padding: .75rem;
  }

  #batch-grid-wrapper {
    margin-inline: 0;
    padding: .7rem 0 .85rem;
  }

  #batch-grid-wrapper > div {
    min-width: var(--input-matrix-min-width);
  }


  #page-airport.active {
    overflow-x: hidden;
    overflow-y: auto;
  }

  #page-airport .max-w-3xl,
  #page-airport #airport-form,
  #page-airport #airport-form > * {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  #page-airport #airport-form {
    display: block;
    overflow: visible;
    padding: 1rem;
  }

  #page-airport #airport-form > * {
    display: block;
    margin-bottom: .85rem;
  }

  #page-airport #airport-form input,
  #page-airport #airport-form button[type="submit"] {
    display: block;
    width: 100%;
    max-width: 100%;
    min-height: 48px;
    font-size: 16px;
  }

  #page-airport .surface:has(#airport-bus-log-body) {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  #page-airport .surface:has(#airport-bus-log-body) table {
    width: max-content;
    min-width: 760px;
  }

  .sat-arrivals-board {
    margin: .75rem 0;
    padding: .75rem;
  }

  .gate-archive-toolbar,
  .gate-archive-record-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .gate-archive-record-stats {
    justify-content: flex-start;
  }

  .gate-archive-clear-search {
    width: 100%;
  }

  .confirm-overlay,
  #confirm-dialog,
  #dorm-modal,
  #dorm-edit-modal,
  #archive-edit-modal,
  #airport-bus-edit-modal,
  #bus-arrival-confirm-modal,
  #init-success-overlay {
    align-items: flex-start;
    padding: max(.5rem, env(safe-area-inset-top)) max(.5rem, env(safe-area-inset-right)) max(.75rem, env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left));
  }

  .modal-content,
  .confirm-overlay > .modal-content,
  #confirm-dialog > .surface,
  #confirm-dialog > div {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - max(1rem, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    padding: .75rem;
    border-radius: var(--mg-radius-lg);
  }


  #dorm-modal.confirm-overlay:not(.hidden) .modal-content > .flex.justify-between.items-center.mb-4 > button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 52px;
    min-height: 44px;
    padding: 0 .78rem;
    border: 1px solid var(--mg-border-glass);
    border-radius: var(--mg-radius-pill);
    background: var(--mg-surface-soft);
    color: transparent;
    font-size: 0;
  }

  #dorm-modal.confirm-overlay:not(.hidden) .modal-content > .flex.justify-between.items-center.mb-4 > button::before {
    content: "BACK";
    color: var(--mg-text);
    font-size: .76rem;
    font-weight: 900;
    letter-spacing: .08em;
  }

  #dorm-modal .gate-processing-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "header"
      "meta"
      "assignment"
      "phase"
      "load"
      "footer";
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 1rem);
    gap: .55rem;
    overflow-y: auto;
    scrollbar-gutter: stable;
  }

  #dorm-modal #modal-phase-section[style*="display: none"] + #modal-load-section,
  #dorm-modal #modal-phase-section[style*="display:none"] + #modal-load-section {
    grid-column: 1;
    width: 100%;
    max-width: 100%;
  }

  #dorm-modal .gate-airman-location-grid,
  .gate-airman-location-grid,
  .gate-edit-record-grid,
  #dorm-edit-form,
  .gate-processing-edit-workspace__form {
    grid-template-columns: minmax(0, 1fr);
  }

  #dorm-modal .gate-airman-location-grid > button {
    width: 100%;
  }

  #dorm-modal #modal-phase-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #dorm-modal #modal-load-section > .flex.items-center.justify-center.gap-4 {
    grid-template-columns: repeat(2, minmax(2.1rem, .58fr)) minmax(4.45rem, 1.45fr) repeat(2, minmax(2.1rem, .58fr));
    gap: .28rem;
  }

  #dorm-edit-form > .flex.gap-2.pt-3,
  .gate-processing-edit-workspace__footer,
  #dorm-edit-form .prc-dorm-edit-actions {
    grid-column: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #dorm-edit-form .prc-dorm-edit-actions > button,
  #reopen-dorm-btn {
    width: 100%;
    min-width: 0;
  }

  .mg-skeleton-viewport {
    grid-template-columns: 1fr;
    min-height: 320px;
    padding: .75rem;
  }

  body.login-page {
    align-items: flex-start;
    padding: calc(var(--mg-banner-h) + 1rem + env(safe-area-inset-top)) .75rem max(1rem, env(safe-area-inset-bottom));
  }

  .login-shell {
    width: 100%;
    max-width: 100%;
  }

  .login-card,
  .login-card-surface {
    padding: 1.1rem;
    border-radius: var(--mg-radius-lg);
  }

  .login-title {
    font-size: clamp(3rem, 18vw, 4.4rem);
  }

  .login-identity-strip {
    grid-template-columns: 1fr;
    border-radius: var(--mg-radius-md);
  }

  .login-identity-strip span:last-child {
    padding: .45rem 0 0;
    border-left: 0;
    border-top: 1px solid var(--mg-border-soft);
  }

  body.fullscreen-board #page-board .gate-metrics-container,
  body.gate-fullscreen-board-active #page-board .gate-metrics-container {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.fullscreen-board #page-board .gate-active-buses-block,
  body.gate-fullscreen-board-active #page-board .gate-active-buses-block {
    grid-template-columns: 1fr;
  }

  body.fullscreen-board #page-board #active-buses .prc-bus-card,
  body.fullscreen-board #page-board #active-buses .gate-component-active-bus-card,
  body.gate-fullscreen-board-active #page-board #active-buses .prc-bus-card,
  body.gate-fullscreen-board-active #page-board #active-buses .gate-component-active-bus-card {
    flex-basis: 100%;
    width: 100%;
    max-width: 100%;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  :root {
    --mg-banner-h: 22px;
    --mg-nav-h: 50px;
  }

  .page,
  body.gate-app-shell-ready .page.active {
    padding-top: calc(var(--mg-shell-top) + .5rem);
  }

  #page-board .metric-card,
  #page-squadron .gate-squadron-metric {
    min-height: 72px;
    padding-block: .55rem;
  }

  #page-board .metric-value,
  .gate-squadron-metric-value {
    font-size: clamp(1.45rem, 5.8vh, 2rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto;
    transition-duration: .001ms;
    animation-duration: .001ms;
    animation-iteration-count: 1;
  }

  .mg-skeleton-viewport::before {
    animation: none;
  }
}

@media print {
  .security-banner-fixed,
  .app-nav,
  .command-header-bar,
  #gate-mobile-menu-scrim,
  #gate-mobile-nav-sheet {
    display: none;
  }

  body,
  .page,
  .surface,
  .metric-card,
  .dorm-card,
  .gate-dorm-card,
  .proc-card {
    background: #fff;
    color: #000;
    box-shadow: none;
    backdrop-filter: none;
  }

  .page,
  .page.active {
    display: block;
    width: 100%;
    max-width: none;
    padding: 0;
  }
}

/* --------------------------------------------------------------------------
   15. PRE-CONSOLIDATION RESPONSIVE CONTRACT RESTORATION
   These contracts preserve accepted GATE behavior that existed immediately
   before the September 2026 stylesheet consolidation. They remain inside the
   single canonical visual asset; no retired stylesheet is reactivated.
   -------------------------------------------------------------------------- */

@media (any-pointer: coarse) and (min-width: 768px) and (max-width: 1366px) and (min-height: 561px) {
  html {
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
  }

  body.gate-app-shell-ready[data-gate-active-page='processing'] {
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow-x: hidden;
    overflow-y: hidden;
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
  }

  .security-banner-fixed,
  .app-nav,
  .app-nav.command-header-bar,
  .command-header-bar {
    position: fixed;
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }

  body.gate-app-shell-ready[data-gate-active-page='processing'] #page-processing.active {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-x: none;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scroll-padding-top: calc(var(--mg-shell-top) + .75rem);
    scroll-padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  body.gate-app-shell-ready[data-gate-active-page='processing'] #page-processing.active > .px-4.py-3.flex-shrink-0 {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }

  body.gate-app-shell-ready[data-gate-active-page='processing'] #page-processing.active #proc-dorm-grid {
    flex: 1 0 auto;
    width: 100%;
    min-width: 0;
  }

  #gate-mobile-nav-sheet {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  #page-processing .proc-card:hover {
    transform: none;
  }

  #dorm-modal.confirm-overlay:not(.hidden) {
    align-items: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-top: max(.75rem, env(safe-area-inset-top));
    padding-bottom: max(.75rem, env(safe-area-inset-bottom));
  }

  #dorm-modal .gate-processing-workspace {
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  #dorm-modal .gate-processing-workspace__header,
  #dorm-modal .gate-processing-workspace__footer {
    position: sticky;
    z-index: 2;
    background: var(--mg-surface-strong);
  }

  #dorm-modal .gate-processing-workspace__header {
    top: 0;
  }

  #dorm-modal .gate-processing-workspace__footer {
    bottom: 0;
  }

  #dorm-modal.confirm-overlay:not(.hidden) .modal-content > .flex.justify-between.items-center.mb-4 > button,
  #dorm-modal .gate-processing-workspace__header button,
  #dorm-modal .gate-processing-workspace__footer button {
    min-width: 44px;
    min-height: 44px;
  }
}

@media (max-height: 800px) and (min-width: 761px) {
  #dorm-modal .gate-processing-workspace {
    gap: .5rem .75rem;
    padding: .72rem;
  }

  #dorm-modal .gate-processing-workspace__header {
    min-height: 3.2rem;
    padding: .48rem .68rem;
  }

  #dorm-modal #modal-dorm-name {
    font-size: clamp(1.7rem, 3vw, 2.2rem);
  }

  #dorm-modal .gate-processing-workspace__assignment,
  #dorm-modal .gate-processing-workspace__phase,
  #dorm-modal .gate-processing-workspace__load {
    padding: .58rem;
  }

  #dorm-modal .phase-btn {
    min-height: 2.3rem;
    padding: .42rem .5rem;
    font-size: .7rem;
  }
}

@media (max-width: 900px), (pointer: coarse) and (max-width: 1024px) {
  #page-airport,
  #page-input,
  #page-processing,
  #page-archives {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  #page-input > .flex-shrink-0.px-4.py-3,
  #page-input > .flex-shrink-0.border-t {
    padding-left: 0;
    padding-right: 0;
  }

  #page-input > .flex-shrink-0.px-4.py-3 > .flex {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: .75rem;
  }

  #wg-batch-input,
  #init-wg-btn {
    min-height: 46px;
  }

  #init-wg-btn {
    width: 100%;
  }

  #receiving-windows-panel,
  #archive-receiving-windows-panel {
    grid-template-columns: minmax(0, 1fr);
    gap: .625rem;
  }

  #receiving-windows-panel input,
  #archive-receiving-windows-panel input {
    min-height: 44px;
    font-size: .92rem;
  }

  #batch-grid-wrapper {
    padding: .625rem 0;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  #batch-grid-wrapper > div {
    min-width: 860px;
    padding-bottom: .625rem;
  }

  #batch-grid-wrapper .sticky {
    top: 0;
    z-index: 3;
  }

  #batch-rows-container input,
  #batch-rows-container select,
  #batch-rows-container button {
    min-height: 42px;
    font-size: .88rem;
  }

  #page-processing > .px-4.py-3,
  #page-processing > .px-4.py-3.flex-shrink-0 {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: .625rem;
    padding-left: 0;
    padding-right: 0;
  }

  #page-processing > .px-4.py-3 button,
  #page-processing #closeout-btn {
    width: 100%;
    min-height: 48px;
  }

  #page-archives .max-w-3xl {
    width: 100%;
    max-width: none;
  }

  .gate-archive-toolbar,
  .gate-archive-record-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .gate-archive-search-wrap,
  #gate-archive-search,
  .gate-archive-clear-search {
    width: 100%;
  }

  .gate-archive-record-stats {
    justify-content: flex-start;
  }
}

@media (hover: hover) and (pointer: fine) and (min-width: 768px) and (max-width: 1279px) {
  #main-nav-menu.nav-group-left,
  #nav-links.nav-group-left,
  .app-nav .nav-group-left {
    flex-flow: row nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-gutter: stable;
  }

  #main-nav-menu.nav-group-left > .nav-btn,
  #nav-links.nav-group-left > .nav-btn,
  .app-nav .nav-group-left > .nav-btn {
    flex: 0 0 auto;
  }
}

