/* Diagno Tech Ghost Engine - investor dashboard CSS.
   Filthy-Hand palette mirroring mobile app. Blue-dominant, orange for hero CTA.
   No gradients, no rounded SaaS pills, no emojis, no shadow stacks. ASCII only. */

:root {
  --bg:        #111111;
  --surface:   #1a1a1a;
  --surface-2: #0d0d0d;
  --accent:    #f97316;
  --accent-2:  #ea6a0e;
  --blue:      #4F8EF7;
  --green:     #10D48E;
  --amber:     #F59E0B;
  --red:       #F4426A;
  --success:   #22c55e;
  --danger:    #ef4444;
  --text:      #e0e0e0;
  --text-mut:  #6b7280;
  --border:    #2a2a2a;
  --white:     #ffffff;
  --mono: "JetBrains Mono", "Fira Code", "Consolas", ui-monospace, monospace;
  --sans: "Inter", "Segoe UI", -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--white); }
a.link { color: var(--blue); }
a.link:hover { color: var(--white); text-decoration: underline; }

/* Top bar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; flex-direction: column; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.brand {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.10em;
  color: var(--white);
  text-transform: uppercase;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-mut);
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.user {
  font-family: var(--mono);
  color: var(--text);
  font-size: 13px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 12px 18px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-mut);
  border-bottom: 3px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--white); border-bottom-color: var(--blue); }

/* Main content */
.content { padding: 24px; max-width: 1400px; margin: 0 auto; }

.page-header { margin: 0 0 12px 0; }
.page-title {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 600;
  color: var(--white);
  margin: 0;
  letter-spacing: 0.01em;
}
.page-subtitle {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--text);
  margin: 24px 0 8px 0;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.page-sub { font-size: 12px; color: var(--text-mut); margin-top: 2px; }

/* Section headers in semantic colors (mirror mobile chip palette) */
.page-subtitle.section-blue  { color: var(--blue);  border-left: 3px solid var(--blue);  padding-left: 10px; }
.page-subtitle.section-green { color: var(--green); border-left: 3px solid var(--green); padding-left: 10px; }
.page-subtitle.section-amber { color: var(--amber); border-left: 3px solid var(--amber); padding-left: 10px; }
.page-subtitle.section-red   { color: var(--red);   border-left: 3px solid var(--red);   padding-left: 10px; }

/* Stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
/* 3x3 variant for the trimmed home page (2026-05-16). */
.stat-grid.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 16px 16px 18px;
  min-height: 88px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--border);
}
.stat-card:hover { border-color: var(--text-mut); }
.stat-label {
  color: var(--text-mut);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat-value {
  font-family: var(--mono);
  font-size: 28px;
  color: var(--white);
  margin-top: 6px;
  text-align: right;
  font-weight: 550;
  line-height: 1.1;
}

/* Per-card semantic accents. Left stripe + number tint. */
.stat-card.card--orange::before { background: var(--accent); }
.stat-card.card--orange .stat-value { color: var(--accent); }
.stat-card.card--orange:hover { border-color: var(--accent); }

.stat-card.card--blue::before { background: var(--blue); }
.stat-card.card--blue .stat-value { color: var(--blue); }
.stat-card.card--blue:hover { border-color: var(--blue); }

.stat-card.card--green::before { background: var(--green); }
.stat-card.card--green .stat-value { color: var(--green); }
.stat-card.card--green:hover { border-color: var(--green); }

.stat-card.card--amber::before { background: var(--amber); }
.stat-card.card--amber .stat-value { color: var(--amber); }
.stat-card.card--amber:hover { border-color: var(--amber); }

.stat-card.card--red::before { background: var(--red); }
.stat-card.card--red .stat-value { color: var(--red); }
.stat-card.card--red:hover { border-color: var(--red); }

.refresh-stamp {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-mut);
  margin: 4px 0 18px 0;
  text-align: right;
}

