/* ---------- Design tokens ---------- */
:root {
  /* Brand (from the ชพส. logo palette) */
  --brand-50: #fff6ed;
  --brand-100: #ffe9d5;
  --brand-200: #fdd0a8;
  --brand-500: #f7841f;
  --brand-600: #e3640c;
  --brand-700: #c2410c;
  --brand-800: #9a3412;
  --brand-900: #632a07;

  /* Neutrals (warm stone) */
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f6f2ed;
  --surface-3: #efe9e2;
  --border: #e9e2da;
  --border-strong: #d8cdc1;
  /* Form-field boundaries need >= 3:1 against white (WCAG 1.4.11); #8a7b70 is 4.08:1. */
  --field-border: #8a7b70;
  --ink: #1f1712;
  --ink-2: #4a3d34;
  --ink-3: #6f6157;

  /* Semantic */
  --success: #15803d;
  --success-bg: #ecfdf3;
  --success-border: #bbe5c8;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --danger-border: #fbd0cb;
  --info-bg: #f8f5f1;

  /* Type */
  --body: 'IBM Plex Sans Thai', 'Noto Sans Thai', system-ui, -apple-system, sans-serif;
  --display: 'Kanit', var(--body);
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;

  /* Shape & depth */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 999px;
  --shadow-xs: 0 1px 2px rgba(31, 23, 18, 0.05);
  --shadow-sm: 0 1px 3px rgba(31, 23, 18, 0.06), 0 1px 2px rgba(31, 23, 18, 0.04);
  --shadow-md: 0 8px 24px -8px rgba(31, 23, 18, 0.12), 0 2px 6px -2px rgba(31, 23, 18, 0.06);
  --shadow-lg: 0 24px 48px -12px rgba(31, 23, 18, 0.22);
  --ring: 0 0 0 3px rgba(194, 65, 12, 0.16);

  --topbar-h: 64px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  /* Keep scrolled-to answers and focused controls clear of the sticky topbar + workspace bar (WCAG 2.4.11). */
  scroll-padding-top: calc(var(--topbar-h) + 64px);
}
html:has(body.embed) { scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--fw-regular) 16px/1.75 var(--body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.45; letter-spacing: 0; text-wrap: balance; color: var(--ink); }
h1 { font-family: var(--display); font-weight: var(--fw-semibold); }
h2, h3 { font-family: var(--body); font-weight: var(--fw-semibold); }
button, input, textarea, select { font: inherit; color: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
button, a { touch-action: manipulation; }
a { color: var(--brand-800); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--brand-700); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
::selection { background: var(--brand-100); }

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.skip {
  position: absolute;
  top: -80px;
  left: 12px;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 14px;
  box-shadow: var(--shadow-md);
}
.skip:focus { top: 10px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ---------- Buttons ---------- */
.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: var(--r-md);
  background: var(--brand-700);
  color: #fff;
  font-family: var(--body);
  font-weight: var(--fw-semibold);
  font-size: 15px;
  line-height: 1.3;
  box-shadow: 0 1px 2px rgba(154, 52, 18, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition: background-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}
.primary:hover:not(:disabled) { background: var(--brand-800); }
.primary:active:not(:disabled) { transform: translateY(1px); }
.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: var(--fw-medium);
  line-height: 1.3;
  box-shadow: inset 0 0 0 1px var(--border-strong), var(--shadow-xs);
  transition: background-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.secondary:hover:not(:disabled) { background: var(--surface-2); }
.secondary .icon { width: 16px; height: 16px; color: var(--ink-3); }
.text-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-size: 14px;
  font-weight: var(--fw-medium);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.text-button:hover { background: var(--surface-2); color: var(--ink); }
.text-button .icon { width: 17px; height: 17px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 24px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.club {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  text-decoration: none;
  color: var(--ink);
}
.club img { width: 38px; height: 38px; }
.club strong {
  display: block;
  font: var(--fw-semibold) 20px/1.3 var(--display);
  color: var(--brand-900);
}
.club small {
  display: block;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-3);
}
.divider { width: 1px; height: 28px; background: var(--border); }
.top-name {
  font: var(--fw-semibold) 16px/1.4 var(--body);
  color: var(--ink);
}
.back-home {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: var(--fw-medium);
  color: var(--ink-2);
  text-decoration: none;
}
.back-home:hover { background: var(--surface-2); color: var(--ink); }
.back-home .icon { width: 16px; height: 16px; }
.lang-group {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  gap: 2px;
  padding: 2px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}
.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 44px;
  padding: 4px 12px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: var(--fw-semibold);
  line-height: 1.4;
  color: var(--ink-3);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.lang-btn:hover { color: var(--ink); }
.lang-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--brand-800);
  /* A non-colour cue (underline) marks the selected language (WCAG 1.4.1 / 1.4.11). */
  box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--border), inset 0 -2px 0 var(--brand-700);
}
.mobile-toggle { display: none; }

