/* The OPS stylesheet — index (stack dashboard), agent cockpit, and the
   captures LIST page. The capture DETAIL page (/captures/{id}) does not load
   this file: it wears the Ember product skin (ember-tokens.css +
   capture-ember.css, its own standalone stylesheet). */

/* ── Reset & base ──────────────────────────────────────────────── */

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

:root {
  --font-system: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-border: #dee2e6;
  --color-text: #212529;
  --color-text-muted: #6c757d;
  --color-header-bg: #343a40;
  --color-header-text: #ffffff;
  --color-section-heading: #495057;
  --color-table-stripe: #f1f3f5;
  --color-link: #0d6efd;
  --color-link-hover: #0a58ca;

  /* Status palette (badges, errors, notes) — four tone pairs. */
  --ok-bg: #d1e7dd;
  --ok-text: #0a3622;
  --err-bg: #f8d7da;
  --err-text: #58151c;
  --warn-bg: #fff3cd;
  --warn-text: #664d03;
  --muted-bg: #e2e3e5;
  --muted-text: #41464b;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-system);
  font-size: 14px;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
}

/* ── Page header ───────────────────────────────────────────────── */

.page-header {
  background: var(--color-header-bg);
  color: var(--color-header-text);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.summary-line {
  font-size: 13px;
  color: #adb5bd;
}

.summary-line.has-unhealthy {
  color: #f8d7da;
  font-weight: 600;
}

.header-links {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

/* ── Reconnecting banner ───────────────────────────────────────── */

.reconnect-banner {
  background: #fff3cd;
  color: #664d03;
  border-bottom: 1px solid #ffc107;
  padding: 6px 24px;
  font-size: 13px;
  display: none;
}

.reconnect-banner.visible {
  display: block;
}

/* ── Main content ──────────────────────────────────────────────── */

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

/* ── Sections ──────────────────────────────────────────────────── */

.section {
  margin-bottom: 32px;
}

.section-heading {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-section-heading);
  margin: 0 0 10px 0;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--color-border);
}

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

.service-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  overflow: hidden;
}

.service-table th,
.service-table td {
  padding: 8px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--color-border);
}

.service-table th {
  background: #f1f3f5;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.service-table tbody tr:last-child td {
  border-bottom: none;
}

.service-table tbody tr:nth-child(even) {
  background: var(--color-table-stripe);
}

.service-table .col-name {
  min-width: 140px;
  font-weight: 500;
}

.service-table .col-name a {
  color: var(--color-text);
  text-decoration: none;
  font-weight: 500;
}

.service-table .col-name a:hover {
  color: var(--color-link);
  text-decoration: underline;
}

.service-table .col-skin {
  color: var(--color-text-muted);
  font-size: 12px;
}

.service-table .col-instance-id {
  color: var(--color-text-muted);
  font-size: 11px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  margin-top: 2px;
}

.container-breakdown {
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 400;
  margin-top: 2px;
}

.service-table .col-state,
.service-table .col-health {
  white-space: nowrap;
}

.service-table .col-urls {
  min-width: 120px;
}

.service-table .col-urls a {
  display: inline-block;
  margin-right: 6px;
  color: var(--color-link);
  text-decoration: none;
  font-size: 12px;
}

.service-table .col-urls a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

.service-table .col-actions {
  color: var(--color-text-muted);
  font-size: 12px;
}

.empty-row td {
  color: var(--color-text-muted);
  font-style: italic;
  padding: 16px 12px;
}

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

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: lowercase;
}

/* UA-default trap: the display above beats the UA's [hidden] rule, so
   `badgeEl.hidden = true` (the cockpit browser-suspended chip, agent.js)
   would leave the badge visible. Keep hidden authoritative. Same trap and
   fix as .cockpit-panel[hidden] below. */
.badge[hidden] {
  display: none;
}

