/*
 * Fleet AI — Shared Design System
 *
 * Semantic component classes built on CSS custom properties.
 * Dark mode: add/remove `html.dark` — all variables resolve automatically.
 * Tailwind handles layout; this file handles appearance.
 */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Design tokens ──────────────────────────────────────────────────────────── */

:root {
  /* Backgrounds */
  --bg-primary:   #ffffff;          /* page background          */
  --bg-secondary: #f9fafb;          /* card background          */
  --bg-tertiary:  #f3f4f6;          /* hover states, subtle fills */

  /* Borders */
  --border:        #e5e7eb;
  --border-subtle: #f3f4f6;

  /* Text */
  --text-primary:   #111827;
  --text-secondary: #4b5563;
  --text-tertiary:  #6b7280;

  /* Accent — calm blue */
  --accent:        #2563eb;
  --accent-hover:  #1d4ed8;
  --accent-subtle: #eff6ff;         /* accent background tint   */

  /* Semantic colors */
  --success:        #16a34a;  --success-subtle: #f0fdf4;
  --warning:        #d97706;  --warning-subtle: #fffbeb;
  --danger:         #dc2626;  --danger-subtle:  #fef2f2;
  --info:           #2563eb;  --info-subtle:    #eff6ff;

  /* On-accent / overlay (packet P3) */
  --on-accent:      #ffffff;         /* text/icons on a solid accent or semantic fill */
  --overlay:        rgba(0, 0, 0, 0.55);   /* modal / dialog backdrops */
  --overlay-strong: rgba(0, 0, 0, 0.8);    /* chrome over a live video/canvas surface */
  --overlay-border: rgba(255, 255, 255, 0.1);
  --on-overlay:        rgba(255, 255, 255, 0.6);  /* secondary text on --overlay-strong */
  --on-overlay-strong: rgba(255, 255, 255, 0.8);  /* primary text on --overlay-strong */
  --video-bg:       #000000;         /* letterboxing behind a screen/video canvas */

  /* Shape */
  --radius-sm: 0.25rem;   /*  4px */
  --radius-md: 0.5rem;    /*  8px */
  --radius-lg: 0.75rem;   /* 12px */

  /* Elevation */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 8px 32px rgb(0 0 0 / 0.3);   /* dialogs / modal cards */

  /* Type scale (packet P0.1) — nothing renders below --fs-label; --fs-label is
     only for uppercase, letter-spaced labels (see .fleet-label below). */
  --fs-heading:   1.25rem;    /* 20px  page/section headings */
  --fs-title:     1.0625rem;  /* 17px  card titles, the run outcome sentence */
  --fs-body:      0.9375rem;  /* 15px  body copy */
  --fs-secondary: 0.8125rem;  /* 13px  meta, hints, table cells */
  --fs-label:     0.6875rem;  /* 11px  ONLY with text-transform: uppercase + letter-spacing */
  --lh-tight: 1.25;
  --lh-body: 1.5;

  /* Spacing scale (packet P0.2) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
}

/* Dark theme: true dark (not gray-blue) with same calm-blue accent */
html.dark {
  --bg-primary:   #0f0f0f;
  --bg-secondary: #171717;
  --bg-tertiary:  #222222;

  --border:        #2d2d2d;
  --border-subtle: #1e1e1e;

  --text-primary:   #f0f0f0;
  --text-secondary: #a3a3a3;
  --text-tertiary:  #8a8a8a;

  --accent:        #3b82f6;
  --accent-hover:  #60a5fa;
  --accent-subtle: #172554;

  --success:        #22c55e;  --success-subtle: #052e16;
  --warning:        #f59e0b;  --warning-subtle: #451a03;
  --danger:         #ef4444;  --danger-subtle:  #450a0a;
  --info:           #3b82f6;  --info-subtle:    #172554;

  --on-accent:      #ffffff;
  --overlay:        rgba(0, 0, 0, 0.7);
  --overlay-strong: rgba(0, 0, 0, 0.8);
  --overlay-border: rgba(255, 255, 255, 0.1);
  --on-overlay:        rgba(255, 255, 255, 0.6);
  --on-overlay-strong: rgba(255, 255, 255, 0.8);
  --video-bg:       #000000;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 8px 32px rgb(0 0 0 / 0.5);
}

/* ── Base ───────────────────────────────────────────────────────────────────── */

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

/* ── Card ───────────────────────────────────────────────────────────────────── */

/* The `hidden` attribute must win over any author display rule (a flex
   footer, an inline display) — otherwise el.hidden = true does nothing. */
[hidden] { display: none !important; }

.fleet-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

/* ── Uppercase label helper (packet P0.1) — the ONLY sanctioned use of
   --fs-label; anything else needing 11px text is a label like this one. ──── */

.fleet-label {
  font-size: var(--fs-label);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */

.fleet-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: var(--space-2) var(--space-4);
  font-size: var(--fs-secondary);
  font-weight: 500;
  line-height: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 150ms, border-color 150ms, color 150ms, opacity 150ms;
  white-space: nowrap;
  user-select: none;
}
.fleet-btn:disabled,
.fleet-btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.fleet-btn-primary {
  background-color: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.fleet-btn-primary:hover:not(:disabled) {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
}

.fleet-btn-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}
.fleet-btn-secondary:hover:not(:disabled) {
  background-color: var(--border);
}

.fleet-btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.fleet-btn-ghost:hover:not(:disabled) {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}

.fleet-btn-danger {
  background-color: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.fleet-btn-danger:hover:not(:disabled) {
  background-color: var(--danger-subtle);
}

.fleet-btn-success {
  background-color: var(--success);
  color: var(--on-accent);
  border-color: var(--success);
}
.fleet-btn-success:hover:not(:disabled) {
  filter: brightness(0.92);
}

/* ── Badges ─────────────────────────────────────────────────────────────────── */

.fleet-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  font-size: var(--fs-label);
  font-weight: 500;
  line-height: 1.25rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.fleet-badge-success { background-color: var(--success-subtle); color: var(--success); }
.fleet-badge-warning { background-color: var(--warning-subtle); color: var(--warning); }
.fleet-badge-danger  { background-color: var(--danger-subtle);  color: var(--danger);  }
.fleet-badge-neutral { background-color: var(--bg-tertiary);    color: var(--text-secondary); }
.fleet-badge-info    { background-color: var(--info-subtle);    color: var(--info);    }

/* ── Status dots ────────────────────────────────────────────────────────────── */

.fleet-status-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.fleet-status-dot-idle      { background-color: var(--text-tertiary); }
.fleet-status-dot-executing { background-color: var(--accent); animation: fleet-dot-pulse 1.5s ease-in-out infinite; }
.fleet-status-dot-paused    { background-color: var(--warning); }
.fleet-status-dot-offline   { background-color: var(--danger); }
.fleet-status-dot-online    { background-color: var(--success); }
.fleet-status-dot-remote    { background-color: var(--info); }

@keyframes fleet-dot-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* Inline spinner: sized to the surrounding text, coloured by currentColor. */
.fleet-spinner {
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.4em;
  vertical-align: -0.1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: fleet-spin 0.8s linear infinite;
}

@keyframes fleet-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .fleet-spinner { animation-duration: 2.4s; }
}

/* ── AI action overlay ──────────────────────────────────────────────────────── */

/* Pulsing border on the screen card while the AI is driving */
@keyframes ai-glow-pulse {
  0%, 100% {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.9),
                0 0 16px rgba(59, 130, 246, 0.35),
                var(--shadow-sm);
  }
  50% {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.45),
                0 0 28px rgba(59, 130, 246, 0.55),
                var(--shadow-sm);
  }
}

