/* OraNexus P1-M7 chat UI presentation - UI design revision 12.
   Presentation only: no behavior or data is defined here. */

:root {
  color-scheme: light;
  --surface: #ffffff;
  --surface-subtle: #f5f8fc;
  --text-primary: #18283e;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --selected-bg: #eaf3fa;
  --brand-deep: #0b2e63;
  --action: #1677d2;
  --action-hover: #0f62b3;
  --brand-cyan: #28c9d5;
  --on-brand: #ffffff;
  --disabled-bg: #e2e8f0;
  --disabled-text: #64748b;
  --warning-text: #75603b;
  --warning-bg: #faf8f3;
  --warning-border: #b5a17c;
  --danger: #ad3c42;
  --danger-hover: #8f3036;
  --danger-bg: #fdf0f0;
  --danger-border: #e6c2c4;
  --success: #18724a;
  --success-bg: #edf8f1;
  --sidebar-bg: #f8f8f8;
  --sidebar-text: #303030;
  --sidebar-muted: #6a6a6a;
  --sidebar-selected: #eaeaea;
  --sidebar-border: #e5e5e5;
  --heading-text: var(--brand-deep);
  --interactive-text: var(--action);
  --interactive-text-on-tint: var(--action-hover);
  --focus-ring: var(--action);
  --shadow-rgb: 11 46 99;
  --backdrop: rgb(0 0 0 / 0.25);
  --shadow: 0 10px 30px rgb(var(--shadow-rgb) / 0.08);
  --radius: 16px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --auth-heading-size: 22px;
  --app-header-height: 64px;
  --product-ink: #0b2e63;
  --product-accent: #0863b9;
  --sidebar-motion-duration: 220ms;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #212121;
  --surface-subtle: #292929;
  --text-primary: #eceff3;
  --text-secondary: #adb5c0;
  --border: #42464e;
  --selected-bg: #29394b;
  --brand-deep: #e0ebfa;
  --action: #1677d2;
  --action-hover: #0f62b3;
  --on-brand: #ffffff;
  --disabled-bg: #383b40;
  --disabled-text: #a5abb5;
  --warning-text: #e7c78b;
  --warning-bg: #342d22;
  --warning-border: #8b734a;
  --danger: #ffaaaa;
  --danger-hover: #ffc5c5;
  --danger-bg: #41292d;
  --danger-border: #99616b;
  --success: #99dcb5;
  --success-bg: #22382d;
  --sidebar-bg: #171717;
  --sidebar-text: #e8e8e8;
  --sidebar-muted: #a8a8a8;
  --sidebar-selected: #303030;
  --sidebar-border: #343434;
  --heading-text: #e0ebfa;
  --interactive-text: #8ac2ff;
  --interactive-text-on-tint: #acd3ff;
  --focus-ring: #8ac2ff;
  --shadow-rgb: 0 0 0;
  --backdrop: rgb(0 0 0 / 0.6);
  --product-ink: #c2dbff;
  --product-accent: #91c5ff;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  background: var(--surface);
  color: var(--text-primary);
  line-height: 1.6;
  font-synthesis: none;
}

body.chat-view {
  padding-left: 254px;
}

body.sidebar-collapsed {
  padding-left: 0;
}

[hidden] {
  display: none !important;
}

img {
  max-width: 100%;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
  color: inherit;
}

button:disabled {
  cursor: default;
  opacity: 1;
  background: var(--disabled-bg);
  border-color: var(--disabled-bg);
  color: var(--disabled-text);
}

a {
  color: var(--interactive-text);
}

h1,
h2,
h3,
p {
  margin: 0;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 4px;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -80px;
  z-index: 60;
  padding: 9px 14px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 13px;
}

.skip-link:focus {
  top: 12px;
}

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

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 10px;
}

.overline {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 0 0 8px;
}

.status {
  margin: 0.5rem 0 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.status.error {
  color: var(--danger);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.4rem, 3vw, 2rem);
}

/* ------------------------------------------------------------- topbar */

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 26px;
  background: var(--surface);
}

.logo {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  overflow: hidden;
}

.logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: transparent;
}

.wordmark {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.6px;
  color: var(--heading-text);
  white-space: nowrap;
}

/* Shared two-colour product wordmark; scoped to the marked brand labels. */
.product-wordmark {
  display: inline;
  max-width: 100%;
  white-space: nowrap;
}

.product-wordmark-name,
.product-wordmark-one {
  white-space: nowrap;
}

.product-wordmark-name {
  color: var(--product-ink);
}

.product-wordmark-one {
  color: var(--product-accent);
  font-kerning: normal;
  letter-spacing: 0;
}

.brand-tagline {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-left: 5px;
  line-height: 1.4;
}

.brand-english {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.brand-chinese {
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.env {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-secondary);
}

.env i {
  display: inline-block;
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning-text);
}

.side-open {
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 19px;
  padding: 5px 8px;
  border-radius: 8px;
}

.side-open:hover {
  background: var(--selected-bg);
}

.sidebar-collapsed .side-open {
  display: inline-flex;
}

/* ------------------------------------------------------------ sidebar */

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 254px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: 14px 10px 10px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  overflow: hidden;
}

body.auth-view {
  padding-left: 0;
}

body.auth-view .sidebar,
body.auth-view .side-open,
body.auth-view .sidebar-scrim {
  display: none !important;
}

body.sidebar-collapsed .sidebar {
  display: none;
}

.side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 8px 18px;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.side-brand .logo {
  width: 28px;
  height: 28px;
}

.side-brand .wordmark {
  font-size: 17px;
  letter-spacing: -0.5px;
  color: var(--sidebar-text);
}

.icon-btn {
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--sidebar-muted);
  font-size: 17px;
}

.icon-btn:hover {
  background: var(--sidebar-selected);
}

.side-new {
  border: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 9px;
  text-align: left;
  margin: 0 8px;
  padding: 10px 12px;
  background: var(--sidebar-selected);
  font-size: 14px;
  color: var(--sidebar-text);
}

