/* ============================================================================
   Sentinel — design system + application styles.

   Structure
     1.  Design tokens (light) and the dark override
     2.  Reset & base elements
     3.  Primitives: buttons, fields, badges, cards, tables, menus, dialogs
     4.  App shell: sidebar, topbar, main
     5.  Screens
     6.  Copilot
     7.  Responsive
     8.  Print — the field-form stylesheet
   ==========================================================================*/

/* ---------------------------------------------------------------------------
   1. TOKENS
   Status hues are chosen to stay separable under deuteranopia/protanopia:
   the "good" tone is a teal-leaning green and the "bad" tone a red with a
   distinctly lower lightness, and every status is *also* carried by a text
   label or glyph — colour is never the sole signal.
   ------------------------------------------------------------------------*/
:root {
  color-scheme: light;

  /* Surfaces & text */
  --bg:            #f5f7f9;
  --surface:       #ffffff;
  --surface-2:     #f1f4f7;
  --surface-3:     #e6ebf0;
  --surface-inset: #fafbfc;
  --border:        #dde3ea;
  --border-strong: #c3ccd6;
  --text:          #0f151c;
  --text-2:        #4a5560;
  --text-3:        #6c7783;
  --text-on-brand: #ffffff;

  /* Brand */
  --brand:         #1a4a80;
  --brand-hover:   #143c6a;
  --brand-active:  #102f53;
  --brand-soft:    #e9f0f8;
  --brand-soft-2:  #d5e3f2;
  --brand-border:  #b3cbe4;
  --brand-text:    #1a4a80;

  /* Status */
  --ok:            #0e6f55;
  --ok-soft:       #e2f4ee;
  --ok-border:     #9ed5c3;
  --warn:          #91560a;
  --warn-soft:     #fdf1dd;
  --warn-border:   #e9c78d;
  --danger:        #b02a30;
  --danger-soft:   #fdeced;
  --danger-border: #edb0b3;
  --info:          #1a4a80;
  --info-soft:     #e9f0f8;
  --info-border:   #b3cbe4;
  --neutral:       #5c6772;
  --neutral-soft:  #eef1f4;
  --neutral-border:#d5dce3;

  /* Chart ink */
  --chart-line:    #1a4a80;
  --chart-point:   #1a4a80;
  --chart-grid:    #dde3ea;
  --chart-mean:    #0e6f55;
  --chart-1sd:     #cfd8e2;
  --chart-2sd:     #e9c78d;
  --chart-3sd:     #edb0b3;
  --chart-flag:    #b02a30;

  /* Spacing scale (4px base) */
  --sp-0: 0;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;
  --sp-9: 48px;
  --sp-10: 64px;
  --sp-11: 80px;
  --sp-12: 112px;

  /* Radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-full: 999px;

  /* Elevation */
  --sh-1: 0 1px 2px rgba(15, 21, 28, .05), 0 1px 1px rgba(15, 21, 28, .03);
  --sh-2: 0 2px 6px rgba(15, 21, 28, .07), 0 1px 2px rgba(15, 21, 28, .04);
  --sh-3: 0 8px 24px rgba(15, 21, 28, .10), 0 2px 6px rgba(15, 21, 28, .05);
  --sh-4: 0 20px 48px rgba(15, 21, 28, .16), 0 4px 12px rgba(15, 21, 28, .08);

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs:   11.5px;
  --fs-sm:   12.5px;
  --fs-base: 14px;
  --fs-md:   15.5px;
  --fs-lg:   18px;
  --fs-xl:   22px;
  --fs-2xl:  28px;
  --fs-3xl:  36px;
  --fs-4xl:  46px;

  --nav-w: 244px;
  --topbar-h: 60px;
  --dur: 180ms;
  --ease: cubic-bezier(.2, .7, .3, 1);
}

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

  --bg:            #0c1014;
  --surface:       #151b22;
  --surface-2:     #1b232c;
  --surface-3:     #232d38;
  --surface-inset: #10161c;
  --border:        #29323d;
  --border-strong: #3b4653;
  --text:          #e9eef4;
  --text-2:        #adbac7;
  --text-3:        #8b98a6;
  --text-on-brand: #08111c;

  --brand:         #78b0e8;
  --brand-hover:   #96c3f0;
  --brand-active:  #b0d2f5;
  --brand-soft:    #142334;
  --brand-soft-2:  #1b3048;
  --brand-border:  #2f4c6d;
  --brand-text:    #9cc6ef;

  --ok:            #55cfa8;
  --ok-soft:       #0e2a23;
  --ok-border:     #1f5a49;
  --warn:          #f0b45e;
  --warn-soft:     #2c2114;
  --warn-border:   #5c4523;
  --danger:        #f28b8f;
  --danger-soft:   #2d1619;
  --danger-border: #5e2a2f;
  --info:          #78b0e8;
  --info-soft:     #142334;
  --info-border:   #2f4c6d;
  --neutral:       #97a4b2;
  --neutral-soft:  #1c242d;
  --neutral-border:#333d49;

  --chart-line:    #78b0e8;
  --chart-point:   #9cc6ef;
  --chart-grid:    #29323d;
  --chart-mean:    #55cfa8;
  --chart-1sd:     #3b4653;
  --chart-2sd:     #6d5227;
  --chart-3sd:     #6e3438;
  --chart-flag:    #f28b8f;

  --sh-1: 0 1px 2px rgba(0, 0, 0, .40);
  --sh-2: 0 2px 6px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .30);
  --sh-3: 0 8px 24px rgba(0, 0, 0, .50), 0 2px 6px rgba(0, 0, 0, .35);
  --sh-4: 0 20px 48px rgba(0, 0, 0, .60), 0 4px 12px rgba(0, 0, 0, .40);
}

/* ---------------------------------------------------------------------------
   2. RESET & BASE
   ------------------------------------------------------------------------*/
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5 { margin: 0; font-weight: 600; line-height: 1.25; letter-spacing: -0.011em; }
h1 { font-size: var(--fs-2xl); letter-spacing: -0.021em; }
h2 { font-size: var(--fs-xl); letter-spacing: -0.016em; }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p  { margin: 0 0 var(--sp-3); }
p:last-child { margin-bottom: 0; }

a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { margin: 0; padding-left: 1.25em; }

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