.ai-in-control {
  animation: ai-glow-pulse 2s ease-in-out infinite;
}

/* Dark mode: slightly more intense glow to cut through dark backgrounds */
html.dark .ai-in-control {
  animation: ai-glow-pulse-dark 2s ease-in-out infinite;
}

@keyframes ai-glow-pulse-dark {
  0%, 100% {
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.9),
                0 0 20px rgba(96, 165, 250, 0.45),
                var(--shadow-sm);
  }
  50% {
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.4),
                0 0 34px rgba(96, 165, 250, 0.65),
                var(--shadow-sm);
  }
}

/* Ensure the wrapper div the overlay injects doesn't break flex/grid parents */
.fai-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

/* ── Inputs ─────────────────────────────────────────────────────────────────── */

.fleet-input,
.fleet-textarea {
  display: block;
  width: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  font-size: var(--fs-body);
  line-height: 1.5;
  font-family: inherit;
  transition: border-color 150ms, box-shadow 150ms;
  outline: none;
}
.fleet-input::placeholder,
.fleet-textarea::placeholder {
  color: var(--text-tertiary);
}
.fleet-input:focus,
.fleet-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.fleet-textarea {
  resize: vertical;
  min-height: 5rem;
}

/* ── Nav items ──────────────────────────────────────────────────────────────── */