.side-new:hover {
  filter: brightness(.98);
}

.new-chat-icon {
  width: 16px;
  height: 16px;
  flex: none;
}

.side-scroll {
  flex: 1;
  overflow: auto;
  padding-top: 8px;
  scrollbar-width: thin;
}

.side-label {
  font-size: 12px;
  color: var(--sidebar-muted);
  margin: 14px 12px 7px;
}

.current-topic {
  margin: 0 10px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--sidebar-selected);
  color: var(--sidebar-text);
  font-size: 12px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.current-topic.is-empty {
  background: transparent;
  color: var(--sidebar-muted);
  padding: 8px 12px;
}

.history-subsection {
  margin-top: 20px;
  margin-bottom: 7px;
  font-size: 12px;
  letter-spacing: .01em;
}

/* The active topic keeps its action menu for an opened conversation, but does
   not occupy sidebar space while the welcome screen has no topic yet. */
#topic-section-label[hidden],
#topic-row[hidden] {
  display: none !important;
}

.sidebar-note {
  font-size: 11px;
  color: var(--sidebar-muted);
  margin: 12px;
  line-height: 1.75;
}

.topic-row {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 10px;
  border-radius: 9px;
}

.topic-row.has-topic {
  background: var(--sidebar-selected);
}

.topic-row .current-topic {
  flex: 1;
  min-width: 0;
  margin: 0;
  background: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-more {
  flex: none;
  width: 28px;
  height: 28px;
  margin-right: 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--sidebar-muted);
  font-size: 17px;
}

.topic-more:hover,
.topic-more[aria-expanded="true"] {
  background: var(--sidebar-bg);
}

.topic-menu {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  z-index: 25;
  width: 180px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 8px 30px rgb(var(--shadow-rgb) / 0.12);
}

.topic-menu button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
  font-size: 13px;
}

.topic-menu button:hover {
  background: var(--selected-bg);
}

.topic-action-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text-primary);
}

.topic-action-dialog::backdrop {
  background: var(--backdrop);
}

.topic-action-dialog h2 {
  margin-bottom: 10px;
  font-size: 20px;
  font-weight: 500;
}

.topic-action-dialog > p {
  margin-bottom: 18px;
  font-size: 13px;
  color: var(--text-secondary);
}

.topic-action-dialog label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
}

.topic-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 20px;
  margin-top: 22px;
}

.topic-toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 24px);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow);
  font-size: 12px;
}

.side-account {
  position: relative;
  border-top: 1px solid var(--sidebar-border);
  margin-top: 10px;
  padding-top: 8px;
  display: block;
}

.account-button {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--sidebar-text);
  padding: 9px;
  border-radius: 10px;
  text-align: left;
}

.account-button:hover,
.account-button[aria-expanded="true"] {
  background: var(--sidebar-selected);
}

.account-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sidebar-selected);
  color: var(--sidebar-text);
  font-size: 13px;
}

.account-lines {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
}

.account-lines strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 500;
}

.account-lines small {
  font-size: 10px;
  color: var(--sidebar-muted);
}

.account-more {
  margin-left: auto;
  color: var(--sidebar-muted);
}

.account-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 8px 30px rgb(var(--shadow-rgb) / 0.12);
}

.account-menu button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: transparent;
  padding: 10px 12px;
  text-align: left;
  font-size: 13px;
}

.account-menu button:hover,
.account-menu button:focus-visible {
  background: var(--selected-bg);
}

.account-menu hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 5px 6px;
}

.side-action {
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 8px;
  text-align: left;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--sidebar-text);
}

.side-action:hover {
  background: var(--sidebar-selected);
}

.side-action-danger {
  color: var(--danger);
}

.sidebar-scrim {
  display: none;
}

/* --------------------------------------------------------------- auth */