svg { display: block; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
[data-theme="dark"] :focus-visible { outline-color: var(--brand); }

::selection { background: var(--brand-soft-2); color: var(--text); }

.skip-link {
  position: absolute; left: var(--sp-3); top: -60px; z-index: 200;
  background: var(--surface); color: var(--text);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); box-shadow: var(--sh-3);
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: var(--sp-3); text-decoration: none; }

.noscript { max-width: 40rem; margin: 15vh auto; padding: var(--sp-6); text-align: center; }

/* Utility */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted   { color: var(--text-3); }
.dim     { color: var(--text-2); }
.mono    { font-family: var(--font-mono); font-size: .93em; font-variant-numeric: tabular-nums; }
.nums    { font-variant-numeric: tabular-nums; }
.center  { text-align: center; }
.right   { text-align: right; }
.nowrap  { white-space: nowrap; }
.grow    { flex: 1 1 auto; min-width: 0; }
.row     { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap{ display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.col     { display: flex; flex-direction: column; gap: var(--sp-3); }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); }
.stack > * + * { margin-top: var(--sp-4); }
.eyebrow {
  font-size: var(--fs-xs); font-weight: 650; letter-spacing: .085em;
  text-transform: uppercase; color: var(--text-3);
}

/* Boot splash */
.boot {
  min-height: 100vh; display: grid; place-content: center;
  justify-items: center; gap: var(--sp-4); color: var(--text-3);
}
.boot-mark {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--brand);
  animation: spin 900ms linear infinite;
}
.boot-text { font-size: var(--fs-sm); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
   3. PRIMITIVES
   ------------------------------------------------------------------------*/

/* --- Buttons --- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--sp-2);
  font: inherit; font-size: var(--fs-base); font-weight: 550;
  line-height: 1.2;
  padding: 8px 14px;
  min-height: 36px;
  border-radius: var(--r-sm);
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--sh-1);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              transform var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-2); text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; box-shadow: none; }

.btn-primary {
  --btn-bg: var(--brand); --btn-fg: var(--text-on-brand); --btn-bd: var(--brand);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-quiet { --btn-bg: transparent; --btn-bd: var(--border); box-shadow: none; }
.btn-danger { --btn-bg: var(--surface); --btn-fg: var(--danger); --btn-bd: var(--danger-border); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { min-height: 29px; padding: 4px 10px; font-size: var(--fs-sm); }
.btn-lg { min-height: 46px; padding: 12px 24px; font-size: var(--fs-md); border-radius: var(--r-md); }
.btn-block { width: 100%; }
.btn-multiline {
  white-space: normal; text-align: center; line-height: 1.35;
  padding-top: 10px; padding-bottom: 10px; height: auto;
}
.btn-icon { padding: 0; width: 34px; min-height: 34px; }
.btn-icon.btn-sm { width: 28px; min-height: 28px; }

.btn[data-busy="true"] { position: relative; color: transparent !important; pointer-events: none; }
.btn[data-busy="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent;
  color: var(--text-2);
  animation: spin 700ms linear infinite;
}
.btn-primary[data-busy="true"]::after { color: var(--text-on-brand); }

.link-btn {
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
  color: var(--brand-text); text-decoration: underline; text-underline-offset: 2px;
}

/* --- Fields --- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .label {
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-2);
}
.hint { font-size: var(--fs-sm); color: var(--text-3); }
.field-error { font-size: var(--fs-sm); color: var(--danger); font-weight: 550; }

.input, .select, .textarea {
  font: inherit; font-size: var(--fs-base);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 8px 11px;
  min-height: 36px;
  width: 100%;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft-2);
}
.input:disabled, .textarea:disabled, .select:disabled {
  background: var(--surface-2); color: var(--text-3); cursor: not-allowed;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
.select {
  appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%236c7783' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
[data-theme="dark"] .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%238b98a6' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.input-sm { min-height: 29px; padding: 3px 8px; font-size: var(--fs-sm); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
.form-grid .span-2 { grid-column: 1 / -1; }

/* --- Badges & chips --- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-xs); font-weight: 650; letter-spacing: .01em;
  padding: 2px 8px; border-radius: var(--r-full);
  border: 1px solid var(--neutral-border);
  background: var(--neutral-soft); color: var(--neutral);
  white-space: nowrap;
}
.badge::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex: none;
}
.badge-plain::before { display: none; }
.badge-ok      { background: var(--ok-soft);      color: var(--ok);      border-color: var(--ok-border); }
.badge-warn    { background: var(--warn-soft);    color: var(--warn);    border-color: var(--warn-border); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: var(--danger-border); }
.badge-info    { background: var(--info-soft);    color: var(--info);    border-color: var(--info-border); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-xs); font-weight: 600;
  padding: 1px 7px; border-radius: var(--r-xs);
  background: var(--surface-2); color: var(--text-3);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip-phase { font-family: var(--font); letter-spacing: .02em; }

.pill-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 700;
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid var(--danger-border);
}

/* --- Cards & panels --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card-pad { padding: var(--sp-5); }
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--sp-4); padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: var(--fs-md); }
.card-body { padding: var(--sp-5); }
.card-body-flush { padding: 0; }
.card-foot {
  padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border);
  background: var(--surface-inset);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

.panel {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-4);
}

.callout {
  border: 1px solid var(--info-border); background: var(--info-soft);
  border-radius: var(--r-md); padding: var(--sp-4);
  display: flex; gap: var(--sp-3);
}
.callout-warn { border-color: var(--warn-border); background: var(--warn-soft); }
.callout-danger { border-color: var(--danger-border); background: var(--danger-soft); }
.callout-ok { border-color: var(--ok-border); background: var(--ok-soft); }
.callout h4 { font-size: var(--fs-base); margin-bottom: 2px; }
.callout p { font-size: var(--fs-sm); color: var(--text-2); }

/* --- Stat tiles --- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: var(--sp-3); }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-4);
  display: flex; flex-direction: column; gap: 2px;
  text-align: left; box-shadow: var(--sh-1);
}
a.stat, button.stat { cursor: pointer; font: inherit; color: inherit; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
a.stat:hover, button.stat:hover { border-color: var(--border-strong); box-shadow: var(--sh-2); text-decoration: none; }
.stat-label { font-size: var(--fs-xs); font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.stat-value { font-size: var(--fs-2xl); font-weight: 620; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat-note { font-size: var(--fs-sm); color: var(--text-3); }
.stat-value.is-warn { color: var(--warn); }
.stat-value.is-danger { color: var(--danger); }
.stat-value.is-ok { color: var(--ok); }

/* --- Tables --- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.tbl th {
  text-align: left; font-size: var(--fs-xs); font-weight: 650;
  letter-spacing: .06em; text-transform: uppercase; color: var(--text-3);
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border);
  white-space: nowrap; background: var(--surface-inset);
}
.tbl td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: var(--surface-inset); }
.tbl .col-num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Progress --- */
.bar { height: 6px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--brand); transition: width 420ms var(--ease); }
.bar.is-ok > i { background: var(--ok); }
.bar.is-warn > i { background: var(--warn); }
.bar.is-danger > i { background: var(--danger); }

