:root {
  --sidebar-width: 286px;
  --sidebar-collapsed-width: 68px;
  --topbar-height: 62px;
  --composer-max: 780px;
  --thread-max: 840px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg1);
}

body {
  overflow: hidden;
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

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

.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;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(rgba(19, 19, 22, 0.025) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, rgba(19, 19, 22, 0.025) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(135deg, rgba(216, 155, 0, 0.075), transparent 38%),
    linear-gradient(315deg, rgba(63, 63, 70, 0.06), transparent 42%),
    var(--bg);
  transition: grid-template-columns var(--dur-slow) var(--ease-out);
}

.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
}

.sidebar {
  position: relative;
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  padding: 14px 12px;
  overflow: hidden;
  color: #f7f7f8;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.065), transparent 34%),
    linear-gradient(rgba(255, 255, 255, 0.036) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--neutral-950);
  border-inline-start: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.04) inset;
  transition:
    padding var(--dur-slow) var(--ease-out),
    transform var(--dur-slow) var(--ease-out);
}

.app-shell.sidebar-collapsed .sidebar {
  align-items: center;
  padding: 14px 8px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  width: 100%;
}

.brand-mark,
.topbar-logo-button,
.empty-mark,
.avatar img {
  display: block;
  object-fit: contain;
}

.brand-mark {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  filter: drop-shadow(0 10px 18px rgba(216, 155, 0, 0.28));
}