/* ---------- Layout ---------- */
.workspace {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-h));
}
.sidebar {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 20px 16px 20px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.side-eyebrow {
  padding: 0 8px;
  margin-bottom: 12px;
  font-size: 12px;
  font-weight: var(--fw-semibold);
  line-height: 1.5;
  letter-spacing: 0;
  color: var(--ink-3);
}
.new-chat { width: 100%; }
.new-chat .icon { width: 18px; height: 18px; }
nav { margin-top: 18px; display: grid; gap: 2px; }
nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-2);
  text-decoration: none;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
nav a .nav-icon { width: 19px; height: 19px; color: var(--ink-3); }
nav a em { font-style: normal; font-weight: var(--fw-medium); }
nav a:hover { background: var(--surface-2); color: var(--ink); }
nav a.active { background: var(--brand-50); color: var(--brand-800); }
nav a.active .nav-icon { color: var(--brand-700); }
nav a.active::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand-700);
}
.side-bottom {
  margin-top: auto;
  padding-top: 20px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-3);
}
.private-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: var(--fw-semibold);
  color: var(--ink);
}
.private-note .icon { width: 17px; height: 17px; color: var(--brand-700); }
/* Privacy reminder renders as one card: title row + body. */
.side-bottom > .private-note {
  padding: 12px 12px 0;
  border-radius: var(--r-md) var(--r-md) 0 0;
  background: var(--surface-2);
}
.side-bottom > p {
  margin: 0 0 14px;
  padding: 4px 12px 12px 37px;
  border-radius: 0 0 var(--r-md) var(--r-md);
  background: var(--surface-2);
}
.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  font-size: 13px;
  color: var(--ink-2);
}
.status-dot {
  display: inline-block;
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #a8a29e;
  box-shadow: 0 0 0 3px rgba(168, 162, 158, 0.2);
}
.status-line:has(#connection-status[data-state="ai"]) .status-dot,
.status-line:has(#connection-status[data-state="retrieval"]) .status-dot {
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.18);
}
.status-line:has(#connection-status[data-state="offline"]) .status-dot,
.status-line:has(#connection-status[data-state="unauth"]) .status-dot {
  background: var(--brand-600);
  box-shadow: 0 0 0 3px rgba(227, 100, 12, 0.18);
}

main { min-width: 0; display: flex; flex-direction: column; }

.replica-notice {
  margin: 12px clamp(12px, 3vw, 32px) 0;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.55;
}
.replica-answer-label {
  color: var(--ink-2);
  font-size: 13px;
  font-weight: var(--fw-semibold);
}

/* ---------- Workspace bar ---------- */
.workspace-bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 5;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 32px;
  background: rgba(250, 248, 245, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--ink-3);
}
#view-label { font-weight: var(--fw-semibold); color: var(--ink); font-size: 14.5px; }
.bar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.quota-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--r-full);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
  font-size: 13px;
  font-weight: var(--fw-medium);
  color: var(--ink-2);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.quota-chip::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #16a34a;
}
/* No questions left today. The state class is not "empty": that is the empty-state panel further down. */
.quota-chip.exhausted { background: var(--danger-bg); color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger-border); }
.quota-chip.exhausted::before { background: var(--danger); }

/* ---------- Views ---------- */
.view { width: 100%; max-width: 920px; margin: 0 auto; padding: 0 32px; }
.eyebrow {
  font: var(--fw-semibold) 13px/1.6 var(--body);
  color: var(--brand-700);
  letter-spacing: 0;
}
.eyebrow.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 10px;
  border-radius: var(--r-full);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-xs);
  color: var(--ink-2);
  font-weight: var(--fw-medium);
}
.eyebrow.pill .icon { width: 16px; height: 16px; color: var(--brand-700); }
.lead {
  max-width: 680px;
  font-size: 16.5px;
  line-height: 1.8;
  color: var(--ink-2);
}

/* Welcome */
.welcome { text-align: center; padding: 56px 0 28px; }
.welcome.is-collapsed { padding: 0; }
.welcome.is-collapsed > :not(h1) { display: none; }
.welcome h1 {
  margin: 18px 0 10px;
  font-size: clamp(32px, 3.4vw, 44px);
  line-height: 1.35;
  color: var(--ink);
}
.welcome .lead { margin: 0 auto; }