/* --- Menus --- */
.menu-wrap { position: relative; }
.menu {
  position: absolute; z-index: 60; top: calc(100% + 6px); right: 0;
  min-width: 232px; padding: var(--sp-2);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--sh-3);
}
.menu[hidden] { display: none; }
.menu-label {
  font-size: var(--fs-xs); font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-3);
  padding: var(--sp-2) var(--sp-3) var(--sp-1);
}
.menu-item {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; text-align: left; font: inherit; font-size: var(--fs-base);
  padding: 8px var(--sp-3); border: 0; border-radius: var(--r-sm);
  background: none; color: var(--text); cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); text-decoration: none; }
.menu-item small { display: block; color: var(--text-3); font-size: var(--fs-xs); font-weight: 400; }
.menu-item strong { font-weight: 550; }
.menu-sep { height: 1px; background: var(--border); margin: var(--sp-2) 0; }

/* --- Dialog --- */
dialog.modal {
  padding: 0; border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--sh-4);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
}
dialog.modal::backdrop { background: rgba(9, 14, 20, .5); backdrop-filter: blur(2px); }
[data-theme="dark"] dialog.modal::backdrop { background: rgba(0, 0, 0, .66); }
.modal-head { padding: var(--sp-5) var(--sp-5) var(--sp-3); }
.modal-head h3 { font-size: var(--fs-lg); }
.modal-head p { color: var(--text-2); font-size: var(--fs-sm); margin-top: var(--sp-1); }
.modal-body { padding: 0 var(--sp-5) var(--sp-5); max-height: 62vh; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border);
  background: var(--surface-inset); border-radius: 0 0 var(--r-lg) var(--r-lg);
}
.modal-wide { width: min(880px, calc(100vw - 32px)); }

/* --- Toasts --- */
.toasts {
  position: fixed; z-index: 300; bottom: var(--sp-5); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--sp-2);
  align-items: center; pointer-events: none;
  width: min(440px, calc(100vw - 32px));
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: var(--sp-3);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--neutral);
  border-radius: var(--r-md); box-shadow: var(--sh-3);
  padding: var(--sp-3) var(--sp-4); font-size: var(--fs-base);
  width: 100%;
}
.toast-ok { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--brand); }
.toast .toast-close { margin-left: auto; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 240ms var(--ease); }
  @keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
}

/* --- Loading / empty / error states --- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  border-radius: var(--r-sm);
  min-height: 14px;
}
@media (prefers-reduced-motion: no-preference) {
  .skeleton { animation: shimmer 1.4s ease-in-out infinite; }
  @keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
}
.skeleton-stack { display: flex; flex-direction: column; gap: var(--sp-3); }

.state {
  display: grid; justify-items: center; text-align: center;
  gap: var(--sp-3); padding: var(--sp-9) var(--sp-5);
  color: var(--text-2);
}
.state h3 { color: var(--text); }
.state p { max-width: 46ch; font-size: var(--fs-base); }
.state-icon {
  width: 44px; height: 44px; border-radius: var(--r-md);
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-3);
}
.state-error .state-icon { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger); }

.inline-spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--border-strong); border-top-color: var(--brand);
  animation: spin 700ms linear infinite;
}
@media (prefers-reduced-motion: reduce) { .inline-spinner, .boot-mark { animation-duration: 2.4s; } }

/* ---------------------------------------------------------------------------
   4. APP SHELL
   ------------------------------------------------------------------------*/
.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh; }

