/* ─── Reset & Custom Properties ──────────────────────────────────────────── */

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

:root {
  --bg:           #f5f5f4;
  --surface:      #ffffff;
  --surface-2:    #fafaf9;
  --border:       #e7e5e4;
  --border-2:     #d6d3d1;
  --text:         #1c1917;
  --text-muted:   #78716c;
  --text-xmuted:  #a8a29e;

  --accent:       #1d4ed8;
  --accent-hover: #1e40af;
  --accent-light: #eff6ff;

  --success:      #15803d;
  --success-bg:   #f0fdf4;
  --success-border: #86efac;

  --warning:      #b45309;
  --warning-bg:   #fffbeb;
  --warning-border: #fcd34d;

  --danger:       #b91c1c;
  --danger-bg:    #fef2f2;
  --danger-border: #fca5a5;

  --purple:       #7c3aed;
  --purple-bg:    #f5f3ff;
  --purple-border: #c4b5fd;

  --nav-bg:       #1c1917;
  --nav-text:     #e7e5e4;
  --nav-muted:    #a8a29e;
  --nav-active:   #ffffff;
  --nav-hover:    #d6d3d1;

  --radius-sm:    4px;
  --radius:       6px;
  --radius-lg:    10px;

  --shadow-sm:    0 1px 2px rgba(0,0,0,.06);
  --shadow:       0 1px 4px rgba(0,0,0,.09), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);

  --font:         ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono:    ui-monospace, "SFMono-Regular", Menlo, monospace;
}

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Navigation ─────────────────────────────────────────────────────────── */

.nav {
  background: var(--nav-bg);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,.07);
}

.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 32px;
}

.nav-brand {
  color: var(--nav-active);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -.01em;
  text-decoration: none;
  white-space: nowrap;
}

.nav-brand:hover { text-decoration: none; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.nav-link {
  color: var(--nav-muted);
  font-size: .875rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: color .15s, background .15s;
}

.nav-link:hover {
  color: var(--nav-hover);
  background: rgba(255,255,255,.06);
  text-decoration: none;
}

.nav-link.active {
  color: var(--nav-active);
  background: rgba(255,255,255,.10);
}

.nav-actions {
  margin-left: auto;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */

.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
}

.page-subtitle {
  font-size: .875rem;
  color: var(--text-muted);
  margin-top: 3px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: .875rem;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-2);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-2); color: var(--text); }