@media (max-width: 1000px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-grid.stat-grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* Tables */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}
.data-table th, .data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table th {
  color: var(--blue);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--surface-2);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.data-table tbody tr:nth-child(even) { background: #161616; }
.data-table tbody tr:hover td { background: rgba(79, 142, 247, 0.08); }
.data-table td.num, .data-table th.num { text-align: right; }
/* Empty-state cell (audit follow-up 2026-05-16):
   Previously `.data-table .muted` applied text-align: center + padding: 18px
   to every td with class="muted" -- which broke alignment on data rows
   like the model breadcrumb in _parts_rows.html and the appliance cell in
   _models_rows.html. Scope to a dedicated class used only on the
   "No parts match" / "No models" / "No bulletins" cells. */
.data-table .empty-cell { color: var(--text-mut); text-align: center; padding: 18px; }
.data-table .small { font-size: 11px; }

.num { text-align: right; }
.mono { font-family: var(--mono); }
/* CSS specificity fix (2026-05-16): `.data-table th, .data-table td`
   has specificity (0,0,1,1) and pinned text-align:left. The bare
   `.text-right` (0,0,1,0) loses. Scope to .data-table so it wins. */
.data-table .text-right { text-align: right; }
.muted { color: var(--text-mut); }
.small { font-size: 11px; }

/* Part numbers stand out in blue mono in parts tables */
.parts-table td.mono:nth-child(2) { color: var(--blue); }

/* Column-width utility classes (audit follow-up 2026-05-16).
   Replaces inline <th style="width: ..."> declarations that were blocked
   by the hardened CSP (style-src 'self', no 'unsafe-inline'). All values
   are percentages of the data-table parent, except col-w-img which is the
   fixed 64px image cell. */
.text-right { text-align: right; }
.col-w-img { width: 64px; }
.col-w-8  { width: 8%; }
.col-w-10 { width: 10%; }
.col-w-12 { width: 12%; }
.col-w-14 { width: 14%; }
.col-w-18 { width: 18%; }
.col-w-20 { width: 20%; }
.col-w-36 { width: 36%; }
.col-w-70 { width: 70%; }
.col-w-80 { width: 80%; }

/* Images in tables */
.img-cell {
  width: 64px;
  vertical-align: middle;
}
.img-cell img {
  display: block;
  width: 56px;
  height: 56px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.no-img {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-mut);
  display: inline-block;
  width: 56px;
  height: 56px;
  line-height: 56px;
  text-align: center;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 6px;
}

/* Parts table image fallback. Hidden by default; the dashboard.js
   image-error listener flips both classes when an image fails to load.
   Replaces the previous inline style="display:none" (hardening audit fix
   removed 'unsafe-inline' from style-src so inline styles are blocked). */
.part-img-fallback { display: none; }
.img-cell img.part-img.failed { display: none; }
.img-cell img.part-img.failed + .part-img-fallback { display: inline-block; }

.flag-obs {
  background: var(--red);
  color: var(--white);
  padding: 3px 7px;
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.04em;
  display: inline-block;
  border-radius: 4px;
}

/* Forms */
.field-label {
  display: block;
  font-size: 11px;
  color: var(--text-mut);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 12px 0 4px 0;
}
.field-input {
  display: block;
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
  transition: border-color 120ms ease;
}
.field-input::placeholder { color: var(--text-mut); }
.field-input:focus {
  border-color: var(--blue);
}
select.field-input {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-mut) 50%),
    linear-gradient(135deg, var(--text-mut) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) calc(50% - 2px),
    calc(100% - 11px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

/* Filter bar (audit follow-up 2026-05-16):
   Each label+input pair lives in its own .field-group cell so the grid
   doesn't wrap label and input into different rows when the column count
   doesn't divide evenly. Buttons share a .btn-group cell. */
.filter-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 14px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}
.filter-bar .field-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.filter-bar .field-label { margin: 0; }
.filter-bar .btn-group { display: flex; gap: 8px; align-items: stretch; }
.filter-bar .btn-group .btn-primary,
.filter-bar .btn-group .btn-secondary { white-space: nowrap; }