.auth {
  min-height: calc(100vh - 64px);
  min-height: calc(100dvh - 64px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 36px 24px 70px;
  background: var(--surface);
}

.auth-area {
  width: min(360px, 100%);
}

.auth-messages {
  width: 100%;
}

.auth-messages .status {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.7;
}

.auth-messages .status.error {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.panel h2,
.auth-headline {
  font-size: var(--auth-heading-size);
  line-height: 1.35;
  font-weight: 500;
  letter-spacing: -0.7px;
  color: var(--heading-text);
  text-align: center;
}

.auth-headline {
  margin: 0 0 10px;
}

.panel h2 {
  margin: 0 0 10px;
}

.panel-sub {
  color: var(--text-secondary);
  margin: 0 0 35px;
  font-size: 13px;
  line-height: 1.8;
  text-align: center;
}

.auth-panel {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.auth-panel label {
  display: block;
  margin: 18px 0 7px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}

.auth-panel input:not(.otp) {
  padding: 13px 14px;
  font-size: 14px;
  line-height: 1.5;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 7px;
}

.field-head label {
  margin: 0;
}

input,
textarea {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-secondary);
  opacity: 1;
}

input:focus,
textarea:focus {
  border-color: var(--focus-ring);
}

input.otp {
  text-align: center;
  letter-spacing: 0.55em;
  font-family: var(--mono);
  font-size: 1.15rem;
  padding-left: 0.95em;
}

.panel-hint {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.8;
  margin: 10px 0 0;
  overflow-wrap: anywhere;
}

.panel-link-row {
  margin: 12px 0 0;
  text-align: right;
}

.panel-foot {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.8;
}

.auth-foot {
  width: 100%;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.8;
  text-align: center;
  margin: 28px 0 0;
}

.login-restriction {
  width: 100%;
  margin: 34px 0 0;
  padding-top: 21px;
  border-top: 1px solid var(--border);
  color: var(--warning-text);
  font-size: 11px;
  line-height: 1.8;
}

.login-restriction strong {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
}

.primary {
  display: block;
  width: auto;
  margin: 0;
  padding: 12px 20px;
  border: 1px solid var(--action);
  border-radius: 22px;
  background: var(--action);
  color: var(--on-brand);
  font-size: 13px;
  font-weight: 600;
}

.primary:hover:not(:disabled) {
  background: var(--action-hover);
  border-color: var(--action-hover);
}

.auth-panel .primary {
  width: 100%;
  margin-top: 26px;
  padding: 13px 20px;
}

.primary.inline {
  display: inline-block;
  width: auto;
  margin: 0;
  flex: none;
}

.link {
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--interactive-text);
  text-decoration: none;
  font-size: 13px;
}

.link:hover {
  text-decoration: underline;
}

.link:disabled {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
  opacity: 0.65;
}

/* --------------------------------------------------------- chat layout */

.workspace {
  display: flex;
  flex-direction: column;
  max-width: 1320px;
  min-height: calc(100vh - 64px);
  min-height: calc(100dvh - 64px);
  margin: 0 auto;
  padding: 12px 34px 0;
}

.page-head {
  display: none;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto 18px;
}

.workspace.is-welcome .page-head {
  display: block;
  order: 1;
  text-align: center;
  margin: auto auto 18px;
}

.page-head h1 {
  font-size: 27px;
  line-height: 1.4;
  font-weight: 500;
  letter-spacing: -0.7px;
  color: var(--heading-text);
  margin: 0 0 9px;
}

.workspace.is-welcome .page-head h1 {
  font-size: 32px;
  letter-spacing: -1px;
  margin-bottom: 12px;
}

.page-head .eyebrow {
  display: none;
}

.chat-sub {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.8;
  margin: 0;
}

.workspace.is-welcome .chat-sub {
  font-size: 14px;
}

.notice {
  order: 0;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto 28px;
  padding: 11px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 12px;
  line-height: 1.8;
}

.notice strong {
  font-weight: 600;
}

.notice-icon {
  width: 18px;
  height: 18px;
  flex: none;
  display: grid;
  place-items: center;
  margin-top: 2px;
  border: 1px solid var(--warning-border);
  border-radius: 50%;
  color: var(--warning-text);
  font-size: 12px;
}

.work-grid {
  order: 2;
  flex: 1;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.workspace.panel-open .work-grid {
  grid-template-columns: minmax(0, 1fr) 340px;
}

.workspace.is-welcome .work-grid {
  flex: 0;
  margin-bottom: auto;
}

.thread {
  width: 100%;
  max-width: 1080px;
  min-height: calc(100vh - 240px);
  min-height: calc(100dvh - 240px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.workspace.is-welcome .thread {
  max-width: 800px;
  min-height: 0;
}

.dialogue {
  padding: 6px 0 4px;
  animation: dialogue-in 0.16s ease-out;
}

.workspace.is-welcome .dialogue {
  display: none;
}

@keyframes dialogue-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.question-row {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 10px;
  margin: 0 0 34px;
}

.question-bubble {
  max-width: 82%;
  margin: 0;
  padding: 13px 20px;
  border: 0;
  border-radius: 22px;
  background: var(--selected-bg);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.avatar {
  width: 28px;
  height: 28px;
  flex: none;
  display: none;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 11px;
}

.answer-header {
  display: flex;
  align-items: center;
  gap: 11px;
  flex-wrap: wrap;
  margin: 0 0 18px;
}

.answer-logo {
  width: 26px;
  height: 26px;
}

.answer-header strong {
  font-size: 14px;
  font-weight: 500;
}

.status-label {
  display: inline-block;
  max-width: 100%;
  padding: 3px 7px;
  border: 1px solid var(--warning-border);
  border-radius: 5px;
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------- answer */

.answer {
  margin: 0;
}

.answer.is-insufficient {
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-subtle);
}

.answer-title {
  font-size: 22px;
  line-height: 1.5;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--text-primary);
  margin: 0 0 10px;
}

.answer-body {
  font-size: 15px;
  line-height: 1.95;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.answer-body p {
  margin: 10px 0;
  white-space: pre-wrap;
}

.answer-body p:first-child {
  margin-top: 0;
}

.answer-body h3,
.answer-body h4,
.answer-body h5 {
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: -0.2px;
  line-height: 1.6;
  margin: 20px 0 8px;
}

.answer-body h3 {
  font-size: 17px;
}

.answer-body h4 {
  font-size: 16px;
}

.answer-body h5 {
  font-size: 15px;
}

.answer-body ul,
.answer-body ol {
  margin: 10px 0;
  padding-left: 1.5em;
}

.answer-body li {
  margin: 5px 0;
  padding-left: 2px;
  white-space: pre-wrap;
}

.answer-body strong {
  font-weight: 600;
}

.badge {
  display: inline-block;
  max-width: 100%;
  margin-top: 12px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--selected-bg);
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------- citations */

.source-summary {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.source-summary > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

.source-summary > summary::-webkit-details-marker {
  display: none;
}

.source-summary > summary::before {
  content: "›";
  display: inline-block;
  color: var(--text-secondary);
  transition: transform 0.15s ease;
}

.source-summary[open] > summary::before {
  transform: rotate(90deg);
}

.citations {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.citation-group-label {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.6;
}

.citation {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-subtle);
  color: var(--text-primary);
  font-size: 12px;
  text-align: left;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.citation:hover {
  border-color: var(--action);
  background: var(--selected-bg);
  color: var(--interactive-text-on-tint);
}

.citation-index {
  flex: none;
  color: var(--interactive-text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.citation-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.citation-title {
  font-size: 12px;
  line-height: 1.6;
}

.citation-sub {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.6;
}

.citation-open {
  flex: none;
  margin-left: auto;
  color: var(--text-secondary);
  font-size: 11px;
}

.hint {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.8;
  margin: 10px 0 0;
}

.citations .hint {
  margin: 0;
}

/* -------------------------------------------------------- loading/error */

.loading {
  margin: 0;
}

.state-card {
  padding: 12px 0 32px;
}

.loading-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 500;
  margin: 0;
}

.loading-sub {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.8;
  margin: 8px 0 18px;
}

.loading-dots {
  display: flex;
  gap: 7px;
  margin: 0 0 18px;
}

.loading-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--action);
  animation: m7pulse 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

.loading-bar {
  width: min(30rem, 82%);
  height: 6px;
  margin: 0;
  border-radius: 999px;
  background: var(--surface-subtle);
  animation: m7fade 1.4s ease-in-out infinite;
}

@keyframes m7pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

@keyframes m7fade {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

.error-card {
  margin: 0;
  padding: 12px 0 32px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-primary);
}

.error-card .overline {
  color: var(--danger);
}

.error-title {
  font-size: 19px;
  font-weight: 500;
  line-height: 1.6;
  margin: 0 0 8px;
  color: var(--danger);
}

.chat-error-text {
  margin: 0;
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.85;
}

.chat-retry {
  display: inline-block;
  margin-top: 14px;
}

.chat-disclaimer {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.7;
  text-align: center;
  margin: 12px 0 18px;
}

/* ------------------------------------------------------------ composer */

.composer {
  position: sticky;
  bottom: 0;
  z-index: 3;
  flex-shrink: 0;
  margin-top: auto;
  padding: 24px 0 14px;
  background: var(--surface);
}

.workspace.is-welcome .composer {
  position: relative;
  margin-top: 0;
  padding-top: 8px;
  background: transparent;
}

.composer-box {
  padding: 15px 19px 12px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: none;
}

.workspace.is-welcome .composer-box {
  box-shadow: 0 3px 20px rgb(var(--shadow-rgb) / 0.0118);
}

.composer-box:focus-within {
  border-color: var(--focus-ring);
}

#chat-question {
  display: block;
  width: 100%;
  height: calc(3.6em + 4px);
  min-height: calc(3.6em + 4px);
  max-height: calc(3.6em + 4px);
  padding: 2px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.8;
  resize: none;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}

#chat-question:focus,
#chat-question:focus-visible {
  outline: none;
}

.composer-caret-probe {
  position: fixed;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  border: 0;
  margin: 0;
}

.composer-bottom {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 3px;
}


.composer-send {
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  flex: none;
}

.composer-send:disabled {
  width: 36px;
  min-width: 36px;
  padding: 4px;
  border-radius: 50%;
  font-size: 10px;
  line-height: 1.1;
}

.composer-send {
  font-size: 0;
  line-height: 0;
}

.composer-send svg {
  display: block;
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.welcome-prompts {
  display: none;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 10px auto 0;
}

.workspace.is-welcome .welcome-prompts {
  display: flex;
}

.welcome-prompts button {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
}

.welcome-prompts button:hover {
  background: var(--selected-bg);
  color: var(--interactive-text-on-tint);
}

.keyboard-note {
  color: var(--text-secondary);
  font-size: 11px;
  text-align: center;
  margin: 9px 0 0;
}

/* ------------------------------------------------------ source details */

.details-panel {
  position: sticky;
  top: 20px;
  min-width: 0;
  max-height: calc(100vh - 40px);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  overflow: auto;
}

.details-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.details-top h2 {
  font-size: 16px;
  font-weight: 500;
  margin: 0;
}

.close {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 7px;
  background: var(--surface-subtle);
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 1;
}

.close:hover {
  background: var(--selected-bg);
}

.source-category {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.7;
  margin: 16px 0 8px;
}

#citation-metadata dl {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 12px 14px;
  margin: 18px 0;
  font-size: 12px;
}

#citation-metadata dt {
  color: var(--text-secondary);
  font-weight: 400;
}

#citation-metadata dd {
  margin: 0;
  font-size: 12px;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

#citation-metadata .group-title {
  grid-column: 1 / -1;
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 12px;
}

#citation-metadata .group-title:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.passage-note {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.8;
  margin: 16px 0 0;
}

.details-scrim {
  position: fixed;
  inset: 0;
  z-index: 29;
  background: var(--backdrop);
}

/* ------------------------------------------------------ session/dialog */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--backdrop);
}