.fleet-nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: var(--fs-secondary);
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms, color 150ms;
  background: none;
  border: none;
  text-align: left;
}
.fleet-nav-item:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
}
.fleet-nav-item.active {
  background-color: var(--accent-subtle);
  color: var(--accent);
}
.fleet-nav-item.active:hover {
  background-color: var(--accent-subtle);
  color: var(--accent-hover);
}

/* ── Table ──────────────────────────────────────────────────────────────────── */

.fleet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-secondary);
}
.fleet-table thead th {
  /* Uppercase label: kept small (below the 0.8125rem floor) but with wider
     letter-spacing so it stays legible at AA contrast — see fleet.css U0.4. */
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: var(--fs-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background-color: var(--bg-secondary);
}
.fleet-table tbody td {
  padding: 0.875rem 1rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.fleet-table tbody tr:last-child td {
  border-bottom: none;
}
.fleet-table tbody tr:hover td {
  background-color: var(--bg-secondary);
}

/* ── Tabs ───────────────────────────────────────────────────────────────────── */

.fleet-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.625rem 1rem;
  font-size: var(--fs-secondary);
  font-weight: 500;
  color: var(--text-secondary);
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  cursor: pointer;
  text-decoration: none;
  transition: color 150ms, border-color 150ms;
  white-space: nowrap;
  user-select: none;
}
.fleet-tab:hover {
  color: var(--text-primary);
}
.fleet-tab-active,
.fleet-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Empty state ────────────────────────────────────────────────────────────── */

.fleet-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  text-align: center;
}
.fleet-empty-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: var(--radius-lg);
  background-color: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  color: var(--text-tertiary);
}
.fleet-empty-title {
  font-size: var(--fs-title);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.375rem;
}
.fleet-empty-desc {
  font-size: var(--fs-body);
  color: var(--text-secondary);
  max-width: 20rem;
  line-height: 1.6;
  margin: 0;
}

/* Compact variant (ui/lib/empty.js, packet P1.2) — half the padding, for an
   empty state living inside an already-padded card rather than a full page
   section. */
.fleet-empty-state-compact {
  padding: 1.5rem 1rem;
}

/* ── Skeleton loading placeholders (ui/lib/skeleton.js, packet P1.1) ──────────
   `.fleet-skeleton` bars shimmer via a moving gradient; disabled entirely
   under prefers-reduced-motion, where they just sit at a flat fill. */

.fleet-skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--border) 37%, var(--bg-tertiary) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: fleet-shimmer 1.4s ease infinite;
}

.fleet-skeleton-line {
  height: var(--fs-secondary);
}

.fleet-skeleton-cell {
  height: 2.25rem;
  flex: 1 1 auto;
}

.fleet-skeleton-card {
  height: 7rem;
}

