:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --accent-light: #eef2ff;
  --user-bg: #f3f4f6;
  --assistant-bg: #ffffff;
  --thinking-bg: #f8fafc;
  --thinking-border: #cbd5e1;
  --error: #b91c1c;
  --warn-bg: #fffbeb;
  --warn-border: #fcd34d;
  --success-bg: #f0fdf4;
  --success-border: #86efac;
  --max-w: 760px;
}

* { box-sizing: border-box; }

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

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Layout ─────────────────────────────────── */
.container {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 32px 20px 80px;
}
.container-wide { max-width: 960px; }
.container-task { max-width: 1200px; }

/* ── Typography ─────────────────────────────── */
h1 { font-size: 1.55rem; margin: 0 0 10px; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 22px 0 7px; }
h3 { font-size: 1rem; font-weight: 600; margin: 16px 0 5px; }
p  { margin: 7px 0; }
small, .muted { color: var(--muted); font-size: 0.88rem; }
ul { padding-left: 20px; }
ul li { margin: 4px 0; }
a { color: var(--accent); }

/* ── Progress bar ───────────────────────────── */
.progress-bar {
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 28px;
}
.progress-bar > div {
  height: 100%;
  background: var(--accent);
  transition: width 0.35s ease;
}

/* ── Cards ──────────────────────────────────── */
.card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  margin: 14px 0;
  background: #fff;
}
.card-section {
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 14px;
}