.modal {
  width: min(400px, 100%);
  padding: 26px;
}

.modal h2 {
  font-size: 20px;
  font-weight: 500;
  margin: 0 0 8px;
}

.modal .panel-sub {
  text-align: left;
  margin-bottom: 18px;
}

.modal .primary {
  width: 100%;
}

.modal .panel-hint {
  margin-top: 12px;
}

.settings-dialog {
  width: min(650px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 20px 90px rgb(var(--shadow-rgb) / 0.14);
  overflow: auto;
}

.settings-dialog::backdrop {
  background: var(--backdrop);
}

.settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.settings-heading h2 {
  font-size: 18px;
  font-weight: 500;
  margin: 0;
}

.settings-heading .icon-btn {
  color: var(--text-secondary);
}

.settings-heading .icon-btn:hover {
  background: var(--selected-bg);
}

.settings-content {
  padding: 20px 24px 24px;
}

.settings-nav {
  padding: 15px 10px;
  background: var(--surface-subtle);
}

.settings-layout {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  min-height: 280px;
}

.settings-nav button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 12px;
  margin-bottom: 4px;
  text-align: left;
  font-size: 12px;
}

.settings-nav button[aria-pressed="true"] {
  color: var(--interactive-text-on-tint);
  background: var(--selected-bg);
}

#account-email {
  overflow-wrap: anywhere;
  min-width: 0;
  text-align: right;
}

.settings-content h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.setting-row small {
  display: block;
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.7;
}

.setting-row select {
  min-width: 120px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 12px;
}

.settings-foot {
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.8;
  margin: 16px 0 0;
}

/* --------------------------------------------------------- large text */

.large-reading .answer-body {
  font-size: 17px;
  line-height: 2;
}

.large-reading .answer-title {
  font-size: 24px;
}

.large-reading .question-bubble {
  font-size: 16px;
}

/* --------------------------------------------------------- responsive */

