/* OKLCH neutrals tinted toward an ISAAC-blue hue (250°) so the dashboard
   reads as "instrument cluster", not generic admin-cream. */
:root {
  --bg: oklch(0.98 0.005 250);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.965 0.006 250);
  --border: oklch(0.92 0.008 250);
  --text: oklch(0.22 0.012 250);
  --muted: oklch(0.55 0.012 250);
  --accent: oklch(0.55 0.18 250);

  --ok: oklch(0.62 0.16 145);
  --warn: oklch(0.72 0.15 75);
  --bad: oklch(0.6 0.2 25);
}

* { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 4rem;
  color: var(--text);
  background: var(--bg);
}
/* Dark instrument-cluster header so both partner logos (white-on-transparent)
   render correctly without bleaching out. */
header {
  background: oklch(0.22 0.02 250);
  margin: -1.25rem -1rem 1rem;
  padding: 0.9rem 1.25rem;
  color: oklch(0.95 0.005 250);
  border-bottom: 1px solid oklch(0.32 0.025 250);
}
.header-inner {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1.25rem;
  align-items: center;
  max-width: 1100px;
  margin: 0 auto;
}
.header-title h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.005em;
}
.header-title .muted {
  margin: 0;
  font-size: 0.78rem;
  color: oklch(0.7 0.012 250);
}
.brand-luthi {
  height: 32px;
  width: auto;
  display: block;
}
.brand-isaac {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  opacity: 0.9;
  transition: opacity 150ms;
}
.brand-isaac:hover { opacity: 1; }
.brand-isaac img {
  height: 22px;
  width: auto;
  display: block;
}
/* Slim "Signed in as X · Sign out" bar under the main header row. */
.header-user {
  max-width: 1100px;
  margin: 0.5rem auto 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.78rem;
  color: oklch(0.7 0.012 250);
}
.header-user .muted { color: oklch(0.7 0.012 250); }
.header-user strong { color: oklch(0.95 0.005 250); font-weight: 500; }
.logout-form { margin: 0; display: inline-flex; }
.logout-form button {
  background: transparent;
  color: oklch(0.85 0.01 250);
  border: 1px solid oklch(0.35 0.025 250);
  border-radius: 4px;
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem;
  cursor: pointer;
}
.logout-form button:hover {
  background: oklch(0.32 0.025 250);
  color: oklch(0.98 0.005 250);
}
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
code { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 0.9em; }

/* ─── Strip header (Health + Today, collapsed by default) ─── */
.strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.strip-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
}
.strip-detail summary {
  display: flex; align-items: baseline; gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  list-style: none;
}
.strip-detail summary::-webkit-details-marker { display: none; }
.strip-detail summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-block;
}
.strip-detail[open] summary::before { transform: rotate(90deg); }
.strip-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.strip-value { font-size: 0.9rem; }
.strip-detail[open] > div { padding: 0.75rem; border-top: 1px solid var(--border); }

.status-ok { color: var(--ok); font-weight: 600; }
.status-bad { color: var(--bad); font-weight: 600; }

