/* BE.Yond — editorial warmth, clear controls, calm conversation.
   Integration contract: HTML/JS own semantics, keyboard behavior and state.
   This stylesheet intentionally uses only local assets and solid colors. */
@font-face {
  font-family: "Bodoni Moda";
  src: url("/fonts/bodoni-moda-latin.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --cream: #FFFDF5;
  --bordeaux: #5A1730;
  --ink: #33302D;
  --beige: #F7F1E8;
  --muted: #6B595F;
  --line: #E7DCD5;
  --gold: #C2A36B;
  --body-font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --heading-font: "Bodoni Moda", Georgia, "Times New Roman", serif;
  --sidebar-width: 292px;
  --content-width: 900px;
  --radius: 16px;
  --shadow: 0 12px 40px rgb(51 48 45 / 6%);
}

*, *::before, *::after { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); }
body {
  margin: 0;
  min-width: 280px;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--body-font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  overflow-wrap: break-word;
}
button, input, textarea, select {
  font: inherit;
  color: inherit;
}
button {
  min-height: 44px;
  min-width: 44px;
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 160ms ease, box-shadow 160ms ease, color 160ms ease;
}
button:disabled {
  cursor: not-allowed;
  opacity: .58;
}
button, a, input, textarea { scroll-margin: 12px; }
a { color: var(--bordeaux); text-underline-offset: .2em; }
img { max-width: 100%; }
svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  vertical-align: middle;
  stroke: currentColor;
}
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  color: var(--bordeaux);
  font-family: var(--heading-font);
  font-weight: 600;
  font-optical-sizing: auto;
  line-height: 1.18;
  letter-spacing: -.025em;
  text-wrap: balance;
}
h1 { font-size: clamp(34px, 4vw, 48px); }
h2 { font-size: clamp(28px, 3vw, 36px); }
h3 { font-size: 26px; }
p { margin: 0 0 1em; }
:where(button, a, input, textarea, select, [tabindex]):focus-visible {
  outline: 3px solid var(--bordeaux);
  outline-offset: 3px;
}
.hidden { display: none !important; }
.mobile-only { display: none; }
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 14px;
  color: var(--muted);
  font-family: var(--body-font);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .16em;
  line-height: 1.5;
  text-transform: uppercase;
}
.brand-mark {
  color: var(--bordeaux);
  font-family: var(--heading-font);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -.035em;
  line-height: 1.2;
}
.brand-mark span { color: inherit; }
.brand-mark.small { font-size: 24px; }
.primary, .secondary, .new-chat, .send-btn {
  border-radius: 13px;
  padding: 12px 18px;
  font-weight: 600;
  line-height: 1.35;
}
.primary, .new-chat, .send-btn {
  background: var(--bordeaux);
  color: var(--cream);
}
.primary:hover:not(:disabled), .new-chat:hover:not(:disabled),
.send-btn:hover:not(:disabled) {
  box-shadow: inset 0 0 0 1px var(--cream), 0 3px 12px rgb(90 23 48 / 12%);
}
.secondary {
  background: var(--beige);
  color: var(--bordeaux);
  border-color: var(--line);
}
.secondary:hover:not(:disabled) { border-color: var(--bordeaux); }
.full { width: 100%; margin-top: 12px; }
.text-btn {
  padding: 9px 2px;
  border-radius: 7px;
  background: transparent;
  color: var(--bordeaux);
  font-size: 13px;
  text-align: left;
}
.text-btn:hover:not(:disabled) { text-decoration: underline; text-underline-offset: 4px; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 10px;
  border-radius: 12px;
  background: transparent;
  color: var(--bordeaux);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover:not(:disabled) { background: var(--beige); border-color: var(--line); }
label {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
}
input:not([type="hidden"]):not([type="file"]), textarea {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 15px;
  background: var(--cream);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  caret-color: var(--bordeaux);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus, textarea:focus { border-color: var(--bordeaux); }
input[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--bordeaux); }
.error, .error-text {
  color: var(--bordeaux);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.error { min-height: 21px; margin: 14px 0 0; }
.error-text { border-left: 3px solid var(--bordeaux); padding-left: 10px; }

/* Authentication: complete, modest original logo; editorial copy, focused form. */
.auth-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
  align-items: center;
  gap: clamp(40px, 7vw, 100px);
  width: min(1160px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(32px, 5vw, 72px);
  background: var(--cream);
}
.auth-story { min-width: 0; padding: 8px 0; }
.auth-logo { margin-bottom: 32px; }
.auth-logo img {
  display: block;
  width: min(236px, 100%);
  max-width: 260px;
  height: auto;
  object-fit: contain;
  object-position: center;
}
.auth-story-copy { max-width: 460px; }
.auth-story-copy h1 { margin-bottom: 20px; }
.auth-story-copy p:not(.eyebrow) {
  max-width: 40ch;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.7;
}
.auth-card {
  min-width: 0;
  width: 100%;
  padding: clamp(28px, 3vw, 40px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--beige);
  box-shadow: var(--shadow);
}
.auth-card .brand-mark { margin-bottom: 32px; }
.auth-card h2 { margin-bottom: 12px; font-size: 32px; }
.auth-card > .muted { margin-bottom: 0; font-size: 15px; }
.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 26px 0 24px;
}
.auth-tabs button {
  position: relative;
  min-height: 48px;
  padding: 12px 10px 15px;
  border-radius: 12px;
  background: var(--bordeaux);
  color: var(--cream);
  font-size: 14px;
  font-weight: 600;
}
.auth-tabs button.active::after,
.auth-tabs button[aria-selected="true"]::after {
  content: "";
  position: absolute;
  right: 18px;
  bottom: 7px;
  left: 18px;
  height: 2px;
  border-radius: 1px;
  background: var(--cream);
}
.auth-tabs button:hover:not(:disabled) { box-shadow: inset 0 0 0 1px var(--cream); }
#authForm { display: grid; gap: 16px; }
#authForm label input { display: block; margin-top: 7px; }
#authForm .full { margin-top: 6px; }
#authForm .error { margin-top: 0; }

/* Conversation shell: messages are the sole flexible scrolling main region. */
.chat-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--cream);
}
.sidebar {
  display: flex;
  flex-direction: column;
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  min-width: 0;
  min-height: 0;
  padding: 26px 18px 16px;
  border-right: 1px solid var(--line);
  background: var(--beige);
}
.side-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 0 8px;
}
.new-chat {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  margin: 22px 0 24px;
  text-align: left;
  font-size: 14px;
}
.side-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #B9A58F var(--beige);
  padding: 4px 5px 12px;
  margin: 0 -5px;
}
.nav-section { margin-bottom: 28px; }
.side-label {
  display: block;
  margin: 0 0 12px;
  padding: 0 8px;
  color: var(--muted);
  font-family: var(--body-font);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  line-height: 1.5;
  text-transform: uppercase;
}
.area-tabs { display: grid; gap: 8px; }
.area-tab {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--bordeaux);
  color: var(--cream);
  font-size: 14px;
  line-height: 1.35;
  text-align: left;
}
.area-symbol {
  display: grid;
  flex: 0 0 24px;
  place-items: center;
  width: 24px;
  height: 24px;
  font-size: 17px;
  font-weight: 500;
}
.area-label { min-width: 0; overflow-wrap: anywhere; }
.area-tab.active .area-label,
.area-tab[aria-selected="true"] .area-label {
  font-weight: 650;
  text-decoration-line: underline;
  text-decoration-color: var(--cream);
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
  text-decoration-skip-ink: none;
}
.area-tab:hover:not(:disabled) { box-shadow: inset 0 0 0 1px var(--cream); }
.area-tab.active, .area-tab[aria-selected="true"] { border-color: var(--cream); }
:where(.primary, .new-chat, .send-btn, .auth-tabs button, .area-tab):focus-visible {
  outline: 3px solid var(--bordeaux);
  outline-offset: 3px;
  box-shadow: inset 0 0 0 2px var(--cream);
}
.history-section { margin: 0; }
.chat-list { display: grid; gap: 5px; margin: 0; }
.chat-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 3px;
  width: 100%;
  min-width: 0;
  min-height: 50px;
  padding: 10px 12px;
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.chat-title {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  line-height: 1.4;
}
.chat-item time { color: var(--muted); font-size: 11px; line-height: 1.5; }
.chat-item:hover:not(:disabled) { background: var(--cream); border-color: var(--line); }
.chat-item.active, .chat-item[aria-current="true"] {
  border-color: var(--line);
  border-left: 3px solid var(--bordeaux);
  background: var(--cream);
}
.chat-item.active .chat-title { font-weight: 600; }
.side-bottom {
  flex: 0 0 auto;
  margin-top: 16px;
  padding: 16px 8px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
#userEmail {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.6;
}
.main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--cream);
}
.topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 84px;
  padding: 18px clamp(22px, 3.5vw, 48px);
  border-bottom: 1px solid var(--line);
  background: var(--cream);
}
.topbar-title { flex: 1 1 auto; min-width: 0; }
.topbar-title strong {
  display: block;
  color: var(--bordeaux);
  font-family: var(--heading-font);
  font-size: 25px;
  font-weight: 600;
  line-height: 1.2;
}
.topbar-title span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.topbar-badge {
  flex: 0 0 auto;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--beige);
  color: var(--bordeaux);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.messages {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #B9A58F var(--cream);
  padding: 32px clamp(20px, 5vw, 72px) 28px;
  scroll-padding-block: 24px;
}
.welcome {
  max-width: 650px;
  margin: clamp(24px, 6vh, 72px) auto 32px;
  text-align: center;
}
.welcome-mark {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: 0 auto 24px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--beige);
  color: var(--bordeaux);
  font-family: var(--heading-font);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -.04em;
}
.welcome .eyebrow { margin-bottom: 12px; }
.welcome h2 { margin-bottom: 16px; font-size: clamp(30px, 3.6vw, 42px); }
.welcome > .muted { max-width: 46ch; margin: 0 auto; line-height: 1.7; }
.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 28px auto 0;
}
.suggestions button {
  max-width: 100%;
  min-height: 44px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--beige);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  text-align: left;
  overflow-wrap: anywhere;
}
.suggestions button:hover:not(:disabled) { color: var(--bordeaux); border-color: var(--bordeaux); }
.welcome-note { margin: 20px auto 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: var(--content-width);
  min-width: 0;
  margin: 0 auto 24px;
}
.message-avatar {
  display: grid;
  flex: 0 0 36px;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-top: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--cream);
  color: var(--bordeaux);
  font-family: var(--heading-font);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -.04em;
  user-select: none;
}
/* Visible BE. fallback badge if an assistant message omits its avatar node. */
.message.assistant:not(:has(.message-avatar))::before {
  content: "BE.";
  display: grid;
  flex: 0 0 36px;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-top: 3px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--cream);
  color: var(--bordeaux);
  font-family: var(--heading-font);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -.04em;
}
.bubble {
  min-width: 0;
  max-width: 100%;
  padding: 16px 20px;
  border-radius: 18px;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.assistant .bubble {
  flex: 0 1 auto;
  background: var(--beige);
  border: 1px solid var(--line);
  border-top-left-radius: 6px;
}
.message.user { justify-content: flex-end; padding-left: 48px; }
.user .bubble {
  max-width: min(82%, 690px);
  background: var(--bordeaux);
  color: var(--cream);
  border-top-right-radius: 6px;
}
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .message-content:empty { display: none; }
.bubble a { color: inherit; }
.bubble h1, .bubble h2, .bubble h3 { margin: 16px 0 10px; font-size: 26px; }
.user .bubble :is(h1, h2, h3, h4, h5, h6) { color: var(--cream); }
.generated-image {
  display: block;
  width: min(100%, 440px);
  height: auto;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  max-width: 100%;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--cream);
  color: var(--bordeaux);
  font-size: 14px;
  line-height: 1.45;
  text-decoration: none;
  white-space: normal;
  overflow-wrap: anywhere;
}
.bubble .file-card { color: var(--bordeaux); }
.file-card label { min-width: 0; color: inherit; cursor: inherit; }
.file-card:hover { border-color: var(--bordeaux); }
.loading-dots { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; }
.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bordeaux);
  animation: beyond-pulse 1.35s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 150ms; }
