/* MEUCOM shared stylesheet.
   Design tokens + component conventions: docs/design-system.md (evidence trail there).
   Palette derived from the unit's own properties:
   - upm.15thmeu.net site generator (manifest theme_color #912114 on #1b1b1b,
     header gradient #912114 -> #330403, gold links #f1b824, khaki #c3c39c)
   - www.15thmeu.net front page (#c00 scarlet, #CA8416 gold, near-black surfaces)
   Dark-only, dependency-free, system fonts. */

:root {
  /* Brand reds (see design-system.md section 2.1 for sources) */
  --red-950: #330403;
  --red-800: #76190f;
  --red-700: #912114;   /* primary brand red (UPM manifest theme_color) */
  --red-600: #8c101c;
  --red-500: #cc0000;   /* vivid accent; decoration only, never text on dark */
  --red-300: #ff6b5c;   /* derived tint: red TEXT on dark (AA validated) */
  --brand-gradient: linear-gradient(90deg, #912114, #330403);

  /* Gold accents (sparing) */
  --gold-400: #f1b824;
  --gold-300: #ebb445;
  --gold-600: #ca8416;

  /* Neutrals */
  --bg: #1b1b1b;
  --surface-1: #202020;
  --surface-2: #242424;
  --surface-3: #2c2c2c;
  --thead: #333333;
  --border-strong: #101010;
  --border: rgba(255, 255, 255, 0.14);
  --text: #f4f4f4;
  --muted: #a9a9a9;
  --khaki: #c3c39c;

  /* Semantic */
  --success: #7dc981;
  --warn: #e5a83b;
  --danger: #ff6b5c;
  --danger-fill: #8c101c;
  --info: #8ab8d0;
  --success-bg: rgba(125, 201, 129, 0.14);
  --warn-bg: rgba(229, 168, 59, 0.14);
  --danger-bg: rgba(255, 107, 92, 0.14);
  --info-bg: rgba(138, 184, 208, 0.14);
  --neutral-bg: rgba(255, 255, 255, 0.08);

  /* Type */
  --font-sans: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Roboto Mono", Menlo, monospace;

  /* Shape + spacing */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-pill: 999px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

  /* Back-compat aliases (older page-local styles reference these) */
  --panel: var(--surface-2);
  --panel-2: var(--surface-3);
  --accent: var(--red-700);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

:focus-visible {
  outline: 2px solid var(--gold-400);
  outline-offset: 2px;
}

/* Top nav (injected by /js/shell.js): the unit's red gradient band. */
.hq-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0 var(--space-4);
  background: var(--brand-gradient);
  border-bottom: 1px solid var(--border-strong);
  height: 56px;
}
.hq-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: var(--space-5);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}
/* Crest slot: clean placeholder until the real crest image lands.
   Drop <img src="..." alt=""> inside .crest and the dashed ring disappears. */
.hq-brand .crest {
  width: 32px; height: 32px;
  border: 1px dashed rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.78);
  overflow: hidden;
  flex: none;
}
.hq-brand .crest img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.hq-brand .crest:has(img) { border-style: solid; border-color: transparent; }
.hq-nav a.nav-link {
  color: rgba(255, 255, 255, 0.78);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.hq-nav a.nav-link:hover { color: #fff; background: rgba(0, 0, 0, 0.25); }
.hq-nav a.nav-link.active {
  color: #fff;
  background: rgba(0, 0, 0, 0.25);
  box-shadow: inset 0 -2px 0 var(--gold-400);
}
.hq-nav .spacer { flex: 1; }
.hq-nav .whoami { color: rgba(255, 255, 255, 0.78); font-size: 13px; margin-right: var(--space-2); }
.hq-nav button.logout {
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-sm);
  padding: 6px var(--space-3);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
}
.hq-nav button.logout:hover { color: #fff; border-color: rgba(255, 255, 255, 0.7); }

main.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-4) 64px;
}
h1 { font-size: 24px; font-weight: 700; margin: 0 0 var(--space-2); }
h2 { font-size: 18px; font-weight: 600; margin: 0 0 var(--space-3); }
h3 { font-size: 16px; font-weight: 600; margin: 0 0 var(--space-2); }
.h-khaki { color: var(--khaki); }  /* UPM secondary-heading treatment */
p.lede { color: var(--muted); margin: 0 0 var(--space-6); }
a { color: var(--gold-400); }
a:hover { color: var(--gold-300); }
code, kbd, .mono { font-family: var(--font-mono); }
kbd {
  font-size: 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
}

/* Cards */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.card.accent-success { border-left: 3px solid var(--success); }
.card.accent-warn    { border-left: 3px solid var(--warn); }
.card.accent-danger  { border-left: 3px solid var(--red-500); }
.card.accent-info    { border-left: 3px solid var(--info); }
/* Kanban/queue staleness (recruiting pipeline, SLA chips: workflow-ux-design 3.2) */
.card.sla-amber { border-left: 3px solid var(--warn); }
.card.sla-red   { border-left: 3px solid var(--red-500); }
.card.sla-red .meta { color: var(--danger); }