.nav {
  grid-row: 1 / -1;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.nav-brand {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4);
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.nav-brand:hover { text-decoration: none; }
.brand-mark { flex: none; }
.brand-name { display: block; font-size: var(--fs-md); font-weight: 640; letter-spacing: -.015em; }
.brand-sub {
  display: block; font-size: var(--fs-xs); color: var(--text-3); line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.nav-list { list-style: none; margin: 0; padding: var(--sp-3) var(--sp-3); display: flex; flex-direction: column; gap: 1px; }
.nav-section { padding: var(--sp-4) var(--sp-3) var(--sp-1); }
.nav-link {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 7px var(--sp-3); border-radius: var(--r-sm);
  color: var(--text-2); font-size: var(--fs-base); font-weight: 520;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link .ico { flex: none; color: var(--text-3); }
.nav-link[aria-current="page"] {
  background: var(--brand-soft); color: var(--brand-text); font-weight: 600;
}
.nav-link[aria-current="page"] .ico { color: var(--brand-text); }
.nav-link .pill-count { margin-left: auto; }

.nav-foot { margin-top: auto; padding: var(--sp-3); border-top: 1px solid var(--border); }
.nav-user { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); min-width: 0; }
.avatar {
  flex: none; width: 30px; height: 30px; border-radius: var(--r-full);
  background: var(--brand-soft); color: var(--brand-text);
  display: grid; place-items: center;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .02em;
  border: 1px solid var(--brand-border);
}
.nav-user-name { display: block; font-size: var(--fs-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-user-role { display: block; font-size: var(--fs-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--topbar-h);
  padding: var(--sp-3) var(--sp-6);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  font-size: var(--fs-md); font-weight: 620; letter-spacing: -.012em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-sub { font-size: var(--fs-sm); color: var(--text-3); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }
.nav-toggle { display: none; }

main.main { padding: var(--sp-6); padding-bottom: var(--sp-11); max-width: 1360px; width: 100%; }
/* Clear the fixed Copilot FAB so it never occludes content in the bottom-right.
   FAB is 46px tall at --sp-5 from the edge; reserve height + gutter + breathing room. */
main.main > * { scroll-margin-bottom: 96px; }
main.main::after { content: ""; display: block; height: 84px; pointer-events: none; }
/* Right-hand rails sit under the FAB on tall pages — pad them individually so
   their last card's text clears it even when the page itself is not scrolled. */
.qc-layout > *:last-child,
.month-layout > *:last-child { padding-bottom: 84px; }
.page-head { margin-bottom: var(--sp-6); }
.page-head h1 { font-size: var(--fs-xl); }
.page-head p { color: var(--text-2); margin-top: var(--sp-2); max-width: 74ch; }

.section { margin-top: var(--sp-7); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.section-head h2 { font-size: var(--fs-lg); }

.backdrop-scrim { display: none; }

/* ---------------------------------------------------------------------------
   5. SCREENS
   ------------------------------------------------------------------------*/

/* --- 5a. Auth / marketing --- */
.marketing { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.mk-nav {
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6); border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.mk-nav .grow { display: flex; }
.mk-main { flex: 1 1 auto; }
.mk-hero {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: var(--sp-10); align-items: center;
  max-width: 1180px; margin: 0 auto; padding: var(--sp-11) var(--sp-6);
}
.mk-hero h1 { font-size: var(--fs-4xl); letter-spacing: -.028em; line-height: 1.08; }
.mk-lede { font-size: var(--fs-md); color: var(--text-2); margin-top: var(--sp-5); max-width: 54ch; line-height: 1.62; }
.mk-cta { display: flex; gap: var(--sp-3); margin-top: var(--sp-7); flex-wrap: wrap; }
.mk-points { list-style: none; padding: 0; margin: var(--sp-7) 0 0; display: grid; gap: var(--sp-3); }
.mk-points li { display: flex; gap: var(--sp-3); align-items: flex-start; font-size: var(--fs-base); color: var(--text-2); }
.mk-points .ico { color: var(--ok); flex: none; margin-top: 2px; }

.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--sh-3); padding: var(--sp-7); }
.auth-card h2 { font-size: var(--fs-xl); }
.auth-card .field + .field { margin-top: var(--sp-4); }
.auth-alt { margin-top: var(--sp-5); font-size: var(--fs-sm); color: var(--text-2); text-align: center; }
.auth-divider { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-5) 0; color: var(--text-3); font-size: var(--fs-sm); }
.auth-divider::before, .auth-divider::after { content: ""; height: 1px; background: var(--border); flex: 1; }

.mk-band { border-top: 1px solid var(--border); background: var(--surface); }
.mk-band-inner { max-width: 1180px; margin: 0 auto; padding: var(--sp-10) var(--sp-6); }
.mk-grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: var(--sp-6); }
.mk-feature h3 { font-size: var(--fs-md); margin-bottom: var(--sp-2); }
.mk-feature p { color: var(--text-2); font-size: var(--fs-base); }
.mk-feature .ico-box {
  width: 36px; height: 36px; border-radius: var(--r-sm); margin-bottom: var(--sp-4);
  display: grid; place-items: center; background: var(--brand-soft);
  color: var(--brand-text); border: 1px solid var(--brand-border);
}
.mk-foot { border-top: 1px solid var(--border); padding: var(--sp-6); text-align: center; color: var(--text-3); font-size: var(--fs-sm); }

/* --- 5b. Year Wheel --- */
.wheel-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px;
  gap: var(--sp-7); align-items: start;
}
.wheel-stage {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); box-shadow: var(--sh-1);
  padding: var(--sp-5); position: relative;
}
.wheel-svg { width: 100%; height: auto; max-width: 620px; margin: 0 auto; overflow: visible; }

.seg { cursor: pointer; }
.seg-shape {
  transition: fill var(--dur) var(--ease), stroke var(--dur) var(--ease), transform 220ms var(--ease);
  transform-origin: 300px 300px;
}
.seg:hover .seg-shape { filter: brightness(1.03); }
[data-theme="dark"] .seg:hover .seg-shape { filter: brightness(1.22); }
.seg:focus { outline: none; }
.seg:focus-visible .seg-focus { opacity: 1; }
.seg-focus { opacity: 0; pointer-events: none; }
.seg-label { font-size: 13px; font-weight: 640; letter-spacing: .06em; fill: var(--text-2); pointer-events: none; }
.seg-num   { font-size: 11px; font-weight: 700; fill: var(--text-3); pointer-events: none; }
.seg.is-current .seg-label { fill: var(--brand-text); font-size: 14px; }
.seg.is-current .seg-num { fill: var(--brand-text); }
.seg-annual .seg-label { fill: var(--text-2); }

.wheel-hub-year { font-size: 13px; font-weight: 650; letter-spacing: .12em; fill: var(--text-3); }
.wheel-hub-pct { font-size: 44px; font-weight: 600; letter-spacing: -.02em; fill: var(--text); }
.wheel-hub-note { font-size: 12px; fill: var(--text-3); }
.wheel-hub-month { font-size: 13px; font-weight: 620; fill: var(--brand-text); }

@media (prefers-reduced-motion: no-preference) {
  .wheel-animate .seg-shape,
  .wheel-animate .seg-arc { opacity: 0; animation: seg-in 520ms var(--ease) forwards; }
  .wheel-animate .seg-label,
  .wheel-animate .seg-num { opacity: 0; animation: fade-in 380ms var(--ease) forwards; animation-delay: 420ms; }
  .wheel-animate .wheel-hub { opacity: 0; animation: fade-in 460ms var(--ease) 520ms forwards; }
  @keyframes seg-in { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }
  @keyframes fade-in { to { opacity: 1; } }
}

.wheel-legend { display: flex; flex-wrap: wrap; gap: var(--sp-4); justify-content: center; margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; border: 1px solid rgba(0,0,0,.12); flex: none; }
[data-theme="dark"] .legend-swatch { border-color: rgba(255,255,255,.16); }

.sys-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.sys-row {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  color: var(--text); text-align: left; width: 100%;
  background: none; border-left: 0; border-right: 0; border-top: 0;
  font: inherit; cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.sys-row:last-child { border-bottom: 0; }
.sys-row:hover { background: var(--surface-inset); text-decoration: none; }
.sys-row.is-current { background: var(--brand-soft); }
.sys-month { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .05em; color: var(--text-3); text-transform: uppercase; }
.sys-row.is-current .sys-month { color: var(--brand-text); }
.sys-name { display: block; font-size: var(--fs-base); font-weight: 550; line-height: 1.35; }
.sys-meta { display: block; font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }

/* --- 5c. This Month --- */
.month-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--sp-6); align-items: start; }
.scope-box {
  border-left: 3px solid var(--brand-border); background: var(--surface-inset);
  padding: var(--sp-3) var(--sp-4); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  color: var(--text-2); font-size: var(--fs-base); line-height: 1.6;
}
.section-title {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  background: var(--surface-inset); border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-2);
  position: sticky; top: var(--topbar-h); z-index: 8;
}

