/* GaiS candidate demo pages — shared stylesheet (v1.4, CD-01 stage 1)
 *
 * Used only by /chat/<name>_demo.html. The original chat pages keep their own
 * chat.css untouched.
 *
 * Interaction pattern follows the accepted Mary concept: a plain conversation,
 * the finished work inline, then edit/copy/ready. Each candidate keeps its own
 * name, portrait and already-defined identity colour. No analytics, cookies,
 * external fonts or requests, model provider or sending.
 */

:root {
  --bg: #fffcf8;
  --surface: #ffffff;
  --surface-2: #f7f0e9;
  --ink: #262220;
  --muted: #6d6058;
  --line: #e7dcd1;
  --line-strong: #d2c3b4;
  --wash: rgba(255, 252, 248, .90);
  --shadow: 0 1px 2px rgba(60, 44, 30, .05), 0 8px 24px rgba(60, 44, 30, .07);
  --radius: 16px;
  --tap: 44px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

html[data-theme="dark"] {
  --bg: #17191c;
  --surface: #20232a;
  --surface-2: #272b33;
  --ink: #f3efe9;
  --muted: #b6aea3;
  --line: #343a45;
  --line-strong: #48505e;
  --wash: rgba(23, 25, 28, .92);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 26px rgba(0, 0, 0, .35);
}

/* Per-candidate identity: the already-approved colour for that Agent. */
body.demo-john    { --accent: #708090; --on-accent: #ffffff; --accent-ink: #4c5865; --portrait: url("/images/agents/john.webp"); }
body.demo-mary    { --accent: #c98e97; --on-accent: #2e2126; --accent-ink: #8d636a; --portrait: url("/images/agents/mary.webp"); }
body.demo-james   { --accent: #9caf88; --on-accent: #2e2126; --accent-ink: #5d6a50; --portrait: url("/images/agents/james.webp"); }
body.demo-jane    { --accent: #f4e9d2; --on-accent: #2e2126; --accent-ink: #6b6250; --portrait: url("/images/agents/jane.webp"); }
body.demo-william { --accent: #1f3a5f; --on-accent: #ffffff; --accent-ink: #1f3a5f; --portrait: url("/images/agents/william.webp"); }
body.demo-anne    { --accent: #d8c7e8; --on-accent: #2e2126; --accent-ink: #6b5d78; --portrait: url("/images/agents/anne.webp"); }
body.demo-thomas  { --accent: #a89988; --on-accent: #2e2126; --accent-ink: #6d6155; --portrait: url("/images/agents/thomas.webp"); }
body.demo-sarah   { --accent: #b8e2d0; --on-accent: #2e2126; --accent-ink: #4a635a; --portrait: url("/images/agents/sarah.webp"); }

html[data-theme="dark"] body.demo-john    { --accent-ink: #b6c2ce; }
html[data-theme="dark"] body.demo-mary    { --accent-ink: #e7b8bf; }
html[data-theme="dark"] body.demo-james   { --accent-ink: #c6d4b6; }
html[data-theme="dark"] body.demo-jane    { --accent-ink: #efe3ca; }
html[data-theme="dark"] body.demo-william { --accent-ink: #a3b6d0; }
html[data-theme="dark"] body.demo-anne    { --accent-ink: #e2d5ee; }
html[data-theme="dark"] body.demo-thomas  { --accent-ink: #d3c6b8; }
html[data-theme="dark"] body.demo-sarah   { --accent-ink: #cdeade; }

* { box-sizing: border-box; }

/* Real hidden states: every hidden node is hidden, whatever its display. */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 var(--sans);
  -webkit-text-size-adjust: 100%;
}

/* Optional background: this candidate's own portrait behind everything.
 * On by default for these eight demos; the switch turns it off and the saved
 * choice is honoured. Painted on a pseudo-element so it cannot be clicked,
 * focused or announced, and causes no layout shift. A 90% wash keeps text
 * contrast effectively unchanged. Suppressed where a wash is not honest. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  display: none;
}
html[data-backdrop="on"] body::before {
  display: block;
  background-image: linear-gradient(var(--wash), var(--wash)), var(--portrait);
  background-repeat: no-repeat, no-repeat;
  background-position: calc(100% + 12px) calc(100% + 6px), calc(100% + 12px) calc(100% + 6px);
  background-size: auto, min(320px, 44vw) auto;
  background-attachment: fixed, fixed;
}
@media (forced-colors: active) {
  html[data-backdrop="on"] body::before { display: none; }
}
@media (prefers-contrast: more) {
  html[data-backdrop="on"] body::before { display: none; }
}
@media print {
  html[data-backdrop="on"] body::before { display: none; }
}

.app { position: relative; z-index: 1; display: flex; flex-direction: column; min-height: 100dvh; }

.skip {
  position: absolute; left: -9999px; top: 0;
  padding: 10px 14px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); z-index: 60;
}
.skip:focus { left: 12px; top: 12px; }

header.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.mark {
  position: relative; flex: 0 0 auto; overflow: hidden;
  border-radius: 11px; background: var(--accent);
  display: grid; place-items: center;
  width: 34px; height: 34px;
}
.mark .initial { color: var(--on-accent); font-weight: 650; font-size: 16px; line-height: 1; }
.mark img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 8%; display: block;
}
.who { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.who .name { font-weight: 650; letter-spacing: .01em; }
.who .org { font-size: 12.5px; color: var(--muted); }
.spacer { flex: 1 1 auto; }
.iconbtn {
  appearance: none; border: 1px solid var(--line); background: var(--surface);
  color: var(--accent-ink); border-radius: 12px;
  min-width: var(--tap); min-height: var(--tap); padding: 0 12px;
  font: inherit; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
}
.iconbtn:hover { background: var(--surface-2); }
.iconbtn.quiet { background: transparent; border-color: transparent; }
.iconbtn svg { width: 18px; height: 18px; }

main.thread { flex: 1 1 auto; padding: 22px 16px 8px; }
.col { max-width: 700px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

.empty { margin: 4vh auto 0; text-align: center; max-width: 520px; }
.empty .mark { width: 60px; height: 60px; border-radius: 18px; margin: 0 auto 16px; }
.empty .mark .initial { font-size: 26px; }
.empty h1 {
  font-family: var(--serif); font-weight: 600;
  font-size: clamp(1.5rem, 4.4vw, 1.9rem); line-height: 1.15;
  margin: 0 0 8px; letter-spacing: -.01em;
}
.empty p { margin: 0; color: var(--muted); }
.chip {
  margin-top: 18px; appearance: none;
  border: 1px solid var(--accent-ink); background: transparent;
  color: var(--accent-ink); border-radius: 999px; padding: 11px 18px;
  min-height: var(--tap); font: inherit; font-size: 15px; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
.empty .or { margin-top: 12px; font-size: 13.5px; color: var(--muted); }

.msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.msg .meta { font-size: 12.5px; color: var(--muted); }
.msg .body {
  padding: 13px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user { align-items: flex-end; }
.msg.user .body {
  background: color-mix(in srgb, var(--accent) 26%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 46%, var(--line));
  box-shadow: none;
  border-bottom-right-radius: 6px;
}
.msg.agent .body { border-bottom-left-radius: 6px; }

.draft {
  margin-top: 10px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); overflow: hidden; box-shadow: var(--shadow);
}
.draft header {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.draft .kind { font-size: 12.5px; color: var(--muted); }
.draft .subj { font-weight: 600; font-size: 15px; }
.draft .letter {
  padding: 16px; font-size: 15.5px; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.draft .letter:focus { outline: 2px solid var(--accent-ink); outline-offset: -4px; border-radius: 6px; }
.draft .letter[contenteditable="true"] {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.draft .note { padding: 0 16px 12px; font-size: 13px; color: var(--muted); }
.draft .confirm { font-size: 13px; color: var(--accent-ink); padding: 0 16px 12px; }
.draft .actions {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-2) 60%, var(--surface));
}
.act {
  appearance: none; font: inherit; font-size: 14.5px; min-height: var(--tap);
  padding: 0 16px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--accent-ink);
}
.act:hover { background: var(--surface-2); }
.act.primary { background: var(--accent-ink); border-color: var(--accent-ink); color: var(--surface); }
html[data-theme="dark"] .act.primary { color: #17191c; }
.act.primary:hover { filter: brightness(1.06); }
.act:disabled { opacity: .7; cursor: default; }

.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.pill {
  font-size: 11.5px; padding: 2px 9px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--accent) 16%, var(--surface));
  color: var(--ink);
}

footer {
  position: sticky; bottom: 0; z-index: 5;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.composer {
  max-width: 700px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 18px; box-shadow: var(--shadow); padding: 8px 8px 8px 6px;
}
.composer textarea {
  flex: 1 1 auto; resize: none; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; line-height: 1.45; padding: 10px 6px;
  max-height: 132px; min-height: var(--tap);
}
.composer textarea:focus { outline: none; }
.composer .round {
  appearance: none; border: 1px solid transparent; border-radius: 50%;
  width: var(--tap); height: var(--tap); min-width: var(--tap);
  display: grid; place-items: center;
  background: transparent; color: var(--accent-ink); cursor: pointer;
}
.composer .round:hover { background: var(--surface-2); }
.composer .round.send { background: var(--accent-ink); color: var(--surface); }
html[data-theme="dark"] .composer .round.send { color: #17191c; }
.composer .round.send:disabled { opacity: .45; cursor: default; }
.composer .round svg { width: 20px; height: 20px; display: block; }
.under {
  max-width: 700px; margin: 7px auto 0;
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12px; color: var(--muted); flex-wrap: wrap;
}
.under .notice { color: var(--accent-ink); }

:where(button, textarea, [tabindex], a, summary):focus-visible {
  outline: 3px solid var(--accent-ink); outline-offset: 2px;
}

dialog {
  border: 1px solid var(--line-strong); border-radius: 18px; padding: 0;
  background: var(--surface); color: var(--ink);
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 24px 60px rgba(30, 20, 14, .30);
}
dialog::backdrop { background: rgba(24, 20, 16, .45); }
dialog .inner { padding: 18px 20px 20px; }
dialog h2 { font-family: var(--serif); font-size: 19px; margin: 0 0 14px; }
.block { border-top: 1px solid var(--line); padding: 14px 0 0; margin-top: 14px; }
.block:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  min-height: var(--tap); cursor: pointer;
}
.switch .label { font-size: 15.5px; }
.switch input {
  appearance: none; width: 46px; height: 26px; border-radius: 999px;
  background: var(--line-strong); position: relative; flex: 0 0 auto;
  cursor: pointer; transition: background .15s; margin: 0;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
  transition: transform .15s;
}
.switch input:checked { background: var(--accent-ink); }
.switch input:checked::after { transform: translateX(20px); }
.small { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
dialog .close { margin-top: 18px; width: 100%; min-height: var(--tap); }

@media (max-width: 560px) {
  header.topbar { padding-left: 12px; padding-right: 12px; }
  .iconbtn.quiet { padding: 0 10px; font-size: 13px; }
  main.thread { padding: 18px 12px 8px; }
  .empty { margin-top: 2vh; }
  .msg .body, .draft .letter { font-size: 15.5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

@media print {
  header.topbar, footer, dialog { display: none !important; }
  body { background: #fff; color: #000; }
}