@keyframes fleet-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .fleet-skeleton { animation: none; }
}

/* ── Cost card + sparkline (docs/dashboard-ux-phase4-packets.md packet P2) ────
   `.fleet-sparkline` is the bare inline SVG (ui/lib/sparkline.js) -- shrink
   to fit wherever it's dropped, whether that's the Home cost card, an
   Agents card, or the agent detail spend block. */

.fleet-cost-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
}

.fleet-cost-card-head {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.fleet-cost-card-head strong {
  color: var(--text-primary);
}

.fleet-sparkline {
  display: block;
  flex-shrink: 0;
}

.fleet-cost-card-caption {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-secondary);
  color: var(--text-tertiary);
}

/* Agent card (ui/ai_agents.js) and agent detail spend block (ui/ai_agent_detail.js)
   sparklines -- same SVG, just a top margin so it doesn't crowd the row above. */
.fleet-agent-card-spark,
.fleet-agent-spend-spark {
  margin-top: var(--space-2);
}

/* ── Machine card (agent list) ──────────────────────────────────────────────── */

.fleet-machine-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 150ms, box-shadow 150ms;
}
.fleet-machine-card:hover {
  border-color: var(--accent);
}

/* ── Card kebab / overflow menu ─────────────────────────────────────────────── */

.fleet-card-kebab {
  padding: 0.25rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  opacity: 0.35;
  transition: opacity 150ms, background-color 150ms;
}
.fleet-machine-card:hover .fleet-card-kebab,
.fleet-card-kebab:focus,
.fleet-card-kebab:hover {
  opacity: 1;
}

.fleet-card-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 9rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 50;
  padding: 0.25rem;
}

.fleet-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: var(--fs-secondary);
  font-weight: 500;
  color: var(--text-primary);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  transition: background-color 150ms, color 150ms;
}
.fleet-dropdown-item:hover {
  background-color: var(--bg-tertiary);
}
.fleet-dropdown-item-danger {
  color: var(--danger);
}
.fleet-dropdown-item-danger:hover {
  background-color: var(--danger-subtle);
  color: var(--danger);
}

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */

::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background-color: var(--text-tertiary); }

/* ── Help popover (ui/lib/help.js) ─────────────────────────────────────────── */

.fleet-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
  padding: 0;
  font-size: var(--fs-label);
  font-weight: 600;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color 150ms, background-color 150ms, border-color 150ms;
}
.fleet-help:hover {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
}
.fleet-help:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.fleet-popover {
  max-width: 20rem;
  padding: 0.75rem 0.875rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-secondary);
  line-height: 1.5;
  color: var(--text-primary);
  z-index: 60;
}
.fleet-popover strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: var(--fs-secondary);
}
.fleet-popover p {
  margin: 0 0 0.375rem;
  color: var(--text-secondary);
}
.fleet-popover small {
  display: block;
  color: var(--text-tertiary);
  font-size: var(--fs-label);
}

/* ── Toasts (ui/lib/toast.js) ───────────────────────────────────────────────── */

#fleet-toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 22rem;
}

.fleet-toast {
  padding: 0.625rem 0.875rem;
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-tertiary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-secondary);
  color: var(--text-primary);
  cursor: pointer;
  animation: fleet-toast-in 180ms ease-out;
}
.fleet-toast-success { border-left-color: var(--success); }
.fleet-toast-error   { border-left-color: var(--danger);  }
.fleet-toast-info    { border-left-color: var(--info);    }

.fleet-toast-exit {
  opacity: 0;
  transition: opacity 180ms ease-in;
}

