/* === Scopidea - Ideation Engine - refined CSS === */

:root {
  /* Colors */
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --bg-card: #ffffff;
  --fg: #0f172a;
  --fg-muted: #64748b;
  --fg-subtle: #94a3b8;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-hover: #4338ca;
  --warn-bg: #fffbeb;
  --warn-fg: #92400e;
  --warn-border: #fde68a;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --code-bg: #f6f6f7;
  --success: #16a34a;
  --error: #dc2626;

  /* Geometry */
  --max-width: 760px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);

  /* Fonts */
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 4rem 1.5rem 6rem;
}

/* ===== Form page (split-pane layout) ============================ */
/* Geist is loaded by the form template only; result/all-ideas pages
   keep their own typography. */
.form-page {
  --font-sans: "Geist", -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --pane-radius: 16px;
  --pane-shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 8px 30px rgba(15, 23, 42, 0.04);
  background: linear-gradient(135deg, #f8f9fb 0%, #f1f4f9 100%);
  min-height: 100vh;
}

.form-page-main {
  max-width: 1280px;
  padding: 3rem 1.5rem 5rem;
  display: flex;
  flex-direction: column;
  gap: 2.25rem;
}

.page-header {
  text-align: center;
  margin: 0.25rem 0 0.5rem;
}
.page-header .brand { margin: 0; }
.page-header .brand h1 {
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  background: linear-gradient(135deg, #4f46e5 0%, #7c5cdb 50%, #00a8e8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.page-header .brand-sub {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}
.page-subtitle {
  margin: 0.7rem 0 0;
  font-size: 1rem;
  color: var(--fg-muted);
}

.split-pane {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 2rem;
  align-items: start;
}

.pane {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--pane-radius);
  box-shadow: var(--pane-shadow);
  padding: 2rem 2rem 2.25rem;
}

.pane-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 18rem;
  gap: 0.85rem;
  color: var(--fg-muted);
}
.pane-empty[hidden] { display: none; }
.pane-empty p { margin: 0; font-size: 0.95rem; }
.pane-empty-icon {
  width: 3rem;
  height: 3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.4rem;
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.10) 0%, rgba(0, 168, 232, 0.12) 100%);
  color: var(--accent);
  font-weight: 600;
}

/* In split-pane mode, the progress card already lives inside its pane,
   so drop its outer chrome to avoid a card-in-a-card look. */
.results-pane .progress {
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* Sticky-ish input pane on tall screens keeps the form near eye level
   while the run is in flight. */
@media (min-height: 820px) and (min-width: 1100px) {
  .input-pane { position: sticky; top: 1.5rem; }
}

/* Mobile collapse */
@media (max-width: 1024px) {
  .form-page-main { padding: 2rem 1rem 3rem; gap: 1.5rem; }
  .split-pane { grid-template-columns: 1fr; gap: 1.25rem; }
  .pane { padding: 1.5rem 1.25rem; }
  .page-header .brand h1 { font-size: 2.2rem; }
}
/* Primary Run button on the form page gets the gradient + full-width
   look from the inspiration. The plain accent fallback elsewhere is
   untouched. */
.form-page .button-row { margin-top: 1.75rem; }
.form-page .button-row button[type="submit"] {
  flex: 1;
  width: 100%;
  padding: 0.95rem 1.4rem;
  font-size: 0.98rem;
  background: linear-gradient(135deg, #4f46e5 0%, #6d28d9 100%);
  border: 0;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.18);
}
.form-page .button-row button[type="submit"]:hover:not(:disabled) {
  background: linear-gradient(135deg, #4338ca 0%, #5b21b6 100%);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.28);
}
.form-page .button-row button[type="submit"]:active:not(:disabled) {
  transform: translateY(0);
}

/* "Open results →" button inside the right pane echoes the run button. */
.form-page .open-result-btn {
  background: linear-gradient(135deg, #4f46e5 0%, #6d28d9 100%);
  padding: 0.75rem 1.35rem;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.18);
}
.form-page .open-result-btn:hover {
  background: linear-gradient(135deg, #4338ca 0%, #5b21b6 100%);
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.28);
}
/* ===== /Form page =============================================== */

/* === Typography ============================================ */

h1 {
  font-size: 1.95rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin: 0 0 0.4rem;
  color: var(--fg);
}

.brand {
  margin: 0 0 0.9rem;
  line-height: 1;
}
.brand h1 {
  font-size: 2.35rem;
  letter-spacing: -0.03em;
  margin: 0;
  line-height: 1.05;
}
.brand-sub {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-subtle);
}

h2 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 1rem;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

/* === Form ================================================== */

.form-section { margin-bottom: 1.75rem; }
.form-section:last-of-type { margin-bottom: 0; }

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg);
  margin-bottom: 0.45rem;
  letter-spacing: 0.01em;
}
label .helper {
  font-weight: 400;
  color: var(--fg-subtle);
  font-size: 0.78rem;
}
label .helper.recommended {
  color: var(--accent);
  font-weight: 600;
}