/* Buttons - primary is blue (dominant). Orange accent stays on hero stats only. */
.btn-primary {
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 40px;
}
.btn-primary:hover { background: #3a78d8; }
.btn-primary:disabled { background: var(--text-mut); cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  min-height: 40px;
  line-height: 18px;
}
.btn-secondary:hover { border-color: var(--blue); color: var(--blue); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary:disabled:hover { border-color: var(--border); color: var(--text); }

/* Login page */
.login-shell {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
}
.login-header { margin-bottom: 24px; text-align: center; }
.login-header .brand { font-size: 16px; margin-bottom: 4px; }
.login-card form .field-label:first-child { margin-top: 0; }
.login-card .btn-primary { width: 100%; margin-top: 18px; }
.login-card .field-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79, 142, 247, 0.18);
}
.login-footnote {
  margin-top: 18px;
  font-size: 11px;
  color: var(--text-mut);
  line-height: 1.5;
  text-align: center;
}

.error-banner {
  background: rgba(244, 66, 106, 0.10);
  border: 1px solid var(--red);
  border-radius: 8px;
  color: var(--red);
  padding: 10px 12px;
  font-size: 12px;
  margin-bottom: 12px;
}

/* Bars (appliance distribution) - blue per Athallah direction.
   Hardening audit (2026-05-15): width is set via CSS custom property by
   dashboard.js (data-bar-width attribute), replacing inline style= so CSP
   can drop style-src 'unsafe-inline'. */
.bar {
  background: var(--blue);
  height: 10px;
  display: inline-block;
  vertical-align: middle;
  border-radius: 2px;
  width: var(--bar-width-px, 0);
}
.bar-text {
  display: none; /* ASCII fallback kept for accessibility */
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 24px 0;
}
.pagination .muted { font-family: var(--mono); }
.pagination .page-indicator {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--blue);
  letter-spacing: 0.04em;
}

.parts-summary {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-mut);
  margin-bottom: 6px;
}

/* Key-value grid for model detail */
.kv-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 6px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin: 0 0 18px 0;
}
.kv-grid dt {
  font-size: 11px;
  color: var(--text-mut);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.kv-grid dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
}

/* Appliance distribution bars take inline width style for accuracy */
.appliance-table .bar { vertical-align: middle; margin-right: 6px; }

/* Mobile fallback - dashboard is desktop-first but stays readable */
@media (max-width: 720px) {
  .content { padding: 12px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .filter-bar { grid-template-columns: 1fr; }
  .filter-bar .btn-group { justify-content: flex-end; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 6px 8px; }
}

/* Document viewer (bulletins / wiring PNG pager). Blue-dominant, minimal */
.doc-title {
  border-left: 3px solid var(--blue);
  padding-left: 10px;
  color: var(--blue);
}
.doc-viewer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin: 12px 0;
  text-align: center;
  min-height: 200px;
}
.doc-page {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.doc-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 12px 0 24px 0;
}
.doc-nav .page-indicator {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--blue);
  letter-spacing: 0.04em;
  padding: 0 12px;
}
.btn-secondary.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}
/* Compact "Open document" pill inside bulletin / wiring tables */
.doc-open-pill {
  font-size: 10px;
  padding: 4px 10px;
  min-height: 0;
  margin-left: 8px;
  line-height: 14px;
}

/* ====================================================================
   Slice 2 of per-engineer auth migration (2026-05-17) — engineers page.
   Webcam capture frame + enrolment form + engineers table styling.
   Theme: blue-dominant Filthy-Hand palette, matches the rest of the
   dashboard.
   ==================================================================== */

.engineers-page .page-header { margin-bottom: 20px; }
.engineers-page .page-header h1 { margin: 0 0 6px; color: var(--text); }
.engineers-page .page-sub { color: var(--text-mut); font-size: 13px; margin: 0; }

.enroll-card { padding: 20px; margin-bottom: 18px; }
.enroll-card h2 { margin: 0 0 14px; font-size: 17px; color: var(--text); }

.enroll-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .enroll-grid { grid-template-columns: 1fr; }
}