@keyframes fleet-toast-in {
  from { transform: translateY(0.5rem); opacity: 0; }
  to   { transform: translateY(0);      opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .fleet-toast       { animation: none; }
  .fleet-toast-exit   { transition: none; }
}

.fleet-toast-link {
  color: inherit;
  text-decoration: none;
}
.fleet-toast-link:hover {
  text-decoration: underline;
}

/* ── Attention bell (ui/lib/attention.js, docs/dashboard-ux-phase3-packets.md
   packet G1) — a header bell + popover on every page, driven by one poller
   against GET /api/attention. ───────────────────────────────────────────── */

.fleet-bell-wrap {
  position: relative;
}

.fleet-bell-count {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  border-radius: 999px;
  background-color: var(--warning);
  color: #1a1207;
  font-size: var(--fs-label);
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}
.fleet-bell-count-danger {
  background-color: var(--danger);
  color: #2a0a0a;
}

.fleet-bell-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 22rem;
  max-width: calc(100vw - 2rem);
  max-height: 26rem;
  overflow-y: auto;
  padding: 0;
}

.fleet-attention-group {
  padding: 0.5rem 0.875rem;
  border-bottom: 1px solid var(--border-subtle);
}
.fleet-attention-group:last-of-type {
  border-bottom: none;
}

.fleet-attention-group-heading {
  font-size: var(--fs-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  margin-bottom: 0.375rem;
}

.fleet-attention-empty {
  margin: 0;
  padding: 0.25rem 0;
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
}

.fleet-attention-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0;
  text-decoration: none;
  color: inherit;
}
.fleet-attention-row:hover .fleet-attention-row-text {
  text-decoration: underline;
}

.fleet-attention-row-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-secondary);
  color: var(--text-primary);
}

.fleet-attention-row-meta {
  flex-shrink: 0;
  font-size: var(--fs-label);
  color: var(--text-tertiary);
}

.fleet-attention-footer {
  padding: 0.625rem 0.875rem;
  border-top: 1px solid var(--border-subtle);
}

.fleet-attention-notify {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
  cursor: pointer;
}

.fleet-attention-notify-hint {
  margin-top: 0.25rem;
  font-size: var(--fs-label);
  color: var(--text-tertiary);
}

/* ── Confirm dialog (ui/lib/dialog.js, packet U8) ─────────────────────────────
   A real two-step confirmation for destructive actions, replacing the
   native browser confirmation prompt. Focus is trapped inside .fleet-dialog
   while open. */

.fleet-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background-color: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.fleet-dialog {
  width: min(26rem, 100%);
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.25rem;
}

.fleet-dialog-title {
  margin: 0 0 0.5rem;
  font-size: var(--fs-title);
  font-weight: 600;
  color: var(--text-primary);
}

.fleet-dialog-body {
  margin: 0 0 1.25rem;
  font-size: var(--fs-secondary);
  line-height: 1.5;
  color: var(--text-secondary);
}

.fleet-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ── Choose dialog (ui/lib/dialog.js chooseDialog, packet R2.4) ───────────── */

.fleet-dialog-options {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0 0 1.25rem;
  max-height: 16rem;
  overflow-y: auto;
}

.fleet-dialog-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: var(--fs-secondary);
  font-family: inherit;
  text-align: left;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.fleet-dialog-option:hover:not(:disabled) {
  background-color: var(--border);
}
.fleet-dialog-option:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.fleet-dialog-option-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.fleet-dialog-option-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fleet-dialog-option-hint {
  flex-shrink: 0;
  font-size: var(--fs-secondary);
  color: var(--text-tertiary);
}

/* ── Chip — neutral pill for types (connection, channel) ─────────────────────
   Colour is reserved for .fleet-badge-* (states); chips never vary by colour. */

.fleet-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  font-size: var(--fs-secondary);
  font-weight: 500;
  line-height: 1.25rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ── Filter bar (U1) ──────────────────────────────────────────────────────── */

.fleet-filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}
.fleet-filterbar .fleet-input,
.fleet-filterbar select {
  height: 2.25rem;
  width: auto;
}

/* ── Runs table: sticky columns + row chevron (U1.2) ─────────────────────── */