@media (max-width: 1050px) {
  body.chat-view {
    padding-left: 228px;
  }

  /* Keep the collapsed state authoritative at this breakpoint; otherwise the
     later 228px rule above reintroduces a gutter after the sidebar is hidden. */
  body.chat-view.sidebar-collapsed {
    padding-left: 0;
  }

  .sidebar {
    width: 228px;
  }

  .workspace {
    padding: 12px 22px 0;
  }

  .workspace.panel-open .work-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .details-panel {
    position: fixed;
    top: 110px;
    right: 18px;
    bottom: auto;
    z-index: 30;
    width: 310px;
    max-height: 75vh;
    overflow: auto;
    box-shadow: 0 12px 60px rgb(var(--shadow-rgb) / 0.14);
  }
}

@media (max-width: 860px) {
  .auth {
    padding-top: 34px;
  }

  .brand-tagline {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --app-header-height: 59px;
  }
  body.chat-view,
  body.sidebar-collapsed {
    padding-left: 0;
  }

  .topbar {
    height: 59px;
    padding: 0 18px;
  }

  .wordmark {
    font-size: 19px;
  }

  .side-open {
    display: inline-flex;
  }

  .sidebar {
    width: 270px;
    display: flex;
    box-shadow: 0 0 50px rgb(var(--shadow-rgb) / 0.2);
  }

  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 19;
    background: var(--backdrop);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--sidebar-motion-duration) ease,
                visibility 0s linear var(--sidebar-motion-duration);
  }

  .sidebar-scrim.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity var(--sidebar-motion-duration) ease,
                visibility 0s linear 0s;
  }

  body.chat-view.sidebar-mobile-open {
    overflow: hidden;
  }

  .workspace {
    min-height: calc(100vh - 59px);
    min-height: calc(100dvh - 59px);
    padding: 24px 18px 0;
  }

  .workspace.is-welcome .page-head h1 {
    font-size: 26px;
  }

  .workspace.is-welcome .chat-sub {
    font-size: 12px;
  }

  .notice {
    padding: 10px 12px;
    margin-bottom: 24px;
    font-size: 11px;
  }

  .thread {
    min-height: calc(100vh - 270px);
    min-height: calc(100dvh - 270px);
  }

  .question-bubble {
    max-width: 88%;
    font-size: 13px;
  }

  .answer-title {
    font-size: 20px;
  }

  .answer-body {
    font-size: 14px;
  }

  .composer {
    padding-top: 10px;
  }

  .composer-box {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 8px;
    padding: 7px 8px 7px 14px;
    border-radius: 22px;
  }

  #chat-question {
    grid-column: 1;
    grid-row: 1;
    height: auto;
    min-height: calc(1.55em + 4px);
    max-height: calc(1.55em * 5 + 4px);
    font-size: 16px;
    line-height: 1.55;
    overflow-y: hidden;
  }

  .composer-bottom {
    grid-column: 2;
    grid-row: 1;
    justify-content: flex-end;
    gap: 0;
    margin-top: 0;
  }

  .details-panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 82vh;
    border-radius: 20px 20px 0 0;
    z-index: 31;
  }

  .details-scrim {
    z-index: 30;
  }

  .auth {
    min-height: calc(100vh - 59px);
    min-height: calc(100dvh - 59px);
    padding: 40px 25px 60px;
  }

  .panel h2,
  .auth-headline {
    font-size: var(--auth-heading-size);
  }

  .settings-heading {
    padding: 18px;
  }

  .settings-content {
    padding: 18px;
  }

  .settings-layout {
    grid-template-columns: 100px minmax(0, 1fr);
  }

  .settings-nav {
    padding: 12px 6px;
  }

  .settings-nav button {
    padding: 9px;
    font-size: 11px;
  }

  .setting-row {
    gap: 12px;
  }

  .welcome-prompts {
    gap: 7px;
  }

  .welcome-prompts button {
    padding: 8px 11px;
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  .env {
    display: none;
  }

  .workspace {
    padding-top: 18px;
  }

  .page-head h1,
  .workspace.is-welcome .page-head h1 {
    font-size: 23px;
  }

  #citation-metadata dl {
    grid-template-columns: minmax(0, 1fr);
  }

  #citation-metadata dd {
    padding-bottom: 8px;
  }

  .settings-dialog {
    width: calc(100vw - 20px);
  }

  .composer-send {
    width: 34px;
    height: 34px;
    min-width: 34px;
  }
}

/* Dock the active conversation to the viewport. Only the answer scrolls;
   growing input text consumes space upward instead of moving the footer. */
.workspace:not(.is-welcome) {
  height: calc(100vh - var(--app-header-height));
  height: calc(100dvh - var(--app-header-height));
  min-height: 0;
}

.workspace:not(.is-welcome) > .notice {
  flex-shrink: 0;
  margin-bottom: 16px;
}

.workspace:not(.is-welcome) .work-grid {
  min-height: 0;
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
}

.workspace:not(.is-welcome) .thread {
  height: 100%;
  min-height: 0;
  min-width: 0;
}

.workspace:not(.is-welcome) .dialogue {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}

.workspace:not(.is-welcome) .composer {
  position: relative;
  bottom: auto;
  margin-top: 0;
  padding: 12px 0 4px;
  flex: none;
}

.workspace:not(.is-welcome) .chat-disclaimer {
  flex: none;
  margin: 4px 0 calc(8px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 1051px) {
  .workspace:not(.is-welcome) .details-panel {
    max-height: calc(100% - 20px);
  }
}

/* Full-width native scroll viewport, independent from the reading column. */
.workspace {
  max-width: none;
  padding-inline: 0;
}

.workspace > .notice,
.workspace > .page-head {
  width: calc(100% - 68px);
}

.workspace:not(.is-welcome) .thread {
  max-width: none;
}

.workspace:not(.is-welcome) .dialogue {
  padding: 6px 26px 4px 34px;
  scrollbar-gutter: stable;
  scrollbar-color: transparent transparent;
  transition: scrollbar-color 240ms ease;
  scroll-behavior: auto;
}

.dialogue-content {
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
}
.conversation-turn + .conversation-turn { margin-top: 36px; }
.turn-display-status { margin-top: 10px; }

.workspace:not(.is-welcome) .composer,
.workspace:not(.is-welcome) .chat-disclaimer {
  width: calc(100% - 68px);
  max-width: 1080px;
  margin-inline: auto;
}

.workspace.is-welcome .thread {
  width: calc(100% - 68px);
}

.dialogue::-webkit-scrollbar { width: 8px; }
.dialogue::-webkit-scrollbar-track { background: transparent; }
.dialogue::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 8px;
  background: transparent;
  background-clip: padding-box;
  transition: background-color 240ms ease;
}