.loading-dots span:nth-child(3) { animation-delay: 300ms; }
@keyframes beyond-pulse {
  0%, 80%, 100% { opacity: .35; }
  40% { opacity: 1; }
}

/* Column composer: textarea above roomy tools, never a squeezed one-line row. */
.attachments, .composer-status, .composer {
  flex: 0 0 auto;
  width: min(var(--content-width), calc(100% - 48px));
  margin-right: auto;
  margin-left: auto;
}
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.attachments:empty, .composer-status:empty { display: none; }
.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  padding: 3px 4px 3px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--beige);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
}
.attachment-label {
  min-width: 0;
  max-width: 34ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment > span:not(.attachment-label) { color: var(--muted); font-size: 11px; }
.remove-attachment {
  display: inline-flex;
  flex: 0 0 44px;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 10px;
  border-radius: 9px;
  background: transparent;
  color: var(--bordeaux);
}
.remove-attachment:hover { border-color: var(--line); background: var(--cream); }
.composer-status { margin-bottom: 6px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  margin-bottom: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--cream);
  box-shadow: 0 6px 24px rgb(51 48 45 / 5%);
}
.composer:focus-within { border-color: var(--bordeaux); }
.composer textarea {
  display: block;
  flex: 0 1 auto;
  width: 100%;
  min-height: 56px;
  max-height: 180px;
  max-height: min(180px, 25dvh);
  overflow-y: auto;
  resize: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 11px;
  background: transparent;
  font-family: var(--body-font);
  font-size: 16px;
  line-height: 1.5;
}
.composer textarea:focus-visible { outline-offset: 0; outline-width: 2px; }
.composer-footer {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.composer-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; min-width: 0; }
.composer-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 9px 11px;
  border-radius: 11px;
  background: var(--beige);
  color: var(--bordeaux);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
}
.composer-btn:hover:not(:disabled) { border-color: var(--bordeaux); }
.composer-btn.recording {
  border-color: var(--bordeaux);
  background: var(--bordeaux);
  color: var(--cream);
  box-shadow: inset 0 0 0 2px var(--cream);
}
.composer-btn:disabled { opacity: .58; cursor: not-allowed; }
.composer-btn.recording:focus-visible { box-shadow: inset 0 0 0 2px var(--cream); }
.tool-label { white-space: nowrap; }
.send-btn {
  display: inline-flex;
  flex: 0 0 46px;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  padding: 12px;
}
.send-btn svg { width: 22px; height: 22px; }
.disclaimer {
  flex: 0 0 auto;
  margin: 0 auto;
  max-width: 900px;
  padding: 0 24px max(14px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

/* Native modal: no synthetic HTML required for overlay or keyboard focus. */
.image-dialog {
  width: min(520px, calc(100% - 32px));
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  padding: 28px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(51 48 45 / 18%);
}
.image-dialog::backdrop { background: rgb(51 48 45 / 42%); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.dialog-header h2 { font-size: 30px; }
#closeImageDialog {
  display: inline-flex;
  flex: 0 0 44px;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 10px;
  border-radius: 11px;
  background: var(--beige);
  color: var(--bordeaux);
}
#closeImageDialog:hover { border-color: var(--bordeaux); }
#imageForm { display: grid; gap: 20px; }
#imagePrompt { display: block; min-height: 140px; max-height: 260px; margin-top: 8px; resize: vertical; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; }
.toast {
  position: fixed;
  z-index: 100;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  max-width: min(420px, calc(100% - 32px));
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--bordeaux);
  border-radius: 13px;
  background: var(--beige);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.menu-backdrop { display: none; }

/* Mobile navigation: JS controls .open, backdrop, Escape and focus trap.
   Closed drawer visibility also removes its controls from keyboard traversal. */
@media (max-width: 800px) {
  .mobile-only { display: inline-flex; }
  .auth-shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
    width: min(600px, 100%);
    padding: 28px 24px 40px;
  }
  .auth-story { text-align: center; padding: 0; }
  .auth-logo { margin-bottom: 20px; }
  .auth-logo img { width: 150px; margin: 0 auto; }
  .auth-story-copy { margin: 0 auto; }
  .auth-story-copy h1 { margin-bottom: 12px; font-size: 34px; }
  .auth-story-copy p:not(.eyebrow) { margin: 0 auto; font-size: 15px; }
  .auth-card { padding: 28px; }
  .auth-card .brand-mark { margin-bottom: 24px; }
  .chat-shell { width: 100%; }
  .sidebar {
    position: fixed;
    z-index: 40;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-width), calc(100vw - 32px));
    height: 100vh;
    height: 100dvh;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-100%);
    transition: transform 200ms ease, visibility 200ms;
    box-shadow: 12px 0 40px rgb(51 48 45 / 12%);
  }
  .sidebar.open { visibility: visible; pointer-events: auto; transform: translateX(0); }
  .menu-backdrop {
    display: block;
    position: fixed;
    z-index: 30;
    inset: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: rgb(51 48 45 / 40%);
    touch-action: none;
  }
  body:has(.sidebar.open) { overflow: hidden; }
  .main { width: 100%; }
  .topbar { gap: 12px; min-height: 76px; padding: 12px 18px; padding-top: max(12px, env(safe-area-inset-top)); }
  .topbar-title strong { font-size: 23px; }
  .topbar-title span { font-size: 11px; }
  .topbar-badge { display: none; }
  .messages { padding: 24px 18px; }
  .welcome { margin-top: 30px; }
  .welcome h2 { font-size: 32px; }
  .welcome > .muted { font-size: 15px; }
  .message { gap: 9px; margin-bottom: 20px; }
  .bubble { padding: 13px 15px; }
  .message.user { padding-left: 32px; }
  .user .bubble { max-width: 90%; }
  .attachments, .composer-status, .composer { width: calc(100% - 28px); }
  .composer { padding: 10px; border-radius: 17px; }
  .composer-footer { gap: 8px; }
  .composer textarea { max-height: min(150px, 22dvh); }
  .disclaimer { padding-right: 18px; padding-left: 18px; }
  .toast { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
  .auth-shell { padding: 22px 18px 32px; gap: 24px; }
  .auth-logo img { width: 128px; }
  .auth-story-copy h1 { font-size: 30px; }
  .auth-card { padding: 24px 20px; border-radius: 20px; }
  .auth-card h2 { font-size: 29px; }
  .topbar { gap: 9px; padding-right: 14px; padding-left: 10px; }
  .topbar-title strong { font-size: 22px; }
  .messages { padding: 22px 14px; }
  .welcome { margin-top: 22px; }
  .welcome-mark { width: 54px; height: 54px; margin-bottom: 20px; font-size: 25px; }
  .welcome h2 { font-size: 29px; }
  .suggestions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 22px; }
  .suggestions button { width: 100%; text-align: center; }
  .message-avatar, .message.assistant:not(:has(.message-avatar))::before {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    font-size: 16px;
  }
  .message { gap: 8px; }
  .bubble { padding: 12px 13px; border-radius: 15px; }
  .message.user { padding-left: 22px; }
  .user .bubble { max-width: 95%; }
  .composer-tools { gap: 5px; }
  .composer-btn { width: 44px; padding: 10px; }
  /* Keep semantic tool labels available to accessibility APIs on narrow screens. */
  .tool-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
  .attachment { flex-wrap: wrap; gap: 4px; }
  .attachment-label { max-width: 22ch; }
  .image-dialog { padding: 22px 20px; }
  .dialog-header h2 { font-size: 27px; }
  .dialog-actions > button { flex: 1 1 auto; }
}

