/* Chat page. Palette and system type follow the workspace page; answers are
   set in a serif reading column because they are essay-style analysis. */

:root {
  --paper: #f4f3ed;
  --ink: #252b35;
  --muted: #626c75;
  --line: #dedfd9;
  --line-soft: #ebebe5;
  --navy: #243b4b;
  --navy-soft: #3b5363;
  --link: #33505f;
  --orange: #f47735;
  --green: #286345;
  --green-wash: #edf6ef;
  --warm: #965326;
  --warm-wash: #fff3ec;
  --warm-line: #efd7c6;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-synthesis: none;
  scroll-padding-bottom: calc(var(--dock-height, 150px) + 16px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -60px;
  left: 16px;
  z-index: 10;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
}
.skip-link:focus { top: 12px; }

.page {
  display: flex;
  flex-direction: column;
  max-width: 800px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 36px 24px 0;
}

/* Masthead */
.masthead-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.mark {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--orange);
  color: #fff;
  font-size: 27px;
}
.brand-name { margin: 0 0 2px; color: var(--muted); font-size: 13px; font-weight: 600; }
h1 { margin: 0; font-size: clamp(22px, 3.4vw, 28px); font-weight: 650; letter-spacing: -0.6px; line-height: 1.15; }

/* Buttons and fields */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--navy);
  border-radius: 9px;
  background: var(--navy);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}