.workspace .dialogue.scroll-active,
.workspace .dialogue.scroll-edge,
.workspace .dialogue.scroll-dragging,
.workspace .dialogue:focus-visible {
  scrollbar-color: var(--text-secondary) transparent;
  scrollbar-color: color-mix(in srgb, var(--text-secondary) 48%, transparent) transparent;
}

.dialogue.scroll-active::-webkit-scrollbar-thumb,
.dialogue.scroll-edge::-webkit-scrollbar-thumb,
.dialogue.scroll-dragging::-webkit-scrollbar-thumb,
.dialogue:focus-visible::-webkit-scrollbar-thumb,
.dialogue::-webkit-scrollbar-thumb:hover,
.dialogue::-webkit-scrollbar-thumb:active {
  background-color: var(--text-secondary);
  background-color: color-mix(in srgb, var(--text-secondary) 48%, transparent);
}

.answer-display-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 30px;
  padding-bottom: 5px;
}

.answer-display-controls > span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text-secondary);
  font-size: 11px;
}

.answer-display-controls .link { flex: none; font-size: 11px; }
.is-welcome .answer-display-controls { display: none; }
.answer[aria-busy="true"] { animation: none; }

@media (max-width: 760px) {
  .workspace { padding-inline: 0; }
  .workspace > .notice, .workspace > .page-head,
  .workspace.is-welcome .thread,
  .workspace:not(.is-welcome) .composer,
  .workspace:not(.is-welcome) .chat-disclaimer { width: calc(100% - 36px); }
  .workspace:not(.is-welcome) .dialogue { padding-inline: 18px 10px; }
  .answer-display-controls { gap: 8px; }
}

@media (forced-colors: active) {
  .workspace .dialogue { scrollbar-color: auto; }
}

/* Short presentation-only transitions; requests are never gated by animations. */
button,
.composer-box {
  transition: background-color 120ms ease, border-color 120ms ease,
              color 120ms ease, opacity 120ms ease, box-shadow 120ms ease;
}

button:active:not(:disabled) {
  opacity: 0.82;
}

.sidebar {
  opacity: 1;
  transform: translateX(0);
  transition: opacity 140ms ease, transform 160ms ease, display 160ms;
  transition-behavior: allow-discrete;
}

body.sidebar-collapsed .sidebar {
  opacity: 0;
  transform: translateX(-10px);
  pointer-events: none;
}

body.auth-view .sidebar {
  transition: none;
  opacity: 0;
  pointer-events: none;
}

.account-menu,
.topic-menu {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 120ms ease, transform 140ms ease, display 140ms;
  transition-behavior: allow-discrete;
}

.account-menu[hidden],
.topic-menu[hidden] {
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
}

.answer,
.loading,
.error-card,
.details-panel:not([hidden]),
.source-summary[open] > .citations,
.settings-dialog[open],
.topic-action-dialog[open] {
  animation: content-reveal 160ms ease-out;
}

.composer[aria-busy="true"] .composer-send svg {
  opacity: 0.55;
}

.composer-send svg {
  transition: opacity 120ms ease;
}

@keyframes content-reveal {
  from { opacity: 0; }
  to { opacity: 1; }
}

@starting-style {
  .sidebar { opacity: 0; transform: translateX(-10px); }
  .account-menu, .topic-menu { opacity: 0; transform: translateY(4px); }
}

@media (max-width: 760px) {
  .sidebar {
    opacity: 1;
    visibility: hidden;
    transform: translateX(-100%);
    pointer-events: none;
    transition: transform var(--sidebar-motion-duration) ease,
                visibility 0s linear var(--sidebar-motion-duration);
  }
  body.sidebar-mobile-open .sidebar {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    pointer-events: auto;
    transition: transform var(--sidebar-motion-duration) ease,
                visibility 0s linear 0s;
  }
}

@media (max-width: 760px) and (pointer: coarse) {
  #chat-question {
    font-size: 16px;
  }
}

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

  .dialogue {
    animation: none;
  }

  .source-summary > summary::before {
    transition: none;
  }

  .loading-dots span,
  .loading-bar {
    animation: none;
  }
}

/* ------------------------------------------------ candidate chat history */
.history-note {
  margin: 0 12px 8px;
  font-size: 10px;
  line-height: 1.6;
  color: var(--sidebar-muted);
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-row {
  position: relative;
  display: flex;
  align-items: center;
  margin: 0 8px;
}

.conversation-item {
  display: block;
  width: 100%;
  padding: 9px 38px 9px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  font-size: 14px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item:hover {
  background: var(--sidebar-selected);
}

.conversation-item.is-active,
.conversation-item[aria-current="true"] {
  background: var(--sidebar-selected);
  font-weight: 600;
}

.conversation-item .conversation-pin {
  display: inline-block;
  margin-right: 5px;
  color: var(--sidebar-muted);
  font-size: 10px;
  font-weight: 400;
}

.conversation-more {
  position: absolute;
  right: 5px;
  top: 50%;
  width: 26px;
  height: 26px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--sidebar-muted);
  opacity: 0;
}

.conversation-row:hover .conversation-more,
.conversation-more:focus-visible,
.conversation-more[aria-expanded="true"] {
  opacity: 1;
}

.conversation-more:hover,
.conversation-more[aria-expanded="true"] {
  background: var(--sidebar-selected);
}

.conversation-item-menu {
  position: absolute;
  z-index: 8;
  top: calc(100% - 2px);
  right: 4px;
  min-width: 104px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
}

.conversation-item-menu button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-primary);
  padding: 7px 8px;
  text-align: left;
  font-size: 12px;
}