@media (max-height: 600px) and (min-width: 801px) {
  .sidebar { padding-top: 14px; }
  .new-chat { margin-top: 12px; margin-bottom: 16px; }
  .topbar { min-height: 68px; padding-top: 12px; padding-bottom: 12px; }
  .welcome { margin-top: 12px; }
  .composer textarea { min-height: 48px; max-height: 100px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .loading-dots span { opacity: .7; }
}

@media (forced-colors: active) {
  :where(button, a, input, textarea, [tabindex]):focus-visible { outline: 3px solid Highlight; }
  .area-tab.active, .area-tab[aria-selected="true"], .composer-btn.recording { border: 2px solid Highlight; }
  .area-tab.active .area-label, .area-tab[aria-selected="true"] .area-label { text-decoration-color: currentColor; }
  .auth-tabs button.active::after, .auth-tabs button[aria-selected="true"]::after { background: Highlight; }
  .loading-dots span { background: CanvasText; }
}

/* Integration: icon display must not override desktop-only visibility. */
@media (min-width: 801px) {
  .icon-btn.mobile-only { display: none; }
}
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.auth-footnote { margin: 22px 0 0; font-size: 13px; line-height: 1.6; }

/* Mobile navigation feedback and safe formatted assistant text. */
.area-tab { gap: 0; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.sidebar .side-scroll { -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.navigation-status { flex: 0 0 auto; margin: 0 0 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--cream); font-size: 13px; line-height: 1.5; }
.toast { pointer-events: none; }
.assistant .message-content { white-space: normal; overflow-wrap: anywhere; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content p { margin: 0 0 .9em; line-height: 1.65; }
.message-content strong { font-weight: 700; }
.message-content ul, .message-content ol { margin: .6em 0 1em; padding-left: 1.35em; }
.message-content li { margin: .35em 0; padding-left: .15em; }
.message-content li p { margin-bottom: .4em; }
.message-content blockquote { border-left: 3px solid var(--bordeaux); margin: .8em 0; padding: .15em 0 .15em 1em; color: var(--muted); }
.message-content h1, .message-content h2, .message-content h3, .message-content h4 { font-family: var(--heading-font); font-size: 24px; line-height: 1.3; margin: 1em 0 .5em; }
.message-content a { color: var(--bordeaux); text-decoration: underline; text-underline-offset: 3px; }
.message-content pre { white-space: pre; overflow-x: auto; max-width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--cream); }
.message-content code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
.message-content :not(pre) > code { background: var(--cream); border-radius: 4px; padding: 1px 4px; }
.markdown-table { max-width: 100%; overflow-x: auto; margin: 1em 0; }
.markdown-table table { border-collapse: collapse; font-size: .95em; }
.markdown-table th, .markdown-table td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.markdown-table th { background: var(--cream); }
@media (max-width: 800px) {
  .sidebar { will-change: transform; }
  .message-content h1, .message-content h2, .message-content h3, .message-content h4 { font-size: 22px; }
}

/* PDF export: explicit review before creating a private document. */
.pdf-toolbar-btn { flex: 0 0 auto; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: var(--cream); color: var(--bordeaux); font-size: 14px; font-weight: 600; }
.pdf-toolbar-btn:hover { background: var(--beige); }
.message-actions { margin-top: 12px; }
.message-pdf-btn { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--bordeaux); background: var(--cream); font-size: 13px; }
.pdf-dialog { width: min(760px, calc(100% - 32px)); max-height: calc(100dvh - 32px); padding: 28px; border: 1px solid var(--line); border-radius: 24px; color: var(--ink); background: var(--cream); box-shadow: var(--shadow); overflow-y: auto; }
.pdf-dialog::backdrop { background: rgb(51 48 45 / 42%); }
.pdf-dialog .dialog-header h2 { margin: 0; font-size: 32px; }
#pdfForm { display: grid; gap: 20px; }
.pdf-meta { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: 16px; }
.pdf-meta select { display: block; width: 100%; margin-top: 7px; min-height: 48px; padding: 11px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: var(--cream); font: inherit; }
.pdf-meta input { margin-top: 7px; }
#pdfContent { display: block; margin-top: 7px; min-height: 190px; max-height: 380px; resize: vertical; line-height: 1.6; }
#pdfForm details { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--beige); }
#pdfForm summary { cursor: pointer; min-height: 30px; font-size: 14px; font-weight: 600; }
.pdf-selection { display: grid; max-height: 220px; overflow-y: auto; gap: 10px; margin-top: 14px; }
.pdf-source, .pdf-checkbox { display: flex; align-items: flex-start; gap: 12px; }
#pdfForm input[type="checkbox"] { width: 20px; height: 20px; min-height: 20px; flex: 0 0 20px; padding: 0; margin-top: 3px; accent-color: var(--bordeaux); }
.pdf-source span { min-width: 0; }
.pdf-source small, .pdf-checkbox small { display: block; color: var(--muted); line-height: 1.5; font-size: 13px; font-weight: 400; overflow-wrap: anywhere; }
.pdf-source strong { font-size: 13px; }
.pdf-source-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.pdf-help { font-size: 13px; color: var(--muted); margin: 12px 0 0; line-height: 1.5; }
.pdf-preview-box h3 { font-size: 25px; margin: 18px 0 12px; }
.pdf-status { margin: 0; color: var(--bordeaux); font-size: 14px; line-height: 1.5; }
.pdf-status:empty, .pdf-result:empty { display: none; }
.pdf-download { display: inline-flex; text-decoration: none; align-items: center; min-height: 48px; }
@media (max-width: 800px) { .pdf-toolbar-btn { max-width: 88px; padding: 8px 10px; font-size: 12px; line-height: 1.3; } .pdf-dialog { padding: 22px 18px; } .pdf-dialog .dialog-header h2 { font-size: 26px; } .pdf-meta { grid-template-columns: minmax(0, 1fr); } .pdf-source-actions > button { width: 100%; } .pdf-dialog .dialog-actions > button { width: 100%; } }