.coming-soon {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--muted);
}
.coming-soon .badge { margin-bottom: var(--space-3); }

/* Badges: uppercase micro chips (phase markers). Gold outline, used sparingly. */
.badge {
  display: inline-block;
  border: 1px solid var(--gold-600);
  color: var(--gold-400);
  border-radius: var(--radius-pill);
  font-size: 12px;
  padding: 3px var(--space-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Status pills: eligibility badges, SLA chips, ticket states (design-system.md 5). */
.pill {
  display: inline-block;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  white-space: nowrap;
}
.pill-success { background: var(--success-bg); color: var(--success); }
.pill-warn    { background: var(--warn-bg);    color: var(--warn); }
.pill-danger  { background: var(--danger-bg);  color: var(--danger); }
.pill-info    { background: var(--info-bg);    color: var(--info); }
.pill-neutral { background: var(--neutral-bg); color: var(--muted); }

/* Dashboard tiles */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-4);
}
a.tile {
  display: block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-5);
  color: var(--text);
  text-decoration: none;
}
a.tile:hover { border-color: var(--red-500); }
a.tile h3 { margin: 0 0 6px; font-size: 16px; color: var(--text); }
a.tile p { margin: 0; color: var(--muted); font-size: 13px; }

/* Tables (UPM treatment: #333 head, hairline rows, rounded wrapper) */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  background: var(--thead);
  color: var(--text);
  text-align: left;
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
}
tbody td {
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--border);
}
tbody tr:hover { background: var(--surface-3); }

/* Buttons */
button.primary, button.secondary, button.danger {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 10px var(--space-4);
  cursor: pointer;
  border: 0;
}
button.primary { background: var(--red-700); color: #fff; }
button.primary:hover { background: #a4231b; }   /* derived hover step, white text 7.4:1 */
button.primary:active { background: var(--red-800); }
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { border-color: var(--muted); }
button.danger { background: var(--danger-fill); color: #fff; }
button.danger:hover { background: var(--red-800); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

/* Forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px var(--space-3);
  font: inherit;
  font-size: 15px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold-400); }
.error-msg { color: var(--danger); font-size: 13px; margin-top: var(--space-3); min-height: 18px; text-align: center; }
.ok-msg { color: var(--success); font-size: 13px; }

/* Login (the only navless page) */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-4); }
.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-7);
  border-top: 4px solid var(--red-700);
}
.login-box .crest {
  width: 56px; height: 56px;
  margin: 0 auto var(--space-3);
  border: 1px dashed var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  overflow: hidden;
}
.login-box .crest img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.login-box .crest:has(img) { border-style: solid; border-color: transparent; }
.login-box h1 { text-align: center; letter-spacing: 0.05em; }
.login-box .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: var(--space-6); }
.login-box button.primary { width: 100%; margin-top: var(--space-5); padding: 11px; font-size: 15px; }
.sso-note {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* Loading / empty / error placeholder box (roster, ORBAT, future data pages) */
.state-box {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--muted);
}
.state-box .error { color: var(--danger); }
.state-box button { margin-top: var(--space-3); }