textarea,
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

textarea {
  min-height: 10rem;
  resize: vertical;
}

/* Prompt textarea with inline attach icon */
.prompt-wrap { position: relative; }
.prompt-wrap textarea {
  padding-bottom: 2.6rem;  /* leave room for the icon */
}
.attach-btn {
  position: absolute;
  bottom: 0.5rem;
  right: 0.55rem;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.attach-btn:hover {
  background: var(--bg-soft);
  color: var(--fg);
  border-color: var(--border);
}
.attach-btn:active { transform: none; }
.attach-btn svg { display: block; }

textarea:focus,
input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

input[type="number"] { max-width: 5.5rem; }

input[type="file"] {
  font-size: 0.85rem;
  color: var(--fg-muted);
  padding: 0.4rem 0;
  width: 100%;
}
input[type="file"]::file-selector-button {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45rem 0.95rem;
  margin-right: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--fg);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
input[type="file"]::file-selector-button:hover {
  background: var(--bg-soft);
  border-color: var(--border-strong);
}

.file-chips {
  margin-top: 0.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}
.file-chips:empty { display: none; }

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.35rem 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--fg-muted);
  line-height: 1.5;
  word-break: break-all;
}
.file-chip-label {
  display: inline-block;
}
.file-chip-remove {
  border: 0;
  background: transparent;
  color: currentColor;
  cursor: pointer;
  padding: 0;
  width: 1.15rem;
  height: 1.15rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  opacity: 0.55;
  font-size: 1.05rem;
  font-family: inherit;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.file-chip-remove:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.08);
}
.file-chip-remove:focus-visible {
  opacity: 1;
  outline: 2px solid currentColor;
  outline-offset: 1px;
}
.file-chip.loading {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft, rgba(91, 51, 38, 0.08));
}
.file-chip.loading::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: file-chip-spin 0.7s linear infinite;
}
.file-chip.ready {
  color: var(--fg);
  border-color: var(--border-strong, var(--border));
  background: var(--bg);
}
.file-chip.ready::before {
  content: "✓";
  color: var(--success, #16a34a);
  font-weight: 700;
}
.file-chip.error {
  color: var(--error, #dc2626);
  border-color: var(--error, #dc2626);
  background: #fef2f2;
}
.file-chip.error::before {
  content: "✗";
  font-weight: 700;
}
@keyframes file-chip-spin {
  to { transform: rotate(360deg); }
}

/* Pill-style radio / checkbox group */
.option-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.option-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  user-select: none;
  margin: 0;
  letter-spacing: 0;
}
.option-pill:hover { border-color: var(--border-strong); }
.option-pill input { margin: 0; cursor: pointer; }
.option-pill:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* Tier pills are taller cards with a description line under the name. */
.tier-row {
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
}
.tier-pill {
  border-radius: var(--radius-md);
  padding: 0.7rem 1rem;
  gap: 0.75rem;
}
.tier-pill > span {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
}
.tier-pill strong { font-weight: 600; font-size: 0.92rem; }

/* Question-mark info tip with hover/focus tooltip */
.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg-muted);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0;
  cursor: help;
  user-select: none;
  vertical-align: middle;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.info-tip:hover,
.info-tip:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.info-tip::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 0.45rem);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 16rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease, visibility 0.12s ease;
  box-shadow: var(--shadow-md);
  z-index: 50;
}
.info-tip::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 0.05rem);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--fg);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease, visibility 0.12s ease;
  z-index: 50;
}
.info-tip:hover::after,
.info-tip:focus-visible::after,
.info-tip:hover::before,
.info-tip:focus-visible::before {
  opacity: 1;
  visibility: visible;
}