.fleet-runs-sticky-status,
.fleet-runs-sticky-instruction {
  position: sticky;
  z-index: 1;
  background-color: var(--bg-secondary);
}
.fleet-runs-sticky-status {
  left: 0;
  min-width: 6.5rem;
}
.fleet-runs-sticky-instruction {
  left: 6.5rem;
  min-width: 14rem;
  max-width: 22rem;
  border-right: 1px solid var(--border);
}
.fleet-runs-table thead th.fleet-runs-sticky-status,
.fleet-runs-table thead th.fleet-runs-sticky-instruction {
  z-index: 2;
}
.fleet-runs-instruction {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.fleet-runs-chevron {
  color: var(--text-tertiary);
  text-align: right;
  width: 2rem;
}

/* ── Runs cards: <720px replacement for the table (U1.2) ──────────────────── */

.fleet-run-card {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background-color: var(--bg-secondary);
  text-decoration: none;
  margin-bottom: 0.625rem;
}
.fleet-run-card:last-child {
  margin-bottom: 0;
}
.fleet-run-card:hover {
  background-color: var(--bg-tertiary);
}
.fleet-run-card-meta {
  font-size: var(--fs-secondary);
  color: var(--text-tertiary);
}

@media (max-width: 720px) {
  .fleet-runs-table-wrap { display: none; }
  .fleet-run-card-list   { display: block !important; }
}

/* ── Home: "Needs you" (U5) ───────────────────────────────────────────────── */

.fleet-attention-row {
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border-subtle);
}
.fleet-attention-row:last-child {
  border-bottom: none;
}
.fleet-attention-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-secondary);
  color: var(--text-primary);
  text-decoration: none;
}
.fleet-attention-summary:last-child {
  border-bottom: none;
}
.fleet-attention-summary:hover {
  color: var(--accent);
}
.fleet-attention-arrow {
  color: var(--text-tertiary);
  margin-left: auto;
}
/* Empty "Needs you": a single line instead of the empty-state block. */
.fleet-attention-clear {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
}
.fleet-attention-clear svg,
.fleet-attention-clear i {
  color: var(--success);
  flex-shrink: 0;
}
.fleet-attention-clear strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ── Run detail: summary strip + step timeline (docs/dashboard-ux-phase2-
   packets.md packet R2) ──────────────────────────────────────────────────── */

#run-facts,
#run-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* One segment per plan step (ui/lib/run_progress.js): the run page's header
   and the computer page's live-view header. */
.run-progress {
  flex: 1 1 14rem;
  min-width: 8rem;
  display: flex;
  align-items: center;
  gap: 3px;
}
.run-progress[hidden] { display: none; }
.run-seg {
  flex: 1 1 0;
  min-width: 3px;
  height: 8px;
  padding: 0;
  border: none;
  border-radius: 2px;
  background-color: var(--border);
  cursor: pointer;
}
.run-seg-done    { background-color: var(--success); }
.run-seg-current { background-color: var(--accent); animation: fleet-dot-pulse 1.5s ease-in-out infinite; }
.run-seg-failed  { background-color: var(--danger); }
.run-seg-stopped { background-color: var(--text-tertiary); }
.run-seg:hover,
.run-seg:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) {
  .run-seg-current { animation: none; }
}

/* ── "Needs you" gate bar (ui/lib/gate_bar.js, packet R4) ─────────────────────
   Sticky amber bar rendered wherever GET /api/tasks/{id}/summary reports a
   `waiting` payload -- run detail (#run-gate-bar) and computer detail
   (#machine-gate-bar). */

.fleet-gate-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--warning);
  background-color: var(--warning-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  animation: fleet-gate-bar-in 180ms ease-out;
}

.fleet-gate-icon {
  flex-shrink: 0;
  font-size: var(--fs-title);
  line-height: 1;
  color: var(--warning);
}

.fleet-gate-text {
  flex: 1 1 16rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  font-size: var(--fs-secondary);
}

.fleet-gate-text strong {
  font-size: var(--fs-body);
  font-weight: 600;
  color: var(--text-primary);
}