.check-item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto auto;
  gap: var(--sp-3) var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.check-item:last-child { border-bottom: 0; }
.check-item.has-finding { background: var(--danger-soft); }
[data-theme="dark"] .check-item.has-finding { background: color-mix(in srgb, var(--danger-soft) 70%, transparent); }
.check-num {
  font-size: var(--fs-sm); font-weight: 700; color: var(--text-3);
  font-variant-numeric: tabular-nums; padding-top: 5px;
}
.check-text { font-size: var(--fs-base); line-height: 1.5; }
.check-tags { display: flex; gap: var(--sp-2); margin-top: 6px; flex-wrap: wrap; }

.yna { display: flex; gap: 4px; }
.yna input { position: absolute; opacity: 0; width: 0; height: 0; }
.yna label {
  display: grid; place-items: center;
  min-width: 38px; height: 32px; padding: 0 8px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text-2);
  font-size: var(--fs-sm); font-weight: 650; cursor: pointer;
  transition: all var(--dur) var(--ease);
  user-select: none;
}
.yna label:hover { background: var(--surface-2); }
.yna input:checked + label { border-width: 1.5px; font-weight: 700; }
.yna input[value="Y"]:checked + label { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.yna input[value="N"]:checked + label { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.yna input[value="NA"]:checked + label { background: var(--neutral-soft); color: var(--neutral); border-color: var(--neutral); }
.yna input:focus-visible + label { outline: 2px solid var(--brand); outline-offset: 2px; }

.initials-field { width: 74px; }
.initials-field input { text-transform: uppercase; text-align: center; letter-spacing: .08em; font-weight: 600; }

.finding {
  grid-column: 1 / -1;
  margin-top: var(--sp-2);
  border: 1px solid var(--danger-border); background: var(--surface);
  border-left: 3px solid var(--danger);
  border-radius: var(--r-sm); padding: var(--sp-3) var(--sp-4);
  display: flex; align-items: flex-start; gap: var(--sp-3); flex-wrap: wrap;
}
.finding .ico { color: var(--danger); flex: none; margin-top: 2px; }
.finding-title { font-size: var(--fs-sm); font-weight: 650; color: var(--danger); }
.finding-note { font-size: var(--fs-sm); color: var(--text-2); }
@media (prefers-reduced-motion: no-preference) {
  .finding { animation: finding-in 260ms var(--ease); }
  @keyframes finding-in { from { opacity: 0; transform: translateY(-4px); } }
}

.save-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-3); min-height: 20px; }
.save-status.is-saved { color: var(--ok); }
.save-status.is-error { color: var(--danger); }

.review-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-4); }

.sig-preview {
  font-family: "Segoe Script", "Bradley Hand", "Snell Roundhand", cursive;
  font-size: var(--fs-xl); color: var(--text);
  border-bottom: 1px solid var(--border-strong);
  padding: var(--sp-2) var(--sp-1); min-height: 44px;
}

/* --- 5d. Personnel --- */
.person-card { display: grid; gap: var(--sp-4); }
.track { display: flex; gap: 4px; align-items: center; }
.track-step {
  flex: 1 1 0; height: 6px; border-radius: var(--r-full);
  background: var(--surface-3); position: relative;
}
.track-step.is-done { background: var(--ok); }
.track-label { font-size: var(--fs-xs); color: var(--text-3); }

.comp-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.comp-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm);
  background: var(--surface-inset); border: 1px solid var(--border);
  flex-wrap: wrap;
}
.comp-row.is-due { border-color: var(--warn-border); background: var(--warn-soft); }
.comp-row.is-overdue { border-color: var(--danger-border); background: var(--danger-soft); }
.comp-label { font-size: var(--fs-sm); font-weight: 550; }
.comp-due { font-size: var(--fs-xs); color: var(--text-3); }

/* --- 5e. Instruments --- */
.cadence-group + .cadence-group { margin-top: var(--sp-4); }
.cadence-head {
  display: flex; align-items: center; gap: var(--sp-3);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-3);
  padding-bottom: var(--sp-2); border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-2);
}
.task-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto;
  gap: var(--sp-3); align-items: center;
  padding: var(--sp-2) 0;
}
.task-name { font-size: var(--fs-base); line-height: 1.4; }
.task-note { font-size: var(--fs-xs); color: var(--text-3); }
.task-row.is-overdue .task-name { font-weight: 600; }

.instrument-head { display: flex; align-items: flex-start; gap: var(--sp-4); flex-wrap: wrap; }
.instrument-title h3 { font-size: var(--fs-md); }
.instrument-meta { font-size: var(--fs-sm); color: var(--text-3); }
.is-out-of-service { opacity: .78; }

/* --- 5f. QC --- */
.qc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--sp-6); align-items: start; }
.lj-chart { width: 100%; height: auto; }
.lj-band-1 { fill: var(--chart-1sd); opacity: .30; }
.lj-band-2 { fill: var(--chart-2sd); opacity: .22; }
.lj-band-3 { fill: var(--chart-3sd); opacity: .20; }
.lj-grid { stroke: var(--chart-grid); stroke-width: 1; }
.lj-mean { stroke: var(--chart-mean); stroke-width: 1.5; stroke-dasharray: 6 4; }
.lj-axis-label { font-size: 10.5px; fill: var(--text-3); font-variant-numeric: tabular-nums; }
.lj-axis-title { font-size: 11px; fill: var(--text-3); font-weight: 600; }
.lj-line { fill: none; stroke: var(--chart-line); stroke-width: 1.6; stroke-linejoin: round; }
.lj-pt { fill: var(--surface); stroke: var(--chart-point); stroke-width: 1.8; cursor: pointer; transition: r var(--dur) var(--ease); }
.lj-pt:hover { r: 5.5; }
.lj-pt.is-flag { fill: var(--chart-flag); stroke: var(--chart-flag); }
.lj-pt.is-warn { fill: var(--warn); stroke: var(--warn); }
.lj-pt.is-involved { fill: var(--warn); stroke: var(--warn); }
.lj-pt.is-selected { stroke: var(--text); stroke-width: 2.6; }
.lj-pt:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.lj-flag-ring { fill: none; stroke: var(--chart-flag); stroke-width: 1.4; opacity: .5; }
@media (prefers-reduced-motion: no-preference) {
  .lj-flag-ring { animation: pulse-ring 2.4s ease-in-out infinite; }
  @keyframes pulse-ring { 0%,100% { opacity: .18; r: 9; } 50% { opacity: .62; r: 12; } }
}