/* Composer */
.composer {
  background: var(--surface);
  border: 1px solid var(--field-border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  padding: 18px 20px 14px;
  overflow: hidden;
  transition: box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}
.composer:focus-within { border-color: var(--brand-700); box-shadow: var(--ring), var(--shadow-md); }
.composer textarea {
  display: block;
  width: 100%;
  min-height: 92px;
  max-height: 300px;
  resize: vertical;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 16px;
  line-height: 1.8;
  color: var(--ink);
}
.composer textarea::placeholder { color: var(--ink-3); }
.composer-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 8px 0 12px;
}
.privacy-hint {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-3);
}
.privacy-hint .icon { width: 15px; height: 15px; color: var(--brand-700); }
.kbd-hint {
  padding: 1px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  font-size: 12px;
  color: var(--ink-3);
}
.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
#cancel .icon { width: 12px; height: 12px; fill: currentColor; }
.send { min-height: 44px; padding: 10px 20px; font-size: 15px; }
.send .icon { width: 16px; height: 16px; }
.consent {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-2);
  cursor: pointer;
}
.consent input {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--brand-700);
  cursor: pointer;
}
.below-composer {
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-3);
}
.char-count {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.char-count:empty { display: none; }
.char-count.near-limit { color: var(--danger); font-weight: var(--fw-semibold); }
.review-box {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
  justify-items: start;
}
.review-prompt {
  font-size: 13.5px;
  font-weight: var(--fw-semibold);
  color: var(--ink-2);
}
.review-stars { display: inline-flex; gap: 2px; }
.star-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 4px;
  border-radius: var(--r-sm);
  font-size: 26px;
  line-height: 1;
  color: var(--ink-3);
  transition: color 0.15s var(--ease), transform 0.15s var(--ease);
}
.star-btn.on { color: var(--brand-600); }
.star-btn:hover { color: var(--brand-600); transform: translateY(-1px); }
.review-comment-label {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 560px;
  font-size: 13px;
  font-weight: var(--fw-medium);
  color: var(--ink-2);
}
.review-comment {
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--field-border);
  font-size: 14.5px;
  line-height: 1.7;
  color: var(--ink);
  resize: vertical;
}
.review-comment:focus { outline: 2px solid transparent; outline-offset: 2px; box-shadow: inset 0 0 0 1.5px var(--brand-700), var(--ring); }
.review-hint { font-size: 13px; line-height: 1.6; color: var(--danger); }
.review-hint:empty { display: none; }
.review-done {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 13.5px;
  color: var(--ink-2);
}
.review-stars-static { color: var(--brand-600); font-size: 18px; letter-spacing: 2px; }
.review-edit, .review-cancel { min-height: 44px; padding: 4px 10px; }
.review-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.library-count { margin: 0 0 12px; }
.library-count:empty { display: none; }
.dialog-more { display: flex; margin: 18px auto 6px; }

/* Feedback */
.feedback {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--danger-bg);
  box-shadow: inset 0 0 0 1px var(--danger-border);
  font-size: 14px;
  line-height: 1.6;
  color: var(--danger);
}
.feedback.info { background: var(--info-bg); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--border); }
.feedback.ok { background: var(--success-bg); color: var(--success); box-shadow: inset 0 0 0 1px var(--success-border); }
.feedback:empty { display: none; }
/* While the pending card is visible it already communicates progress visually; keep the status text
   in the accessibility tree (visually hidden, not display:none) so screen readers still hear it. */
#pending-answer:not([hidden]) ~ #feedback.info {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Suggestions */
.suggestions { margin-top: 40px; }
.suggestion-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.suggestion-heading h2 { margin-top: 2px; font-size: 18px; line-height: 1.5; }
.muted { font-size: 13px; color: var(--ink-3); }
.suggestion-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.suggestion-grid button {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  min-width: 0;
  min-height: 44px;
  padding: 16px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-xs);
  text-align: left;
  transition: box-shadow 0.18s var(--ease), transform 0.18s var(--ease), background-color 0.18s var(--ease);
}
.topic-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background: var(--brand-50);
  color: var(--brand-700);
  box-shadow: inset 0 0 0 1px var(--brand-100);
}
.topic-icon .icon { width: 20px; height: 20px; }
.suggestion-grid strong {
  display: block;
  font-size: 15.5px;
  font-weight: var(--fw-semibold);
  line-height: 1.45;
  color: var(--ink);
}
.suggestion-grid small {
  display: block;
  margin-top: 4px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-3);
}
.arrow {
  margin-left: auto;
  align-self: center;
  flex-shrink: 0;
  color: var(--ink-3);
  opacity: 0.6;
  transition: transform 0.18s var(--ease), opacity 0.18s var(--ease), color 0.18s var(--ease);
}
.arrow .icon { width: 17px; height: 17px; }
@media (hover: hover) and (pointer: fine) {
  .suggestion-grid button:hover {
    box-shadow: inset 0 0 0 1px var(--brand-200), var(--shadow-md);
    transform: translateY(-1px);
  }
  .suggestion-grid button:hover .arrow { opacity: 1; color: var(--brand-700); transform: translateX(2px); }
}