.inline-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.helper {
  font-size: 0.8rem;
  color: var(--fg-subtle);
}

/* Buttons */
.button-row {
  margin-top: 2.5rem;
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}
button {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.7rem 1.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: white;
  cursor: pointer;
  letter-spacing: 0;
  transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}
button:hover { background: var(--accent-hover); }
button:active { transform: translateY(1px); }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
button.secondary {
  background: var(--bg-card);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
}
button.secondary:hover {
  background: var(--bg-soft);
  border-color: var(--fg-muted);
}

/* === Progress panel ======================================== */

.progress {
  margin-top: 2rem;
  padding: 1.25rem 1.5rem 1.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.progress[hidden] { display: none; }
.progress-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.85rem;
}
.progress h2 {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fg-muted);
  font-weight: 600;
}
.timer {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.timer[data-state="running"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.timer[data-state="running"]::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 0.5em;
  vertical-align: middle;
  animation: timer-pulse 1.2s ease-in-out infinite;
}
@keyframes timer-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50%      { opacity: 1.0;  transform: scale(1.15); }
}
.timer[data-state="done"] {
  color: var(--success);
  border-color: var(--success);
  background: #ecfdf5;
}
.timer[data-state="error"] {
  color: var(--error);
  border-color: var(--error);
  background: #fef2f2;
}
.progress ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.65;
}
.progress li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.15rem 0;
  color: var(--fg);
}
.progress li.error { color: var(--error); }
.progress li.done { color: var(--success); font-weight: 500; }
.progress li.done-prev { color: var(--fg-muted); }
.progress li.done-prev .icon { color: var(--success); }

.open-result-row {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.open-result-btn {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  background: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: background 0.15s;
}
.open-result-btn:hover { background: var(--accent-hover); color: white; }

.progress li .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  margin-top: 4px;
  font-size: 0.85rem;
}
.progress li.error .icon { color: var(--error); }
.progress li.done .icon { color: var(--success); }
.progress li.step .icon { color: var(--fg-subtle); }

/* Animated spinner only for the most-recent step in flight */
@keyframes spin { to { transform: rotate(360deg); } }
.progress li.step .icon::after {
  content: "•";
  color: var(--fg-subtle);
}
.progress li:last-child.step .icon::after {
  content: "";
  display: block;
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* === Result page =========================================== */

.result-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.5rem;
  margin-bottom: 2.5rem;
}
.result-header h1 { margin-bottom: 1rem; }

.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.4rem 1.5rem;
  font-size: 0.82rem;
}
.meta dt {
  color: var(--fg-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
  padding-top: 2px;
}
.meta dd {
  margin: 0;
  color: var(--fg);
}

.warning-banner {
  background: var(--warn-bg);
  color: var(--warn-fg);
  border: 1px solid var(--warn-border);
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-md);
  margin-bottom: 2rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* Markdown-rendered body */
.result-body {
  font-size: 1rem;
  line-height: 1.75;
}
.result-body h1,
.result-body h2,
.result-body h3 {
  margin-top: 2.25rem;
  margin-bottom: 0.75rem;
  letter-spacing: -0.015em;
}
.result-body h1 { font-size: 1.55rem; font-weight: 700; }
.result-body h2 { font-size: 1.2rem; font-weight: 600; }
.result-body h3 { font-size: 1.05rem; font-weight: 600; }
.result-body p { margin: 0 0 1rem; }
.result-body strong { font-weight: 650; color: var(--fg); }
.result-body ul, .result-body ol { padding-left: 1.5rem; margin: 0 0 1rem; }
.result-body li { margin-bottom: 0.4rem; }
.result-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.18em;
  text-decoration-thickness: 1px;
}
.result-body code {
  background: var(--code-bg);
  padding: 0.12em 0.35em;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  border: 1px solid var(--border);
}
.result-body pre {
  background: var(--code-bg);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  border-radius: var(--radius-md);
  margin: 1.25rem 0;
  border: 1px solid var(--border);
  font-size: 0.88rem;
  line-height: 1.55;
}
.result-body pre code {
  background: transparent;
  padding: 0;
  border: 0;
}
.result-body table {
  border-collapse: collapse;
  margin: 1.25rem 0;
  width: 100%;
  font-size: 0.9rem;
}
.result-body th, .result-body td {
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.result-body th {
  background: var(--bg-soft);
  font-weight: 600;
}
.result-body blockquote {
  border-left: 3px solid var(--border-strong);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--fg-muted);
}