/* ── Forms ──────────────────────────────────── */
label {
  display: block;
  margin-top: 14px;
  font-weight: 500;
  font-size: 0.95rem;
}
.label-hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.82rem;
  margin-left: 4px;
}
input[type=text],
input[type=number],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--fg);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  margin-top: 5px;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
textarea { min-height: 80px; resize: vertical; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='7' viewBox='0 0 12 7'%3E%3Cpath d='M1 1l5 4.5L11 1' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
input[type=checkbox],
input[type=radio] { accent-color: var(--accent); }

/* ── Buttons ────────────────────────────────── */
.btn {
  background: var(--accent);
  color: var(--accent-fg);
  border: 1px solid transparent;
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { background: #1d4ed8; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.secondary {
  background: #fff;
  color: var(--fg);
  border-color: var(--border);
}
.btn.secondary:hover { background: #f9fafb; }
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

/* ── Callouts ───────────────────────────────── */
.callout {
  border-radius: 7px;
  padding: 13px 16px;
  margin: 14px 0;
  font-size: 0.92rem;
}
.callout-info    { background: var(--accent-light); border: 1px solid #bfdbfe; }
.callout-warn    { background: var(--warn-bg);      border: 1px solid var(--warn-border); }
.callout-success { background: var(--success-bg);   border: 1px solid var(--success-border); }
.callout strong  { font-weight: 600; }

/* ── Narrative bar ──────────────────────────── */
.narrative-bar {
  border-left: 3px solid var(--accent);
  padding: 11px 15px;
  background: var(--accent-light);
  border-radius: 0 6px 6px 0;
  margin: 14px 0;
}
.narrative-bar p { margin: 5px 0; font-size: 0.93rem; }

/* ── Spec table ─────────────────────────────── */
.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-top: 10px;
}
.spec-table tr { border-bottom: 1px solid var(--border); }
.spec-table tr:last-child { border-bottom: none; }
.spec-table td { padding: 7px 0; color: var(--muted); }
.spec-table td:first-child { font-weight: 500; color: var(--fg); width: 44%; }

/* ── Badge ──────────────────────────────────── */
.badge {
  font-size: 0.76rem;
  background: var(--accent-light);
  color: #1e40af;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge.standard { background: #f3f4f6; color: #374151; }

/* ── Slider grid ────────────────────────────── */
.slider-grid { display: flex; flex-direction: column; gap: 20px; }
.slider-row  { display: flex; flex-direction: column; gap: 6px; }
.slider-item-text { font-size: 0.93rem; font-weight: 500; }
.slider-controls  { display: flex; align-items: center; gap: 10px; }
.slider-input {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 20px;
  background: linear-gradient(
    to bottom,
    transparent 7.5px,
    var(--border) 7.5px,
    var(--border) 12.5px,
    transparent 12.5px
  );
  cursor: pointer;
  padding: 0;
  margin: 0;
  border: none;
  outline: none;
  align-self: center;
  box-sizing: content-box;
}
.slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
}
.slider-input::-moz-range-track {
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  border: none;
}
.slider-input::-moz-range-thumb {
  height: 18px;
  width: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--border);
  box-sizing: border-box;
}
.slider-anchor      { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.slider-value-label { font-size: 0.85rem; font-weight: 700; color: var(--accent); min-width: 20px; text-align: center; }

/* ── Likert 1–7 scale ───────────────────────────── */
.likert-grid { display: flex; flex-direction: column; }
.likert-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.likert-row:last-child { border-bottom: none; padding-bottom: 0; }
.likert-text { font-size: 0.93rem; font-weight: 500; }
.likert-scale { display: flex; align-items: center; gap: 10px; }
.likert-options { display: flex; flex: 1; justify-content: space-between; }
.likert-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  min-width: 28px;
}
.likert-label span { font-size: 0.78rem; color: var(--muted); }
.likert-label input[type=radio] { accent-color: var(--accent); cursor: pointer; }
.likert-anchor { font-size: 0.75rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.likert-anchor-left { min-width: 105px; text-align: right; }
.likert-anchor-right { min-width: 105px; }

/* ── Chat layout ────────────────────────────── */
.chat-layout { display: flex; gap: 18px; align-items: stretch; height: calc(100vh - 340px); min-height: 520px; }

.chat-shell {
  flex: 3;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  height: 100%;
}
.chat-header {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 4px;
  flex-shrink: 0;
}
.chat-header strong { font-size: 0.95rem; }
.chat-prompt-counter {
  font-size: 0.82rem;
  color: var(--muted);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 220px;
}
.msg { display: flex; flex-direction: column; }
.msg .who { font-size: 0.74rem; color: var(--muted); margin-bottom: 4px; }
.bubble {
  padding: 10px 14px;
  border-radius: 10px;
  max-width: 90%;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.93rem;
  line-height: 1.55;
}
.msg.user            { align-items: flex-end; }
.msg.user .bubble    { background: var(--user-bg); }
.msg.assistant       { align-items: flex-start; }
.msg.assistant .bubble { background: var(--assistant-bg); border: 1px solid var(--border); }

.thinking {
  background: var(--thinking-bg);
  border: 1px dashed var(--thinking-border);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 6px;
  font-size: 0.88rem;
  color: #334155;
  max-width: 90%;
}
.thinking-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 4px;
}

.loading-bubble { display: flex; align-items: center; min-width: 48px; }
.spinner {
  display: inline-block;
  width: 17px;
  height: 17px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.72s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chat-input-row {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex;
  gap: 8px;
  background: #fff;
  flex-shrink: 0;
}
.chat-input-row textarea { min-height: 42px; max-height: 150px; margin-top: 0; }

/* ── Task panel ─────────────────────────────── */
.task-panel {
  flex: 4;
  min-width: 260px;
  max-width: 580px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  background: #fff;
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
}
.task-panel-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.task-panel-icon   { font-size: 1.2rem; }
.task-panel-title  { font-weight: 600; font-size: 0.97rem; }
.task-instructions { font-size: 0.85rem; color: var(--muted); margin: 0 0 12px; }
.task-question {
  background: #f8fafc;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 11px 14px;
  margin-bottom: 14px;
  font-size: 0.93rem;
  line-height: 1.65;
}
.task-answer-label { font-size: 0.86rem; font-weight: 600; margin-bottom: 5px; display: block; }
.task-answer-input { font-size: 0.91rem; min-height: 80px; resize: vertical; }
.task-copy-btn  { width: 100%; margin: 10px 0 12px; font-size: 0.86rem; }
.task-done-btn  { width: 100%; margin-top: 10px; }

/* ── Completion code ────────────────────────── */
.completion-code {
  font-family: ui-monospace, "Cascadia Code", "Fira Mono", monospace;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
  background: var(--accent-light);
  border: 2px dashed #bfdbfe;
  border-radius: 7px;
  padding: 18px;
  text-align: center;
  margin: 16px 0;
}

/* ── Misc ───────────────────────────────────── */
.error   { color: var(--error); font-size: 0.87rem; margin-top: 6px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 780px) {
  .chat-layout { flex-direction: column; }
  .task-panel  { max-width: 100%; position: static; }
  .chat-shell  { height: calc(100vh - 230px); }
}
