:root {
  color-scheme: light dark;

  --bg: #f7f7f5;
  --bg-card: #ffffff;
  --border: #e5e5e2;
  --fg: #101418;
  --fg-muted: #5f6b76;
  --accent: #1f6feb;
  --danger: #d93025;
  --success: #1e8e3e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --bg-card: #161b22;
    --border: #30363d;
    --fg: #e6edf3;
    --fg-muted: #8b949e;
    --accent: #58a6ff;
    --danger: #f85149;
    --success: #3fb950;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family:
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}
/* No global hover underline — too noisy on cards + nav. Specific link
   types (external URLs, button-links) add their own underline. */
a:hover {
  text-decoration: none;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

.muted {
  color: var(--fg-muted);
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  background: var(--border);
  color: var(--fg);
}
.badge.success {
  background: rgba(31, 142, 62, 0.15);
  color: var(--success);
}
.badge.danger {
  background: rgba(217, 48, 37, 0.15);
  color: var(--danger);
}
.badge.pending {
  background: rgba(31, 111, 235, 0.15);
  color: var(--accent);
}

.button {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.submit-build-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 132px;
}
.button-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 999px;
  animation: button-spinner 0.75s linear infinite;
  flex: 0 0 auto;
}
@keyframes button-spinner {
  to {
    transform: rotate(360deg);
  }
}

input,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--fg);
  font: inherit;
}
textarea {
  min-height: 120px;
  resize: vertical;
}

/* Plan 042 — server-rendered dashboard additions. */

