/* SAIGE - custom styles on top of Tailwind */

:root {
  --grid-line: rgba(0,0,0,0.06);
}

body { font-feature-settings: 'cv02','cv03','cv04','cv11'; }

/* Card base */
.card {
  background: #fff;
  border: 1px solid #dee2ea;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 1px 2px rgba(20,30,50,0.03);
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.card-title {
  font-weight: 600;
  font-size: 0.875rem;
  color: #1c212c;
}
.card-sub {
  font-size: 0.75rem;
  color: #5b6372;
  margin-top: 2px;
}

/* KPI tile */
.kpi {
  background: #fff;
  border: 1px solid #dee2ea;
  border-radius: 12px;
  padding: 1rem 1.25rem;
}
.kpi-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5b6372;
}
.kpi-value {
  font-size: 1.625rem;
  font-weight: 700;
  color: #0e121a;
  line-height: 1.2;
  margin-top: 4px;
}
.kpi-sub {
  font-size: 0.75rem;
  color: #5b6372;
  margin-top: 2px;
}

/* Heatmap cells */
.heatmap-cell {
  border-radius: 3px;
  transition: transform 120ms ease;
  cursor: default;
}
.heatmap-cell:hover { transform: scale(1.15); outline: 2px solid #2563eb; }

/* Chart container */
.chart-host {
  position: relative;
  width: 100%;
  height: 280px;
}
.chart-host.tall { height: 360px; }
.chart-host.short { height: 200px; }

/* Severity dot */
.dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }
.dot-high { background: #ef4444; }
.dot-medium { background: #f59e0b; }
.dot-low { background: #10b981; }

/* Utility table */
.table-clean {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
.table-clean th {
  text-align: left;          /* default; numeric columns override below */
  font-weight: 600;
  color: #5b6372;
  padding: 8px 10px;
  border-bottom: 1px solid #dee2ea;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
/* Higher specificity than `.table-clean th` so per-cell utilities win.
   Tailwind's `text-right` / `text-center` would otherwise lose the cascade. */
.table-clean th.text-right  { text-align: right;  }
.table-clean th.text-center { text-align: center; }
.table-clean td {
  padding: 10px;
  border-bottom: 1px solid #f1f3f7;
  color: #2c323e;
  vertical-align: middle;
}
/* Numeric columns: equal-width digits + decimal alignment.
   Apply to both the header and the cells so 'TOKENS' / 'COST' visually
   sit above their values without drifting. */
.table-clean th.text-right,
.table-clean td.text-right,
.kpi-value,
.kpi .kpi-sub strong {
  font-variant-numeric: tabular-nums;
}
.table-clean tr:hover td { background: #f7f8fa; }

/* Insight card */
.insight {
  border-left: 3px solid #2563eb;
  background: #f7f8fa;
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
}
.insight.high { border-color: #ef4444; }
.insight.medium { border-color: #f59e0b; }
.insight.low { border-color: #10b981; }
.insight h4 { font-weight: 600; font-size: 0.875rem; margin-bottom: 4px; color: #0e121a; }
.insight p { font-size: 0.8125rem; color: #2c323e; line-height: 1.55; }
.insight .recommend { margin-top: 8px; font-size: 0.8125rem; color: #1d4ed8; font-weight: 500; }

/* Skeleton shimmer */
.skel { background: linear-gradient(90deg, #eef0f4 0%, #f7f8fa 50%, #eef0f4 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 4px; }
@keyframes shimmer { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

/* Empty-state — used inside chart hosts and table containers when the
   current filter window returns no data. Always include an icon + title
   so the user is never staring at blank white space. */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #5b6372;
  text-align: center;
  padding: 1.5rem 1rem;
  min-height: 180px;
}
.chart-host .empty-state {
  position: absolute;
  inset: 0;
  min-height: 0;
}
.empty-state-icon {
  width: 36px;
  height: 36px;
  color: #c2c8d4;
  margin-bottom: 10px;
}
.empty-state-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #2c323e;
}
.empty-state-subtitle {
  font-size: 0.75rem;
  margin-top: 4px;
  color: #5b6372;
  max-width: 420px;
  line-height: 1.5;
}
/* Inline page banner — sits above page content when the window is empty. */
.no-data-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  font-size: 0.8125rem;
  margin-bottom: 1rem;
}
.no-data-banner .lucide {
  flex-shrink: 0;
  color: #ea580c;
}

/* Auto-jump notice (informational) — soft accent, friendly tone. */
.auto-jump-banner {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 10px;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
}
.auto-jump-badge {
  flex-shrink: 0;
  width: 36px; height: 36px;
  background: #2563eb;
  color: #fff;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.auto-jump-title { font-size: 0.875rem; font-weight: 700; color: #1e3a8a; }
.auto-jump-sub   { font-size: 0.75rem; color: #1e40af; margin-top: 2px; line-height: 1.5; opacity: 0.95; }
.auto-jump-action {
  font-size: 0.75rem;
  font-weight: 700;
  color: #1d4ed8;
  background: #fff;
  border: 1px solid #bfdbfe;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  white-space: nowrap;
}
.auto-jump-action:hover { background: #eff6ff; }
.auto-jump-action-sub {
  font-size: 0.7rem;
  color: #2563eb;
  text-decoration: underline;
  white-space: nowrap;
}

/* "No data" warning — louder, attention-grabbing because the user CHOSE this date. */
.empty-window-banner {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 20px;
  border-radius: 10px;
  background: linear-gradient(135deg, #fff7ed 0%, #fed7aa 100%);
  border: 2px solid #f97316;
  color: #7c2d12;
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.15);
}
.empty-window-icon {
  flex-shrink: 0;
  width: 40px; height: 40px;
  background: #ea580c;
  color: #fff;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  animation: empty-pulse 2s ease-in-out infinite;
}
@keyframes empty-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}
.empty-window-title { font-size: 1rem; font-weight: 700; color: #7c2d12; }
.empty-window-sub   { font-size: 0.8125rem; color: #9a3412; margin-top: 4px; line-height: 1.55; }
.empty-window-sub strong { color: #7c2d12; font-weight: 700; }
.empty-window-action {
  font-size: 0.8125rem;
  font-weight: 700;
  color: #fff;
  background: #ea580c;
  padding: 7px 14px;
  border-radius: 6px;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(234, 88, 12, 0.3);
}
.empty-window-action:hover { background: #c2410c; }
.empty-window-action-sub {
  font-size: 0.7rem;
  color: #ea580c;
  text-decoration: underline;
  white-space: nowrap;
}

/* Live alert pulse on the geo map — gentle red breathing for SVG circles.
   Kept as a fallback for the geo-state choropleth markers; the live-alert
   pins use the radar-ping DivIcon below for a more attention-grabbing look. */
@keyframes saige-alert-pulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%      { opacity: 0.6; transform: scale(1.07); }
}
.saige-alert-pulse {
  animation: saige-alert-pulse 1.6s ease-in-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}

/* ============================================================
   Leaflet map z-index containment — prevent map tiles/controls
   from rendering above the sticky topbar (z-1200) or sub-bar.
   ============================================================ */
.leaflet-container { z-index: 0; }
.leaflet-pane      { z-index: 400; }
.leaflet-top, .leaflet-bottom { z-index: 800; }

/* ============================================================
   Sonar-dot marker for live alerts on the geo map.
   ------------------------------------------------------------
   Minimalist, easy-to-click design:
     1. .alert-hit  — invisible 32px square: generous hit area
        for clicking even when alerts overlap densely.
     2. .alert-dot  — solid colored center (10px) with white halo,
        scales 1.4× on hover.
     3. .alert-pulse — single expanding ring; subtle "alive" cue
        without the visual noise of 3-ring HUD glyphs.

   Severity tiers swap --ping-color and pulse cadence:
     .ping-high    → red    #ef4444, fast (1.6s)
     .ping-medium  → amber  #f59e0b, mid  (2.2s)
     .ping-low     → cyan   #06b6d4, slow (2.8s)
   ============================================================ */
.saige-alert-ping {
  position: relative;
  width:  32px;
  height: 32px;
  cursor: pointer;
  /* IMPORTANT: pointer-events ON so clicks land on the marker (the click
     target was previously suppressed and selection on dense maps was
     practically impossible). */
  pointer-events: auto;
  --ping-color: #ef4444;
  --ping-glow:  rgba(239, 68, 68, 0.55);
  --ping-speed: 1.6s;
  transition: transform 0.15s ease-out;
}
.saige-alert-ping:hover { transform: scale(1.18); z-index: 10; }
.saige-alert-ping:hover .alert-dot {
  box-shadow:
    0 0 0 3px #fff,
    0 0 0 5px var(--ping-color),
    0 0 16px var(--ping-color);
}

/* Severity tiers */
.saige-alert-ping.ping-high   { --ping-color: #ef4444; --ping-glow: rgba(239, 68, 68, 0.55); --ping-speed: 1.6s; }
.saige-alert-ping.ping-medium { --ping-color: #f59e0b; --ping-glow: rgba(245, 158, 11, 0.55); --ping-speed: 2.2s; }
.saige-alert-ping.ping-low    { --ping-color: #06b6d4; --ping-glow: rgba(6, 182, 212, 0.55);   --ping-speed: 2.8s; }

/* Big hit area — the marker's clickable surface. Transparent. */
.saige-alert-ping .alert-hit {
  position: absolute;
  inset: 0;
  border-radius: 999px;
}

/* Solid center dot with white outline. The user's primary visual anchor. */
.saige-alert-ping .alert-dot {
  position: absolute;
  top: 50%; left: 50%;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 999px;
  background: var(--ping-color);
  box-shadow:
    0 0 0 2px #fff,
    0 0 0 3px var(--ping-color),
    0 0 8px var(--ping-glow);
  transition: box-shadow 0.15s ease-out;
}

/* Single expanding ring — "alive" pulse, stops well within the hit area. */
.saige-alert-ping .alert-pulse {
  position: absolute;
  top: 50%; left: 50%;
  width: 14px; height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--ping-color);
  border-radius: 999px;
  opacity: 0;
  animation: saige-alert-pulse-ring var(--ping-speed) ease-out infinite;
  pointer-events: none;
}
@keyframes saige-alert-pulse-ring {
  0%   { transform: scale(0.7); opacity: 0.75; }
  100% { transform: scale(2.4); opacity: 0;    }
}

/* Selected state — apply via JS when user clicks an alert. Persistent
   accent ring so the user can trace which alert's popup is open. */
.saige-alert-ping.is-selected .alert-dot {
  box-shadow:
    0 0 0 3px #fff,
    0 0 0 6px var(--ping-color),
    0 0 18px var(--ping-color);
}

/* Reduced-motion users: keep the static dot, drop the pulse. */
@media (prefers-reduced-motion: reduce) {
  .saige-alert-ping .alert-pulse { animation: none; opacity: 0; }
  .saige-alert-pulse             { animation: none; }
}

/* KPI delta arrows — pulse gently to draw the eye toward change. */
@keyframes saige-arrow-up {
  0%, 100% { transform: translateY(0); }
  45%      { transform: translateY(-3px); }
  55%      { transform: translateY(-3px); }
}
@keyframes saige-arrow-down {
  0%, 100% { transform: translateY(0); }
  45%      { transform: translateY(3px); }
  55%      { transform: translateY(3px); }
}
.delta-up   { animation: saige-arrow-up   1.6s ease-in-out infinite; transform-origin: center; }
.delta-down { animation: saige-arrow-down 1.6s ease-in-out infinite; transform-origin: center; }
.kpi-delta  { font-variant-numeric: tabular-nums; }

/* Slider styling — used for refresh & speed sliders. */
.saige-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: #dee2ea;
  border-radius: 999px;
  outline: none;
}
.saige-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2563eb;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #2563eb;
  cursor: pointer;
}
.saige-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2563eb;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #2563eb;
  cursor: pointer;
}

/* Print export styling */
@media print {
  header, aside, .no-print { display: none !important; }
  main { padding: 0 !important; }
  .card { box-shadow: none; border-color: #ccc; page-break-inside: avoid; }
}

/* ====================================================================
   AGENT WORKFORCE HUD — operational monitoring view.

   Light theme by default to match the rest of SAIGE. Tier color is
   carried by the gauge ring, the pulse dot, and the card border accent
   — strong enough to scan from across the room without going full dark.
   TV mode (body.hud-tv) inverts to dark for wall-display use.
   ==================================================================== */

.hud {
  background: #fff;
  border: 1px solid #dee2ea;
  border-radius: 12px;
  padding: 1.25rem;
  color: #1c212c;
  position: relative;
  box-shadow: 0 1px 2px rgba(20,30,50,0.03);
}
.hud-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 14px;
}

/* HUD-level inline KPI chips. Numeric content reads as monospace; padding
   keeps them visually distinct from the layout buttons next to them. */
.hud-stat {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 4px 10px;
  border: 1px solid #dee2ea;
  border-radius: 6px;
  background: #f7f8fa;
}
.hud-stat-label { font-size: 0.6rem;  color: #5b6372; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600; }
.hud-stat-value { font-size: 0.8rem;  color: #0e121a; font-weight: 700; }
.hud-stat-value[data-friction-class="bad"]  { color: #b91c1c; }
.hud-stat-value[data-friction-class="warn"] { color: #b45309; }
.hud-stat-value[data-friction-class="good"] { color: #047857; }

.hud-grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .hud-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Two side-by-side groups (ongoing | completed). On large screens this gives
   6 visible card columns total (2 groups × 3 tier columns each). On smaller
   screens it stacks vertically so the tier columns inside each group still
   read as 3-up. */
.hud-tier-split {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
}
@media (min-width: 1280px) {
  .hud-tier-split { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
}

.hud-status-group {
  background: #fff;
  border: 1px solid #dee2ea;
  border-radius: 10px;
  padding: 10px 12px 12px;
}
.hud-status-group[data-status="ongoing"]   { border-top: 3px solid #2563eb; }
.hud-status-group[data-status="completed"] { border-top: 3px solid #94a3b8; }

.hud-status-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px dashed #dee2ea;
}
.hud-status-title {
  font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em;
  text-transform: uppercase;
  display: inline-flex; align-items: center; gap: 8px;
  color: #1c212c;
}
.hud-status-group[data-status="ongoing"]   .hud-status-title { color: #1d4ed8; }
.hud-status-group[data-status="completed"] .hud-status-title { color: #475569; }
.hud-status-sub { font-size: 0.7rem; color: #5b6372; letter-spacing: 0.02em; }

/* Open-chat live indicator on ongoing cards */
.hud-card-open-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  font-weight: 700;
  color: #1d4ed8;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.1);
  border: 1px solid rgba(37, 99, 235, 0.25);
  letter-spacing: 0.04em;
  margin-left: auto;
  margin-right: 6px;
}

/* Each tier gets its own column. Subtle tinted background that hints
   the tier without screaming dark mode. */
.hud-col {
  background: #f7f8fa;
  border: 1px solid #dee2ea;
  border-radius: 10px;
  padding: 10px;
  display: flex; flex-direction: column;
  min-height: 200px;
  /* Cap relative to the user's viewport so the page never grows past the
     fold — but generous enough to fit ~8 compact cards per column before
     internal scroll. */
  max-height: calc(100vh - 14rem);
}
.hud-col-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px 10px;
  border-bottom: 1px dashed #dee2ea;
  margin-bottom: 8px;
}
.hud-col-title {
  font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em;
  text-transform: uppercase;
  display: inline-flex; align-items: center; gap: 8px;
}
.hud-col-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem; font-weight: 700;
  padding: 1px 8px; border-radius: 999px;
  background: #eef0f4;
  color: #2c323e;
}
.hud-col-body { flex: 1; overflow-y: auto; padding-right: 2px; }
.hud-col-body::-webkit-scrollbar { width: 6px; }
.hud-col-body::-webkit-scrollbar-thumb { background: #c2c8d4; border-radius: 6px; }

/* TIER · 6: each tier column splits into a 2-col card grid inside, so
   the visible card-column count is 3 outer × inner = 6. Breakpoint
   collapses to 1-col only on tablet (≤768px) so most desktops get the
   dense view. */
.hud[data-layout="tier"] .hud-col-body {
  display: grid;
  grid-template-columns: repeat(var(--hud-tier-inner, 1), minmax(0, 1fr));
  gap: 8px;
  align-content: start;
}
.hud[data-layout="tier"] .hud-col-body > .hud-card { margin-bottom: 0; }
@media (max-width: 768px) {
  .hud[data-layout="tier"] .hud-col-body { grid-template-columns: 1fr; }
}

/* Tier accents — apply to column header AND a subtle top stripe. */
.hud-col[data-tier="critical"] { background: linear-gradient(180deg, rgba(239,68,68,0.05) 0%, #f7f8fa 60%); border-color: rgba(239,68,68,0.25); }
.hud-col[data-tier="critical"] .hud-col-title { color: #b91c1c; }
.hud-col[data-tier="critical"] .hud-col-count { background: rgba(239,68,68,0.10); color: #b91c1c; }

.hud-col[data-tier="watch"]    { background: linear-gradient(180deg, rgba(245,158,11,0.05) 0%, #f7f8fa 60%); border-color: rgba(245,158,11,0.25); }
.hud-col[data-tier="watch"]    .hud-col-title { color: #b45309; }
.hud-col[data-tier="watch"]    .hud-col-count { background: rgba(245,158,11,0.10); color: #b45309; }

.hud-col[data-tier="healthy"]  { background: linear-gradient(180deg, rgba(16,185,129,0.05) 0%, #f7f8fa 60%); border-color: rgba(16,185,129,0.25); }
.hud-col[data-tier="healthy"]  .hud-col-title { color: #047857; }
.hud-col[data-tier="healthy"]  .hud-col-count { background: rgba(16,185,129,0.10); color: #047857; }

/* ----- Agent card ------------------------------------------------------ */
.hud-card {
  position: relative;
  background: #fff;
  border: 1px solid #dee2ea;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  font-family: 'Inter', sans-serif;
}
.hud-card:hover {
  transform: translateY(-1px);
  border-color: #2563eb;
  box-shadow: 0 0 0 1px rgba(37,99,235,0.25), 0 4px 10px -6px rgba(20,30,50,0.18);
}
.hud-card[data-tier="critical"] {
  border-color: rgba(239,68,68,0.4);
  box-shadow: 0 0 0 1px rgba(239,68,68,0.06);
}
.hud-card[data-tier="critical"]:hover {
  border-color: #ef4444;
  box-shadow: 0 0 0 1px rgba(239,68,68,0.45), 0 4px 12px -4px rgba(239,68,68,0.30);
}
.hud-card[data-tier="watch"]   { border-color: rgba(245,158,11,0.35); }
.hud-card[data-tier="watch"]:hover  { border-color: #f59e0b; box-shadow: 0 0 0 1px rgba(245,158,11,0.40); }
.hud-card[data-tier="healthy"] { border-color: rgba(16,185,129,0.30); }
.hud-card[data-tier="healthy"]:hover { border-color: #10b981; box-shadow: 0 0 0 1px rgba(16,185,129,0.40); }

.hud-card-row1 {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 2px;
  font-size: 0.65rem;
  color: #5b6372;
  font-family: 'JetBrains Mono', monospace;
}
.hud-card-id { letter-spacing: 0.04em; }

.hud-pulse {
  display: inline-block; width: 8px; height: 8px; border-radius: 999px;
  background: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,0.15);
}
.hud-card[data-tier="critical"] .hud-pulse { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,0.18); animation: hud-blink 1.4s ease-in-out infinite; }
.hud-card[data-tier="watch"]    .hud-pulse { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,0.18); }
@keyframes hud-blink { 0%,100% { opacity: 1 } 50% { opacity: 0.35 } }

.hud-card-name {
  font-weight: 700; color: #0e121a;
  font-size: 0.78rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 4px;
}

.hud-card-row2 { display: flex; align-items: center; gap: 10px; }

/* Friction-score radial gauge. Conic gradient draws the score arc, the
   pseudo-element punches the centre out so the score number sits inside
   a clean circle. Track color stays subtle on white. */
.hud-gauge {
  flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  background: conic-gradient(from -90deg, var(--gauge-color, #2563eb) calc(var(--gauge-pct) * 1%), #eef0f4 0);
}
.hud-gauge::before {
  content: ''; position: absolute; inset: 3px; border-radius: 999px;
  background: #fff;
}
.hud-gauge-value {
  position: relative;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.65rem;
  color: #0e121a;
}
.hud-card[data-tier="critical"] .hud-gauge { --gauge-color: #ef4444; }
.hud-card[data-tier="watch"]    .hud-gauge { --gauge-color: #f59e0b; }
.hud-card[data-tier="healthy"]  .hud-gauge { --gauge-color: #10b981; }

.hud-stats { flex: 1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 8px; }
.hud-stat-line {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 6px;
  font-size: 0.65rem;
  font-family: 'JetBrains Mono', monospace;
}
.hud-stat-line .lbl  { color: #8c93a4; letter-spacing: 0.03em; font-weight: 600; }
.hud-stat-line .val  { color: #2c323e; font-weight: 700; }
.hud-stat-line .val.warn { color: #b45309; }
.hud-stat-line .val.bad  { color: #b91c1c; }

/* Empty column placeholder */
.hud-col-empty {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  color: #8c93a4;
  font-size: 0.75rem;
  font-style: italic;
}

/* ----- Layout selector (Tier · Wall · column count) ------------------- */
.hud-layout-btn {
  color: #5b6372;
  background: transparent;
  border: 0;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: background 0.12s ease, color 0.12s ease;
}
.hud-layout-btn:hover { color: #1c212c; }
.hud-layout-btn-active {
  background: #fff;
  color: #1d4ed8;
  box-shadow: 0 1px 2px rgba(20,30,50,0.06);
}

/* ----- Wall mode: dense ranked grid, no tier columns ----------------- */
.hud-wall {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(var(--hud-cols, 5), minmax(0, 1fr));
  max-height: 70vh;
  overflow-y: auto;
  padding: 4px;
  background: #f7f8fa;
  border: 1px solid #dee2ea;
  border-radius: 10px;
}
.hud-wall::-webkit-scrollbar { width: 6px; }
.hud-wall::-webkit-scrollbar-thumb { background: #c2c8d4; border-radius: 6px; }
@media (max-width: 1100px) {
  .hud-wall { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .hud-wall { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.hud-wall .hud-card { margin-bottom: 0; }

/* ----- TV mode — body class added when "TV" toggle is on.
   Inverts the HUD to a dark wall-display theme: high contrast on a CRT/LCD
   in a dim ops room, autorefresh holds the data live. Everything outside
   the HUD is hidden so a single panel fills the screen. -------------- */
body.hud-tv {
  background: #060912;
  overflow: hidden;
}
body.hud-tv header,
body.hud-tv aside,
body.hud-tv .no-print,
body.hud-tv #hudWorkforce ~ section,
body.hud-tv .sticky.top-16 {
  display: none !important;
}
body.hud-tv main {
  padding: 0 !important;
  max-width: none !important;
}
body.hud-tv #hudWorkforce {
  position: fixed; inset: 0;
  margin: 0;
  border-radius: 0;
  border: 0;
  padding: 1.5rem 2rem;
  display: flex; flex-direction: column;
  z-index: 100;
  background: linear-gradient(180deg, #060912 0%, #0a0f1c 100%);
  color: #cfd6e6;
  box-shadow: none;
}
body.hud-tv #hudClock { color: #e2e8f0; }
body.hud-tv .hud-head { margin-bottom: 1.25rem; color: #cfd6e6; }
body.hud-tv .hud-head .text-ink-500,
body.hud-tv .hud-head .text-ink-700,
body.hud-tv .hud-layout-btn { color: #8b94aa; }
body.hud-tv .hud-layout-toggle { background: rgba(255,255,255,0.04); border-color: #1f2740; }
body.hud-tv .hud-layout-btn-active { background: rgba(96,165,250,0.18); color: #cbd5e1; box-shadow: inset 0 0 0 1px rgba(96,165,250,0.35); }
body.hud-tv #hudTvToggle { background: rgba(255,255,255,0.04); border-color: #1f2740; color: #cbd5e1; }
body.hud-tv .hud-stat { background: rgba(255,255,255,0.03); border-color: #1f2740; }
body.hud-tv .hud-stat-label { color: #8b94aa; }
body.hud-tv .hud-stat-value { color: #e2e8f0; font-size: 1rem; }

body.hud-tv .hud-grid,
body.hud-tv .hud-wall { flex: 1; max-height: none; background: rgba(0,0,0,0.25); border-color: #1f2740; }
body.hud-tv .hud-col { background: rgba(0,0,0,0.28); border-color: #1f2740; max-height: none; }
body.hud-tv .hud-col[data-tier="critical"] { background: rgba(239,68,68,0.06); }
body.hud-tv .hud-col[data-tier="watch"]    { background: rgba(245,158,11,0.06); }
body.hud-tv .hud-col[data-tier="healthy"]  { background: rgba(16,185,129,0.06); }
body.hud-tv .hud-col-head { border-bottom-color: #1f2740; }
body.hud-tv .hud-col-count { background: rgba(255,255,255,0.06); color: #cbd5e1; }

body.hud-tv .hud-card {
  background: linear-gradient(180deg, #131a2c 0%, #0f1524 100%);
  border-color: #1f2740;
  padding: 14px 16px;
}
body.hud-tv .hud-card-name { color: #e2e8f0; font-size: 1rem; }
body.hud-tv .hud-card-row1 { color: #8b94aa; }
body.hud-tv .hud-card[data-tier="critical"] { border-color: rgba(239,68,68,0.45); box-shadow: 0 0 14px -6px rgba(239,68,68,0.4); }
body.hud-tv .hud-card[data-tier="watch"]    { border-color: rgba(245,158,11,0.32); }
body.hud-tv .hud-card[data-tier="healthy"]  { border-color: rgba(16,185,129,0.28); }
body.hud-tv .hud-gauge { width: 48px; height: 48px; background: conic-gradient(from -90deg, var(--gauge-color, #2563eb) calc(var(--gauge-pct) * 1%), rgba(255,255,255,0.06) 0); }
body.hud-tv .hud-gauge::before { background: #0f1524; }
body.hud-tv .hud-gauge-value { color: #e2e8f0; font-size: 0.875rem; }
body.hud-tv .hud-stat-line { font-size: 0.8125rem; }
body.hud-tv .hud-stat-line .lbl { color: #6b748a; }
body.hud-tv .hud-stat-line .val { color: #cbd5e1; }
body.hud-tv .hud-stat-line .val.warn { color: #fcd34d; }
body.hud-tv .hud-stat-line .val.bad  { color: #fca5a5; }

/* Floating exit button — only visible in TV mode */
.hud-tv-exit {
  position: fixed;
  top: 1rem; right: 1rem;
  z-index: 200;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  font-size: 0.75rem; font-weight: 700;
  color: #fca5a5;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s ease;
}
.hud-tv-exit:hover { opacity: 1; }
body:not(.hud-tv) .hud-tv-exit { display: none !important; }

/* High-Friction Sessions grid — 6 cols × 3 rows on desktop wall display.
   Auto-collapses on smaller viewports so cards stay readable. */
.risk-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 768px)  { .risk-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .risk-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1366px) { .risk-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
@media (min-width: 1600px) { .risk-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.risk-card { min-height: 120px; }

/* Mobile responsive — tables can horizontal-scroll inside their cards
   without us wrapping every <table> tag. min-width keeps columns legible
   so they don't crush on narrow viewports.
   Cards themselves get tighter padding so KPIs fit two-up at phone width. */
@media (max-width: 768px) {
  .card { padding: 1rem; overflow-x: auto; }
  .kpi  { padding: 0.75rem 1rem; }
  .kpi-value { font-size: 1.375rem; }
  .table-clean { min-width: 480px; }
  .card-title { font-size: 0.8125rem; }
  /* Allow text wrapping in headers that previously had nowrap. */
  .table-clean th { white-space: normal; }
}


/* ========================================================================
   Agent presence — shared between embedded HUD pill (agents.php) and the
   dedicated wallboard (agent_status.php).

   ON_CHAT  = green   (good)
   IDLE     = amber   (warn) — needs supervisor nudging if it sticks
   OFFLINE  = grey    (ink)  — neutral, not on shift
   ======================================================================== */
.presence-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 6px;
  font-size: 0.625rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
  border-radius: 999px; border: 1px solid transparent;
  white-space: nowrap;
}
.presence-pill .presence-dot {
  width: 6px; height: 6px; border-radius: 50%;
  display: inline-block; flex: 0 0 6px;
}
.presence-pill-on_chat {
  color: #047857; background: rgba(16,185,129,0.10);
  border-color: rgba(16,185,129,0.35);
}
.presence-pill-on_chat .presence-dot {
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16,185,129,0.55);
  animation: presence-throb 1.6s ease-out infinite;
}
.presence-pill-idle {
  color: #b45309; background: rgba(245,158,11,0.10);
  border-color: rgba(245,158,11,0.35);
}
.presence-pill-idle .presence-dot { background: #f59e0b; }
.presence-pill-offline {
  color: #5b6372; background: rgba(91,99,114,0.08);
  border-color: rgba(91,99,114,0.25);
}
.presence-pill-offline .presence-dot { background: #94a3b8; }

@keyframes presence-throb {
  0%   { box-shadow: 0 0 0 0   rgba(16,185,129,0.55); }
  60%  { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0   rgba(16,185,129,0); }
}

.hud-presence-rollup {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: 6px;
}

/* ========================================================================
   Agent Status wallboard — page B (?page=agent_status)
   Three-column live-presence view, presence-first.
   ======================================================================== */
.agent-status-page {
  display: flex; flex-direction: column; gap: 1rem;
}
.status-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 1rem;
  padding: 14px 18px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid #dee2ea;
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(20,30,50,0.03);
}
.status-head-l, .status-head-r {
  display: flex; align-items: center; gap: 1rem;
}
.status-clock { display: flex; align-items: baseline; gap: 8px; }
.status-clock-date {
  font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: #5b6372;
}
.status-head-meta {
  font-size: 0.6875rem; color: #5b6372;
  letter-spacing: 0.04em; text-transform: uppercase;
}

.status-rollup {
  display: flex; gap: 8px;
}
.status-rollup-card {
  display: flex; flex-direction: column; align-items: center;
  min-width: 76px;
  padding: 8px 14px;
  border: 1px solid; border-radius: 10px;
  background: #fff;
}
.status-rollup-num { font-size: 1.5rem; font-weight: 800; line-height: 1; font-feature-settings: 'tnum'; }
.status-rollup-lbl { font-size: 0.625rem; font-weight: 700; letter-spacing: 0.08em; margin-top: 4px; }
.status-rollup-on_chat { border-color: rgba(16,185,129,0.45); }
.status-rollup-on_chat .status-rollup-num { color: #047857; }
.status-rollup-on_chat .status-rollup-lbl { color: #047857; }
.status-rollup-idle    { border-color: rgba(245,158,11,0.45); }
.status-rollup-idle .status-rollup-num { color: #b45309; }
.status-rollup-idle .status-rollup-lbl { color: #b45309; }
.status-rollup-offline { border-color: rgba(91,99,114,0.30); }
.status-rollup-offline .status-rollup-num { color: #475569; }
.status-rollup-offline .status-rollup-lbl { color: #475569; }

.status-empty {
  padding: 3rem; text-align: center; color: #5b6372;
  border: 1px dashed #cbd5e1; border-radius: 12px; background: #fff;
}

.status-wall {
  display: grid; gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 1100px) {
  .status-wall { grid-template-columns: 1fr; }
}

.status-col {
  display: flex; flex-direction: column;
  background: #fff;
  border: 1px solid #dee2ea;
  border-radius: 12px;
  overflow: hidden;
}
.status-col-head {
  padding: 10px 14px;
  border-bottom: 1px solid #dee2ea;
  background: #f8fafc;
}
.status-col-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.75rem; font-weight: 800;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.status-col-count {
  margin-left: auto;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; padding: 1px 8px;
  font-size: 0.6875rem; font-weight: 800;
  background: rgba(0,0,0,0.06); border-radius: 999px;
  color: #1c212c;
}
.status-col-sub {
  font-size: 0.6875rem; color: #5b6372; margin-top: 2px;
}
.status-col-on_chat .status-col-head { background: rgba(16,185,129,0.06); }
.status-col-on_chat .status-col-title { color: #047857; }
.status-col-idle    .status-col-head { background: rgba(245,158,11,0.06); }
.status-col-idle    .status-col-title { color: #b45309; }
.status-col-offline .status-col-head { background: rgba(91,99,114,0.05); }
.status-col-offline .status-col-title { color: #475569; }

.status-col-body {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px;
  min-height: 120px;
  max-height: 70vh; overflow-y: auto;
}
.status-col-empty {
  font-size: 0.75rem; color: #9aa1ad; padding: 1rem; text-align: center; font-style: italic;
}

/* ----- Tile (one agent) ----- */
.status-tile {
  display: block;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-left: 4px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  text-decoration: none; color: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.status-tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(15,23,42,0.07);
  border-color: #94a3b8;
}
.status-col-on_chat .status-tile { border-left-color: #10b981; }
.status-col-idle    .status-tile { border-left-color: #f59e0b; }
.status-col-offline .status-tile { border-left-color: #94a3b8; }
.status-tile.idle-stale-warn     { border-left-color: #f97316; background: rgba(249,115,22,0.04); }
.status-tile.idle-stale-critical { border-left-color: #ef4444; background: rgba(239,68,68,0.06); }

.status-tile-header {
  display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.status-tile-presence .presence-dot {
  width: 8px; height: 8px; border-radius: 50%;
}
.status-col-on_chat .status-tile-presence .presence-dot {
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16,185,129,0.55);
  animation: presence-throb 1.6s ease-out infinite;
}
.status-col-idle    .status-tile-presence .presence-dot { background: #f59e0b; }
.status-col-offline .status-tile-presence .presence-dot { background: #94a3b8; }

.status-tile-name {
  font-size: 0.8125rem; font-weight: 700; color: #1c212c;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.status-tile-multi {
  font-size: 0.6875rem; font-weight: 800;
  color: #b45309; background: rgba(245,158,11,0.12);
  padding: 1px 6px; border-radius: 4px;
}
.status-tile-stats {
  display: grid; grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 4px;
}
.status-tile-stat {
  display: flex; flex-direction: column;
  padding: 4px 6px;
  background: rgba(15,23,42,0.03);
  border-radius: 4px;
}
.status-tile-stat-lbl {
  font-size: 0.5625rem; font-weight: 700; letter-spacing: 0.06em;
  color: #5b6372; text-transform: uppercase;
}
.status-tile-stat-val {
  font-size: 0.8125rem; font-weight: 700; color: #1c212c;
  font-feature-settings: 'tnum'; line-height: 1.2;
}
.status-tile-foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 6px;
  font-size: 0.625rem; color: #94a3b8;
  font-family: ui-monospace, monospace;
}

.status-foot {
  font-size: 0.75rem; color: #5b6372;
  padding: 12px 18px;
  border: 1px solid #e5e7eb; border-radius: 10px;
  background: #fafbfc;
}
.status-foot p { margin: 0; line-height: 1.5; }
.presence-inline-on_chat { color: #047857; font-weight: 700; }
.presence-inline-idle    { color: #b45309; font-weight: 700; }
.presence-inline-offline { color: #475569; font-weight: 700; }
.status-foot code {
  background: rgba(0,0,0,0.04);
  padding: 0 4px; border-radius: 3px;
  font-size: 0.6875rem;
}