.wg-verdict {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4); border-radius: var(--r-md);
  border: 1px solid var(--danger-border); background: var(--danger-soft);
}
.wg-rule {
  font-family: var(--font-mono); font-size: var(--fs-xl); font-weight: 700;
  color: var(--danger); letter-spacing: -.01em;
}
.wg-steps { list-style: none; padding: 0; margin: 0; counter-reset: wg; display: flex; flex-direction: column; gap: var(--sp-3); }
.wg-steps li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: var(--sp-3); font-size: var(--fs-base); line-height: 1.5; }
.wg-steps li::before {
  counter-increment: wg; content: counter(wg);
  width: 24px; height: 24px; border-radius: var(--r-full);
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-text);
  border: 1px solid var(--brand-border);
  font-size: var(--fs-xs); font-weight: 700;
}

/* --- 5g. Narrative --- */
.doc {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
  padding: var(--sp-9) var(--sp-10);
  max-width: 900px; margin: 0 auto;
}
.doc-head { text-align: center; padding-bottom: var(--sp-6); border-bottom: 2px solid var(--text); margin-bottom: var(--sp-7); }
.doc-lab { font-size: var(--fs-lg); font-weight: 650; letter-spacing: .01em; }
.doc-title { font-size: var(--fs-sm); font-weight: 650; letter-spacing: .12em; text-transform: uppercase; color: var(--text-2); margin-top: var(--sp-2); }
.doc-note { font-size: var(--fs-sm); color: var(--text-3); margin-top: var(--sp-2); }
.doc-section { margin-bottom: var(--sp-8); }
.doc-h {
  font-size: var(--fs-sm); font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-2);
  padding-bottom: var(--sp-2); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
}
.doc-body p { font-size: var(--fs-base); line-height: 1.72; margin-bottom: var(--sp-4); }
.doc-list { list-style: none; padding: 0; margin: 0; }
.doc-month { display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: var(--sp-4); padding: var(--sp-2) 0; border-bottom: 1px dotted var(--border); font-size: var(--fs-base); }
.doc-month:last-child { border-bottom: 0; }
.doc-month-name { font-weight: 650; }
.doc-events-month { font-weight: 650; margin: var(--sp-4) 0 var(--sp-2); font-size: var(--fs-base); }
.doc-event { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: var(--sp-4); padding: 3px 0; font-size: var(--fs-base); }
.doc-bullets { padding-left: 1.2em; }
.doc-bullets li { margin-bottom: var(--sp-2); line-height: 1.65; }
.doc-sigs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-8); margin-top: var(--sp-9); }
.sig-line { border-top: 1px solid var(--text); padding-top: var(--sp-2); margin-top: var(--sp-8); }
.sig-role { font-size: var(--fs-sm); font-weight: 600; }
.sig-name { font-size: var(--fs-sm); color: var(--text-2); }
.doc-edit-area { width: 100%; }

/* --- 5h. SOPs --- */
.sop-body {
  font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.7;
  white-space: pre-wrap; word-break: break-word;
  background: var(--surface-inset); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: var(--sp-5);
  max-height: 620px; overflow-y: auto;
}
.gap-mark {
  display: block; margin: var(--sp-3) 0; padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm); border-left: 3px solid var(--warn);
  background: var(--warn-soft); color: var(--text);
  font-family: var(--font); white-space: normal;
}
.gap-mark.sev-critical { border-left-color: var(--danger); background: var(--danger-soft); }
.gap-mark.sev-minor { border-left-color: var(--neutral); background: var(--neutral-soft); }
.gap-head { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-1); }
.gap-std { font-size: var(--fs-xs); font-weight: 650; color: var(--text-2); }
.gap-text { font-size: var(--fs-sm); color: var(--text); }
.gap-sugg { font-size: var(--fs-sm); color: var(--text-2); margin-top: var(--sp-2); padding-left: var(--sp-3); border-left: 2px solid var(--border-strong); }

/* --- 5i. Pricing / Why --- */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(266px, 1fr)); gap: var(--sp-5); align-items: stretch; }
.plan {
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-6); box-shadow: var(--sh-1);
}
.plan.is-featured { border-color: var(--brand); box-shadow: var(--sh-3); position: relative; }
.plan-flag {
  position: absolute; top: -11px; left: var(--sp-6);
  background: var(--brand); color: var(--text-on-brand);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 10px; border-radius: var(--r-full);
}
.plan-name { font-size: var(--fs-md); font-weight: 650; }
.plan-price { font-size: var(--fs-3xl); font-weight: 620; letter-spacing: -.03em; margin: var(--sp-3) 0 0; }
.plan-price small { font-size: var(--fs-base); font-weight: 500; color: var(--text-3); letter-spacing: 0; }
.plan-for { font-size: var(--fs-sm); color: var(--text-2); margin-top: var(--sp-2); min-height: 2.8em; }
.plan-features { list-style: none; padding: 0; margin: var(--sp-5) 0 var(--sp-6); display: grid; gap: var(--sp-3); }
.plan-features li { display: flex; gap: var(--sp-3); font-size: var(--fs-base); color: var(--text-2); align-items: flex-start; }
.plan-features .ico { color: var(--ok); flex: none; margin-top: 3px; }
.plan .btn { margin-top: auto; }