.badge-running,
.badge-healthy {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.badge-exited,
.badge-unhealthy {
  background: var(--err-bg);
  color: var(--err-text);
}

.badge-restarting,
.badge-starting {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.badge-created,
.badge-missing,
.badge-none,
.badge-shared {
  background: var(--muted-bg);
  color: var(--muted-text);
}

.badge-pending {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.badge-browser-suspended {
  background: var(--err-bg);
  color: var(--err-text);
}

/* Capture status/partial badges — see lib/dom.js's CAPTURE_STATUS_BADGE_CLASS. */

.badge-capture-incomplete {
  background: var(--muted-bg);
  color: var(--muted-text);
}

.badge-capture-ready,
.badge-capture-synthesized {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.badge-capture-synthesizing {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.badge-capture-failed,
.badge-capture-corrupt {
  background: var(--err-bg);
  color: var(--err-text);
}

.badge-capture-partial {
  background: var(--warn-bg);
  color: var(--warn-text);
}

/* ── Action buttons ─────────────────────────────────────────────── */

.action-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
}

.action-btn:hover:not(:disabled) {
  background: #e9ecef;
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.action-group {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.action-error {
  font-size: 11px;
  color: var(--err-text);
}

/* ── Infra action-log panel ───────────────────────────────────────
   A <tr>/<td colspan> inserted right after an infra row (see app.js's
   getActionLogPanel), holding a <details> that streams one lifecycle
   action's compose output. Hidden until the action's `started` frame
   arrives; reuses .turn-spinner and .log-output from elsewhere. */

.action-log-row td {
  padding-top: 0;
  border-top: none;
}

.action-log summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.action-log .log-output {
  max-height: 200px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  margin-top: 6px;
}

/* ── Spawn form ─────────────────────────────────────────────────── */

.spawn-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.spawn-form select,
.spawn-form input[type="text"] {
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text);
}

.spawn-form button[type="submit"] {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 12px;
  border: 1px solid var(--color-link);
  border-radius: 4px;
  background: var(--color-link);
  color: #ffffff;
  cursor: pointer;
}

.spawn-form button[type="submit"]:hover:not(:disabled) {
  background: var(--color-link-hover);
  border-color: var(--color-link-hover);
}

.spawn-form button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#spawn-error {
  font-size: 12px;
  color: var(--err-text);
}

/* ── Cockpit: header extensions ────────────────────────────────── */

.cockpit-header {
  flex-wrap: wrap;
  gap: 10px 16px;
}

.back-link {
  color: #adb5bd;
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}

.back-link:hover {
  color: #ffffff;
  text-decoration: underline;
}

.cockpit-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.02em;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

.cockpit-instance-id {
  font-size: 11px;
  color: #adb5bd;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
}

.cockpit-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cockpit-skin {
  font-size: 12px;
  color: #adb5bd;
  padding: 1px 6px;
  border: 1px solid #495057;
  border-radius: 10px;
}

.cockpit-links {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.header-link {
  font-size: 12px;
  font-weight: 500;
  color: #adb5bd;
  text-decoration: none;
  padding: 2px 8px;
  border: 1px solid #495057;
  border-radius: 4px;
  white-space: nowrap;
}

.header-link:hover {
  color: #ffffff;
  border-color: #adb5bd;
}

/* ── Session chip (Sign in / who am I / Sign out) ─────────────── */

.session-chip {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Headers without a `.header-links` nav (its margin-left:auto) push the
 * chip to the right edge themselves. */
.session-chip--end {
  margin-left: auto;
}

.session-name {
  font-size: 12px;
  color: #adb5bd;
  white-space: nowrap;
}

.session-admin {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #ffc107;
  border: 1px solid #665c1e;
  border-radius: 4px;
  padding: 1px 5px;
}

/* The sign-out control is a button, not an anchor — same header-link look. */
button.header-link {
  background: none;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

button.header-link:disabled {
  opacity: 0.5;
  cursor: default;
}

.session-error {
  font-size: 12px;
  color: #f8d7da;
}

.kill-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--err-text);
  border-color: var(--err-bg);
  background: var(--err-bg);
  white-space: nowrap;
}

.kill-btn:hover:not(:disabled) {
  background: #f8d7da;
  border-color: #f5c2c7;
}

/* Two-step inline confirm (lib/confirm_click.js) — replaces window.confirm(),
   which Chrome's dialog-suppression heuristic can silently no-op. First
   click arms a button into this state; a second click within the window
   fires the guarded action. A solid fill so it reads as "one click away",
   distinct from a resting .kill-btn's already-reddish "this is dangerous". */
.confirm-armed {
  background: var(--err-text);
  border-color: var(--err-text);
  color: #fff;
}

.confirm-armed:hover:not(:disabled) {
  background: #46141c;
  border-color: #46141c;
}

/* ── Cockpit: panel layout ─────────────────────────────────────── */
/* Two columns: the Agent chat panel on the left, and `.cockpit-stack` —
   Browser over Live Logs — filling the rest of the screen. The Browser
   panel (`#browser-panel`) stays `hidden` until agent.js's initViewer
   confirms the instance has a headed browser (GET .../viewer 200s):
   while it is hidden, the logs panel grows to fill the whole stack (the
   :has() rule below); once it appears, it takes the stack's height and
   logs shrink to a short strip beneath it. */

.cockpit-content {
  display: flex;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 57px); /* full height minus header */
  box-sizing: border-box;
  overflow: hidden;
}

.cockpit-stack {
  flex: 3;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  min-height: 0;
}

.cockpit-stack #browser-panel {
  flex: 1 1 auto;
  min-height: 0;
}

/* Short strip under the (large) Browser panel; .log-output scrolls inside. */
.cockpit-stack .cockpit-logs {
  flex: 0 0 180px;
  min-height: 0;
}

/* No headed browser on this instance (panel hidden) → logs own the stack. */
.cockpit-stack:not(:has(> #browser-panel:not([hidden]))) .cockpit-logs {
  flex: 1 1 auto;
}

.cockpit-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  overflow: hidden;
}

/* Same UA-default trap as .badge[hidden] above: without this, the
   display: flex beats the UA's [hidden] rule and the Browser panel
   (hidden until the viewer endpoint confirms a headed browser) would
   render for every agent. */
.cockpit-panel[hidden] {
  display: none;
}

.panel-heading {
  margin: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  background: #f1f3f5;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Live-status chip in the agent panel's heading (see observeStatusText). */
.thinking-status {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
  padding: 1px 8px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
}

.thinking-status:empty {
  display: none;
}

/* ── Cockpit: chat panel ───────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 8px;
  word-break: break-word;
}

.chat-bubble-user {
  align-self: flex-end;
  background: #dbe4ff;
  border-bottom-right-radius: 2px;
}

.chat-bubble-assistant {
  align-self: flex-start;
  background: #f1f3f5;
  border-bottom-left-radius: 2px;
}

.chat-bubble-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  color: var(--color-text-muted);
}

.chat-bubble-content {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  font-size: 13px;
  font-family: var(--font-system);
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-bg);
  color: var(--color-text);
  resize: none;
  line-height: 1.4;
}

.chat-input:focus {
  outline: 2px solid var(--color-link);
  outline-offset: 1px;
}

.send-btn {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  background: var(--color-link);
  color: #ffffff;
  border-color: var(--color-link);
  white-space: nowrap;
}

.send-btn:hover:not(:disabled) {
  background: var(--color-link-hover);
  border-color: var(--color-link-hover);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Cockpit: browser panel (embedded neko live viewer) ─────────
   The 8/5 ratio matches the neko sidecar's 1600×1000 display. */

/* Fills the Browser panel below its heading; the neko client letterboxes
   the actual display inside the iframe itself, so no aspect-ratio here. */
.viewer-frame {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: 0;
  background: #000;
}

/* Lives inside the panel heading (a space-between flex row); the heading's
   uppercase/letter-spacing must not bleed into the button label. */
.viewer-seat-toggle {
  text-transform: none;
  letter-spacing: normal;
}

/* ── Cockpit: logs panel ───────────────────────────────────────── */

.log-output {
  flex: 1;
  margin: 0;
  padding: 10px 14px;
  overflow-y: auto;
  font-size: 11px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  line-height: 1.5;
  color: var(--color-text);
  background: #f8f9fa;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Cockpit: panel status / error ─────────────────────────────── */

.panel-error {
  padding: 6px 14px;
  font-size: 12px;
  color: var(--err-text);
  background: #f8d7da;
  border-top: 1px solid #f5c2c7;
  flex-shrink: 0;
}

.panel-note {
  padding: 4px 14px;
  font-size: 11px;
  color: var(--color-text-muted);
  background: #fff3cd;
  border-top: 1px solid #ffc107;
  flex-shrink: 0;
}

/* ── Cockpit: chat turn timeline ───────────────────────────────── */

.turn-spinner {
  width: 10px;
  height: 10px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-link);
  border-radius: 50%;
  animation: turn-spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

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

.turn-thinking,
.turn-tool {
  font-size: 12px;
}

.turn-disclosure,
.turn-tool-head {
  background: none;
  border: none;
  padding: 2px 0;
  font: inherit;
  color: var(--color-text);
  text-align: left;
}

.turn-disclosure,
button.turn-tool-head {
  cursor: pointer;
}

div.turn-tool-head {
  cursor: default;
}

/* Hermes' per-call summary, shown muted after the tool name (secondary). */
.turn-tool-sublabel {
  margin-left: 6px;
  color: var(--color-text-muted);
}

.turn-thinking-body {
  margin: 2px 0 4px 16px;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--color-text-muted);
  background: #f8f9fa;
  border-left: 2px solid var(--color-border);
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

.turn-tool-body {
  margin: 2px 0 4px 16px;
}

.turn-tool-args {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  color: var(--color-text-muted);
  word-break: break-all;
}

.turn-tool-result {
  margin: 4px 0 0;
  padding: 6px 8px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  background: #f8f9fa;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.turn-answer:empty {
  display: none;
}

/* ── Captures list ─────────────────────────────────────────────── */

.service-table .col-title {
  min-width: 160px;
  font-weight: 500;
}

.service-table tbody tr.row-clickable {
  cursor: pointer;
}

.service-table tbody tr.row-clickable:hover {
  background: #e9ecef;
}

.badge-space {
  margin-left: 6px;
}