/* Top nav strip: argot mark on the left, breathing room around it. */
.topnav {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.topnav .argot-mark {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Identity strip directly under the top nav. Less visually loud. */
.operator-strip {
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
  font-size: 13px;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Business list cards: clickable link wrappers stay un-decorated. */
.business-card-link {
  color: inherit;
  text-decoration: none;
  display: block;
}
.business-card-link:hover .card {
  border-color: var(--accent);
}

.refresh-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.refresh-status {
  display: flex;
  justify-content: flex-end;
  height: 0;
  overflow: visible;
}
.refresh-indicator {
  display: none;
  color: var(--fg-muted);
  font-size: 12px;
  line-height: 1;
}
[data-refresh-error] > .refresh-heading .refresh-indicator,
[data-refresh-error] > .refresh-status .refresh-indicator {
  display: inline;
}

/* Row links inside cards (business detail's build list, build detail's
   activity feed). Reset link styling so the row reads as data, not nav. */
.build-row, .decision-row {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.build-row:last-child, .decision-row:last-child { border-bottom: none; }
.build-row:hover { background: rgba(127,127,127,0.05); }

/* Button-styled-as-link (sign out, etc). Keep underline so it reads as a
   verb, not chrome. Matches operator expectations from the React dashboard. */
.button-link {
  background: none; border: none; color: var(--accent);
  cursor: pointer; padding: 0; font: inherit; text-decoration: underline;
}

/* Real buttons. */
.button {
  padding: 8px 16px; border: 1px solid var(--border); background: var(--bg);
  color: var(--fg); border-radius: 6px; cursor: pointer; font: inherit;
  font-size: 14px; line-height: 1.2;
}
.button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.button.reject { color: var(--danger); border-color: var(--danger); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Build detail headings + cards: more breathing room, monospace build id. */
h1, h2 { font-weight: 600; }
h1 { font-size: 28px; margin: 16px 0 8px; }
h1.build-id {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 22px;
  letter-spacing: 0.02em;
}
h2 { font-size: 18px; margin: 32px 0 12px; }

/* Long intent / payload text in cards: wrap nicely, don't overflow. */
.card pre, .event-body { white-space: pre-wrap; word-break: break-word; }

/* Container slightly wider — 1040px feels right for dashboards on retina. */
.container { max-width: 1040px; }

/* SSE codex log */
.event-line { padding: 4px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
.event-line:last-child { border-bottom: none; }
.event-body {
  margin: 4px 0 0 0; padding: 6px 8px; background: rgba(0,0,0,0.18);
  border-radius: 4px; white-space: pre-wrap; word-break: break-word;
  max-height: 220px; overflow: auto;
}

/* Plan 042 — matrix login scene. Ported from the React dashboard's
   MatrixScene component. Only applied to .matrix-scene pages
   (sign-in + auth callback). Dashboard pages keep the clean theme. */
.matrix-scene {
  background: #000;
  color: #5ee881;
  font-family: "Courier New", "Lucida Console", "Liberation Mono", ui-monospace, monospace;
  min-height: 100vh;
}
.matrix-scene canvas#rain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: 0.85;
}
.matrix-scene::before {
  content: ""; position: fixed; inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.22) 3px, rgba(0,0,0,0.22) 4px
  );
  pointer-events: none; z-index: 2;
}
.matrix-scene::after {
  content: ""; position: fixed; inset: 0;
  background: radial-gradient(
    ellipse at center,
    rgba(0,0,0,0.55) 0%, rgba(0,0,0,0) 35%, rgba(0,0,0,0.75) 100%
  );
  pointer-events: none; z-index: 1;
}
.matrix-scene main {
  position: relative; z-index: 3; min-height: 100vh;
  display: grid; place-items: center; gap: 32px; padding: 32px;
}
.matrix-mark {
  color: #5ee881; text-decoration: none;
  font-size: clamp(24px, 5.5vw, 64px); font-weight: 700;
  letter-spacing: 0.1em;
  text-shadow: 0 0 2px #5ee881, 0 0 8px rgba(94,232,129,0.5), 0 0 18px rgba(0,0,0,0.9);
  animation: argot-flicker 5.2s infinite;
  margin: 0;
}
a.matrix-mark:hover { text-decoration: none; }
@keyframes argot-flicker {
  0%, 91%, 100% { opacity: 1; }
  92% { opacity: 0.88; } 93% { opacity: 1; }
  96% { opacity: 0.94; } 97% { opacity: 1; }
}
.matrix-caret {
  display: inline-block; margin-left: 2px;
  animation: argot-blink 1s steps(1, end) infinite;
}
@keyframes argot-blink {
  0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; }
}
.matrix-link, .matrix-button {
  color: #5ee881; background: rgba(0,0,0,0.4);
  border: 1px solid rgba(94,232,129,0.4); border-radius: 2px;
  padding: 10px 18px; font-family: inherit; font-size: 14px;
  letter-spacing: 0.2em; text-transform: uppercase; text-decoration: none;
  opacity: 0.85; cursor: pointer; transition: opacity 120ms, border-color 120ms;
}
.matrix-link:hover, .matrix-button:hover {
  opacity: 1; border-color: #5ee881; text-decoration: none;
}
.matrix-button[disabled] { opacity: 0.4; cursor: not-allowed; }
.matrix-input {
  width: 100%; padding: 10px 12px; background: rgba(0,0,0,0.5);
  border: 1px solid rgba(94,232,129,0.4); border-radius: 2px;
  color: #5ee881; font-family: inherit; font-size: 14px; letter-spacing: 0.04em;
}
.matrix-input:focus {
  outline: none; border-color: #5ee881; box-shadow: 0 0 0 1px rgba(94,232,129,0.4);
}
.matrix-input::placeholder { color: rgba(94,232,129,0.45); }
.matrix-panel {
  background: rgba(0,0,0,0.55); border: 1px solid rgba(94,232,129,0.35);
  border-radius: 2px; padding: 24px; width: min(100%, 380px);
  backdrop-filter: blur(2px);
}
.matrix-label {
  display: block; font-size: 11px; letter-spacing: 0.2em;
  text-transform: uppercase; opacity: 0.7; margin-bottom: 8px;
}
.matrix-hint { font-size: 12px; opacity: 0.6; margin-top: 16px; }
.matrix-error { font-size: 12px; color: #ff8484; margin-top: 12px; }
@media (prefers-reduced-motion: reduce) {
  .matrix-caret { animation: none; opacity: 0.7; }
  .matrix-mark { animation: none; }
  .matrix-scene canvas#rain { display: none; }
}

/* SSE worker log lines (tee'd via slog.LogHandler). Color-code by
   level so operators can scan errors quickly. */
.event-log { font-size: 13px; }
.event-log .event-meta {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--fg-muted);
}
.event-log .log-info  { color: var(--accent); }
.event-log .log-warn  { color: #c89800; }
.event-log .log-error { color: var(--danger); }
.event-log .log-debug { color: var(--fg-muted); }

/* Failed run details — inline under the row so operators don't dig
   for the why. The error line is the worker's wrap, the <details>
   block carries codex's own last_message (often a refusal or
   constraint-conflict explanation). */
.failure-details {
  margin: 6px 0 4px 0;
  padding: 8px 12px;
  background: rgba(220, 53, 69, 0.06);
  border-left: 3px solid var(--danger);
  border-radius: 0 4px 4px 0;
}
.failure-error {
  color: var(--danger);
  font-size: 13px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  margin-bottom: 6px;
}
.failure-reason summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--fg-muted);
  user-select: none;
}
.failure-reason pre {
  margin: 6px 0 0 0;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
}

/* Activity panel — ambient single-line "thinking stream". The dot
   keeps a visual heartbeat even when text hasn't changed; sse-swap
   replaces the text on each event. */
.activity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  min-height: 24px;
  font-size: 13px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-muted);
  animation: activity-pulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}
.activity-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
@keyframes activity-pulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1; }
}