.value-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(272px, 1fr)); gap: var(--sp-5); }
.value-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-5); box-shadow: var(--sh-1); }
.value-card h3 { font-size: var(--fs-md); margin-bottom: var(--sp-2); }
.value-card p { color: var(--text-2); }
.value-card .ico-box {
  width: 34px; height: 34px; border-radius: var(--r-sm); margin-bottom: var(--sp-4);
  display: grid; place-items: center; background: var(--brand-soft);
  color: var(--brand-text); border: 1px solid var(--brand-border);
}
.faq dt { font-weight: 620; margin-top: var(--sp-5); }
.faq dd { margin: var(--sp-2) 0 0; color: var(--text-2); }

/* --- 5j. Corrective actions --- */
.ca-card { border-left: 3px solid var(--danger); }
.ca-card.is-closed { border-left-color: var(--ok); }
.ca-meta { font-size: var(--fs-sm); color: var(--text-3); }
.ca-field-label { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }

/* ---------------------------------------------------------------------------
   6. COPILOT
   ------------------------------------------------------------------------*/
.copilot-fab {
  position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 90;
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 52px; width: 52px; padding: 0; border-radius: var(--r-full);
  background: var(--brand); color: var(--text-on-brand);
  border: 1px solid var(--brand);
  box-shadow: var(--sh-3);
  font: inherit; font-size: var(--fs-base); font-weight: 600; cursor: pointer;
  overflow: hidden; white-space: nowrap;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease),
              width var(--dur) var(--ease), padding var(--dur) var(--ease);
}
/* Collapsed to a circle by default so it occludes as little content as possible;
   the label expands on hover/focus. Keeps it discoverable without covering text. */
.copilot-fab-label {
  max-width: 0; opacity: 0; overflow: hidden;
  transition: max-width var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.copilot-fab:hover, .copilot-fab:focus-visible {
  width: auto; padding: 0 18px;
}
.copilot-fab:hover .copilot-fab-label,
.copilot-fab:focus-visible .copilot-fab-label {
  max-width: 12ch; opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
  .copilot-fab, .copilot-fab > * { transition: none; }
}
.copilot-fab:hover { background: var(--brand-hover); }
.copilot-fab:active { transform: translateY(1px); }

.copilot {
  position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 95;
  width: min(390px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 100px));
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-lg); box-shadow: var(--sh-4);
  overflow: hidden;
}
@media (prefers-reduced-motion: no-preference) {
  .copilot { animation: copilot-in 220ms var(--ease); }
  @keyframes copilot-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }
}
.copilot-head {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border);
  background: var(--surface-inset);
}
.copilot-head h3 { font-size: var(--fs-base); }
.copilot-head p { font-size: var(--fs-xs); color: var(--text-3); }
.copilot-log { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); }
.cp-msg { display: flex; flex-direction: column; gap: var(--sp-2); max-width: 92%; }
.cp-msg.is-user { align-self: flex-end; align-items: flex-end; }
.cp-bubble {
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  font-size: var(--fs-base); line-height: 1.55;
  background: var(--surface-2); border: 1px solid var(--border);
}
.cp-msg.is-user .cp-bubble { background: var(--brand); color: var(--text-on-brand); border-color: var(--brand); }
.cp-actions { display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }
.cp-action {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-sm); font-weight: 550;
  padding: 5px 11px; border-radius: var(--r-full);
  background: var(--brand-soft); color: var(--brand-text);
  border: 1px solid var(--brand-border); cursor: pointer; font-family: inherit;
  text-align: left;
}
.cp-action:hover { background: var(--brand-soft-2); text-decoration: none; }
.copilot-form { display: flex; gap: var(--sp-2); padding: var(--sp-3); border-top: 1px solid var(--border); background: var(--surface-inset); }
.cp-suggests { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------------------------------------------------------------------------
   7. RESPONSIVE
   ------------------------------------------------------------------------*/
@media (max-width: 1180px) {
  .wheel-layout, .qc-layout, .month-layout { grid-template-columns: minmax(0, 1fr); }
  .mk-hero { grid-template-columns: minmax(0, 1fr); gap: var(--sp-8); padding: var(--sp-9) var(--sp-5); }
  .mk-hero h1 { font-size: var(--fs-3xl); }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: fixed; z-index: 120; left: 0; top: 0; bottom: 0;
    width: min(280px, 84vw); height: 100vh;
    transform: translateX(-102%);
    transition: transform 240ms var(--ease);
    box-shadow: var(--sh-4);
  }
  .app.nav-open .nav { transform: translateX(0); }
  .app.nav-open .backdrop-scrim {
    display: block; position: fixed; inset: 0; z-index: 110;
    background: rgba(9, 14, 20, .45);
  }
  .nav-toggle { display: inline-flex; }
  main.main { padding: var(--sp-4); }
  .topbar { padding: var(--sp-3) var(--sp-4); }
  .doc { padding: var(--sp-6) var(--sp-5); }
  .doc-sigs { grid-template-columns: minmax(0, 1fr); gap: var(--sp-6); }
}

