:root {
  --bg: #f2f2f3;
  --surface: #ffffff;
  --surface-raised: #f2f2f3;
  --surface-tertiary: #dedddf;
  --border: #dedddf;
  --border-soft: #f2f2f3;
  --text: #120a1d;
  --text-muted: #77717f;
  --text-secondary: #443f4a;
  --accent: #7f27eb;
  --accent-strong: #6018b8;
  --accent-pressed: #4d0f99;
  --ok: #0e8761;
  --warn: #e13c52;
  --font-display: "Poppins", sans-serif;
  --font-body: "Inter", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --radius-2xl: 16px;
  --radius-round: 999px;
  --shadow-float: 0 0 32px -4px rgba(18, 10, 29, 0.15);
  --shadow-modal: 0 16px 40px rgba(18, 10, 29, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.masthead-title {
  display: flex;
  align-items: center;
  gap: 14px;
}

.seal-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.seal-mark svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
}

.masthead h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--text);
}

.masthead-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.status-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: var(--radius-round);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-muted);
  white-space: nowrap;
}

.status-pill.running {
  color: var(--accent-strong);
  border-color: var(--accent);
  background: #f4ebfd;
}

.status-pill.error {
  color: var(--warn);
  border-color: var(--warn);
  background: #fdecee;
}

/* ---------- docket bar (new run form) ---------- */

.docket-bar {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.docket-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.docket-field label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.docket-field select,
.docket-field input {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text);
  background: var(--surface-raised);
  border: 3px solid transparent;
  border-radius: var(--radius-2xl);
  padding: 8px 14px;
  min-width: 160px;
  outline: none;
  transition: border-color 0.15s ease;
}

.docket-field select:focus,
.docket-field input:focus {
  border-color: var(--accent);
}

.docket-field input::placeholder {
  color: var(--text-muted);
}

.docket-field select:disabled,
.docket-field input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.file-run-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: #ffffff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-round);
  padding: 12px 22px;
  cursor: pointer;
  margin-left: auto;
  transition: background 0.15s ease;
}

.file-run-btn:hover:not(:disabled) {
  background: var(--accent-strong);
}

.file-run-btn:active:not(:disabled) {
  background: var(--accent-pressed);
}

.file-run-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn-arrow {
  transition: transform 0.15s ease;
}

.file-run-btn:hover:not(:disabled) .btn-arrow {
  transform: translateX(2px);
}

/* ---------- progress feed (the wire) ---------- */

.progress-feed {
  margin: 16px 28px 0;
  padding: 4px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  max-height: 220px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
}

.feed-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 5px 16px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-soft);
  animation: feed-in 0.15s ease-out;
}

@keyframes feed-in {
  from {
    opacity: 0;
    transform: translateY(-2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.feed-dot {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.feed-line.stage {
  color: var(--accent-strong);
}

.feed-line.stage .feed-dot {
  background: var(--accent);
}

.feed-line.pass .feed-dot,
.feed-line.draft-done .feed-dot {
  background: var(--ok);
}

.feed-line.pass,
.feed-line.draft-done {
  color: var(--text);
}

.feed-line.discard {
  color: var(--text-muted);
}

.feed-line.draft-start {
  color: var(--text);
}

.feed-line.draft-start .feed-dot {
  background: var(--accent-strong);
  animation: feed-pulse 1s ease-in-out infinite;
}

@keyframes feed-pulse {
  50% {
    opacity: 0.3;
  }
}

.feed-line.draft-fail .feed-dot,
.feed-line.error .feed-dot {
  background: var(--warn);
}

.feed-line.draft-fail,
.feed-line.error {
  color: var(--warn);
}

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

  .feed-line.draft-start .feed-dot {
    animation: none;
  }
}

/* ---------- run receipt ---------- */

.run-receipt[hidden] {
  display: none;
}

.run-receipt {
  margin: 16px 28px 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.run-receipt strong {
  color: var(--text);
  font-weight: 600;
}

.run-receipt.error {
  border-color: var(--warn);
  color: var(--warn);
  background: #fdecee;
}

/* ---------- layout ---------- */

.layout {
  padding-bottom: 40px;
}

.ledger {
  overflow-y: auto;
}

.ledger-loading,
.ledger-empty {
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

.ledger-row {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 900px;
  text-align: left;
  padding: 14px 28px;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  background: none;
  cursor: pointer;
  color: var(--text);
  font-family: var(--font-body);
}

.ledger-row:hover,
.ledger-row.active {
  background: var(--surface-raised);
}

.ledger-row.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.row-seal {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  color: var(--accent-strong);
  background: #f4ebfd;
  border: none;
  border-radius: 50%;
}

.row-body {
  flex: 1;
  min-width: 0;
}

.row-title {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-docket {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.row-score {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ---------- detail (rendered inside the modal) ---------- */

.record-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}

.record-seal {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-strong);
  background: #f4ebfd;
  border: none;
  border-radius: 50%;
}

.detail h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 30px;
  margin: 0 0 4px;
  max-width: 620px;
  line-height: 1.15;
  color: var(--text);
}

.record-docket {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.meta-table {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 24px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  margin-bottom: 28px;
  max-width: 620px;
}

.meta-table dt {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  align-self: center;
}

.meta-table dd {
  margin: 0;
  color: var(--text);
}

.body {
  max-width: 620px;
  line-height: 1.65;
  font-size: 15px;
  color: var(--text-secondary);
}

.body h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  margin-top: 28px;
  color: var(--text);
}

.body blockquote {
  border-left: 2px solid var(--accent);
  margin: 0;
  padding-left: 16px;
  color: var(--text-muted);
  font-style: italic;
}

.body ul,
.body ol {
  padding-left: 20px;
}

@media (max-width: 720px) {
  .modal-panel {
    padding: 24px;
  }

  .detail {
    padding: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn-arrow {
    transition: none;
  }
}

/* ---------- modal ---------- */

.modal-overlay[hidden] {
  display: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 10, 29, 0.35);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 20px;
  overflow-y: auto;
  z-index: 100;
  animation: overlay-in 0.12s ease-out;
}

@keyframes overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-panel {
  position: relative;
  width: 100%;
  max-width: 680px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 40px 48px;
  box-shadow: var(--shadow-modal);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--surface-raised);
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
  background: var(--surface-tertiary);
}

/* ---------- generation view (live draft typing) ---------- */

.generating-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.generating-seal {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  background: var(--accent-strong);
  border: none;
  border-radius: 50%;
  animation: feed-pulse 1s ease-in-out infinite;
}

.generating-seal .pulse-dot {
  display: none;
}

.generating-eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.generating-topic {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  margin: 0;
  color: var(--text);
}

.generating-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 24px;
  margin: 0 0 16px;
  min-height: 1.2em;
  color: var(--text);
}

.live-text {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 50vh;
  overflow-y: auto;
}

.live-text .cursor {
  display: inline-block;
  width: 0.5em;
  background: var(--accent-strong);
  animation: cursor-blink 1s step-end infinite;
}

@keyframes cursor-blink {
  50% {
    opacity: 0;
  }
}

.generating-state {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
  margin-bottom: 16px;
}

.generating-state.declined {
  color: var(--warn);
}

.generating-state.failed {
  color: var(--warn);
}

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

  .generating-seal .pulse-dot,
  .live-text .cursor {
    animation: none;
  }
}