/* Mobile */
@media (max-width: 640px) {
  main { padding: 2rem 1.1rem 3rem; }
  h1 { font-size: 1.55rem; }
  .button-row { flex-direction: column; }
  .button-row button { width: 100%; }
  .meta { grid-template-columns: 1fr; gap: 0.1rem; }
  .meta dt { padding-top: 0.5rem; }
}

/* === Template-editor buttons (top right of the form page) ============ */
.edit-templates {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  z-index: 50;
}
.edit-template-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.edit-template-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-soft);
}
.edit-template-btn.has-session-edit {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.edit-template-badge {
  font-family: var(--font-body, inherit);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}
@media (max-width: 640px) {
  .edit-templates {
    top: auto;
    bottom: 0.6rem;
    right: 0.6rem;
    flex-direction: column;
    align-items: flex-end;
  }
  .edit-template-btn { font-size: 0.72rem; padding: 0.4rem 0.65rem; }
}

/* === Debug toggle (top-left) ========================================= */
.debug-toggle {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 50;
}
.debug-toggle button {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg-muted, var(--fg));
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  opacity: 0.7;
}
.debug-toggle button:hover {
  border-color: var(--border-strong);
  background: var(--bg-soft);
  opacity: 1;
}
.debug-toggle button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  opacity: 1;
}
@media (max-width: 640px) {
  .debug-toggle {
    top: auto;
    bottom: 0.6rem;
    left: 0.6rem;
  }
}

/* Debug-only controls are visible only when the Debug toggle is on. */
body:not(.debug-on) .debug-only {
  display: none !important;
}

.debug-overrides .debug-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem 0.9rem;
  margin-top: 0.5rem;
}
.debug-knob {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.debug-knob label {
  font-size: 0.78rem;
  color: var(--fg-muted);
  font-family: var(--font-mono);
}
.debug-knob select {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  background: var(--bg-card);
  color: var(--fg);
  font-size: 0.88rem;
}
@media (max-width: 640px) {
  .debug-overrides .debug-grid {
    grid-template-columns: 1fr;
  }
}

/* === Template-editor modal =========================================== */
.template-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1.25rem;
}
.template-modal[hidden] { display: none; }
.template-modal-panel {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  width: min(960px, 100%);
  height: min(80vh, 760px);
  overflow: hidden;
}
.template-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.template-modal-head h2 {
  margin: 0;
  font-size: 1rem;
  font-family: var(--font-mono);
  color: var(--fg);
}
.template-modal-close {
  border: 0;
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}
.template-modal-close:hover { color: var(--fg); background: var(--bg-soft); }
#template-modal-textarea {
  flex: 1 1 auto;
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  padding: 1rem 1.1rem;
  background: var(--bg);
  color: var(--fg);
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
#template-modal-textarea:disabled { color: var(--fg-subtle); }
.template-modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-soft);
}
.template-modal-sessiononly {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--fg);
  cursor: pointer;
}
.template-modal-actions {
  display: inline-flex;
  gap: 0.5rem;
}
.template-modal-cancel,
.template-modal-save {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  padding: 0.45rem 0.95rem;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.template-modal-cancel:hover {
  background: var(--bg-soft);
}
.template-modal-save {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.template-modal-save:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.template-modal-error {
  padding: 0.6rem 1.1rem;
  background: #fef2f2;
  color: #b91c1c;
  border-top: 1px solid #fecaca;
  font-size: 0.85rem;
}
.template-modal-error[hidden] { display: none; }