.fleet-gate-text span {
  color: var(--text-secondary);
}

/* PACKET HR1 (handoff replies): the model's handoff message keeps its line breaks
   (a proposed table) and scrolls inside the bar instead of pushing the page down. */
.fleet-gate-text .fleet-gate-detail {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 9em;
  overflow: auto;
}

/* A bar with a reply box wants a wide text column: the buttons wrap under it on a
   narrow page instead of squeezing the message. */
.fleet-gate-bar-reply .fleet-gate-text {
  flex-basis: 28rem;
}

.fleet-gate-text .fleet-gate-hint {
  color: var(--text-tertiary);
}

/* A reply box + "Send reply" (gate bar, live feed card, agent run banner). The button
   wraps under the box on a narrow screen. */
.fleet-reply-row {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.fleet-reply-row .fleet-textarea {
  flex: 1 1 14rem;
  min-width: 0;
  width: auto;
  min-height: 0;
  max-height: 10rem;
  font-size: var(--fs-secondary);
}

.fleet-reply-row .fleet-btn {
  flex-shrink: 0;
}

.fleet-gate-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  flex-shrink: 0;
}

.fleet-gate-note {
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
}

@keyframes fleet-gate-bar-in {
  from { transform: translateY(-0.5rem); opacity: 0; }
  to   { transform: translateY(0);       opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .fleet-gate-bar { animation: none; }
}

/* ── Add Computer wizard (ui/computers_modal.js, packet G3) ───────────────── */

.fleet-wizard-steps {
  list-style: none;
  display: flex;
  gap: var(--space-2);
  padding: 0;
  margin: 0 0 1.25rem;
  font-size: var(--fs-secondary);
  color: var(--text-tertiary);
}

.fleet-wizard-step:not(:last-child)::after {
  content: '\00b7';
  margin-left: 0.5rem;
  color: var(--border);
}

.fleet-wizard-step.is-active { color: var(--text-primary); font-weight: 600; }
.fleet-wizard-step.is-done   { color: var(--success); }

.fleet-wizard-substeps {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.fleet-wizard-substeps > li {
  padding: 0.875rem;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.fleet-wizard-details summary {
  cursor: pointer;
  font-size: var(--fs-secondary);
  font-weight: 600;
  color: var(--text-secondary);
}

.fleet-wizard-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* New-computer highlight: the computers-list card (or row) for a computer
   just added over RDP gets a brief accent ring; ui/computers.js removes the
   class again after 5s (packet G3.1). */
.fleet-card-new {
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-md);
}

/* ── Home: first-run checklist (G2, docs/dashboard-ux-phase3-packets.md) ──── */

.fleet-onboarding-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: 0.5rem;
}
.fleet-onboarding-head h2 {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
}
.fleet-onboarding-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.fleet-onboarding-step {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border-subtle);
}
.fleet-onboarding-step:last-child {
  border-bottom: none;
}
.fleet-onboarding-glyph {
  flex-shrink: 0;
  width: 1.25rem;
  text-align: center;
  font-size: var(--fs-body);
  line-height: 1.5rem;
}
.fleet-onboarding-step.is-done .fleet-onboarding-glyph { color: var(--success); }
.fleet-onboarding-step.is-next .fleet-onboarding-glyph { color: var(--accent); }
.fleet-onboarding-step.is-todo .fleet-onboarding-glyph { color: var(--text-tertiary); }
.fleet-onboarding-step-body {
  flex: 1;
  min-width: 0;
}
.fleet-onboarding-step-title {
  margin: 0;
  font-size: var(--fs-secondary);
  font-weight: 600;
  color: var(--text-primary);
}
.fleet-onboarding-step.is-done .fleet-onboarding-step-title,
.fleet-onboarding-step.is-todo .fleet-onboarding-step-title {
  color: var(--text-secondary);
  font-weight: 500;
}
.fleet-onboarding-step-count {
  font-weight: 400;
  color: var(--text-tertiary);
  margin-left: 0.375rem;
}
.fleet-onboarding-step-hint {
  margin: 0.125rem 0 0;
  font-size: var(--fs-secondary);
  color: var(--text-tertiary);
}
.fleet-onboarding-step.is-next .fleet-onboarding-step-hint {
  color: var(--text-secondary);
}
.fleet-onboarding-action {
  flex-shrink: 0;
  align-self: center;
  font-size: var(--fs-secondary);
  padding: 0.25rem 0.625rem;
  height: auto;
  line-height: 1.5;
}
.fleet-onboarding-action-text {
  flex-shrink: 0;
  align-self: center;
  font-size: var(--fs-secondary);
  color: var(--text-tertiary);
  max-width: 12rem;
  text-align: right;
}