.btn-success {
  background: #16a34a;
  color: #fff;
  border-color: #16a34a;
}
.btn-success:hover { background: #15803d; border-color: #15803d; color: #fff; }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}
.btn-danger:hover { background: #fee2e2; color: var(--danger); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm {
  font-size: .8125rem;
  padding: 4px 10px;
}

.btn-lg {
  font-size: .9375rem;
  padding: 10px 20px;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  font-size: .75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid transparent;
  white-space: nowrap;
  letter-spacing: .01em;
}

.badge-blue    { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.badge-amber   { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.badge-green   { background: #f0fdf4; color: #15803d; border-color: #86efac; }
.badge-red     { background: #fef2f2; color: #b91c1c; border-color: #fca5a5; }
.badge-purple  { background: #f5f3ff; color: #7c3aed; border-color: #c4b5fd; }
.badge-gray    { background: #f5f5f4; color: #78716c; border-color: #d6d3d1; }
.badge-orange  { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }

/* ─── Cards ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-body {
  padding: 20px;
}

.card-title {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--text);
}

/* ─── Tables ─────────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th a {
  color: var(--text-muted);
  text-decoration: none;
}
thead th a:hover { color: var(--text); }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

tbody td {
  padding: 11px 14px;
  vertical-align: middle;
  color: var(--text);
}

.col-title { min-width: 200px; max-width: 280px; }
.col-narrow { white-space: nowrap; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */

.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-hint {
  font-size: .8125rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  font-family: var(--font);
  font-size: .9375rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 8px 12px;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.5;
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2378716c' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 8px;
}

/* Radio cards (track selector) */
.radio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.radio-card {
  position: relative;
  cursor: pointer;
}

.radio-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.radio-card-inner {
  display: block;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color .15s, background .15s;
}

.radio-card input:checked + .radio-card-inner {
  border-color: var(--accent);
  background: var(--accent-light);
}

.radio-card:hover .radio-card-inner { border-color: var(--border-2); }

.radio-card-title {
  font-weight: 600;
  font-size: .9375rem;
  margin-bottom: 4px;
}

.radio-card-desc {
  font-size: .8125rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ─── Stage Pipeline ─────────────────────────────────────────────────────── */

.pipeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.stage-card {
  border-left: 3px solid var(--border-2);
  padding: 0;
  margin-left: 20px;
  position: relative;
}

.stage-card::before {
  content: '';
  position: absolute;
  left: -9px;
  top: 20px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--border-2);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border-2);
}

.stage-card + .stage-card { margin-top: 0; }

/* Status variants */
.stage-card.completed { border-left-color: var(--success-border); }
.stage-card.completed::before {
  background: var(--success);
  box-shadow: 0 0 0 1px var(--success);
}

.stage-card.awaiting_review { border-left-color: var(--warning-border); }
.stage-card.awaiting_review::before {
  background: #f59e0b;
  box-shadow: 0 0 0 1px #f59e0b;
}

.stage-card.running { border-left-color: #93c5fd; }
.stage-card.running::before {
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}

.stage-card.pending { border-left-color: var(--border); opacity: .6; }
.stage-card.pending::before { background: var(--text-xmuted); }

/* Current input stage (Stage 1, memoir Stage 4) */
.stage-card.input_required { border-left-color: var(--accent); }
.stage-card.input_required::before {
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 1px var(--accent); }
  50% { box-shadow: 0 0 0 4px rgba(29,78,216,.3); }
}

.stage-inner {
  padding: 14px 18px 14px 14px;
}

.stage-header {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.stage-number {
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-xmuted);
  min-width: 20px;
}

.stage-name {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.stage-tags {
  display: flex;
  gap: 5px;
  align-items: center;
}

.stage-desc {
  font-size: .8125rem;
  color: var(--text-muted);
  margin: 6px 0 0 30px;
  line-height: 1.45;
}

/* Stage output area */
.stage-output {
  margin: 12px 0 0 30px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: .875rem;
  line-height: 1.6;
}

.stage-output h2 { font-size: 1rem; margin: 12px 0 6px; }
.stage-output h3 { font-size: .9375rem; margin: 10px 0 4px; }
.stage-output p { margin-bottom: 8px; }
.stage-output p:last-child { margin-bottom: 0; }
.stage-output ul, .stage-output ol { padding-left: 20px; margin-bottom: 8px; }
.stage-output li { margin-bottom: 3px; }
.stage-output table { font-size: .8125rem; }
.stage-output table th, .stage-output table td { padding: 5px 10px; border: 1px solid var(--border); }
.stage-output table th { background: var(--surface-2); font-weight: 600; }
.stage-output strong { color: var(--text); }
.stage-output code { font-family: var(--font-mono); font-size: .8125rem; background: var(--border); padding: 1px 4px; border-radius: 3px; }
.stage-output hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.stage-output-collapsed {
  max-height: 100px;
  overflow: hidden;
  position: relative;
}
.stage-output-collapsed::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0; right: 0;
  height: 40px;
  background: linear-gradient(transparent, var(--surface-2));
}

/* Checkpoint / review area */
.checkpoint-area {
  margin: 14px 0 4px 30px;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius);
  padding: 16px;
}

.checkpoint-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--warning);
  margin-bottom: 10px;
}

.checkpoint-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* Stage 1 input area */
.stage-input-area {
  margin: 14px 0 4px 30px;
  background: var(--accent-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 16px;
}

/* HTMX loading indicator */
.htmx-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  font-size: .875rem;
  color: var(--text-muted);
  margin: 12px 0 0 30px;
}
.htmx-request .htmx-indicator { display: flex; }
.htmx-request .btn-trigger { opacity: .5; pointer-events: none; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

/* ─── Filters / toolbar ──────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-spacer { flex: 1; }

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-pill {
  font-size: .8125rem;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 99px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s, color .12s;
}

.filter-pill:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.filter-pill.active { background: var(--text); color: #fff; border-color: var(--text); }

/* ─── Piece header ───────────────────────────────────────────────────────── */

.piece-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.piece-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.piece-title-input {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -.02em;
  border: none;
  background: transparent;
  padding: 0;
  width: 100%;
  color: var(--text);
  font-family: var(--font);
}

.piece-title-input:focus {
  outline: none;
  border-bottom: 2px solid var(--accent);
}

.piece-stats {
  display: flex;
  gap: 20px;
  margin-top: 12px;
  font-size: .8125rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.piece-stat strong {
  color: var(--text);
  font-weight: 600;
}

/* ─── Word count row ─────────────────────────────────────────────────────── */

.wc-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.wc-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 48px;
}

.wc-label {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-xmuted);
}

.wc-value {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--text);
}

.wc-value.empty { color: var(--text-xmuted); }

.wc-divider {
  color: var(--text-xmuted);
  font-size: .75rem;
}

/* ─── Pipeline board (kanban) ────────────────────────────────────────────── */

.kanban {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  align-items: start;
}

.kanban-col {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.kanban-col-header {
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kanban-cards {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 60px;
}

.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
}

.kanban-card-title {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kanban-card-meta {
  font-size: .75rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ─── Settings sections ──────────────────────────────────────────────────── */

.settings-grid {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: start;
}

.settings-nav {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: sticky;
  top: 72px;
}

.settings-nav-item {
  display: block;
  padding: 10px 16px;
  font-size: .875rem;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: background .12s, color .12s;
}

.settings-nav-item:last-child { border-bottom: none; }
.settings-nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.settings-nav-item.active { color: var(--accent); font-weight: 600; background: var(--accent-light); }

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 20px;
}

.settings-section-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.settings-section-title {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--text);
}

.settings-section-desc {
  font-size: .8125rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.settings-section-body {
  padding: 20px;
}

.provider-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.provider-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.provider-row:last-child { border-bottom: none; }

.provider-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.provider-dot.on  { background: var(--success); }
.provider-dot.off { background: var(--text-xmuted); }

.provider-name { font-size: .875rem; font-weight: 500; flex: 1; }
.provider-env  { font-size: .8125rem; color: var(--text-muted); font-family: var(--font-mono); }

/* Toggle switch */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-2);
  border-radius: 99px;
  cursor: pointer;
  transition: background .2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: var(--shadow-sm);
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ─── Markdown rendered output ───────────────────────────────────────────── */

.md h1 { font-size: 1.125rem; font-weight: 700; margin: 14px 0 6px; }
.md h2 { font-size: 1rem; font-weight: 700; margin: 12px 0 5px; }
.md h3 { font-size: .9375rem; font-weight: 600; margin: 10px 0 4px; }
.md p { margin-bottom: 8px; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { padding-left: 18px; margin-bottom: 8px; }
.md li { margin-bottom: 3px; }
.md table { width: 100%; font-size: .8125rem; margin: 10px 0; border-collapse: collapse; }
.md table th, .md table td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; }
.md table th { background: var(--surface-2); font-weight: 600; }
.md strong { font-weight: 600; }
.md em { font-style: italic; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.md code { font-family: var(--font-mono); font-size: .8125rem; background: var(--border); padding: 1px 5px; border-radius: 3px; }

/* ─── Empty states ───────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2rem;
  margin-bottom: 12px;
}

.empty-state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state-desc {
  font-size: .875rem;
  max-width: 360px;
  margin: 0 auto 16px;
}

/* ─── Notifications ──────────────────────────────────────────────────────── */

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: .875rem;
  margin-bottom: 16px;
}

.notice-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.notice-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
.notice-warn    { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }

/* ─── Miscellaneous ──────────────────────────────────────────────────────── */

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.text-muted { color: var(--text-muted); }
.text-small { font-size: .8125rem; }
.font-mono  { font-family: var(--font-mono); }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::marker { display: none; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .main { padding: 16px 14px 40px; }
  .nav-inner { padding: 0 14px; gap: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .radio-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-nav { position: static; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .hide-mobile { display: none; }
  .piece-stats { gap: 12px; }
  .kanban { grid-template-columns: 1fr; }
  .wc-row { gap: 8px; }

  thead th:nth-child(n+4) { display: none; }
  tbody td:nth-child(n+4) { display: none; }
}

@media (max-width: 480px) {
  .nav-links { gap: 2px; }
  .nav-link { padding: 5px 7px; font-size: .8125rem; }
  .pipeline { margin-left: 0; }
  .stage-card { margin-left: 14px; }
}

/* ─── Pipeline progress bar ─────────────────────────────────────────────────── */

.pipeline-progress {
  margin: 0 0 20px 30px;
  padding: 14px 18px;
  background: var(--surface-2, #f8f9fa);
  border: 1px solid var(--border-2, #e0e0e0);
  border-left: 3px solid var(--accent, #4f8ef7);
  border-radius: 8px;
}

.pipeline-progress-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: .875rem;
}

.pipeline-progress-header strong {
  color: var(--text-1, #111);
}

.pipeline-progress-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: .8125rem;
  color: var(--text-muted, #666);
  font-variant-numeric: tabular-nums;
}

.pipeline-stage-label {
  font-size: .8125rem;
  color: var(--text-muted, #666);
  margin-bottom: 8px;
  padding-left: 26px;
}

.progress-track {
  height: 6px;
  background: var(--border-2, #e0e0e0);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent, #4f8ef7);
  border-radius: 3px;
  transition: width .4s ease;
  min-width: 4px;
}

.pipeline-progress-error {
  margin: 0 0 20px 30px;
  padding: 12px 16px;
  background: #fff5f5;
  border: 1px solid #fca5a5;
  border-radius: 8px;
  font-size: .875rem;
  color: #b91c1c;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── API Balances widget ─────────────────────────────────────────────────── */

.api-balances-card {
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 20px;
}

.api-balances-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.api-balances-title {
  font-size: .8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted, #78716c);
}

.api-balances-link {
  font-size: .8125rem;
  color: var(--accent, #1d4ed8);
  text-decoration: none;
}
.api-balances-link:hover { text-decoration: underline; }

.api-balances-rows {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.api-balance-row {
  display: grid;
  grid-template-columns: 12px 100px 1fr 1fr;
  align-items: center;
  gap: 8px;
  font-size: .8125rem;
}

.api-balance-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green  { background: #16a34a; }
.dot-amber  { background: #d97706; }
.dot-red    { background: #dc2626; }
.dot-gray   { background: #9ca3af; }

.api-balance-name   { color: var(--text, #1c1917); font-weight: 500; }
.api-balance-amount { color: var(--text, #1c1917); font-family: var(--font-mono, monospace); font-size: .8rem; }
.api-balance-week   { text-align: right; }

/* ─── Feedback Dialog ──────────────────────────────────────────────────────── */

.feedback-dialog {
  border: 1px solid var(--border, #e7e5e4);
  border-radius: 10px;
  padding: 0;
  width: min(720px, 96vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface, #fff);
  box-shadow: 0 8px 32px rgba(0,0,0,.14);
}

.feedback-dialog::backdrop {
  background: rgba(0,0,0,.45);
}

.feedback-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border, #e7e5e4);
}

.feedback-textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  margin: 16px 20px 0;
  width: calc(100% - 40px);
  min-height: 160px;
  font-size: .875rem;
  font-family: var(--font-sans, inherit);
  border: 1px solid var(--border, #e7e5e4);
  border-radius: 6px;
  resize: vertical;
  background: var(--surface-raised, #fafaf9);
  color: var(--text, #1c1917);
}

.feedback-textarea:focus {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: -1px;
}

.feedback-dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px 16px;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 20px;
}

.compare-pre {
  font-size: .725rem;
  font-family: var(--font-mono, monospace);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-raised, #fafaf9);
  border: 1px solid var(--border, #e7e5e4);
  border-radius: 6px;
  padding: 8px 10px;
  max-height: 300px;
  overflow-y: auto;
  margin: 0;
}

/* ── Angle selection cards (Stage 2) ─────────────────────────────────────── */
.angle-recommendation {
  font-size: .8125rem;
  color: var(--text-muted);
  margin: 0 0 14px;
  font-style: italic;
}

.angle-select-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Hide the native radio but keep it focusable */
.angle-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.angle-card {
  display: block;
  cursor: pointer;
  border-radius: var(--radius);
}

.angle-card-inner {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: #fff;
  transition: border-color .15s, background .15s, box-shadow .15s;
}

.angle-card:hover .angle-card-inner {
  border-color: var(--accent);
  background: var(--accent-light);
}

.angle-card:has(input:checked) .angle-card-inner {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}

.angle-card-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}

.angle-card-num {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  white-space: nowrap;
}

.angle-card-title {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.angle-card-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.angle-field {
  font-size: .8125rem;
  color: var(--text);
  line-height: 1.5;
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 6px;
}

.angle-field-label {
  font-weight: 600;
  color: var(--text-muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding-top: 2px;
  white-space: nowrap;
}

.angle-field-value {
  color: var(--text);
}

.angle-thesis .angle-field-label { color: var(--accent); }
.angle-thesis .angle-field-value { font-style: italic; }

.angle-wordcount .angle-field-value {
  font-weight: 600;
  color: var(--text);
}

/* Action area hidden until an angle card is selected */
.angle-action-area {
  display: none;
  padding-top: 6px;
}

.angle-select-form:has(input[type="radio"]:checked) .angle-action-area {
  display: block;
}