/* ---------- Messages ---------- */
.messages:not(:empty) { display: grid; gap: 18px; padding: 28px 0 18px; }
.message {
  overflow-wrap: anywhere;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-sm);
  padding: 22px 26px;
}
.message.user {
  justify-self: end;
  max-width: min(78%, 640px);
  padding: 14px 18px;
  border-radius: var(--r-xl) var(--r-xl) 6px var(--r-xl);
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px var(--brand-100);
}
.message-label {
  margin-top: 0;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12.5px;
  font-weight: var(--fw-semibold);
  color: var(--ink-3);
}
.message.user .message-label { margin-bottom: 4px; color: var(--brand-800); }
.message.assistant .message-label {
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  font-size: 14px;
}
.message.assistant .message-label::before,
.pending-avatar {
  content: '';
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--surface) url('./logo.svg') center / 22px no-repeat;
  box-shadow: inset 0 0 0 1px var(--border);
}
.message p {
  white-space: pre-wrap;
  font-size: 15.5px;
  line-height: 1.85;
  color: var(--ink);
}
.message p + p { margin-top: 10px; }
.message.user p { font-size: 15px; line-height: 1.75; }
.message h3 {
  margin: 20px 0 6px;
  font-size: 16.5px;
  line-height: 1.5;
  color: var(--ink);
}
.message .message-label + h3 { margin-top: 14px; }
.answer-list {
  display: grid;
  gap: 6px;
  margin: 6px 0 4px;
  padding-left: 22px;
  font-size: 15.5px;
  line-height: 1.8;
  color: var(--ink);
}
.answer-list li::marker { color: var(--brand-600); }
.section-cites { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.section-cites .source-button {
  position: relative;
  justify-content: center;
  min-width: 38px;
  min-height: 30px;
  padding: 2px 10px;
  margin: 0;
  border-radius: var(--r-full);
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px var(--brand-100);
  color: var(--brand-800);
  font-size: 12.5px;
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}
/* Expand the hit area to 44px without enlarging the chip. */
.section-cites .source-button::after { content: ''; position: absolute; inset: -7px -3px; }
.section-cites .source-button:hover { background: var(--brand-100); }
.message .notice {
  margin: 18px 0 0;
  font-size: 14px;
  line-height: 1.7;
}
.message-sources {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
}
.message-sources-label {
  display: block;
  font-size: 12.5px;
  font-weight: var(--fw-semibold);
  letter-spacing: 0;
  color: var(--ink-3);
}
.source-button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin: 4px 6px 4px 0;
  padding: 7px 13px;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.45;
  text-align: left;
  transition: background-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.source-button:hover { background: var(--surface-2); }
.source-row {
  display: flex;
  width: 100%;
  gap: 12px;
  margin: 0;
  padding: 10px 12px;
}
.source-row:hover { box-shadow: inset 0 0 0 1px var(--border-strong); }
.source-id {
  flex-shrink: 0;
  min-width: 40px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px rgba(194, 65, 12, 0.22);
  color: var(--brand-800);
  font-size: 12px;
  font-weight: var(--fw-semibold);
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.source-body { display: grid; min-width: 0; flex: 1; }
.source-title { font-weight: var(--fw-medium); color: var(--ink); }
.source-page { font-size: 12.5px; color: var(--ink-3); }
.source-row .icon { width: 16px; height: 16px; color: var(--ink-3); }

/* Pending answer */
.pending-answer {
  margin: 18px 0 18px;
  padding: 18px 22px 20px;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-sm);
}
#cancel { margin-top: 12px; min-height: 44px; }
.messages:empty + .pending-answer { margin-top: 28px; }
.pending-head { display: flex; align-items: center; gap: 10px; }
.pending-head strong { font-size: 14.5px; font-weight: var(--fw-semibold); color: var(--ink); }
.pending-answer p { margin: 8px 0 14px 40px; font-size: 13.5px; line-height: 1.65; color: var(--ink-3); }
.dots { display: inline-flex; gap: 4px; margin-left: 2px; }
.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-600);
  animation: dot 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.skeleton { display: grid; gap: 10px; margin-left: 40px; }