/* Personnel-file drawer (shared by roster + ORBAT via /js/member-drawer.js) */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(440px, 92vw);
  background: var(--surface-1);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  z-index: 41;
  overflow-y: auto;
  padding: var(--space-5);
}
.drawer .drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-4);
}
.drawer h2 { margin: 0; }
.drawer .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.drawer .sub .mono { font-family: var(--font-mono); }
.drawer .close {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: var(--radius-sm); cursor: pointer; padding: 4px 10px; font: inherit;
}
.drawer .close:hover { color: var(--text); border-color: var(--muted); }
.drawer h3 { color: var(--khaki); margin-top: var(--space-5); }
.drawer .none { color: var(--muted); font-size: 13px; }
.drawer .profile-note { color: var(--muted); font-size: 12px; margin-top: var(--space-5); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px var(--space-3); font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv dd.mono { font-family: var(--font-mono); }
ul.record-list { list-style: none; margin: 0; padding: 0; }
ul.record-list li {
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
  align-items: baseline;
}
ul.record-list li:first-child { border-top: 0; }
ul.record-list .when { color: var(--muted); font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
ul.record-list .rtype { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; margin-right: 6px; }

/* ============================================================================
   Ribbon rack + personnel modal + roster sections (roster overhaul).
   Built on the shared tokens; reusable by the future service-record card.
   ============================================================================ */

/* --- Ribbon rack component (public/js/ribbon-rack.js) --------------------- */
/* Authoritative ribbon-rack layout (shared by roster modal + service card).
   A single column, top row first; the incomplete row is chunked onto TOP by
   lib/awards.js rackRows and centered here. app.css mirrors this rule. */
.ribbon-rack { display: inline-flex; flex-direction: column; align-items: center; gap: 3px; }
.ribbon-rack .rr-row { display: flex; gap: 3px; justify-content: center; }
.rr-cell {
  position: relative;
  width: 68px; height: 26px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
/* Medals are portrait; ribbon bars are landscape. contain keeps either honest. */
.rr-img { width: 100%; height: 100%; object-fit: contain; display: block; }
.rr-fallback {
  display: none;
  font-family: var(--font-mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.03em; color: var(--khaki); text-align: center; padding: 0 2px;
}
/* Ribbons with no art yet render as a FILLED neutral/scarlet bar (never a hole):
   the exact ribbon-cell size, with the award initials centered on it. Both the
   seeded placeholder and an image that 404s (rr-missing) land here. */
.rr-cell.rr-placeholder,
.rr-cell.rr-missing {
  background: linear-gradient(180deg, #a72c22 0%, #86211a 50%, #5f130c 100%);
  border-color: #45100b;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), inset 0 0 0 1px rgba(0, 0, 0, 0.22), 0 1px 1px rgba(0, 0, 0, 0.4);
}
.rr-cell.rr-placeholder .rr-fallback,
.rr-cell.rr-missing .rr-fallback {
  display: flex; align-items: center;
  color: #ffe9de; font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
.rr-empty { color: var(--muted); font-size: 13px; margin: 0; }
/* Caption list under a rack (name + date + citation) */
ul.rr-captions { list-style: none; margin: var(--space-3) 0 0; padding: 0; }
ul.rr-captions li {
  padding: var(--space-2) 0; border-top: 1px solid var(--border);
  font-size: 13px; display: flex; gap: var(--space-3); justify-content: space-between; align-items: baseline;
}
ul.rr-captions li:first-child { border-top: 0; }
ul.rr-captions .when { color: var(--muted); font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
ul.rr-captions .cite { color: var(--muted); font-size: 12px; display: block; margin-top: 2px; }

/* --- Personnel modal (centered pop-up; mobile = full-screen sheet) -------- */
.hq-modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0.62);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-5);
}
.hq-modal {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(720px, 100%);
  max-height: min(88vh, 900px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.hq-modal .modal-head {
  position: relative;
  background: var(--brand-gradient);
  padding: var(--space-5) var(--space-6);
  color: #fff;
  flex: 0 0 auto;
}
.hq-modal .modal-head h2 { margin: 0; font-size: 22px; color: #fff; }
.hq-modal .modal-head .sub {
  margin-top: 6px; font-size: 13px; color: rgba(255, 255, 255, 0.85);
  display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center;
}
.hq-modal .modal-head .sub .mono { font-family: var(--font-mono); }
.hq-modal .modal-head .close {
  position: absolute; top: var(--space-4); right: var(--space-4);
  background: rgba(0, 0, 0, 0.25); border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff; border-radius: var(--radius-sm); cursor: pointer;
  padding: 4px 10px; font: inherit; line-height: 1.4;
}
.hq-modal .modal-head .close:hover { background: rgba(0, 0, 0, 0.45); }
.hq-modal .modal-body { padding: var(--space-5) var(--space-6); overflow-y: auto; flex: 1 1 auto; }
.hq-modal .modal-body h3 {
  color: var(--khaki); margin: var(--space-5) 0 var(--space-3);
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border); padding-bottom: 6px;
}
.hq-modal .modal-body section:first-child h3 { margin-top: 0; }
.hq-modal .none { color: var(--muted); font-size: 13px; }
.hq-modal .profile-note { color: var(--muted); font-size: 12px; margin-top: var(--space-5); }
@media (max-width: 640px) {
  .hq-modal-overlay { padding: 0; }
  .hq-modal { width: 100%; height: 100%; max-height: 100%; border-radius: 0; border: 0; }
}

/* --- Roster grouping toggle + section rows -------------------------------- */
.group-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.group-toggle button {
  background: transparent; color: var(--muted); border: 0; cursor: pointer;
  font: inherit; font-size: 13px; padding: 8px 14px;
}
.group-toggle button + button { border-left: 1px solid var(--border); }
.group-toggle button.active { background: var(--red-700); color: #fff; font-weight: 600; }
tr.section-row th {
  background: var(--surface-1);
  color: var(--khaki);
  text-transform: uppercase; letter-spacing: 0.06em; font-size: 12px;
  text-align: left; padding: 10px var(--space-3);
  border-top: 2px solid var(--red-800);
  position: sticky; top: 0; z-index: 1;
}
tr.section-row .sec-count { color: var(--muted); font-weight: 400; margin-left: 8px; letter-spacing: 0; text-transform: none; }