.enroll-form-col { display: flex; flex-direction: column; gap: 10px; }
.enroll-camera-col { display: flex; flex-direction: column; gap: 10px; }

.camera-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--surface-2, #0d0d0d);
  /* Theme-matching blue border (2026-05-17 polish — was orange --accent,
     out of place against the rest of the blue-dominant dashboard). */
  border: 1px solid var(--blue, #4F8EF7);
  border-radius: 10px;
  overflow: hidden;
}
.camera-frame video,
.camera-frame canvas,
.camera-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* [hidden] must beat the generic display:block above. Without these
   explicit selectors a `hidden` <img> still renders + leaks its alt
   text in the top-left of the frame. */
.camera-frame video[hidden],
.camera-frame canvas[hidden],
.camera-frame img[hidden] { display: none !important; }

.camera-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.enroll-status {
  font-size: 13px;
  color: var(--text-mut);
  min-height: 18px;
  margin-top: 4px;
}
.enroll-status--ok  { color: var(--green, #10D48E); }
.enroll-status--err { color: var(--red, #F4426A); }

.result-card { padding: 20px; margin-bottom: 18px; }
.result-card h2 { margin: 0 0 6px; color: var(--text); }
.result-card[hidden] { display: none; }

.result-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 14px 0;
}
.result-grid dt { color: var(--text-mut); font-size: 13px; }
.result-grid dd {
  margin: 0;
  color: var(--text);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
}
.result-pin {
  font-size: 22px !important;
  letter-spacing: 4px;
  color: var(--blue, #4F8EF7);
  font-weight: 700;
}

.engineers-list-card { padding: 20px; }
.engineers-list-card h2 { margin: 0 0 14px; font-size: 17px; color: var(--text); }
.engineers-list { min-height: 60px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.badge--ok   { background: rgba(16,212,142,0.16); color: var(--green, #10D48E); }
.badge--warn { background: rgba(245,158,11,0.18); color: var(--amber, #F59E0B); }
.badge--off  { background: rgba(107,114,128,0.22); color: var(--text-mut, #9ca3af); }

/* Engineers page: tab toggle for webcam vs upload (2026-05-17) */
.enroll-image-col { display: flex; flex-direction: column; gap: 10px; }

.enroll-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-2, #0d0d0d);
  border-radius: 8px;
  padding: 2px;
}
.enroll-tab {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-mut, #9ca3af);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.enroll-tab.tab--active {
  background: var(--surface, #1a1a1a);
  color: var(--text, #e0e0e0);
}
.enroll-tab:hover:not(.tab--active) { color: var(--text, #e0e0e0); }

.camera-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.upload-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  color: var(--text-mut, #9ca3af);
  gap: 6px;
}
/* The display:flex above beats [hidden]'s default display:none, so the
   "No file selected" placeholder kept rendering on top of an uploaded
   photo. Force it back when JS toggles hidden=true. */
.upload-empty[hidden] { display: none !important; }
.upload-empty p { margin: 0; font-size: 13px; }

.file-pick-btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Engineers page: per-row action buttons (suspend / unsuspend / reset PIN). */
.row-actions-cell {
  white-space: nowrap;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.row-action {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border, #2a2a2a);
  background: var(--surface-2, #0d0d0d);
  color: var(--text, #e0e0e0);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.row-action:hover { background: var(--surface, #1a1a1a); }
.row-action--secondary { border-color: var(--blue, #4F8EF7); color: var(--blue, #4F8EF7); }
.row-action--secondary:hover { background: rgba(79,142,247,0.10); }
.row-action--danger { border-color: var(--red, #F4426A); color: var(--red, #F4426A); }
.row-action--danger:hover { background: rgba(244,66,106,0.10); }
.row-action--ok { border-color: var(--green, #10D48E); color: var(--green, #10D48E); }
.row-action--ok:hover { background: rgba(16,212,142,0.10); }

/* Engineers list table — polish (2026-05-17) */
.engineers-list .data-table th,
.engineers-list .data-table td {
  padding: 11px 14px;
  vertical-align: middle;
}
.engineers-list .cell-eid {
  font-family: var(--mono);
  color: var(--blue, #4F8EF7);
  font-weight: 600;
  letter-spacing: 0.4px;
}
.engineers-list .cell-name {
  color: var(--text, #e0e0e0);
  font-weight: 500;
}
.engineers-list .cell-time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text, #e0e0e0);
}
.engineers-list .cell-empty {
  color: #4a4f58;          /* muted en-dash — visible but recedes */
  font-family: var(--mono);
  text-align: center;
  letter-spacing: 0;
}
/* Tighter action buttons in the row to give the table breathing room. */
.engineers-list .row-action {
  padding: 4px 10px;
  font-size: 11px;
}

/* ====================================================================
   Themed modal + toast (replaces native confirm/prompt/alert).
   2026-05-17 polish — matches dashboard blue-dominant Filthy-Hand palette.
   ==================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
  /* Quick fade-in. transform-only animation so older browsers stay smooth. */
  animation: modalFade 0.12s ease-out;
}

@keyframes modalFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  background: var(--surface, #1a1a1a);
  border: 1px solid var(--border, #2a2a2a);
  border-radius: 12px;
  width: 100%;
  max-width: 460px;
  padding: 22px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
  animation: modalCardIn 0.16s ease-out;
}

@keyframes modalCardIn {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: none;            opacity: 1; }
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--white, #fff);
  letter-spacing: 0.2px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text, #e0e0e0);
}
.modal-body p { margin: 0; }
.modal-body-spacer { height: 4px; }

.modal-input-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-mut, #9ca3af);
  margin-top: 4px;
}
.modal-input {
  width: 100%;
  font-size: 15px;
  padding: 11px 12px;
  border-radius: 8px;
  background: var(--surface-2, #0d0d0d);
  border: 1px solid var(--border, #2a2a2a);
  color: var(--text, #e0e0e0);
  outline: none;
  transition: border-color 0.12s ease;
}
.modal-input:focus { border-color: var(--blue, #4F8EF7); }
.modal-input-err {
  min-height: 16px;
  color: var(--red, #F4426A);
  font-size: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.modal-btn {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--border, #2a2a2a);
  background: var(--surface-2, #0d0d0d);
  color: var(--text, #e0e0e0);
  cursor: pointer;
  min-width: 96px;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.modal-btn:hover { background: var(--surface, #1a1a1a); }
.modal-btn--cancel { /* default style, kept explicit */ }
.modal-btn--primary {
  background: var(--blue, #4F8EF7);
  border-color: var(--blue, #4F8EF7);
  color: #fff;
}
.modal-btn--primary:hover { background: #3877dd; border-color: #3877dd; }
.modal-btn--ok {
  background: var(--green, #10D48E);
  border-color: var(--green, #10D48E);
  color: #062818;
}
.modal-btn--ok:hover { background: #0db97c; border-color: #0db97c; }
.modal-btn--danger {
  background: var(--red, #F4426A);
  border-color: var(--red, #F4426A);
  color: #fff;
}
.modal-btn--danger:hover { background: #d92e57; border-color: #d92e57; }

/* ====================================================================
   Toast — single-shot status messages (replaces alert()).
   ==================================================================== */

#toast-root {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface, #1a1a1a);
  border-left: 3px solid var(--blue, #4F8EF7);
  color: var(--text, #e0e0e0);
  font-size: 13px;
  padding: 12px 14px 12px 14px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
  max-width: 420px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  animation: toastIn 0.14s ease-out;
}
@keyframes toastIn {
  from { transform: translateY(-6px); opacity: 0; }
  to   { transform: none;             opacity: 1; }
}
.toast--ok  { border-left-color: var(--green, #10D48E); }
.toast--err { border-left-color: var(--red,   #F4426A); }

.toast-close {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: var(--text-mut, #9ca3af);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.toast-close:hover { color: var(--text, #e0e0e0); }

/* ===================================================================
   Engineer record page (2026-05-22)
   =================================================================== */

/* Make the engineer-list ID column a link through to the record page. */
.eid-link {
  color: var(--blue, #4F8EF7);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  text-decoration: none;
}
.eid-link:hover { text-decoration: underline; }

.engineer-record .back-link {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--blue, #4F8EF7);
  font-size: 13px;
  text-decoration: none;
}
.engineer-record .back-link:hover { text-decoration: underline; }

.record-header .eid-mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--blue, #4F8EF7);
}
.record-header .dot-sep,
.conv-head-meta .dot-sep,
.chat-meta .dot-sep { color: var(--text-mut, #9ca3af); margin: 0 8px; }
.muted-sub { color: var(--text-mut, #9ca3af); font-size: 12px; }

/* 4-up summary row reuses the home-page stat-card look. */
.stat-grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 760px) { .stat-grid-4 { grid-template-columns: repeat(2, 1fr); } }

/* One conversation = one card with a header strip and a chat transcript. */
.conv-card {
  border: 1px solid #242424;
  border-radius: 10px;
  background: #0d0d0d;
  margin-bottom: 16px;
  overflow: hidden;
}
.conv-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #161616;
  border-bottom: 1px solid #242424;
  border-left: 3px solid var(--blue, #4F8EF7);
}
.conv-model { color: var(--white, #ffffff); font-weight: 600; }
.conv-job {
  margin-left: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-mut, #9ca3af);
}
/* Left block grows to fill the row so the meta (count + date) and chevron
   always pin to the right -- keeps that column aligned across rows regardless
   of how long the model name / job ref is. */
.conv-head-main { flex: 1 1 auto; min-width: 0; }
.conv-head-meta { color: var(--text-mut, #9ca3af); font-size: 12px; white-space: nowrap; text-align: right; }

.chat-log { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.chat-msg { display: flex; flex-direction: column; max-width: 80%; }
.chat-msg--user { align-self: flex-end; align-items: flex-end; }
.chat-msg--assistant { align-self: flex-start; align-items: flex-start; }
.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-msg--user .chat-bubble {
  background: var(--blue, #4F8EF7);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}
.chat-msg--assistant .chat-bubble {
  background: #1c1c1c;
  color: var(--white, #e0e0e0);
  border: 1px solid #2a2a2a;
  border-bottom-left-radius: 4px;
}
.chat-meta { margin-top: 4px; padding: 0 6px; font-size: 11px; color: var(--text-mut, #9ca3af); }

/* AI-retrieved cards (parts/wiring/bulletins) the AI attached to the engineer
   this turn, surfaced under the assistant bubble for review + eval/debug. */
.retrieved-refs {
  margin-top: 6px;
  padding: 8px 10px;
  max-width: 600px;
  background: #161616;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
}
.refs-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-mut, #9ca3af);
  margin-bottom: 6px;
}
.refs-group { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; margin-top: 4px; }
.refs-label { font-size: 11px; color: var(--blue, #4F8EF7); min-width: 56px; font-weight: 600; }
.ref-chip {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 8px;
  background: #202020;
  color: var(--white, #e0e0e0);
  border: 1px solid #2f2f2f;
}
.ref-chip--obsolete { border-color: rgba(245,158,11,0.5); color: var(--amber, #F59E0B); }

/* Captured-media thumbnail grid. Without these the <img> renders at natural
   (full-camera) resolution and fills the whole page. Fixed-size tiles in a
   responsive grid; click a thumbnail to enlarge it in the in-page lightbox
   (initMediaLightbox in dashboard.js). */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  padding: 4px 0;
}
.media-item {
  background: #161616;
  border: 1px solid #242424;
  border-radius: 10px;
  overflow: hidden;
}
.media-thumb {
  display: block;
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: #0e0e0e;
  cursor: pointer;
}
.media-audio-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 12px;
  font-size: 12px;
  color: var(--text-mut, #9ca3af);
}
.media-meta {
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-mut, #9ca3af);
  border-top: 1px solid #242424;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge--blue { background: rgba(79,142,247,0.18); color: var(--blue, #4F8EF7); }

/* In-page lightbox: click a captured-media thumbnail to enlarge it without
   leaving the dashboard. Backdrop + centered image + close button, all
   styled here (no inline styles — CSP style-src 'self'). */
.media-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.85);
}
.media-lightbox-img {
  max-width: 92%;
  max-height: 92%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
.media-lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.media-lightbox-close:hover { background: rgba(255, 255, 255, 0.22); }

/* Collapsible conversation cards: the header is the click target. */
.conv-card > summary.conv-head { cursor: pointer; list-style: none; user-select: none; }
.conv-card > summary.conv-head::-webkit-details-marker { display: none; }
.conv-card > summary.conv-head:hover { background: #1b1b1b; }
.conv-card:not([open]) > summary.conv-head { border-bottom: none; }
.conv-chevron {
  color: var(--text-mut, #9ca3af);
  font-size: 13px;
  margin-left: 12px;
  transition: transform 0.15s ease;
}
.conv-card[open] > summary.conv-head .conv-chevron { transform: rotate(90deg); }

/* Per-answer review form (admin review-and-tune). Lives under an assistant
   bubble; the toggle reveals a small card with the verdict pills + correction. */
.review-form { margin-top: 8px; width: 100%; max-width: 600px; }
.review-form-toggle {
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-size: 12px;
  color: var(--blue, #4F8EF7);
  padding: 2px 0;
}
.review-form-toggle::-webkit-details-marker { display: none; }
.review-form-toggle::before { content: "\25B8\00a0"; font-size: 10px; }
.review-form[open] .review-form-toggle::before { content: "\25BE\00a0"; }
.review-form-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  padding: 12px;
  background: #141414;
  border: 1px solid #262626;
  border-radius: 10px;
}
.review-verdicts { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-verdict {
  padding: 5px 14px;
  border-radius: 999px;
  border: 1px solid #2f2f2f;
  background: #1c1c1c;
  color: var(--text-mut, #9ca3af);
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.btn-verdict:hover { border-color: #3a3a3a; color: var(--white, #e0e0e0); }
.btn-verdict--ok.btn-verdict--active   { background: #0e2c1d; border-color: #22c55e; color: #4ade80; }
.btn-verdict--warn.btn-verdict--active { background: #2e2410; border-color: #f59e0b; color: #fbbf24; }
.btn-verdict--off.btn-verdict--active  { background: #2e1414; border-color: #ef4444; color: #f87171; }
.review-correction,
.review-note-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  background: #0d0d0d;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  color: var(--white, #e0e0e0);
  font-family: inherit;
  font-size: 13px;
}
.review-correction { resize: vertical; min-height: 56px; }
.review-correction:focus,
.review-note-input:focus { outline: none; border-color: var(--blue, #4F8EF7); }
.btn-submit-review {
  align-self: flex-start;
  padding: 7px 18px;
  border-radius: 8px;
  border: none;
  background: var(--blue, #4F8EF7);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-submit-review:hover { filter: brightness(1.08); }
.btn-submit-review:disabled { opacity: 0.5; cursor: default; }
.review-save-status { font-size: 12px; color: var(--text-mut, #9ca3af); }
.review-badge { text-transform: capitalize; }

.part-chip {
  display: inline-block;
  margin: 0 4px 4px 0;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(79, 142, 247, 0.12);
  color: var(--blue, #4F8EF7);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}

/* Field-learning proposals curation worklist (/dashboard/kb-proposals) */
.kb-proposal { margin-bottom: 16px; }
.kb-proposal__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.kb-field { display: block; margin-bottom: 10px; font-size: 13px; color: var(--text-mut); }
.kb-field input[type="text"],
.kb-field textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border, #2a2f3a);
  border-radius: 6px;
  background: var(--surface-2, #161a22);
  color: var(--text, #e6e9ef);
  font: inherit;
}
.kb-proposal__reject {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border, #2a2f3a);
}
.kb-proposal__reject input[type="text"] { flex: 1; padding: 8px 10px; border: 1px solid var(--border, #2a2f3a); border-radius: 6px; background: var(--surface-2, #161a22); color: var(--text, #e6e9ef); font: inherit; }