.brand-copy {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.brand-copy strong {
  overflow: hidden;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy span {
  overflow: hidden;
  color: rgba(247, 247, 248, 0.58);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-collapse-button,
.icon-button,
.settings-button,
.new-chat-button,
.conversation-item,
.clinical-card,
.style-chip,
.composer-tool-button,
.send-button,
.message-action,
.structured-follow-up-option,
.structured-follow-up-scale-button,
.structured-follow-up-submit,
.structured-follow-up-manual,
.settings-card button {
  border: 0;
}

.sidebar-collapse-button,
.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  color: inherit;
  background: transparent;
  border-radius: var(--radius-sm);
  transition:
    color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.sidebar-collapse-button:hover,
.icon-button:hover {
  color: var(--fg1);
  background: var(--surface-hover);
}

.sidebar .sidebar-collapse-button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-collapse-button span,
.menu-button span,
.clear-button span,
.send-button span,
.close-button::before,
.composer-tool-button span {
  display: block;
  width: 18px;
  height: 18px;
  background: currentColor;
}

.sidebar-collapse-button span {
  width: 17px;
  height: 17px;
  mask:
    linear-gradient(135deg, transparent 47%, #000 48% 58%, transparent 59%) 3px 2px / 11px 11px no-repeat,
    linear-gradient(45deg, transparent 47%, #000 48% 58%, transparent 59%) 3px 7px / 11px 11px no-repeat;
}

.menu-button span {
  width: 19px;
  height: 16px;
  mask:
    linear-gradient(#000 0 0) top / 100% 2px no-repeat,
    linear-gradient(#000 0 0) center / 100% 2px no-repeat,
    linear-gradient(#000 0 0) bottom / 100% 2px no-repeat;
}

.clear-button span,
.close-button::before {
  mask:
    linear-gradient(45deg, transparent 45%, #000 46% 54%, transparent 55%),
    linear-gradient(-45deg, transparent 45%, #000 46% 54%, transparent 55%);
}

.brand-meter {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr;
  gap: 8px;
  width: 100%;
}

.brand-meter span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  color: rgba(247, 247, 248, 0.76);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
}

.new-chat-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  color: var(--fg-on-accent);
  background: var(--accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-accent);
  font-weight: 700;
  transition:
    transform var(--dur-fast) var(--ease-spring),
    background var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.new-chat-button:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.new-chat-button span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-pill);
  color: var(--fg-on-accent);
  background: rgba(255, 255, 255, 0.22);
  font-family: var(--font-mono);
  font-size: 18px;
  line-height: 1;
}

.conversation-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  width: 100%;
  overflow: auto;
  padding: 2px 0 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.conversation-list::-webkit-scrollbar {
  width: 8px;
}

.conversation-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-pill);
}

.conversation-item {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  color: rgba(247, 247, 248, 0.7);
  background: transparent;
  border-radius: var(--radius-sm);
  text-align: start;
  transition:
    color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out);
}

.conversation-item:hover,
.conversation-item.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.conversation-item.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

[dir="rtl"] .conversation-item.active {
  box-shadow: inset -3px 0 0 var(--accent);
}

.conversation-item strong,
.conversation-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item strong {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.conversation-item span {
  margin-top: 3px;
  color: rgba(247, 247, 248, 0.42);
  font-family: var(--font-mono);
  font-size: 10px;
}

.clinical-rail {
  display: grid;
  gap: 8px;
  width: 100%;
}

.clinical-label {
  color: rgba(247, 247, 248, 0.46);
  font-family: var(--font-mono);
  font-size: 10px;
}

.clinical-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 54px;
  padding: 9px;
  color: rgba(247, 247, 248, 0.82);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  transition:
    background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.clinical-card:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(216, 155, 0, 0.34);
}

.clinical-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background:
    linear-gradient(rgba(216, 155, 0, 0.86) 0 0) center / 12px 2px no-repeat,
    linear-gradient(90deg, rgba(216, 155, 0, 0.86) 0 0) center / 2px 12px no-repeat,
    rgba(216, 155, 0, 0.14);
}

.clinical-copy {
  min-width: 0;
}

.clinical-copy strong,
.clinical-copy span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clinical-copy strong {
  color: #fff;
  font-size: 12px;
}

.clinical-copy span {
  margin-top: 2px;
  color: rgba(247, 247, 248, 0.5);
  font-size: 11px;
}

.clinical-number {
  color: var(--gold-300);
  font-family: var(--font-mono);
  font-size: 16px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-quick-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  color: rgba(255, 255, 255, 0.76);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 800;
}

.sidebar-quick-link:hover {
  color: #fff;
  background: rgba(216, 155, 0, 0.18);
  border-color: rgba(216, 155, 0, 0.35);
}

.connection-state {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: rgba(247, 247, 248, 0.64);
  font-size: 12px;
}

.state-dot,
.topbar-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(232, 130, 30, 0.12);
}

.connection-state.ok .state-dot,
.topbar-chip-connection.ok .topbar-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(31, 157, 85, 0.12);
}

.connection-state.error .state-dot,
.topbar-chip-connection.error .topbar-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(229, 72, 77, 0.12);
}

.settings-button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}

.settings-button:hover {
  color: var(--gold-100);
  background: rgba(255, 255, 255, 0.12);
}

.app-shell.sidebar-collapsed .brand-copy,
.app-shell.sidebar-collapsed .brand-meter,
.app-shell.sidebar-collapsed .clinical-rail,
.app-shell.sidebar-collapsed .connection-state span:not(.state-dot),
.app-shell.sidebar-collapsed .settings-button,
.app-shell.sidebar-collapsed .sidebar-quick-link,
.app-shell.sidebar-collapsed .conversation-item span,
.app-shell.sidebar-collapsed .conversation-item strong,
.app-shell.sidebar-collapsed .new-chat-button {
  display: none;
}

.app-shell.sidebar-collapsed .brand-block {
  justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-collapse-button {
  position: absolute;
  top: 58px;
  width: 34px;
  height: 34px;
}

.app-shell.sidebar-collapsed .conversation-item {
  min-height: 38px;
  padding: 0;
}

.app-shell.sidebar-collapsed .conversation-item::before {
  content: "";
  display: block;
  width: 10px;
  height: 10px;
  margin: 14px auto;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.3);
}

.app-shell.sidebar-collapsed .conversation-item.active::before {
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(216, 155, 0, 0.12);
}