.health-summary { display: inline-flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.health-pills { display: inline-flex; gap: 0.4rem; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.5rem 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
}
.pill-dot {
  width: 0.45em;
  height: 0.45em;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}
.pill-ok { color: var(--ok); border-color: oklch(0.62 0.16 145 / 0.3); }
.pill-ok .pill-dot { background: var(--ok); box-shadow: 0 0 0 2px oklch(0.62 0.16 145 / 0.18); }
.pill-bad { color: var(--bad); border-color: oklch(0.6 0.2 25 / 0.3); }
.pill-bad .pill-dot { background: var(--bad); box-shadow: 0 0 0 2px oklch(0.6 0.2 25 / 0.18); }
.pill-off { opacity: 0.5; }
.pill-off .pill-dot { background: var(--muted); }

/* ─── Panel base ─── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem 1rem;
  margin-bottom: 1rem;
}
.panel h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
  letter-spacing: -0.005em;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.refresh-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85em;
  border-radius: 4px;
  padding: 0.05rem 0.45rem;
  cursor: pointer;
  line-height: 1.3;
  margin-left: auto;
}
.refresh-btn:hover { color: var(--accent); border-color: var(--accent); }
.panel > details > summary { list-style: none; cursor: pointer; padding: 0.25rem 0; }
.panel > details > summary::-webkit-details-marker { display: none; }
.panel > details > summary::before {
  content: "▸"; color: var(--muted); margin-right: 0.4rem;
  display: inline-block;
  transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
.panel > details[open] > summary::before { transform: rotate(90deg); }
.panel > details[open] > div { margin-top: 0.5rem; }

/* ─── Fleet list ─── */
.panel-fleet { padding-bottom: 0.5rem; }
.fleet { list-style: none; margin: 0; padding: 0; }
.truck {
  border-bottom: 1px solid var(--border);
}
.truck:last-child { border-bottom: none; }
.truck > details > summary {
  display: grid;
  grid-template-columns: 1rem 4rem minmax(14rem, 1fr) minmax(0, 1.6fr);
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.55rem 0.5rem;
  cursor: pointer;
  list-style: none;
  font-variant-numeric: tabular-nums;
  border-radius: 4px;
  transition: background 100ms;
}
.truck > details > summary::-webkit-details-marker { display: none; }
.truck > details > summary::before {
  content: "›";
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1;
  display: inline-block;
  transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
.truck > details[open] > summary::before { transform: rotate(90deg); }
.truck > details > summary:hover { background: var(--surface-2); }

.truck-no {
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.truck-op { color: var(--text); }
.truck-op .muted { font-size: 0.85em; }
.truck-activity {
  display: flex; gap: 0.6rem; align-items: baseline;
  min-width: 0;
}
.truck-activity .when {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 0.88em;
}
.truck-activity .subject {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.truck.truck-quiet .truck-no,
.truck.truck-quiet .truck-op strong {
  color: var(--muted);
  font-weight: 500;
}
.truck.truck-active .truck-no { color: var(--accent); }

/* Logged-in dot */
.dot {
  display: inline-block;
  width: 0.55em; height: 0.55em;
  border-radius: 50%;
  background: var(--muted);
  vertical-align: middle;
  margin-right: 0.25em;
}
.dot-on { background: var(--ok); box-shadow: 0 0 0 3px oklch(0.62 0.16 145 / 0.18); }

/* Truck detail (expanded) */
.truck-detail {
  background: var(--surface-2);
  margin: 0 -1rem;
  padding: 0.75rem 1rem 1rem 2.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.92em;
}
.truck-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.2rem 0.75rem;
  margin: 0 0 0.6rem;
}
.truck-meta dt {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  align-self: center;
}
.truck-meta dd { margin: 0; align-self: center; }

/* ─── Recent messages tables (existing + truck-scoped) ─── */
.recent { width: 100%; border-collapse: collapse; font-size: 0.92em; }
.recent th, .recent td {
  text-align: left;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.recent th {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.recent tr.outcome-sent td:last-child { color: var(--ok); }
.recent tr.outcome-no_route td:last-child,
.recent tr.outcome-oversized td:last-child,
.recent tr.outcome-malformed td:last-child,
.recent tr.outcome-isaac_4xx td:last-child { color: var(--bad); }
.recent tr.outcome-transient_exhausted td:last-child { color: var(--bad); }
.recent tr.outcome-skipped td:last-child { color: var(--muted); }
/* Cold-start seeded: present in the mailbox before the gateway had a cursor,
   deliberately not delivered. Muted like `skipped` — it is a non-event, not a
   failure — but kept as its own rule so it never inherits the red error
   colour if the selector list above is extended. */
.recent tr.outcome-seeded td:last-child { color: var(--muted); }
/* Diagnostic sub-row under a message (NDR reason on a failure, or an
   offline-delivery note on a success): keep it muted, not the red outcome
   colour the :last-child rules above would otherwise apply. */
.recent tr.reason-row td { color: var(--muted) !important; border-top: 0; }
.recent tr.reason-row .reason { white-space: normal; }
/* Marks a 'sent' row that was actually queued OFFLINE for the truck's
   last-known driver — visually distinct from a live delivery. */
.held-retry.held-ok { color: var(--ok); }
.held-retry.held-warn { color: var(--warn); font-weight: 600; }
.held-retry.held-bad { color: var(--bad); font-weight: 600; }
.badge-unconfirmed {
  font-size: 0.72rem;
  padding: 0 0.35rem;
  border-radius: 3px;
  border: 1px solid var(--warn);
  color: var(--warn);
}
.badge-offline {
  display: inline-block;
  font-size: 0.7em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.05em 0.4em;
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--muted);
  vertical-align: middle;
}
.recent-truck { background: var(--surface); border-radius: 4px; }
.recent-load-more {
  text-align: center;
  padding: 0.6rem 0.5rem;
  background: var(--surface-2);
}
.load-more-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: 4px;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.load-more-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--surface);
}

/* ─── Mappings viewer (read-only) ─── */
.mappings { width: 100%; border-collapse: collapse; font-size: 0.92em; }
.mappings th, .mappings td {
  text-align: left;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.mappings th {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.mappings code { font-size: 0.92em; }

/* ─── Top offenders (3-column compact lists) ─── */
.top-offenders {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
}
.top-offenders-section h3 {
  margin: 0 0 0.4rem 0;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.top-offenders-section h3.outcome-skipped { color: var(--muted); }
.top-offenders-section h3.outcome-no_route,
.top-offenders-section h3.outcome-malformed,
.top-offenders-section h3.outcome-transient_exhausted { color: var(--bad); }
.top-offenders-table { width: 100%; border-collapse: collapse; font-size: 0.92em; }
.top-offenders-table td {
  padding: 0.2rem 0.4rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.top-offenders-table td.count {
  text-align: right;
  width: 3em;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 600;
}

/* ─── Tag-failure log viewer ─── */
.tag-failures-toolbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.tag-failures-toolbar select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.15rem 0.4rem;
  font-size: 0.9rem;
}
.tag-failures { width: 100%; border-collapse: collapse; font-size: 0.92em; }
.tag-failures th, .tag-failures td {
  text-align: left;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.tag-failures th {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.tag-failures tr.failure-no_active_driver td:last-child,
.tag-failures tr.failure-active_driver_missing_username td:last-child {
  color: var(--muted);
}
.tag-failures tr.failure-ambiguous_current_driver td:last-child,
.tag-failures tr.failure-isaac_4xx_active_operators td:last-child,
.tag-failures tr.failure-isaac_4xx_recent_positions td:last-child,
.tag-failures tr.failure-isaac_4xx_operator_lookup td:last-child {
  color: var(--bad);
}

/* ─── Health panel internals (kept compact) ─── */
.health { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 1rem; }
.health dt {
  font-size: 0.78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted);
}
.health dd { margin: 0; }
.jobs { width: 100%; border-collapse: collapse; margin-top: 0.5rem; font-size: 0.9em; }
.jobs th, .jobs td {
  text-align: left;
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.jobs th { font-size: 0.78rem; color: var(--muted); }

/* Today counters (used inside collapsed strip — compact layout) */
.counters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.4rem;
}
.counter {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  text-align: left;
}
.counter .label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.counter .value {
  display: block;
  font-size: 1.3rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.counter.total .value, .counter.ndrs .value { color: var(--warn); }
.counter.sent .value { color: var(--ok); }
.counter.ndr .value { color: var(--bad); }
.counter.skipped .value { color: var(--muted); }
.window { margin-top: 0.5rem; font-size: 0.85em; color: var(--muted); }

/* ─── Hide the legacy panels we replaced (kept for direct URL access) ─── */
/* (no rule needed; templates simply don't reference them anymore) */

/* login -------------------------------------------------------------- */
.login-card {
  max-width: 360px;
  margin: 4rem auto;
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.login-card h2 { margin: 0 0 1rem; font-size: 1.25rem; }
.login-card label {
  display: block;
  margin: 0.75rem 0 0.25rem;
  font-size: 0.875rem;
  opacity: 0.75;
}
.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
  box-sizing: border-box;
}
.login-card .banner.error {
  margin: 0.75rem 0;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  background: #ffebe9;
  color: #82071e;
  font-size: 0.875rem;
}
.login-card button[type="submit"] {
  width: 100%;
  margin-top: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
}
.login-card button[type="submit"]:hover { filter: brightness(0.95); }

/* report on-demand controls (issue #30) ------------------------------ */
.report-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
.report-actions .run-report {
  font-size: 0.78rem;
  padding: 0.2rem 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.report-actions .run-report:hover {
  background: var(--surface);
  border-color: var(--accent);
}
.report-actions .run-report:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.report-feedback {
  display: block;
  margin-top: 0.35rem;
  min-height: 1.2em;
  font-size: 0.78rem;
}
.report-status {
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  display: inline-block;
}
.report-status.ok    { background: #d4f4dd; color: #114d22; }
.report-status.warn  { background: #fdf6cf; color: #5a4500; }
.report-status.error { background: #ffebe9; color: #82071e; }

/* OVERRIDE-01: manual operator→truck pin controls */
.pin-badge {
  display: inline-block;
  padding: 0.1em 0.5em;
  border-radius: 0.4em;
  font-size: 0.85em;
  background: oklch(0.72 0.15 75 / 0.18);
  color: var(--warn);
  font-weight: 600;
}
.override-controls {
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-wrap: wrap;
  padding: 0.4em 0.2em 0.2em;
  border-top: 1px dashed var(--border);
  margin-top: 0.3em;
}
.override-controls form {
  display: flex;
  align-items: center;
  gap: 0.4em;
  flex-wrap: wrap;
  margin: 0;
}
.override-controls .ov-input,
.override-controls .ov-expiry {
  padding: 0.25em 0.4em;
  border: 1px solid var(--border);
  border-radius: 0.35em;
  font: inherit;
  background: var(--surface);
  color: var(--text);
}
.override-controls .btn-pin,
.override-controls .btn-clear {
  padding: 0.25em 0.7em;
  border: 1px solid var(--border);
  border-radius: 0.35em;
  cursor: pointer;
  font: inherit;
}
.override-controls .btn-pin { background: var(--accent); color: white; border-color: transparent; }
.override-controls .btn-clear { background: var(--surface-2); color: var(--bad); }
.override-status {
  font-size: 0.85em;
  padding: 0.1em 0.4em;
  border-radius: 0.3em;
}
.override-status.ok    { background: #d4f4dd; color: #114d22; }
.override-status.warn  { background: #fdf6cf; color: #5a4500; }
.override-status.error { background: #ffebe9; color: #82071e; }

.status-badge { margin-right: auto; font-size: 0.8rem; }
.sort-toggle { font-size: 0.75rem; font-weight: 400; margin-left: 0.5rem; }
.sort-toggle a { color: inherit; margin-left: 0.35rem; }
.sort-toggle a.active { font-weight: 600; text-decoration: none; }
.login-card .ms-signin {
  display: block;
  margin: 0.5rem 0 0.25rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid #8c8c8c;
  border-radius: 4px;
  background: #fff;
  color: #5e5e5e;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.login-card .ms-signin:hover { background: #f3f3f3; }
.login-card .login-divider {
  margin: 1rem 0 0;
  font-size: 0.8rem;
  opacity: 0.6;
  text-align: center;
}
.activity-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.activity-table th, .activity-table td { text-align: left; padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); }
.activity-table .nowrap { white-space: nowrap; }
.activity-table tr.audit-login_failed td:nth-child(3),
.activity-table tr.audit-login_throttled td:nth-child(3) { color: #b42318; }
.activity-table tr.audit-user_first_seen td:nth-child(3) { font-weight: 600; }