@media (max-width: 640px) {
  :root { --fs-3xl: 30px; --fs-4xl: 34px; --fs-2xl: 24px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .check-item { grid-template-columns: 26px minmax(0, 1fr); }
  .check-item .yna { grid-column: 2; }
  .check-item .initials-field { grid-column: 2; }
  .section-title { position: static; }
  .task-row { grid-template-columns: minmax(0, 1fr); }
  .task-row > .row { justify-content: space-between; }
  .doc-month, .doc-event { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .doc-month-name { color: var(--text-2); }
  .topbar-sub { display: none; }
  /* Topbar controls collapse to icons rather than wrapping or overflowing.
     Each keeps its aria-label, so the accessible name is unchanged. */
  .topbar .btn-label { display: none; }
  .topbar .btn { padding: 8px 10px; }
  .copilot { right: 8px; bottom: 8px; height: min(520px, calc(100vh - 72px)); }
  .copilot-fab { right: var(--sp-3); bottom: var(--sp-3); }
  .stat-value { font-size: var(--fs-xl); }

  /* At this width a header's trailing meta and a callout's trailing action
     have no room beside the text, so they drop onto their own line rather
     than being squeezed into a two-word column. */
  .card-head { flex-wrap: wrap; }
  .card-head > .col { align-items: flex-start !important; width: 100%; }
  .callout { flex-wrap: wrap; }
  .callout > .btn, .callout > a.btn { width: 100%; }
  .section-head { flex-wrap: wrap; }
  .mk-nav { padding: var(--sp-3) var(--sp-4); flex-wrap: wrap; }
  .doc { padding: var(--sp-5) var(--sp-4); }
}

/* ---------------------------------------------------------------------------
   8. PRINT — the field form.
   Everything that is software disappears. What remains is a black-and-white
   paper form a technologist can carry to the bench and fill in by hand.
   ------------------------------------------------------------------------*/
@media print {
  @page { size: letter portrait; margin: 0.6in 0.55in; }

  :root, [data-theme="dark"] {
    color-scheme: light !important;
    --bg: #fff; --surface: #fff; --surface-2: #fff; --surface-3: #fff;
    --surface-inset: #fff;
    --border: #999; --border-strong: #555;
    --text: #000; --text-2: #222; --text-3: #444;
    --brand: #000; --brand-text: #000; --brand-soft: #fff; --brand-soft-2: #fff;
    --brand-border: #999;
    --ok: #000; --ok-soft: #fff; --ok-border: #999;
    --warn: #000; --warn-soft: #fff; --warn-border: #999;
    --danger: #000; --danger-soft: #fff; --danger-border: #555;
    --neutral: #000; --neutral-soft: #fff; --neutral-border: #999;
    --sh-1: none; --sh-2: none; --sh-3: none; --sh-4: none;
  }

  html, body {
    background: #fff !important;
    color: #000 !important;
    font-size: 10.5pt;
    line-height: 1.42;
  }

  /* No FAB on paper, so no FAB clearance either. */
  main.main::after { display: none; }
  .qc-layout > *:last-child, .month-layout > *:last-child { padding-bottom: 0; }

  /* Chrome: gone. */
  .nav, .topbar, .copilot, .copilot-fab, .toasts, .skip-link,
  .backdrop-scrim, dialog.modal, .no-print, .nav-toggle,
  .menu, .wheel-legend, .mk-nav, .mk-foot,
  .btn, button, .link-btn, .cp-action,
  .save-status, .state-icon {
    display: none !important;
  }

  /* Anything explicitly marked for paper survives. */
  .print-only { display: block !important; }
  .print-show, .print-show * { display: revert !important; }

  .app { display: block !important; }
  main.main { padding: 0 !important; max-width: none !important; }

  /* Two-column working layouts collapse: on paper the side rails are either
     hidden or irrelevant, and a reserved empty column wastes the sheet. */
  .month-layout, .qc-layout, .wheel-layout, .stats, .review-grid, .form-grid {
    display: block !important;
  }
  .col { display: block !important; }

  .card, .panel, .doc, .callout, .stat, .plan, .value-card, .auth-card, .wheel-stage {
    border: 1px solid #999 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    break-inside: avoid;
  }
  .doc { padding: 0 !important; border: 0 !important; max-width: none !important; }
  .card-head, .card-foot, .section-title { background: #fff !important; }
  .section-title { position: static !important; border-top: 1px solid #555; }

  a { color: #000 !important; text-decoration: none !important; }

  h1, h2, h3, h4 { break-after: avoid; }
  .check-item, .doc-section, .comp-row, .task-row, .finding { break-inside: avoid; }
  .check-item { background: #fff !important; padding: 7pt 0 !important; border-bottom: 1px solid #ccc !important; }
  .check-item.has-finding { background: #fff !important; }

  /* Y / N / NA become tick boxes to mark with a pen. */
  .yna { gap: 10pt; }
  .yna input { display: none !important; }
  .yna label {
    display: inline-block !important;
    min-width: 0 !important; height: auto !important; padding: 0 !important;
    border: 0 !important; background: #fff !important; color: #000 !important;
    font-weight: 500 !important; font-size: 10pt;
  }
  .yna label::before {
    content: ""; display: inline-block;
    width: 10pt; height: 10pt; margin-right: 4pt;
    border: 1px solid #000; vertical-align: -1pt;
  }
  .yna input:checked + label { font-weight: 700 !important; }
  .yna input:checked + label::before {
    content: "\2713";
    font-size: 8pt; line-height: 9pt; text-align: center; font-weight: 700;
  }

  /* Written fields become ruled lines. */
  .input, .textarea, .select, .initials-field input {
    border: 0 !important; border-bottom: 1px solid #000 !important;
    border-radius: 0 !important; background: #fff !important; color: #000 !important;
    box-shadow: none !important; padding: 0 !important; min-height: 16pt !important;
  }
  .textarea { min-height: 40pt !important; }

  .badge {
    border: 1px solid #666 !important; background: #fff !important; color: #000 !important;
    border-radius: 0 !important;
  }
  .badge::before { display: none !important; }
  .chip {
    border: 0 !important; background: #fff !important; color: #333 !important;
    padding: 0 !important; font-size: 8.5pt;
  }
  .chip::before { content: "["; }
  .chip::after { content: "]"; }

  /* A date picker has no meaning on paper. */
  input[type="date"]::-webkit-calendar-picker-indicator { display: none !important; }

  .finding {
    border: 1px solid #000 !important; border-left-width: 3px !important;
    background: #fff !important;
  }

  .bar { border: 1px solid #666; height: 8pt; }
  .bar > i { background: #666 !important; }

  .sig-preview, .sig-line { border-color: #000 !important; }

  .print-header { display: block !important; }
  .table-wrap { overflow: visible !important; }
  .sop-body { max-height: none !important; overflow: visible !important; border: 0 !important; padding: 0 !important; }
  .modal-body { max-height: none !important; overflow: visible !important; }
}

/* The paper masthead only exists on paper. */
.print-header { display: none; }
@media print {
  .print-header {
    border-bottom: 2px solid #000; padding-bottom: 6pt; margin-bottom: 12pt;
  }
  .print-header .ph-lab { font-size: 13pt; font-weight: 700; }
  .print-header .ph-title { font-size: 10pt; letter-spacing: .08em; text-transform: uppercase; }
  .print-header .ph-meta { font-size: 9pt; margin-top: 4pt; }
  .print-sig-block { display: block !important; margin-top: 18pt; break-inside: avoid; }
  .print-sig-block .psb-row { display: flex; gap: 24pt; margin-top: 20pt; }
  .print-sig-block .psb-line { flex: 1; border-top: 1px solid #000; padding-top: 3pt; font-size: 9pt; }
}
.print-sig-block { display: none; }