.chat-panel {
  display: grid;
  grid-template-rows: var(--topbar-height) minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 16px;
  background: rgba(250, 250, 250, 0.82);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.topbar .icon-button {
  color: var(--fg2);
}

.topbar .icon-button:hover {
  color: var(--fg1);
}

.topbar-logo-button {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  filter: drop-shadow(0 8px 18px rgba(216, 155, 0, 0.24));
}

.topbar-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.topbar-session {
  min-width: 0;
  overflow: hidden;
  color: var(--fg1);
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.answer-style-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 4px;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.style-chip {
  min-height: 28px;
  padding: 0 12px;
  color: var(--fg3);
  background: transparent;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  transition:
    color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.style-chip.is-active {
  color: var(--fg-on-accent);
  background: var(--accent);
  box-shadow: var(--shadow-accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.topbar-nav-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.topbar-link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  color: var(--fg2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 800;
  transition:
    color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.topbar-link-button:hover {
  color: var(--fg1);
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.topbar-link-button.is-account {
  color: var(--fg-on-accent);
  background: var(--accent);
  border-color: transparent;
  box-shadow: var(--shadow-accent);
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 11px;
  color: var(--fg3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 11px;
}

.clear-button {
  color: var(--fg3);
}

.app-shell.is-empty .clear-button {
  opacity: 0;
  pointer-events: none;
}

.messages {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 28px max(22px, calc((100vw - var(--sidebar-width) - var(--thread-max)) / 2)) 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.messages::-webkit-scrollbar {
  width: 9px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
}

.empty-state {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100%;
  overflow: hidden;
  border-radius: 0;
  text-align: center;
  isolation: isolate;
}

.empty-state.hidden {
  display: none;
}

.stage-video-bg {
  position: absolute;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.18;
  filter: saturate(0.86) contrast(1.04) brightness(1.12);
}

.empty-state::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(250, 250, 250, 0.72), rgba(250, 250, 250, 0.94)),
    linear-gradient(rgba(19, 19, 22, 0.04) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, rgba(19, 19, 22, 0.035) 1px, transparent 1px) 0 0 / 32px 32px;
}

.empty-state-inner {
  display: grid;
  justify-items: center;
  gap: 16px;
  width: min(760px, 100%);
  padding: 24px 14px 34px;
}

.empty-mark-wrap {
  display: inline-grid;
  place-items: center;
  width: 110px;
  height: 110px;
  border: 1px solid rgba(216, 155, 0, 0.22);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(rgba(216, 155, 0, 0.1), rgba(255, 255, 255, 0.72)),
    var(--surface);
  box-shadow:
    0 18px 46px rgba(19, 19, 22, 0.12),
    var(--shadow-accent);
}

.empty-mark {
  width: 88px;
  height: 88px;
  border-radius: var(--radius-md);
  filter: drop-shadow(0 8px 20px rgba(216, 155, 0, 0.22));
}

.empty-state h1 {
  max-width: 720px;
  margin: 0;
  color: var(--fg1);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0;
}

.hero-typing-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  max-width: 620px;
  margin: 0;
  color: var(--fg2);
  font-size: 16px;
  line-height: 1.65;
}

.hero-typing-caret {
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-inline-start: 6px;
  border-radius: var(--radius-xs);
  background: var(--accent);
  animation: caretBlink 1s steps(2) infinite;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: min(700px, 100%);
  margin-top: 4px;
}

.prompt-grid button {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  gap: 5px 12px;
  min-height: 78px;
  padding: 14px;
  color: var(--fg1);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  text-align: start;
  transition:
    transform var(--dur-base) var(--ease-out),
    border-color var(--dur-base) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out),
    background var(--dur-base) var(--ease-out);
}

.prompt-grid button:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.prompt-icon {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  overflow: hidden;
  color: var(--fg-on-accent);
  background: var(--neutral-900);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 22px rgba(19, 19, 22, 0.14);
}

.prompt-icon::before,
.prompt-icon::after {
  content: "";
  display: block;
  background: currentColor;
}

.prompt-icon-symptom::before {
  width: 20px;
  height: 2px;
  border-radius: var(--radius-pill);
  box-shadow:
    0 -8px 0 currentColor,
    0 8px 0 currentColor;
}

.prompt-icon-alert::before {
  width: 3px;
  height: 18px;
  border-radius: var(--radius-pill);
}

.prompt-icon-alert::after {
  width: 5px;
  height: 5px;
  margin-top: 3px;
  border-radius: var(--radius-pill);
}

.prompt-icon-lab::before {
  width: 15px;
  height: 21px;
  border-radius: 3px 3px 8px 8px;
  box-shadow: inset 0 -7px 0 var(--accent);
}

.prompt-icon-context::before {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: var(--radius-pill);
  background: transparent;
  box-shadow:
    -10px 8px 0 -6px var(--accent),
    10px -8px 0 -6px var(--accent);
}

.prompt-grid strong {
  min-width: 0;
  overflow: hidden;
  color: var(--fg1);
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-grid button > span:last-child {
  min-width: 0;
  overflow: hidden;
  color: var(--fg3);
  font-size: 13px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-row {
  display: flex;
  gap: 12px;
  width: min(var(--thread-max), 100%);
  margin: 0 auto 22px;
}

.message-row.user {
  justify-content: flex-start;
}

.message-row.assistant {
  justify-content: flex-start;
}

.message-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  max-width: min(720px, calc(100% - 48px));
}

.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  margin-top: 2px;
  color: #fff;
  background: var(--neutral-900);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}

.message-row.user .avatar {
  display: none;
}

.assistant-avatar {
  background:
    linear-gradient(rgba(216, 155, 0, 0.14), rgba(19, 19, 22, 0.08)),
    #fff;
  border: 1px solid rgba(216, 155, 0, 0.24);
}

.assistant-avatar img {
  width: 34px;
  height: 34px;
}

.message-bubble {
  min-width: 0;
  max-width: min(720px, 100%);
  color: var(--fg1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.message-row.assistant .message-bubble {
  padding: 15px 17px;
  border-inline-start: 3px solid var(--accent);
}

.message-row.user .message-stack {
  align-items: flex-end;
  max-width: min(720px, 86%);
}

.message-row.user .message-bubble {
  padding: 12px 17px;
  color: var(--bubble-user-fg);
  background: var(--bubble-user);
  border-color: transparent;
  border-radius: 22px 22px 6px 22px;
  box-shadow: var(--shadow-accent);
}

[dir="rtl"] .message-row.user .message-bubble {
  border-radius: 22px 22px 22px 6px;
}

.message-row.error .message-bubble {
  border-color: rgba(229, 72, 77, 0.24);
  border-inline-start-color: var(--danger);
}

.chat-usage-meter {
  margin: 0 10px 6px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(200, 150, 15, 0.07);
  border: 1px solid rgba(200, 150, 15, 0.18);
}

.cum-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cum-label {
  font-size: 12px;
  color: var(--color-text-secondary, #888);
  line-height: 1.3;
}

.cum-upgrade {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent, #c8960f);
  text-decoration: none;
  white-space: nowrap;
}

.cum-bar {
  height: 3px;
  border-radius: 2px;
  background: rgba(200, 150, 15, 0.15);
  margin-top: 7px;
  overflow: hidden;
}

.cum-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--accent, #c8960f);
  transition: width 0.4s ease;
}

.cum-fill.is-low { background: var(--danger, #e5484d); }

.cum-cta {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent, #c8960f);
  text-decoration: none;
  text-align: center;
}

.cum-cta:hover { opacity: 0.8; }

.upgrade-prompt {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm, 10px);
  background: rgba(var(--accent-rgb, 255 165 0) / 0.08);
  border: 1px solid rgba(var(--accent-rgb, 255 165 0) / 0.22);
  font-size: 14px;
  color: var(--color-text-secondary, #888);
}

.upgrade-prompt-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.upgrade-link {
  display: inline-block;
  padding: 7px 16px;
  border-radius: var(--radius-xs, 8px);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  border: 1.5px solid currentColor;
  color: var(--color-text-secondary, #888);
  transition: opacity 0.15s;
}

.upgrade-link:hover { opacity: 0.75; }

.upgrade-link.is-primary {
  background: var(--accent, #c8960f);
  border-color: var(--accent, #c8960f);
  color: #fff;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: inherit;
  font-size: 15.5px;
  line-height: 1.85;
}

.message-row.is-revealing .message-text::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.1em;
  margin-inline-start: 5px;
  border-radius: var(--radius-xs);
  background: var(--accent);
  vertical-align: -0.16em;
  animation: caretBlink 900ms steps(2) infinite;
}

.document-job-card {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 11px;
  color: var(--fg2);
  background:
    linear-gradient(135deg, rgba(216, 155, 0, 0.1), transparent 46%),
    var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.document-job-header,
.document-job-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.document-job-header strong {
  overflow: hidden;
  color: var(--fg1);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-job-header span {
  flex: 0 0 auto;
  min-height: 24px;
  padding: 4px 8px;
  color: var(--accent-fg);
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 800;
}

.document-job-card.status-failed .document-job-header span {
  color: var(--danger);
  background: var(--danger-soft);
}

.document-job-card.status-completed .document-job-header span {
  color: var(--success);
  background: var(--success-soft);
}

.document-job-progress {
  position: relative;
  height: 7px;
  overflow: hidden;
  background: rgba(63, 63, 70, 0.12);
  border-radius: var(--radius-pill);
}

.document-job-progress span {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 10%;
  background: linear-gradient(90deg, var(--accent), #f2c14f);
  border-radius: inherit;
  transition: width var(--dur-slow) var(--ease-out);
}

.document-job-card.status-running .document-job-progress span,
.document-job-card.status-queued .document-job-progress span {
  background-size: 160% 100%;
  animation: documentJobPulse 1.2s linear infinite;
}

.document-job-card.status-failed .document-job-progress span {
  background: var(--danger);
}

.document-job-card.status-completed .document-job-progress span {
  background: var(--success);
}

.document-job-meta {
  justify-content: flex-start;
  color: var(--fg3);
  font-size: 12px;
  line-height: 1.5;
}

.document-result-card {
  display: grid;
  gap: 9px;
  padding-top: 2px;
}

.document-result-chips,
.document-result-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.document-result-chips span {
  min-height: 24px;
  padding: 4px 8px;
  color: var(--fg2);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 800;
}

.document-result-values {
  display: grid;
  gap: 6px;
}

.document-result-value {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.document-result-value strong {
  overflow: hidden;
  color: var(--fg1);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-result-value span {
  color: var(--fg2);
  font-size: 12px;
  font-weight: 800;
}

.document-result-value small {
  color: var(--fg3);
  font-size: 11px;
  font-weight: 800;
}

.document-result-value.status-critical small,
.document-result-value.status-high small,
.document-result-value.status-low small {
  color: var(--danger);
}

.document-result-value.status-borderline small {
  color: var(--accent);
}

.document-result-prompts button {
  min-height: 30px;
  padding: 6px 10px;
  color: var(--fg1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 800;
}

.document-result-prompts button:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.message-meta,
.follow-ups,
.sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

@keyframes documentJobPulse {
  from {
    filter: brightness(0.94);
  }
  50% {
    filter: brightness(1.15);
  }
  to {
    filter: brightness(0.94);
  }
}

.risk-badge,
.source-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}

.risk-low {
  color: var(--success);
  background: var(--success-soft);
}

.risk-medium {
  color: var(--warning);
  background: var(--warning-soft);
}

.risk-high,
.risk-emergency {
  color: var(--danger);
  background: var(--danger-soft);
}

.source-pill {
  color: var(--fg3);
  background: var(--surface-inset);
  border: 1px solid var(--border);
}

.safety-note {
  margin-top: 12px;
  padding: 10px 13px;
  color: var(--fg3);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.65;
}

.follow-up-button {
  min-height: 30px;
  padding: 6px 10px;
  color: var(--accent-fg);
  background: var(--accent-soft);
  border-radius: var(--radius-pill);
  font-size: 12px;
  user-select: text;
}

.message-actions {
  display: flex;
  justify-content: flex-start;
  gap: 4px;
  margin-top: 9px;
  padding-inline-start: 4px;
}

.message-icon-action {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  color: var(--fg3);
  background: transparent;
  border-radius: var(--radius-sm);
  transition:
    color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out);
}

.message-icon-action:hover {
  color: var(--fg1);
  background: var(--surface-hover);
}

.message-icon-action svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.message-icon-action.is-confirmed,
.feedback-positive.is-selected {
  color: var(--success);
  background: var(--success-soft);
}

.feedback-negative.is-selected {
  color: var(--danger);
  background: var(--danger-soft);
}

.structured-follow-up {
  width: min(720px, 100%);
  margin-top: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.structured-follow-up-header,
.structured-follow-up-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.structured-follow-up-header strong {
  color: var(--fg1);
  font-size: 14px;
}

.structured-follow-up-header span,
.structured-follow-up-help,
.structured-follow-up-label,
.structured-follow-up-scale > span,
.structured-follow-up-input span {
  color: var(--fg3);
  font-size: 12px;
}

.structured-follow-up-help {
  margin: 8px 0 0;
  line-height: 1.7;
}

.structured-follow-up-field {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.structured-follow-up-label {
  font-weight: 700;
}

.structured-follow-up-options,
.structured-follow-up-scale-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.structured-follow-up-option,
.structured-follow-up-scale-button,
.structured-follow-up-submit,
.structured-follow-up-manual {
  min-height: 34px;
  color: var(--fg2);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition:
    color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}

.structured-follow-up-option {
  padding: 7px 10px;
  text-align: start;
  line-height: 1.5;
}

.structured-follow-up-option.is-selected,
.structured-follow-up-scale-button.is-selected {
  color: var(--fg-on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

.structured-follow-up-scale {
  display: grid;
  gap: 8px;
}

.structured-follow-up-scale-button {
  width: 34px;
  padding: 0;
}

.structured-follow-up-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.structured-follow-up-input input {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  color: var(--fg1);
  background: transparent;
  border: 0;
  outline: 0;
}

.structured-follow-up-footer {
  justify-content: flex-start;
  margin-top: 12px;
}

.structured-follow-up-submit,
.structured-follow-up-manual {
  padding: 0 12px;
  font-weight: 700;
}

.structured-follow-up-submit {
  color: var(--fg-on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

.structured-follow-up-submit:disabled {
  opacity: 0.5;
}

.thinking-status {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  color: var(--fg2);
  font-size: 14px;
}

.thinking-pulse {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(216, 155, 0, 0.12);
  animation: thinkingPulse 1.25s ease-in-out infinite;
}

.thinking-cursor {
  width: 6px;
  height: 1.1em;
  border-radius: var(--radius-xs);
  background: var(--accent);
  animation: caretBlink 900ms steps(2) infinite;
}

.composer {
  width: min(var(--composer-max), calc(100% - 32px));
  margin: 0 auto 16px;
}

.composer-surface {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 42px;
  align-items: end;
  gap: 6px;
  min-height: 56px;
  padding: 7px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px);
  transition:
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.composer-surface:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm);
}

.composer-toolbar {
  display: flex;
  align-items: center;
  min-width: 0;
}

.composer-tool-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 12px;
  color: var(--fg3);
  background: transparent;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  transition:
    color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out);
}

.composer-tool-button:hover {
  color: var(--fg1);
  background: var(--surface-hover);
}

.composer-tool-button span {
  width: 15px;
  height: 15px;
  mask:
    linear-gradient(#000 0 0) 7px 1px / 2px 13px no-repeat,
    linear-gradient(#000 0 0) 2px 6px / 12px 2px no-repeat,
    linear-gradient(#000 0 0) 3px 12px / 10px 2px no-repeat;
}

.composer textarea {
  width: 100%;
  max-height: 200px;
  min-height: 42px;
  resize: none;
  padding: 9px 6px;
  color: var(--fg1);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 15.5px;
  line-height: 1.55;
}

.composer textarea::placeholder {
  color: var(--fg4);
}

.send-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: var(--fg4);
  background: var(--surface-inset);
  border-radius: var(--radius-pill);
  transition:
    transform var(--dur-fast) var(--ease-spring),
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.send-button:not(:disabled),
.send-button.is-ready {
  color: var(--fg-on-accent);
  background: var(--accent);
  box-shadow: var(--shadow-accent);
}

.send-button:not(:disabled):hover,
.send-button.is-ready:hover {
  background: var(--accent-hover);
}

.send-button:not(:disabled):active {
  transform: scale(0.94);
}

.send-button span {
  width: 17px;
  height: 17px;
  background: currentColor;
  clip-path: polygon(50% 0, 100% 48%, 68% 48%, 68% 100%, 32% 100%, 32% 48%, 0 48%);
}

.composer-safety {
  margin: 9px 0 0;
  color: var(--fg4);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.settings-dialog {
  width: min(450px, calc(100vw - 32px));
  padding: 0;
  color: var(--fg1);
  background: transparent;
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.settings-dialog::backdrop {
  background: rgba(19, 19, 22, 0.42);
  backdrop-filter: blur(5px);
}

.settings-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.settings-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-card header strong {
  font-size: 16px;
}

.settings-card label {
  color: var(--fg3);
  font-size: 13px;
  font-weight: 700;
}

.settings-card input {
  min-height: 44px;
  padding: 0 12px;
  color: var(--fg1);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  direction: ltr;
  text-align: left;
}

.settings-card menu {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  padding: 0;
  margin: 0;
}

.settings-card button {
  min-height: 38px;
  padding: 0 14px;
  color: var(--fg2);
  background: var(--surface-inset);
  border-radius: var(--radius-sm);
  font-weight: 700;
}

.settings-card .save-button {
  color: var(--fg-on-accent);
  background: var(--accent);
}

.close-button {
  padding: 0;
}

@keyframes caretBlink {
  0%,
  50% {
    opacity: 1;
  }

  50.01%,
  100% {
    opacity: 0;
  }
}

@keyframes thinkingPulse {
  0%,
  100% {
    transform: scale(0.92);
    opacity: 0.72;
  }

  50% {
    transform: scale(1.08);
    opacity: 1;
  }
}

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

@media (max-width: 1040px) {
  .topbar-main {
    gap: 8px;
  }

  .topbar-session {
    max-width: 40vw;
  }

  .messages {
    padding-inline: 18px;
  }
}

@media (max-width: 840px) {
  body {
    overflow: hidden;
  }

  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .app-shell.sidebar-collapsed .sidebar {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 30;
    align-items: stretch;
    width: min(84vw, var(--sidebar-width));
    padding: 14px 12px;
    transform: translateX(105%);
    box-shadow: var(--shadow-lg);
  }

  .app-shell.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .app-shell.sidebar-collapsed .brand-meter,
  .app-shell.sidebar-collapsed .clinical-rail {
    display: grid;
  }

  .app-shell.sidebar-collapsed .brand-copy {
    display: flex;
  }

  .app-shell.sidebar-collapsed .brand-block {
    justify-content: flex-start;
  }

  .app-shell.sidebar-collapsed .new-chat-button {
    display: flex;
  }

  .app-shell.sidebar-collapsed .connection-state span:not(.state-dot) {
    display: inline;
  }

  .app-shell.sidebar-collapsed .settings-button {
    display: inline-flex;
  }

  .app-shell.sidebar-collapsed .sidebar-quick-link {
    display: inline-flex;
  }

  .app-shell.sidebar-collapsed .conversation-item strong,
  .app-shell.sidebar-collapsed .conversation-item span {
    display: block;
  }

  .app-shell.sidebar-collapsed .conversation-item {
    min-height: 42px;
    padding: 9px 10px;
  }

  .app-shell.sidebar-collapsed .conversation-item::before {
    display: none;
  }

  .app-shell.sidebar-collapsed .sidebar-collapse-button {
    position: static;
    width: 38px;
    height: 38px;
  }

  .topbar {
    padding: 0 10px;
  }

  .topbar-logo-button {
    width: 38px;
    height: 38px;
  }

  .topbar-session {
    max-width: 34vw;
    font-size: 13px;
  }

  .answer-style-switch {
    display: none;
  }

  .topbar-chip {
    min-height: 32px;
    padding: 0 9px;
  }

  .topbar-nav-actions {
    gap: 6px;
  }

  .topbar-link-button {
    min-height: 32px;
    padding: 0 9px;
    font-size: 11px;
  }

  .messages {
    padding: 18px 12px 24px;
  }

  .empty-state-inner {
    gap: 13px;
    padding-top: 18px;
  }

  .empty-mark-wrap {
    width: 92px;
    height: 92px;
    border-radius: var(--radius-lg);
  }

  .empty-mark {
    width: 74px;
    height: 74px;
  }

  .empty-state h1 {
    font-size: 27px;
  }

  .hero-typing-line {
    font-size: 14px;
  }

  .prompt-grid {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .prompt-grid button {
    min-height: 70px;
  }

  .message-row {
    gap: 9px;
    margin-bottom: 18px;
  }

  .message-stack,
  .message-row.user .message-stack {
    max-width: calc(100% - 44px);
  }

  .message-row.user .message-stack {
    max-width: 88%;
  }

  .avatar {
    flex-basis: 32px;
    width: 32px;
    height: 32px;
  }

  .assistant-avatar img {
    width: 30px;
    height: 30px;
  }

  .message-row.assistant .message-bubble,
  .message-row.user .message-bubble {
    padding: 12px 14px;
  }

  .message-text {
    font-size: 14.5px;
  }

  .composer {
    width: calc(100% - 18px);
    margin-bottom: 10px;
  }

  .composer-surface {
    grid-template-columns: minmax(0, 1fr) 42px;
    gap: 4px;
  }

  .composer-toolbar {
    grid-column: 1 / -1;
  }

  .composer-tool-button {
    min-height: 32px;
    padding: 0 10px;
  }

  .composer textarea {
    min-height: 40px;
    padding: 8px 6px;
  }
}

@media (max-width: 480px) {
  .topbar {
    gap: 7px;
  }

  .topbar-main {
    flex: 1;
  }

  .topbar-session {
    max-width: 36vw;
  }

  .topbar-chip span:last-child {
    display: none;
  }

  .topbar-chip {
    width: 34px;
    justify-content: center;
    padding: 0;
  }

  .prompt-grid button > span:last-child {
    white-space: normal;
  }

  .composer-safety {
    font-size: 10px;
  }
}

/* Public chat should feel like a natural conversation. Clinical internals are
   hidden unless an explicit debug flag enables them; only high/emergency risk
   badges surface for ordinary users. */
.app-shell:not(.clinical-details-enabled) .sources,
.app-shell:not(.clinical-details-enabled) .safety-note,
.app-shell:not(.clinical-details-enabled) .structured-follow-up,
.app-shell:not(.clinical-details-enabled) .message-meta {
  display: none !important;
}

.app-shell:not(.clinical-details-enabled) .message-meta:has(.risk-high),
.app-shell:not(.clinical-details-enabled) .message-meta:has(.risk-emergency) {
  display: flex !important;
}

.app-shell.clinical-details-enabled .message-meta,
.app-shell.clinical-details-enabled .sources {
  display: flex;
}

.app-shell.clinical-details-enabled .safety-note,
.app-shell.clinical-details-enabled .structured-follow-up {
  display: block;
}