.skeleton span {
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite linear;
}
.skeleton span:nth-child(1) { width: 92%; }
.skeleton span:nth-child(2) { width: 78%; }
.skeleton span:nth-child(3) { width: 54%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.export-bar {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- Notices ---------- */
.notice {
  margin: 18px 0 24px;
  padding: 12px 16px 12px 44px;
  position: relative;
  border-radius: var(--r-md);
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px var(--brand-100);
  font-size: 14px;
  line-height: 1.75;
  color: var(--brand-900);
}
.notice::before {
  content: 'i';
  content: 'i' / '';
  position: absolute;
  left: 14px;
  top: 14px;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-700);
  color: #fff;
  font: 700 12px/1 Georgia, serif;
}
.superseded-notice { display: grid; gap: 10px; justify-items: start; }
.superseded-notice p { margin: 0; }

/* ---------- Library ---------- */
.document-library, .about { padding-top: 40px; padding-bottom: 8px; }
.document-library h1, .about h1 {
  margin: 6px 0 10px;
  font-size: 30px;
  line-height: 1.4;
  color: var(--ink);
}
.filters {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  align-items: end;
  gap: 12px 14px;
  margin-bottom: 20px;
  padding: 16px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-xs);
}
.filters label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: var(--fw-semibold);
  color: var(--ink-2);
}
.input-icon { position: relative; display: block; }
.input-icon .icon {
  position: absolute;
  left: 13px;
  top: 50%;
  width: 17px;
  height: 17px;
  transform: translateY(-50%);
  color: var(--ink-3);
  pointer-events: none;
}
.filters input[type=search], .filters select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 14px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--field-border);
  font-size: 15px;
  font-weight: var(--fw-regular);
  color: var(--ink);
  transition: box-shadow 0.15s var(--ease);
}
.filters input[type=search] { padding-left: 40px; }
.filters input[type=search]:focus, .filters select:focus {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: inset 0 0 0 1.5px var(--brand-700), var(--ring);
}
.filters .filter-check {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 14px;
  font-weight: var(--fw-regular);
  color: var(--ink-2);
  cursor: pointer;
}
.filters .filter-check input { flex-shrink: 0; width: 18px; height: 18px; margin: 0; accent-color: var(--brand-700); }
#document-list { display: grid; gap: 10px; }
.document {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-xs);
  transition: box-shadow 0.15s var(--ease);
}
.document:hover { box-shadow: inset 0 0 0 1px var(--border-strong), var(--shadow-sm); }
.document-body { min-width: 0; flex: 1; }
.doc-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.doc-category {
  display: inline-block;
  margin-bottom: 4px;
  padding: 1px 9px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  font-size: 12px;
  font-weight: var(--fw-medium);
  line-height: 1.7;
  color: var(--ink-2);
}
.doc-badges .doc-category { margin-bottom: 0; }
.doc-superseded {
  display: inline-block;
  padding: 1px 9px;
  border-radius: var(--r-full);
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px var(--brand-200);
  font-size: 12px;
  font-weight: var(--fw-semibold);
  line-height: 1.7;
  color: var(--brand-900);
}
.document h2 {
  font-size: 16px;
  font-weight: var(--fw-semibold);
  line-height: 1.55;
  color: var(--ink);
}
.document p { margin: 4px 0 0; font-size: 13px; line-height: 1.6; color: var(--ink-3); }
.doc-status { display: flex; align-items: center; gap: 7px; }
.doc-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: #a8a29e; }
.document.is-searchable .doc-status::before { background: #16a34a; }
.document.is-scan .doc-status::before { background: var(--brand-500); }
.document-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px 6px;
  flex-shrink: 0;
  font-size: 13.5px;
}
.document-actions .secondary { min-height: 44px; padding: 6px 14px; font-size: 13.5px; }
.document-actions a,
.doc-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: var(--r-sm);
  font-size: 13.5px;
  font-weight: var(--fw-medium);
  color: var(--ink-2);
  text-decoration: none;
}
.document-actions a:hover { background: var(--surface-2); color: var(--ink); }
.doc-link .icon { width: 15px; height: 15px; color: var(--ink-3); }
.empty {
  padding: 32px 22px;
  border-radius: var(--r-lg);
  border: 1px dashed var(--border-strong);
  background: var(--surface);
  text-align: center;
  font-size: 15px;
  line-height: 1.75;
  color: var(--ink-3);
}
.empty a { display: inline-flex; align-items: center; min-height: 44px; margin: 8px 10px; font-size: 14px; }
.library-feedback { margin: 0 0 16px; }
.empty-actions { margin-top: 14px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.empty-actions a { margin: 0; }

/* ---------- About ---------- */
.about h2 {
  margin: 32px 0 8px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: 18.5px;
  line-height: 1.5;
  color: var(--ink);
}
.about .notice + h2 { border-top: 0; padding-top: 0; margin-top: 8px; }
.about p { max-width: 760px; font-size: 15.5px; line-height: 1.85; color: var(--ink-2); }
.about p + p { margin-top: 8px; }
.about .lead { font-size: 16.5px; color: var(--ink-2); }
.about a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 0;
}
.link-list { display: grid; gap: 8px; max-width: 760px; margin-top: 12px; }
.link-list p { margin: 0 !important; max-width: none; }
.link-list a {
  display: flex;
  width: 100%;
  padding: 10px 16px;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-xs);
  color: var(--ink);
  font-size: 15px;
  font-weight: var(--fw-medium);
  text-decoration: none;
  transition: box-shadow 0.15s var(--ease), background-color 0.15s var(--ease);
}
.link-list a:hover { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border-strong); }

/* ---------- Footer ---------- */
footer {
  width: 100%;
  max-width: 920px;
  margin: auto auto 0;
  padding: 32px 32px 28px;
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--ink-3);
  text-align: center;
}

/* ---------- Source dialog ---------- */
dialog {
  /* Keep focused/scrolled excerpts clear of the sticky dialog header. */
  scroll-padding-top: 80px;
  width: min(800px, calc(100vw - 24px));
  max-height: min(88vh, 88dvh);
  padding: 0 28px 24px;
  border: 0;
  border-radius: var(--r-xl);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(31, 23, 18, 0.06);
}
dialog[open] { animation: dialog-in 0.18s var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
dialog::backdrop { background: rgba(31, 23, 18, 0.42); backdrop-filter: blur(2px); }
.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 -28px 4px;
  padding: 16px 28px 14px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border);
}
.dialog-head h2 { font-size: 18px; line-height: 1.45; }
.dialog-head button { white-space: nowrap; flex-shrink: 0; }
.dialog-head .icon { width: 16px; height: 16px; }
.dialog-feedback { margin: 12px 0 4px; }
.dialog-feedback:empty { display: none; }
.evidence { padding: 20px 0; border-top: 1px solid var(--border); }
.evidence:first-child,
.notice + .evidence { border-top: 0; }
.notice + .evidence { padding-top: 4px; }
.evidence h3 { font-size: 16.5px; line-height: 1.6; color: var(--ink); }
/* Retrieved excerpts the answer did not cite, listed after the cited ones. */
.dialog-uncited-label {
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  letter-spacing: 0;
  color: var(--ink-3);
}
.dialog-uncited-label:first-child { padding-top: 4px; border-top: 0; }
.dialog-uncited-label + .evidence { border-top: 0; padding-top: 10px; }
.evidence .meta {
  display: inline-block;
  margin: 8px 0 4px;
  padding: 1px 10px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  font-size: 12.5px;
  font-weight: var(--fw-medium);
  color: var(--ink-2);
}
.evidence blockquote {
  margin: 12px 0;
  padding: 16px 20px;
  border-left: 3px solid var(--brand-500);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  background: var(--bg);
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.95;
  color: var(--ink);
}
/* One block per printed line of the PDF (sourceDetails in app.mjs). A printed line wider than the dialog wraps
   into balanced halves instead of a full line and a short fragment; without text-wrap support it wraps as before.
   text-wrap must follow white-space, which resets it. */