.conversation-item-menu button:hover {
  background: var(--sidebar-selected);
}


.history-save-notice {
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--warning-border);
  border-radius: 10px;
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 12px;
  line-height: 1.65;
}

@media (max-width: 760px) {
  .conversation-item {
    padding: 10px 38px 10px 10px;
    font-size: 13px;
  }
}

/* Access views are scoped; the approved chat/composer/scroll rules stay intact. */
.access-shell { padding: 72px 24px; }
/* Shared sidebar row geometry: keep action and conversation hit areas equal. */
.side-new,
.conversation-item {
  box-sizing: border-box;
  height: 40px;
  min-height: 40px;
  max-height: 40px;
  padding-top: 0;
  padding-bottom: 0;
  font-size: 14px;
  line-height: 20px;
  flex-shrink: 0;
}
.new-chat-icon { width: 18px; height: 18px; }
.access-card { width: min(100%, 440px); margin: 0 auto; }
.access-card h1 { font-size: 28px; color: var(--text-primary); }
.access-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.owner-dialog { width: min(980px, calc(100vw - 40px)); max-height: calc(100dvh - 40px); padding: 28px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); color: var(--text-primary); overflow: auto; }
.owner-dialog::backdrop { background: rgba(0,0,0,.35); }
.owner-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.owner-heading h2 { margin: 4px 0 8px; }
.owner-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin: 22px 0; padding-bottom: 10px; }
.owner-tabs button { border: 0; background: transparent; color: var(--text-secondary); border-radius: 8px; padding: 9px 12px; }
.owner-tabs button[aria-pressed="true"] { background: var(--sidebar-selected); color: var(--text-primary); }
.owner-reauth, .owner-confirm { margin-top: 20px; padding: 18px; background: var(--surface-subtle); border: 1px solid var(--border); border-radius: 12px; }
.owner-reauth input { max-width: 380px; display: block; margin: 8px 0 16px; }
.owner-invite-form { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px; }
.owner-invite-form > div:first-child { flex: 1; min-width: 220px; }
.owner-dialog label { display: block; font-size: 12px; margin-bottom: 6px; }
.owner-dialog input, .owner-dialog select { border: 1px solid var(--border); background: var(--surface); color: var(--text-primary); border-radius: 10px; padding: 10px 12px; max-width: 100%; }
.owner-dialog input:focus, .owner-dialog select:focus { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.owner-invite-form input { width: 100%; }
.owner-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 24px 0 12px; }
.owner-toolbar label { margin: 0; }
.owner-table-scroll { overflow-x: auto; }
.owner-dialog table { width: 100%; border-collapse: collapse; font-size: 12px; text-align: left; }
.owner-dialog th, .owner-dialog td { padding: 12px 8px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.owner-dialog th { font-weight: 500; color: var(--text-secondary); }
.owner-row-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.owner-pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; margin: 16px 0; }
.owner-confirm { scroll-margin-top: 16px; }
.owner-dialog .status { overflow-wrap: anywhere; }
@media (max-width: 760px) {
  .access-shell { padding: 44px 20px; }
  .owner-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); padding: 18px; }
  .owner-invite-form { align-items: stretch; flex-direction: column; }
  .owner-invite-form > div:first-child { min-width: 0; }
  .owner-dialog input, .owner-dialog select { font-size: 16px; }
}

/* ==========================================================================
   S6 mobile drawer + touch layout (2026-10-29)
   Presentation only. Desktop geometry above 760px is intentionally unchanged.
   ========================================================================== */

.answer-body pre {
  max-width: 100%;
  margin: 12px 0;
  padding: 10px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-subtle);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
  tab-size: 2;
}

.answer-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.answer-body pre code {
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
}

