/* Opgaveskriveren (public/writer.js) and the shared quiz (public/quiz.js),
   docs/writer-spec.md §5.2, §5.3. Every rule is scoped under .writer or
   .quiz / .quiz-modal; colours come from the tokens in style.css :root, so
   dark mode follows. Flat: solid fills and borders only. */

/* ---------- layout: Kladder · Samtale · Kladden ---------- */
.writer {
  /* flex: none: a 0% basis would grow the page to the content height. */
  flex: none; display: grid; gap: 16px; padding: 18px 16px 16px;
  grid-template-columns: 260px minmax(0, 1fr) 380px;
  grid-template-rows: minmax(0, 1fr);
  height: calc(100dvh - 57px); min-height: 560px;
}
.writer[data-open="0"] { grid-template-columns: 260px minmax(0, 1fr); }
.writer[data-open="0"] .wr-talk,
.writer[data-open="0"] .wr-draft,
.writer[data-open="1"] .wr-start { display: none; }
.writer .wr-bar { display: none; }

.writer .wr-col {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.writer .wr-head { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.writer .wr-head h2 { flex: none; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; }
.writer .wr-head .btn { margin-left: auto; }
.writer .wr-talk-title { min-width: 0; font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.writer .hint { font-size: 12px; color: var(--muted); }

/* ---------- Kladder ---------- */
.writer .wr-list { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.writer .wr-item {
  display: flex; flex-direction: column; gap: 3px; width: 100%; padding: 8px 10px; text-align: left;
  border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer;
}
.writer .wr-item:hover { background: var(--surface-2); }
.writer .wr-item.on { background: var(--surface-3); border-color: var(--line); }
.writer .wr-item-top { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 11.5px; color: var(--muted); }
.writer .wr-item-top time { margin-left: auto; white-space: nowrap; }
.writer .wr-item-title { font-weight: 650; line-height: 1.3; overflow-wrap: anywhere; }
.writer .wr-item-ex { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.writer .wr-st { align-self: flex-start; padding: 1px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 700; background: var(--surface-3); color: var(--muted); }
.writer .wr-st.ready { background: var(--accent); color: var(--accent-ink); }
.writer .wr-st.typing { background: color-mix(in srgb, var(--info) 14%, transparent); color: var(--ink); }
.writer .wr-none { padding: 14px 10px; font-size: 12.5px; color: var(--muted); }

/* ---------- start screen ---------- */
.writer .wr-start { overflow-y: auto; }
.writer .wr-start-form { width: min(640px, 100%); margin: 0 auto; padding: 32px 20px; display: flex; flex-direction: column; gap: 12px; }
.writer .wr-start-zebra { display: flex; justify-content: center; }
.writer .wr-start-title { font-size: 26px; letter-spacing: -.02em; text-align: center; }
.writer .wr-start-sub { margin: 0; text-align: center; }
.writer .wr-start-text {
  width: 100%; min-height: 150px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); resize: vertical; font-size: 15px; line-height: 1.5;
}
.writer .wr-field { display: grid; gap: 5px; min-width: 0; }
.writer .wr-field > span { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.writer .wr-field input,
.writer .wr-field select { width: 100%; min-width: 0; height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); }
.writer .wr-start.over .wr-drop { border-color: var(--info); background: color-mix(in srgb, var(--info) 8%, transparent); color: var(--ink); }
.writer .wr-pending { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.writer .wr-pending:empty { display: none; }
.writer .wr-chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--surface-3); font-size: 12.5px; }
.writer .wr-chip span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.writer .wr-chip-x { flex: none; width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.writer .wr-chip-x:hover { background: var(--surface); color: var(--ink); }
.writer .wr-start-foot { display: flex; align-items: center; gap: 10px; }
.writer .wr-start-foot .hint { margin-right: auto; }

/* ---------- Samtale ---------- */
.writer .wr-thread { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.writer .wr-empty { margin: auto; color: var(--muted); }
.writer .wr-msg { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 8px; align-items: start; max-width: min(100%, 720px); }
.writer .wr-msg.me { grid-template-columns: minmax(0, 1fr) 30px; margin-left: auto; max-width: min(88%, 620px); }
.writer .wr-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.writer .wr-msg.me .wr-body { align-items: flex-end; }
.writer .wr-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: 12px; }
.writer .wr-meta time { font-size: 11px; color: var(--muted); }
.writer .wr-tag { padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; background: var(--ink); color: var(--bg); }
.writer .wr-bubble {
  max-width: 100%; min-width: 0; padding: 9px 12px; overflow-wrap: anywhere;
  border-radius: 4px 12px 12px 12px; border: 1px solid var(--line); background: var(--surface-2);
}
.writer .wr-msg.me .wr-bubble {
  border-radius: 12px 4px 12px 12px;
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
}
.writer .wr-quiz { min-width: 0; }
/* An answer's checklist (P14b) reuses the quiz card's own look (.quiz .qz-*
   below): the same checkbox rows, no "Andet" and no send — just the ticks and
   "Lav det til en opgave". */
.writer .wr-answer { min-width: 0; }
.writer .wr-sys { text-align: center; font-size: 12px; color: var(--muted); }
.writer .wr-sys time { margin-left: 6px; font-size: 11px; }
.writer .wr-att-img { margin: 0; width: 160px; max-width: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.writer .wr-att-img img { display: block; width: 100%; height: 110px; object-fit: cover; }
.writer .wr-att-img figcaption { padding: 4px 8px; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.writer .wr-att-file { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.writer .wr-att-file a { min-width: 0; color: var(--info); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* The one-press card between the thread and the typing line (P15): the hint
   and the buttons Søren would otherwise have to open the Kladde tab for. */
.writer .wr-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 14px;
  border-top: 1px solid var(--line); background: var(--surface-2);
}
.writer .wr-actions[hidden] { display: none; }
.writer .wr-act-text { flex: 1 1 14em; min-width: 0; margin: 0; font-size: 12.5px; color: var(--ink); overflow-wrap: anywhere; }
.writer .wr-act-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.writer .wr-act-btns .btn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.writer .wr-typing { display: flex; align-items: center; gap: 8px; padding: 6px 14px; border-top: 1px dashed var(--line); font-size: 12.5px; color: var(--muted); }
.writer .wr-typing.on b { color: var(--ink); }
.writer .wr-typing .z-head { flex: none; }
.writer .wr-act { color: var(--muted); }
.writer .wr-dots { display: inline-flex; gap: 3px; margin-left: 4px; vertical-align: middle; }
.writer .wr-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: wr-dot 1.2s steps(2) infinite; }
.writer .wr-dots i:nth-child(2) { animation-delay: .2s; }
.writer .wr-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes wr-dot { 50% { opacity: .25; } }

.writer .wr-composer { padding: 10px 14px 12px; border-top: 1px solid var(--line); }
.writer .wr-talk.over .wr-composer { background: color-mix(in srgb, var(--info) 8%, var(--surface)); }
.writer .wr-input {
  width: 100%; min-height: 64px; max-height: 40vh; padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); resize: vertical; line-height: 1.5;
}
.writer .wr-composer-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.writer .wr-composer-row .hint { margin-right: auto; }

/* ---------- Kladden ---------- */
.writer .wr-draft { transition: border-color .4s; }
.writer .wr-draft.hl { animation: wr-hl 1.4s ease; }
@keyframes wr-hl { 0%, 50% { border-color: var(--info); } }
.writer .wr-badge { margin-left: auto; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; background: var(--surface-3); color: var(--muted); }
.writer .wr-badge:empty { display: none; }
.writer .wr-badge.ready { background: var(--accent); color: var(--accent-ink); }
.writer .wr-draft-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.writer .wr-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.writer .wr-grid .wr-field:first-child { grid-column: 1 / -1; }
/* Boss Zee's project suggestion until Søren confirms it (she reads no code before). */
.writer .wr-proj-hint {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0; padding: 8px 10px;
  border: 1px solid color-mix(in srgb, var(--info) 35%, var(--line)); border-radius: 8px;
  background: color-mix(in srgb, var(--info) 8%, var(--surface)); font-size: 12.5px; overflow-wrap: anywhere;
}
.writer .wr-proj-hint[hidden] { display: none; }
.writer .wr-proj-text { flex: 1 1 12em; min-width: 0; }
.writer .wr-proj-hint .btn { flex: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.writer .wr-plan { font-size: 13px; color: var(--ink); }
.writer .wr-spec-head { display: flex; align-items: center; gap: 8px; }
.writer .wr-spec-head h3,
.writer .wr-missing h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.writer .wr-spec-head .btn { margin-left: auto; }
.writer .wr-spec { min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); overflow-wrap: anywhere; }
.writer .wr-spec-edit {
  width: 100%; min-height: 260px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); font-family: var(--mono); font-size: 12.5px; line-height: 1.5; resize: vertical;
}
.writer .wr-stale { margin: 0; padding: 8px 10px; border-radius: 8px; font-size: 12.5px; background: color-mix(in srgb, var(--warn) 12%, transparent); }
.writer .wr-missing ul { margin: 6px 0 0; padding-left: 1.2em; font-size: 13px; overflow-wrap: anywhere; }
.writer .wr-draft-foot { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); background: var(--surface-2); }
.writer .wr-draft-foot .btn-danger { margin-left: auto; }

@media (max-width: 1180px) {
  .writer { grid-template-columns: 220px minmax(0, 1fr) 320px; }
  .writer[data-open="0"] { grid-template-columns: 220px minmax(0, 1fr); }
}

/* ---------- one column (≤ 980 px): Samtale | Kladde, list behind a button ---------- */
@media (max-width: 980px) {
  .writer { display: flex; flex-direction: column; gap: 10px; height: calc(100dvh - 104px); min-height: 420px; padding: 12px 16px 16px; }
  .writer .wr-bar { display: flex; align-items: center; gap: 8px; }
  .writer .wr-list-btn { flex: none; }
  .writer[data-list="1"] .wr-list-btn { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .writer .wr-seg { flex: 1; min-width: 0; display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-3); }
  .writer .wr-seg button { flex: 1; min-width: 0; padding: 5px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 650; cursor: pointer; }
  .writer .wr-seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); }
  /* A newer draft version arrived while Samtale was shown (P15). */
  .writer .wr-seg button[data-dot="1"]::after {
    content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 5px; vertical-align: 1px;
    border-radius: 50%; background: var(--accent);
  }
  .writer[data-open="0"] .wr-seg { display: none; }
  .writer .wr-col { flex: 1; }
  .writer .wr-drafts { display: none; }
  .writer[data-list="1"] .wr-drafts { display: flex; }
  .writer[data-list="1"] .wr-start,
  .writer[data-list="1"] .wr-talk,
  .writer[data-list="1"] .wr-draft,
  .writer[data-open="1"][data-pane="talk"] .wr-draft,
  .writer[data-open="1"][data-pane="draft"] .wr-talk { display: none; }
}
@media (max-width: 600px) {
  .writer .wr-start-form { padding: 20px 14px; }
  .writer .wr-start-title { font-size: 21px; }
  .writer .wr-start-foot .hint,
  .writer .wr-composer-row .hint { display: none; }
  .writer .wr-start-foot { justify-content: flex-end; }
  .writer .wr-composer-row [data-wr="send"] { margin-left: auto; }
  .writer .wr-thread { padding: 12px 10px; }
  .writer .wr-msg.me { max-width: 94%; }
  .writer .wr-grid { grid-template-columns: minmax(0, 1fr); }
  .writer .wr-draft-foot .btn { flex: 1 1 auto; }
  .writer .wr-draft-foot .btn-danger { margin-left: 0; }
}

/* ---------- the quiz (inline card and modal) ---------- */
.quiz { display: flex; flex-direction: column; gap: 12px; min-width: 0; margin: 6px 0 0; padding: 12px; border: 1.5px solid var(--ink); border-radius: 12px; background: var(--surface); }
.quiz .qz-q { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.quiz .qz-legend { display: flex; align-items: center; gap: 6px; max-width: 100%; padding: 0; }
.quiz .qz-chip {
  display: inline-block; max-width: 100%; padding: 2px 7px; border-radius: 4px; background: var(--ink); color: var(--bg);
  font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.quiz .qz-n { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.quiz .qz-question { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.quiz .qz-hint { margin: 0; font-size: 11.5px; color: var(--muted); }
.quiz .qz-opts { display: flex; flex-direction: column; gap: 6px; }
.quiz .qz-opt { display: grid; grid-template-columns: 18px minmax(0, 1fr); align-items: start; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); }
.quiz .qz-opt.rec { border-color: color-mix(in srgb, var(--accent) 70%, var(--line)); }
.quiz .qz-opt:has(input:checked) { border-color: var(--ink); background: var(--surface); }
.quiz .qz-opt input[type="radio"],
.quiz .qz-opt input[type="checkbox"] { margin: 3px 0 0; accent-color: var(--ink); cursor: pointer; }
.quiz .qz-opt label { min-width: 0; overflow-wrap: anywhere; cursor: pointer; }
.quiz .qz-label { font-weight: 700; }
.quiz .qz-rec { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px; font-size: 10.5px; font-weight: 800; vertical-align: 1px; background: var(--accent); color: var(--accent-ink); }
.quiz .qz-desc { display: block; margin-top: 2px; font-size: 12.5px; color: var(--muted); }
.quiz .qz-other { grid-template-columns: 18px auto minmax(0, 1fr); align-items: center; }
.quiz .qz-other input[type="radio"],
.quiz .qz-other input[type="checkbox"] { margin: 0; }
.quiz .qz-other-text { width: 100%; min-width: 0; height: 30px; padding: 0 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--surface); }
.quiz .qz-err { margin: 0; font-size: 12.5px; color: var(--danger); }
.quiz .qz-err:empty { display: none; }
.quiz .qz-q.bad .qz-opt { border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.quiz .qz-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.quiz .qz-err-all { flex: 1 1 100%; }

.quiz.quiz-done { gap: 6px; border: 1px solid var(--line); background: var(--surface-2); }
.quiz .qz-done-head { margin: 0; font-size: 12px; font-weight: 700; color: var(--muted); }
.quiz .qz-sum { display: flex; flex-direction: column; gap: 6px; list-style: none; margin: 0; padding: 0; }
.quiz .qz-sum li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; min-width: 0; }
.quiz .qz-sum-q { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.quiz .qz-sum-a { flex-basis: 100%; font-weight: 650; overflow-wrap: anywhere; }

/* ---------- quiz modal (cards in Feedback) ---------- */
.quiz-modal { width: min(600px, calc(100vw - 24px)); max-width: calc(100vw - 16px); max-height: calc(100dvh - 24px); padding: 0; border: 0; border-radius: 16px; overflow: hidden; background: var(--surface); color: var(--ink); }
.quiz-modal::backdrop { background: rgba(10, 10, 14, .45); }
.quiz-modal .qzm-in { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.quiz-modal .qzm-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.quiz-modal .qzm-head h2 { min-width: 0; font-size: 16px; overflow-wrap: anywhere; }
.quiz-modal .qzm-head .btn { flex: none; margin-left: auto; }
/* A long question (up to 50,000 chars) scrolls in its own box; it never squeezes the quiz and its buttons away. */
.quiz-modal .qzm-intro { flex: none; max-height: 30dvh; overflow-y: auto; padding: 10px 16px 0; font-size: 13.5px; overflow-wrap: anywhere; }
.quiz-modal .qzm-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px 16px 16px; }
.quiz-modal .quiz { margin: 0; padding: 0; border: 0; }
@media (max-width: 600px) {
  .quiz-modal { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); border-radius: 14px; }
  .quiz-modal .qzm-in { max-height: calc(100dvh - 16px); }
}