/* ── Search / keyboard shortcuts (ui/lib/palette.js, docs/dashboard-ux-phase3-
   packets.md packet G4) ───────────────────────────────────────────────────── */

.fleet-search-btn {
  gap: 0.5rem;
  padding: 0.375rem 0.625rem;
}

.fleet-kbd,
.fleet-search-kbd,
.fleet-gate-btn-kbd {
  display: inline-block;
  padding: 0.0625rem 0.375rem;
  font-family: inherit;
  font-size: var(--fs-label);
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-tertiary);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

@media (max-width: 640px) {
  .fleet-search-kbd,
  .fleet-gate-btn-kbd {
    display: none;
  }
}

.fleet-palette-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 1rem 1rem;
  background-color: var(--overlay);
}

.fleet-palette-box {
  width: min(34rem, 100%);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  animation: fleet-palette-in 120ms ease-out;
}

/* Movement only: a from-zero opacity animation leaves the box invisible if
   the animation is paused at frame 0 (throttled/background tab). */
@keyframes fleet-palette-in {
  from { transform: translateY(-0.5rem); }
  to   { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .fleet-palette-box { animation: none; }
}

.fleet-palette-input-wrap {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

#fleet-palette-input {
  width: 100%;
  padding: 0.875rem 1rem;
  font-size: var(--fs-body);
  color: var(--text-primary);
  background: transparent;
  border: none;
  outline: none;
}
#fleet-palette-input::placeholder {
  color: var(--text-tertiary);
}

.fleet-palette-results {
  overflow-y: auto;
  padding: 0.5rem 0;
}

.fleet-palette-group {
  padding: 0.375rem 0.5rem;
}
.fleet-palette-group-heading {
  padding: 0.25rem 0.5rem;
  font-size: var(--fs-label);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
}

.fleet-palette-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.fleet-palette-row.is-selected {
  background-color: var(--bg-tertiary);
}
.fleet-palette-row-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--fs-secondary);
  color: var(--text-primary);
}
.fleet-palette-row-meta {
  flex-shrink: 0;
  font-size: var(--fs-label);
  color: var(--text-tertiary);
}

.fleet-palette-empty {
  margin: 0;
  padding: 1rem;
  text-align: center;
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
}

.fleet-shortcuts-sheet {
  width: 20rem;
  max-width: calc(100vw - 2rem);
}
.fleet-shortcuts-sheet strong {
  display: block;
  margin-bottom: 0.5rem;
}
.fleet-shortcuts-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}
.fleet-shortcuts-list li {
  font-size: var(--fs-secondary);
  color: var(--text-secondary);
}
.fleet-shortcuts-list kbd {
  margin-right: 0.25rem;
}

/* ── Run detail header (packet P3.4) ───────────────────────────────────────────
   Under 640px the header row wraps: #run-title drops to its own full-width
   row (clamped to 2 lines) while everything that comes before it in the DOM —
   the back link, badges, elapsed time, live dot, and the Stop button — keeps
   its default flex order and stays together on the first row. ─────────────── */
@media (max-width: 640px) {
  #run-title {
    order: 10;
    flex-basis: 100%;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}