@media (max-width: 760px), (max-height: 520px) and (max-width: 1000px) {
  :root {
    --app-header-height: calc(56px + env(safe-area-inset-top, 0px));
    --mobile-gutter: 16px;
  }

  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
    overscroll-behavior-x: none;
  }

  body.chat-view,
  body.chat-view.sidebar-collapsed {
    padding-left: 0;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 18;
    height: var(--app-header-height);
    padding: env(safe-area-inset-top, 0px) 12px 0;
    gap: 8px;
    background: var(--surface);
  }

  .side-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    margin-left: -4px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
    touch-action: manipulation;
  }

  .topbar > .logo {
    width: 28px;
    height: 28px;
  }

  .topbar > .wordmark {
    font-size: 18px;
  }

  .brand-tagline,
  .top-actions {
    display: none;
  }

  /* ---- off-canvas navigation drawer ---- */
  body .sidebar {
    display: flex;
    width: min(320px, 86vw);
    max-width: 86vw;
    z-index: 40;
    padding: 12px 8px calc(10px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 0 50px rgb(var(--shadow-rgb) / 0.22);
    opacity: 1;
    visibility: hidden;
    transform: translateX(-100%);
    pointer-events: none;
    transition: transform var(--sidebar-motion-duration) ease,
                visibility 0s linear var(--sidebar-motion-duration);
  }

  body.sidebar-mobile-open .sidebar {
    display: flex;
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    pointer-events: auto;
    transition: transform var(--sidebar-motion-duration) ease,
                visibility 0s linear 0s;
  }

  body.auth-view .sidebar,
  body.auth-view .sidebar-scrim,
  body.auth-view .side-open {
    display: none !important;
  }

  .side-top {
    padding: 2px 6px 12px;
  }

  .icon-btn {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    font-size: 24px;
    line-height: 1;
    touch-action: manipulation;
  }

  .side-new {
    min-height: 44px;
    touch-action: manipulation;
  }

  .side-scroll {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .account-button,
  .conversation-item,
  .conversation-more {
    min-height: 44px;
    touch-action: manipulation;
  }

  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 39;
    background: rgb(0 0 0 / 0.42);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--sidebar-motion-duration) ease,
                visibility 0s linear var(--sidebar-motion-duration);
  }

  .sidebar-scrim.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity var(--sidebar-motion-duration) ease,
                visibility 0s linear 0s;
  }

  body:not(.sidebar-mobile-open) .sidebar-scrim {
    pointer-events: none;
  }

  body.sidebar-mobile-open {
    overflow: hidden;
  }

  /* ---- chat column: full width, no horizontal page scroll ---- */
  .workspace,
  .workspace.is-welcome {
    width: 100%;
    max-width: 100%;
    padding-inline: 0;
  }

  .workspace:not(.is-welcome) {
    height: calc(var(--app-viewport-height, 100dvh) - var(--app-header-height));
    min-height: 0;
  }

  .workspace:not(.is-welcome) .work-grid,
  .workspace:not(.is-welcome) .thread,
  .workspace:not(.is-welcome) .dialogue,
  .workspace:not(.is-welcome) .dialogue-content {
    min-width: 0;
    max-width: 100%;
  }

  .workspace:not(.is-welcome) .thread {
    height: 100%;
    min-height: 0;
  }

  .workspace:not(.is-welcome) .dialogue {
    padding: 8px var(--mobile-gutter) 6px;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
  }

  .workspace:not(.is-welcome) .composer {
    width: 100%;
    max-width: 100%;
    padding: 8px var(--mobile-gutter) 0;
  }

  .workspace:not(.is-welcome) .chat-disclaimer {
    width: 100%;
    max-width: 100%;
    margin: 4px 0 calc(6px + env(safe-area-inset-bottom, 0px));
    padding: 0 var(--mobile-gutter);
  }

  .workspace > .notice {
    width: auto;
    max-width: none;
    margin: 0 var(--mobile-gutter) 12px;
    padding: 9px 11px;
    font-size: 11px;
    line-height: 1.7;
  }

  .workspace > .page-head {
    width: auto;
    max-width: none;
    margin-inline: var(--mobile-gutter);
  }

  .workspace.is-welcome .thread {
    width: 100%;
    max-width: 100%;
    padding-inline: var(--mobile-gutter);
  }

  .workspace.is-welcome .composer {
    width: 100%;
    padding-inline: var(--mobile-gutter);
  }

  .details-panel {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 80vh;
    border-radius: 20px 20px 0 0;
    z-index: 31;
  }

  .details-scrim {
    z-index: 30;
  }

  .question-bubble {
    max-width: 92%;
    padding: 10px 14px;
    font-size: 14px;
  }

  .answer-title {
    font-size: 19px;
  }

  .answer-body {
    font-size: 15px;
    line-height: 1.75;
    overflow-wrap: anywhere;
  }

  .answer-body p,
  .answer-body li,
  .answer-body h3,
  .answer-body h4,
  .answer-body h5 {
    overflow-wrap: anywhere;
  }

  .answer-body pre {
    margin-inline: 0;
    max-width: 100%;
    font-size: 12px;
  }

  .composer-box {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 8px;
    padding: 6px 7px 6px 12px;
    border-radius: 22px;
  }

  #chat-question {
    grid-column: 1;
    grid-row: 1;
    height: auto;
    min-height: calc(1.55em + 4px);
    max-height: calc(1.55em * 5 + 4px);
    font-size: 16px;
    line-height: 1.55;
    overflow-y: hidden;
  }

  .composer-bottom {
    grid-column: 2;
    grid-row: 1;
    gap: 0;
    margin-top: 0;
  }

  .composer-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
    touch-action: manipulation;
  }

  .composer-send:disabled {
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 6px;
  }


  .keyboard-note {
    margin-top: 5px;
    font-size: 10.5px;
    line-height: 1.5;
  }

  .answer-display-controls {
    min-height: 26px;
    padding-bottom: 2px;
  }

  .answer-display-controls .link {
    min-height: 32px;
    padding: 4px 2px;
  }

  .dialogue::-webkit-scrollbar {
    width: 4px;
  }

  .conversation-turn + .conversation-turn {
    margin-top: 26px;
  }
}

@media (max-width: 430px) {
  :root {
    --mobile-gutter: 14px;
  }
  .topbar {
    padding-inline: 10px;
  }

  .workspace > .notice {
    margin-bottom: 10px;
    font-size: 10.5px;
  }

  .question-bubble {
    max-width: 94%;
  }

  .composer-box {
    padding: 6px 7px 6px 12px;
    border-radius: 20px;
  }
}

@media (max-width: 360px) {
  :root {
    --mobile-gutter: 12px;
  }

  .topbar > .wordmark {
    font-size: 17px;
  }

  .composer-send {
    width: 38px;
    height: 38px;
    min-width: 38px;
  }

  .composer-send:disabled {
    width: 38px;
    height: 38px;
    min-width: 38px;
  }
}

/* Landscape phones: short viewport. Keep the composer and menu reachable
   without letting the welcome content push the header off-screen. */
@media (max-height: 520px) and (max-width: 1000px) {
  .workspace > .notice {
    display: none;
  }

  .workspace.is-welcome .welcome-prompts {
    display: none;
  }

  .workspace.is-welcome .page-head {
    margin-bottom: 8px;
  }

  .workspace.is-welcome .page-head h1 {
    font-size: 20px;
    margin-bottom: 4px;
  }

  .workspace.is-welcome .chat-sub {
    display: none;
  }

  .workspace.is-welcome .composer {
    padding-top: 0;
  }

  .keyboard-note {
    display: none;
  }

  .workspace:not(.is-welcome) .composer {
    padding-top: 4px;
  }

  .workspace:not(.is-welcome) .chat-disclaimer {
    margin-top: 2px;
    font-size: 10px;
    line-height: 1.4;
  }
}