.button.secondary { border-color: #cfd5d2; background: #fff; color: var(--link); }
.button.compact { min-height: 36px; padding: 7px 12px; font-size: 13px; }
.button:hover:enabled { filter: brightness(0.94); }
.button:disabled { border-color: #e2e4df; background: #ecece7; color: #858d92; cursor: not-allowed; }

select {
  max-width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid #cfd5d2;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 400;
}

/* Development-only mock controls */
.mock-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
  margin-top: 20px;
  padding: 12px 14px;
  border: 1px dashed #e3a47f;
  border-radius: 12px;
  background: #fff8f2;
}
.mock-note { flex: 1 1 320px; margin: 0; color: #4b555c; font-size: 13px; line-height: 1.5; }
.mock-note .badge { margin-right: 6px; }
.mock-control { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%; color: #4b555c; font-size: 13px; font-weight: 650; }
.mock-control select { min-width: 0; }

/* Conversation */
.conversation { flex: 1; padding: 28px 0 20px; }
.empty-state h2 { margin: 0 0 6px; font-size: 18px; font-weight: 650; letter-spacing: -0.3px; }
.empty-state p { max-width: 60ch; margin: 0 0 14px; color: var(--muted); font-size: 15px; line-height: 1.6; }
.examples { display: grid; gap: 8px; max-width: 560px; }
.example {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #33404a;
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.example:hover { border-color: #c4cac6; }

.messages { display: flex; flex-direction: column; gap: 24px; margin: 0; padding: 0; list-style: none; }
.message { display: flex; flex-direction: column; gap: 6px; scroll-margin-top: 16px; }
.who { margin: 0; color: var(--muted); font-size: 13px; font-weight: 650; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: #ebebe4;
  color: #4f595f;
  font-size: 12px;
  font-weight: 600;
}
.badge.is-ok { background: var(--green-wash); color: var(--green); }
.badge.is-mock { background: #fdebe0; color: #9a4a1c; }

.bubble { padding: 12px 16px; border-radius: 14px; font-size: 15.5px; line-height: 1.55; overflow-wrap: anywhere; }
.bubble p, .answer-text p { margin: 0; white-space: pre-wrap; }
.bubble p + p { margin-top: 10px; }

.from-user { align-items: flex-end; }
.from-user .bubble { max-width: min(85%, 600px); border-bottom-right-radius: 4px; background: var(--navy); color: #fff; }
.from-user.is-pending .bubble { background: var(--navy-soft); }
.state { margin: 0; color: var(--muted); font-size: 12px; }

/* Answers read like a page of a study guide. */
.answer { padding: 22px 26px 20px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.answer-text { max-width: 68ch; color: #22282f; font-family: var(--serif); font-size: 17.5px; line-height: 1.62; overflow-wrap: anywhere; }
.answer-text p + p { margin-top: 0.85em; }
.sources { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line-soft); color: #3f4a52; font-size: 13.5px; line-height: 1.55; }
.sources-title { margin: 0 0 4px; color: var(--muted); font-weight: 650; }
.sources ul { margin: 0; padding-left: 18px; }
.locator { color: var(--muted); }

.is-clarification .bubble {
  max-width: min(100%, 640px);
  border: 1px solid var(--line);
  border-left: 4px solid var(--orange);
  border-radius: 4px 12px 12px 4px;
  background: #fff;
}

.progress {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 10px 10px 10px 16px;
  border: 1px dashed #cfd3cc;
  border-radius: 12px;
  color: #3f4a52;
  font-size: 14px;
}
.dots { display: inline-flex; gap: 4px; }
.dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--orange); animation: pulse 1.2s ease-in-out infinite; }
.dots span:nth-child(2) { animation-delay: 0.15s; }
.dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; }
  40% { opacity: 1; }
}
.elapsed, .progress-hint { color: var(--muted); font-variant-numeric: tabular-nums; }
.link-button {
  min-height: 36px;
  margin-left: auto;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--link);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Composer dock */
.dock {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 12px 0 16px;
  background: linear-gradient(to bottom, rgb(244 243 237 / 0), var(--paper) 16px);
}
.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 10px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--warm-line);
  border-radius: 10px;
  background: var(--warm-wash);
  color: var(--warm);
  font-size: 14px;
  line-height: 1.5;
}
.notice[data-tone="info"] { border-color: #d9ddd6; background: #eef0ea; color: #45555e; }
.notice-text { flex: 1 1 260px; margin: 0; }
.notice-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.icon-button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: inherit;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.icon-button:hover { background: rgb(0 0 0 / 0.05); }

.composer-field {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border: 1px solid #cfd3cc;
  border-radius: 14px;
  background: #fff;
}
.composer-field:focus-within { border-color: var(--navy); box-shadow: 0 0 0 3px rgb(36 59 75 / 0.14); }
.composer-field:has(textarea[aria-invalid="true"]) { border-color: #c2622b; }
textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 240px;
  padding: 10px 0;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
}
textarea:focus { outline: none; }
textarea::placeholder { color: #6b747c; }
textarea[readonly] { cursor: progress; }
.composer-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-top: 8px; color: var(--muted); font-size: 12.5px; }
.composer-meta p { margin: 0; }
.subject { color: #3f4a52; font-weight: 650; }
.count { margin-left: auto; font-variant-numeric: tabular-nums; }
.count.is-over { color: #a3461a; font-weight: 650; }

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 20px;
  padding: 14px 0 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
}
.footer a { color: var(--link); font-weight: 600; }
.noscript { margin: 16px; padding: 12px 16px; border-radius: 10px; background: var(--warm-wash); color: var(--warm); }

@media (max-width: 600px) {
  .page { padding: 22px 16px 0; }
  .masthead-row { align-items: flex-start; }
  .masthead-row .button { max-width: 128px; white-space: normal; }
  .mark { width: 34px; height: 34px; border-radius: 9px; font-size: 23px; }
  .answer { padding: 16px 16px 14px; }
  .answer-text { font-size: 17px; }
  .from-user .bubble { max-width: 92%; }
  .mock-control { width: 100%; }
  .mock-control select { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .dots span { animation: none; opacity: 0.7; }
}

/* Always-visible prototype disclosure above the (initially hidden) mock panel. */
.prototype-banner { margin: 14px 0 0; }
.prototype-banner code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Owned conversation history (shown only where the server keeps history). */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.toolbar:has(> :not([hidden])) { min-height: 36px; }
.button.danger { border-color: #a3461a; background: #a3461a; color: #fff; }

body.has-history .page { max-width: 1140px; }
.workspace { display: block; }
.chat-column { display: flex; flex-direction: column; min-width: 0; }

.history { margin-top: 18px; }
.history-title { margin: 0 0 8px; font-size: 15px; font-weight: 650; }
.history-status { margin: 0 0 8px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.history-status:empty { display: none; }
.history-list { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.history-item {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.history-item:hover { background: #ebebe4; }
.history-item[aria-current="true"] { border-color: #cfd5d2; background: #fff; }
.history-item[aria-disabled="true"] { cursor: not-allowed; opacity: 0.7; }
.history-item-title { overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.history-item-meta { display: flex; flex-wrap: wrap; gap: 2px 8px; color: var(--muted); font-size: 12px; }
.history-item-status { color: var(--warm); font-weight: 650; }
.history-more { margin-top: 8px; }

.conversation-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 18px; }
.conversation-title { min-width: 0; margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -0.3px; overflow-wrap: anywhere; }
.conversation-actions { display: flex; gap: 6px; }
.rename-form { margin-bottom: 18px; }
.rename-form label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 13px; font-weight: 650; }
.rename-row { display: flex; flex-wrap: wrap; gap: 6px; }
.rename-row input {
  flex: 1 1 220px;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #cfd5d2;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
.rename-help, .rename-error { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }
.rename-error { color: #a3461a; font-weight: 650; }
.earlier-turns { margin: 0 0 16px; }
.is-unanswered .bubble { background: #6f7f8a; }
.is-unanswered .state { color: var(--warm); font-weight: 650; }
.turn-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.turn-actions .link-button { margin-left: 0; }
.new-subject { min-height: 32px; margin-left: 0; padding: 2px 4px; font-size: 12.5px; }

.dialog { width: min(100vw - 32px, 420px); padding: 20px 22px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); }
.dialog::backdrop { background: rgb(37 43 53 / 0.35); }
.dialog h2 { margin: 0 0 8px; font-size: 18px; }
.dialog p { margin: 0 0 18px; color: #3f4a52; line-height: 1.5; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

@media (min-width: 960px) {
  body.has-history .workspace { display: grid; grid-template-columns: minmax(240px, 280px) minmax(0, 800px); gap: 32px; align-items: start; }
  body.has-history .history {
    position: sticky;
    top: 0;
    max-height: 100vh;
    max-height: 100dvh;
    margin-top: 28px;
    overflow: auto;
  }
  .history-toggle { display: none; }
}

@media (max-width: 959px) {
  .history[data-open="false"] { display: none; }
  .history { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fbfbf8; }
}