.excerpt-line { display: block; white-space: pre-wrap; text-wrap: balance; }
.excerpt-line:empty::before { content: '\200b'; }
.evidence a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 14px;
  font-weight: var(--fw-medium);
}

/* ---------- Embed mode ---------- */
.embed-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.embed-nav { margin-top: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 2px; border-radius: var(--r-md); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.embed-nav a { position: relative; min-height: 44px; padding: 6px 14px; border-radius: 9px; font-size: 13.5px; gap: 6px; }
.embed-nav a.active { background: var(--surface); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--border), inset 0 -2px 0 var(--brand-700); }
.embed-account { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.embed-account .account-feedback { flex-basis: 100%; }
.embed-account-email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.embed-logout { min-height: 44px; padding: 4px 10px; }
.embed-logout .icon { width: 16px; height: 16px; }
.embed-nav a.active::before { display: none; }
.embed-reset { min-height: 44px; padding: 8px 14px; font-size: 13.5px; }
.embed .topbar, .embed .sidebar, .embed #view-label { display: none; }
.embed .workspace { grid-template-columns: 1fr; min-height: 100vh; }
.embed .workspace-bar { top: 0; height: auto; min-height: 58px; padding: 10px 24px; flex-wrap: wrap; gap: 10px; background: var(--surface); }
.embed .welcome { padding-top: 32px; }

/* ---------- Auth ---------- */
body.auth-pending .workspace-bar, body.auth-pending .view { visibility: hidden; }
body.auth-required .sidebar nav,
body.auth-required #new-chat,
body.auth-required .workspace-bar,
body.auth-required .view,
body.auth-required #account-box,
body.auth-required .mobile-toggle { display: none !important; }
body.embed.auth-required .workspace-bar {
  display: flex !important;
  justify-content: flex-end;
}
body.embed.auth-required .embed-nav,
body.embed.auth-required #embed-new-chat,
body.embed.auth-required .embed-account,
body.embed.auth-required .bar-actions { display: none !important; }
/* Sign-in screen: the card stands alone; the sidebar has nothing actionable yet. */
body.auth-required .sidebar { display: none !important; }
body.auth-required .workspace { grid-template-columns: minmax(0, 1fr); }
.auth-gate { width: 100%; max-width: 460px; margin: 56px auto 24px; padding: 0 20px; }
.auth-card {
  padding: 32px 30px 26px;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-md);
}
.auth-logo { display: block; width: 48px; height: 48px; margin-bottom: 18px; }
.auth-card h1 { margin: 4px 0 8px; font-size: 28px; color: var(--ink); }
.auth-card .lead { margin: 0 0 22px; font-size: 15px; line-height: 1.75; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form label { font-size: 14px; font-weight: var(--fw-semibold); color: var(--ink); }
.auth-form input {
  min-height: 48px;
  padding: 10px 14px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--field-border);
  font-size: 16px;
  transition: box-shadow 0.15s var(--ease);
}
.auth-form input:focus { outline: 2px solid transparent; outline-offset: 2px; box-shadow: inset 0 0 0 1.5px var(--brand-700), var(--ring); }
.auth-form input[aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--danger); }
.auth-form input[aria-invalid="true"]:focus { box-shadow: inset 0 0 0 2px var(--danger), var(--ring); }
.auth-form input:focus-visible { outline: 2px solid transparent; }
#auth-code { letter-spacing: 10px; font-size: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.auth-form .primary { min-height: 48px; margin-top: 4px; font-size: 15.5px; }
.auth-actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.auth-sent { margin: 0; font-size: 14px; line-height: 1.7; color: var(--ink-2); overflow-wrap: anywhere; }
.auth-privacy {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--ink-3);
}
.account-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 14px;
  padding: 12px 4px 0;
  border-top: 1px solid var(--border);
}
.account-label { font-size: 12px; color: var(--ink-3); }
.account-email { font-weight: var(--fw-semibold); color: var(--ink); word-break: break-all; }
.quota-status { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.logout { align-self: flex-start; margin: 4px 0 0 -12px; color: var(--ink-2); }
.logout .icon { width: 16px; height: 16px; }
/* A failed sign-out, shown next to the control in every view. */
.account-feedback { margin-top: 6px; padding: 8px 10px; font-size: 12.5px; line-height: 1.55; }

/* ---------- Responsive ---------- */
@media (min-width: 1500px) {
  .view { max-width: 980px; }
  .welcome { padding-top: 72px; }
}
@media (max-width: 1280px) {
  .embed .workspace-bar { position: static; }
  html:has(body.embed) { scroll-padding-top: 16px; }
}
@media (max-width: 1180px) {
  .document { flex-direction: column; align-items: stretch; gap: 10px; }
  .document-actions { justify-content: flex-start; margin-left: -10px; }
  .document-actions .secondary { margin-left: 10px; }
}
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 232px minmax(0, 1fr); }
  .sidebar { padding-left: 12px; padding-right: 12px; }
  nav a.active::before { left: -12px; }
  .view { padding: 0 24px; }
  .workspace-bar { padding: 6px 24px; }
  .topbar { padding: 8px 18px; gap: 12px; }
}
@media (max-width: 960px) {
  /* 16px stops iOS/iPadOS Safari from zooming into fields on focus. */
  .filters input[type=search], .filters select, .review-comment { font-size: 16px; }
}
@media (max-width: 900px) {
  .suggestion-grid { grid-template-columns: 1fr; }
  .suggestion-heading > .muted { display: none; }
  .filters { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  :root { --topbar-h: 60px; }
  .topbar { gap: 8px; padding: 6px 12px; }
  .club img { width: 34px; height: 34px; }
  .club strong { font-size: 18px; }
  .club small { font-size: 11.5px; }
  .divider, .back-home, .top-name { display: none; }
  .topbar .lang-group { margin-left: auto; }
  .lang-btn { min-width: 44px; padding: 4px 10px; font-size: 13px; }
  .mobile-toggle {
    display: grid;
    place-items: center;
    min-width: 44px;
    min-height: 44px;
    border-radius: var(--r-sm);
    color: var(--ink);
  }
  .mobile-toggle .icon { width: 22px; height: 22px; }
  .mobile-toggle[aria-expanded="true"] { background: var(--surface-2); }
  .workspace { display: block; min-height: calc(100vh - var(--topbar-h)); }
  .sidebar {
    display: none;
    position: fixed;
    inset: var(--topbar-h) 0 auto 0;
    top: var(--topbar-h);
    z-index: 9;
    height: auto;
    max-height: calc(100dvh - var(--topbar-h));
    overflow: auto;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { display: flex; }
  nav a.active::before { display: none; }
  /* The drawer keeps a non-colour marker for the current view. */
  nav a.active { box-shadow: inset 3px 0 0 var(--brand-700); }
  .side-bottom { display: none; }
  .sidebar.open .side-bottom {
    display: block;
    margin-top: 14px;
    padding: 14px 0 0;
    border-top: 1px solid var(--border);
  }
  nav { margin-top: 12px; }
  .side-eyebrow { display: none; }
  .workspace-bar { top: var(--topbar-h); min-height: 52px; padding: 6px 12px; font-size: 13px; }
  #view-label { display: none; }
  .bar-actions { width: 100%; justify-content: space-between; }
  .embed .workspace-bar { position: static; padding: 8px 12px; }
  .embed .bar-actions { width: auto; }
  .embed-nav a, .embed-reset { font-size: 13px; padding: 6px 11px; }
  .view { padding: 0 16px; }
  .welcome { padding: 32px 0 22px; }
  .welcome h1 { font-size: 30px; margin-top: 14px; }
  .welcome .lead { font-size: 15px; line-height: 1.75; }
  .eyebrow { font-size: 12.5px; }
  .composer { padding: 14px 16px 12px; border-radius: var(--r-lg); }
  .consent { font-size: 13px; align-items: flex-start; }
  .consent input { margin-top: 2px; }
  .composer textarea { min-height: 96px; }
  .composer-bottom { flex-direction: column; align-items: stretch; gap: 10px; }
  .composer-actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .composer-actions .send { width: 100%; }
  .privacy-hint { font-size: 12.5px; }
  .kbd-hint { display: none; }
  .below-composer { font-size: 12.5px; }
  .suggestions { margin-top: 30px; }
  .suggestion-heading h2 { font-size: 17px; }
  .suggestion-grid { gap: 10px; }
  .suggestion-grid button { padding: 14px; }
  .suggestion-grid strong { font-size: 15px; }
  .suggestion-grid small { font-size: 13px; }
  footer { padding: 26px 16px; font-size: 12px; }
  .document-library, .about { padding-top: 26px; }
  .document-library h1, .about h1 { font-size: 26px; }
  .filters { padding: 14px; }
  .about p { font-size: 15px; }
  .message { padding: 16px 18px; }
  .message.user { max-width: 92%; }
  .message p, .answer-list { font-size: 15px; line-height: 1.8; }
  .message h3 { font-size: 16px; }
  .pending-answer { padding: 16px 18px; }
  .pending-answer p, .skeleton { margin-left: 0; }
  .export-bar .secondary { flex: 1; }
  .evidence blockquote { padding: 14px 15px; font-size: 14.5px; line-height: 1.9; }
  dialog { width: calc(100vw - 16px); max-height: min(92vh, 92dvh); padding: 0 16px 18px; }
  .dialog-head { margin: 0 -16px 4px; padding: 12px 16px; }
  .dialog-head h2 { font-size: 16.5px; }
}
@media (max-width: 640px) {
  .auth-gate { margin-top: 28px; padding: 0 14px; }
  .auth-card { padding: 24px 20px 20px; }
  .bar-actions { gap: 6px; }
  .quota-chip { font-size: 12px; padding: 4px 10px; }
}
@media (max-width: 360px) {
  /* Long English club name would wrap the topbar under the sticky bars. */
  .club small { display: none; }
}
@media (hover: none) {
  .kbd-hint { display: none; }
}
/* Windows High Contrast / forced colours: box-shadows are dropped, so give fields real borders and
   make focus, selected language, and current view visible with system colours. */
@media (forced-colors: active) {
  .composer, .filters input[type=search], .filters select, .auth-form input, .review-comment { border: 1px solid CanvasText; }
  .primary, .secondary, .source-button, .quota-chip, .doc-category, .doc-superseded { border: 1px solid ButtonText; }
  .quota-chip.exhausted { border: 2px dashed ButtonText; }
  .filters input[type=search]:focus, .filters input[type=search]:focus-visible,
  .filters select:focus, .filters select:focus-visible,
  .auth-form input:focus, .auth-form input:focus-visible,
  .review-comment:focus, .review-comment:focus-visible,
  .composer textarea:focus, .composer textarea:focus-visible,
  .composer:focus-within { outline: 2px solid Highlight; outline-offset: 2px; }
  .lang-btn[aria-pressed="true"], .star-btn[aria-pressed="true"], .mobile-toggle[aria-expanded="true"], nav a.active, .embed-nav a.active { outline: 2px solid Highlight; outline-offset: -2px; }
  nav a.active::before { forced-color-adjust: none; background: Highlight; }
  .star-btn.on, .review-stars-static { forced-color-adjust: none; color: Highlight; }
}
@media (scripting: none) {
  body.auth-pending .workspace { display: none; }
}
.noscript-banner {
  margin: 0;
  padding: 14px 18px;
  background: var(--brand-50);
  color: var(--brand-900);
  font-weight: var(--fw-semibold);
  text-align: center;
}
/* A flex summary (44px target) loses the native disclosure marker: draw a chevron that turns when the
   list is open, so the uncited passages read as expandable. */
.other-sources > summary { cursor: pointer; display: flex; align-items: center; gap: 10px; min-height: 44px; list-style: none; }
.other-sources > summary::-webkit-details-marker { display: none; }
.other-sources > summary::before {
  content: '';
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  margin-left: 3px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s var(--ease);
}
.other-sources[open] > summary::before { transform: rotate(45deg); }
.other-sources > summary:hover { color: var(--ink-2); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

/* ---------- Print (chat transcript & document list) ---------- */
@media print {
  .topbar,
  .sidebar,
  .workspace-bar,
  .composer,
  .suggestions,
  .export-bar,
  .below-composer,
  .pending-answer,
  .review-box,
  .skip,
  .filters,
  .document-actions,
  .feedback,
  dialog {
    display: none !important;
  }
  /* Printed answers keep verifiable links: show URLs for external links and cited sources. */
  .view a[href^="http"]::after,
  dialog a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 11px; overflow-wrap: anywhere; word-break: break-all; }
  .source-row[data-url]::after { content: " — " attr(data-url); font-size: 11px; overflow-wrap: anywhere; word-break: break-all; }
  .notice::before { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* With the source dialog open, print the excerpt being read instead of the page behind it. */
  html:has(dialog[open]), body:has(dialog[open]) { height: auto !important; overflow: visible !important; }
  body:has(dialog[open]) > :not(dialog) { display: none !important; }
  body:has(dialog[open]) dialog[open] { display: block !important; position: static; width: auto; max-width: none; max-height: none; overflow: visible; box-shadow: none; }
  body:has(dialog[open]) .dialog-head { position: static; }
  body:has(dialog[open]) .dialog-head button,
  body:has(dialog[open]) .dialog-more,
  body:has(dialog[open]) .superseded-open-current { display: none !important; }
  body { background: #fff; }
  .workspace { display: block; min-height: auto; }
  .view { max-width: none; padding: 0; }
  .welcome { padding: 12px 0 20px; }
  .welcome.is-collapsed { padding: 0; }
  h1, h2, h3 { break-after: avoid; }
  .message { box-shadow: none; border: 1px solid #d6d3d1; }
  .message.user { max-width: 100%; break-inside: avoid; }
  .message .notice, .source-row, .evidence, .superseded-notice, .document { break-inside: avoid; }
  .document { box-shadow: none; border: 1px solid #d6d3d1; }
  footer { max-width: none; padding: 20px 0; text-align: left; }
}
