.chat-strip-header .brand {
  display: flex;
  align-items: center;
  gap: 10px
}

.chat-strip-header .brand img {
  height: 48px;
  width: 48px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0;
  padding: 0
}

.chat-strip-header .brand img.logo.dark {
  display: none
}

html.theme-dark .chat-strip-header .brand img.logo.light {
  display: none
}

html.theme-dark .chat-strip-header .brand img.logo.dark {
  display: inline-block
}

/* Collapsed keeps a mini circular logo persistent; hide title and actions */
.chat-strip-header {
  transition: height .25s ease, padding .25s ease;
}

.chat-strip-header.collapsed {
  height: 36px;
  padding: 4px 6px;
}

.chat-strip-header.collapsed h1 {
  display: none
}

.chat-strip-header.collapsed .status,
.chat-strip-header.collapsed .inline-actions {
  display: none
}

.chat-strip-header.collapsed .brand img {
  height: 30px;
  width: 30px
}

/* Basic, clean, responsive layout */
:root {
  --bg: #f7f8fa;
  /* light background */
  --panel: #ffffff;
  /* panels */
  --muted: #6b7280;
  /* slate-500 */
  --text: #111827;
  /* gray-900 */
  --accent: #16a34a;
  /* green-600 */
  --accent-2: #0ea5e9;
  /* sky-500 */
  --danger: #dc2626;
  /* red-600 */
  --border: #e5e7eb;
  /* gray-200 */
  /* sizing */
  --bubble-max: 860px;
}

/* Large text mode */
html.text-large body {
  font-size: 18px;
}

html.text-large #question {
  font-size: 19px;
}

html.text-large header h1 {
  font-size: 24px;
}

html.text-large .msg .avatar {
  font-size: 15px;
}

* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
  font-size: 16.5px;
  background: var(--bg);
  color: var(--text);
}

#toast-root {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000
}

.toast {
  background: #ffffff;
  color: #111827;
  border: 1px solid var(--border);
  border-left: 4px solid var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .08);
  opacity: .98;
  transition: all .3s
}

.toast.hide {
  opacity: 0;
  transform: translateY(-10px)
}

.toast.success {
  border-left-color: var(--accent)
}

.toast.info {
  border-left-color: var(--accent-2)
}

#global-spinner {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .55);
  z-index: 999
}

.spinner-box {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 28px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18);
  display: flex;
  flex-direction: row;
  gap: 18px;
  align-items: center;
  max-width: 520px;
  width: 90%;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #e5e7eb;
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  flex: 0 0 42px
}

.spinner-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1
}

.spinner-details h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted)
}

.spinner-status {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  opacity: 1;
  transform: translateY(0);
  transition: opacity .25s ease, transform .25s ease
}

.spinner-status.show {
  opacity: 1;
  transform: translateY(0)
}

/* legacy step list styles left for reference but not used in new overlay */
.spinner-steps {
  display: none
}

@keyframes spin {
  to {
    transform: rotate(360deg)
  }
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh
}

/* Top strip now inside chat section so it scrolls with messages */
.chat-strip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 6px 4px;
  background: transparent;
  border-bottom: 1px solid var(--border);
}

.chat-strip-header h1 {
  font-size: 20px;
  margin: 0;
  letter-spacing: .2px
}

.chat-strip-header .status {
  font-size: 13px;
  color: var(--muted)
}

.chat-strip-header .actions {
  display: flex;
  gap: 8px;
  align-items: center
}

.chat-strip-header .inline-actions {
  display: flex;
  gap: 8px;
  align-items: center
}

.mode-select {
  display: none
}

button.icon-btn {
  background: #f3f4f6;
  color: #111827;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  line-height: 1;
  cursor: pointer
}

button.icon-btn:hover {
  background: #e5e7eb
}

main {
  display: block;
  padding: 20px;
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr
  }

  #controls {
    order: -1
  }
}

@media (max-width: 640px) {

  /* Hide composer speaker button on small screens to save space */
  #btn-speaker {
    display: none !important;
  }

  .msg .bubble {
    max-width: 100%;
    padding: 12px 14px
  }

  .msg .avatar {
    min-width: 52px;
    padding: 6px 8px;
    font-size: 12px
  }

  header h1 {
    font-size: 20px
  }

  #question {
    font-size: 16px
  }

  html.text-large #question {
    font-size: 18px
  }

  /* Mobile padding optimizations */
  main {
    padding: 0 !important;
  }

  #chat-section {
    border: none;
    border-radius: 0;
    padding: 0 4px;
    gap: 8px;
  }

  /* Compact bubbles */
  .msg .bubble {
    padding: 8px 10px;
    border-radius: 12px;
  }

  /* Tighter message spacing */
  .msg {
    gap: 6px;
    margin-bottom: 6px;
  }
}

#chat-section {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 20px 14px 20px;
  min-height: calc(100dvh - 150px);
  /* stretch near bottom excluding composer */
}

#messages {
  flex: 1;
  min-height: 300px;
  max-height: none;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 6px 6px 8px 6px;
}

.three-dots {
  width: 36px;
  height: 28px;
  font-weight: 700
}

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-start
}

.msg .avatar {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: #e5e7eb;
  flex: 0 0 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #374151;
  font-size: 18px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .04)
}

.msg.user .avatar.avatar-initial {
  background: #d1fae5;
  color: #065f46
}

.msg.assistant .avatar.avatar-img {
  background: #ffffff;
}

.msg.assistant .avatar.avatar-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block
}

.msg.assistant .avatar.avatar-img img.dark {
  display: none
}

html.theme-dark .msg.assistant .avatar.avatar-img {
  background: #1e293b;
}

html.theme-dark .msg.assistant .avatar.avatar-img img.light {
  display: none
}

html.theme-dark .msg.assistant .avatar.avatar-img img.dark {
  display: block
}

/* Ensure only one image shows inside the compact mobile header mini avatar */
.msg .msg-header .mini-avatar img.dark {
  display: none
}

html.theme-dark .msg .msg-header .mini-avatar img.light {
  display: none
}

html.theme-dark .msg .msg-header .mini-avatar img.dark {
  display: block
}

.passage .meta-chip {
  display: inline-block;
  margin-top: 6px;
}

.msg .bubble {
  background: #ffffff;
  border: 1px solid var(--border);
  padding: 16px 20px;
  border-radius: 6px;
  line-height: 1.6;
  width: 100%;
}

.msg.assistant .bubble {
  background: #ffffff
}

.msg .meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px
}

#chat-form {
  display: flex;
  flex-direction: column;
  gap: 8px
}

#question {
  resize: vertical;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: #111827;
  font-size: 18px
}

#question::placeholder {
  color: #9ca3af;
  font-size: 17px
}

.welcome-focus {
  animation: pulse-focus .9s ease-in-out 1;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .25);
}

@keyframes pulse-focus {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.02);
  }

  100% {
    transform: scale(1);
  }
}

.actions-row {
  display: flex;
  gap: 8px
}

button {
  background: #ffffff;
  color: #111827;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

button#btn-instant {
  background: #ffffff;
  color: #111827;
  border-color: #d1d5db
}

button#btn-instant:hover {
  background: #f9fafb;
  border-color: #cbd5e1
}

html.theme-dark button#btn-instant {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark button#btn-instant:hover {
  background: #334155;
}

button#btn-detailed {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #cbd5e1;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .02);
}

button#btn-detailed:hover {
  background: #e2e8f0;
  border-color: #94a3b8
}

html.theme-dark button#btn-detailed {
  background: #0f172a;
  color: #f1f5f9;
  border-color: #334155;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .05);
}

html.theme-dark button#btn-detailed:hover {
  background: #1e293b;
  border-color: #475569
}

button[disabled] {
  opacity: .6;
  cursor: not-allowed
}

/* Settings popover */
.settings-popover {
  position: fixed;
  top: 60px;
  right: 16px;
  width: 320px;
  max-width: 95vw;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .12);
  z-index: 1000;
  padding: 12px;
}

.settings-popover h2 {
  font-size: 16px;
  margin: 0 0 6px
}

.settings-popover label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted)
}

.settings-section .setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.settings-section .setting-row.name-row {
  justify-content: flex-start;
}

.settings-section .setting-row.name-row input {
  flex: 1;
}

.settings-section .setting-row.font-row select.full-width {
  width: 100%;
}

.check-line {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.35;
  position: relative;
}

.check-line input {
  margin: 3px 0 0 0;
  flex: 0 0 auto;
  position: relative;
  top: 2px;
}

/* Inline first line with checkbox; indent subsequent wrapped lines */
.check-line .check-label {
  flex: 1 1 auto;
  white-space: normal;
  overflow-wrap: break-word;
  max-width: 100%;
  display: block;
}

.check-line .check-label {
  padding-left: 2px;
}

/* Allow wrapping for checkbox labels within popover width */
/* removed duplicate rule above */
.settings-section .setting-row.save-row {
  justify-content: flex-start;
}

.settings-save-btn {
  background: #ffffff;
  color: #111827;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
}

.settings-save-btn:hover {
  background: #f3f4f6;
}

html.theme-dark .settings-save-btn {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark .settings-save-btn:hover {
  background: #334155;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-inline {
  font-size: 13px;
  color: var(--muted);
}

.status-pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  max-height: 28vh;
  overflow: auto;
  font-size: 12px;
  line-height: 1.25;
}

html.theme-dark .status-inline {
  color: #94a3b8;
}

html.theme-dark .status-pre {
  background: #0f172a;
  border-color: #334155;
  color: #e2e8f0;
}

/* Remove header status now relocated */
.chat-strip-header .status {
  display: none !important;
}

.settings-popover input {
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: #111827
}

.toggles {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap
}

.citations {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap
}

.citation {
  background: #f3f4f6;
  color: #111827;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px
}

.meta .citation {
  margin-right: 4px
}

.passage-set {
  margin-top: 10px;
  border-top: 1px dashed var(--border);
  padding-top: 8px
}

.passage-set .passage-progress {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

html.theme-dark .passage-set .passage-progress {
  color: #94a3b8;
}

.tiny-tip {
  animation: fadeIn .25s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.passage {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-top: 6px;
  position: relative
}

.passage .src {
  color: #1f2937;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

html.theme-dark .passage .src {
  color: #e2e8f0;
}

/* reference box is not fully clickable; a link appears inside */
.passage .expanding {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px
}

.passage .expanding .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  animation: pulse 1.2s infinite ease-in-out
}

.passage .expanding .dot:nth-child(2) {
  animation-delay: .15s
}

.passage .expanding .dot:nth-child(3) {
  animation-delay: .3s
}

@keyframes pulse {

  0%,
  80%,
  100% {
    opacity: .3
  }

  40% {
    opacity: 1
  }
}

.passage-expanded {
  margin-top: 6px;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fafafa;
}

html.theme-dark .passage-expanded {
  background: #162133;
  border-color: #334155
}

.continue-reading {
  margin-top: 6px;
  font-size: 13px;
  color: #1f2937;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

html.theme-dark .continue-reading {
  color: #e2e8f0;
  background: #0f172a;
  border-color: #334155
}

.continue-reading.inline {
  margin-right: 8px;
}

/* left icon inside Continue/Full buttons */
.continue-reading .icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  line-height: 1;
}

.collapse-full-btn {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  color: #111827;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 14px;
  z-index: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
  cursor: pointer;
}

html.theme-dark .collapse-full-btn {
  background: #0f172a;
  color: #e2e8f0;
  border-color: #334155;
}

@media (max-width: 900px) {
  .collapse-full-btn {
    right: 12px;
    padding: 9px 12px;
  }
}

/* Progress steps inside a temporary assistant bubble */
.progress-steps {
  list-style: none;
  padding-left: 0;
  margin: 6px 0 0 0
}

.progress-steps li {
  font-size: 13px;
  color: var(--muted);
  padding: 2px 0
}

.progress-steps li.done {
  color: #065f46
}

.progress-steps li.done::before {
  content: "✓ ";
  color: #10b981
}

.progress-steps li.active {
  color: var(--text)
}

footer {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  padding: 10px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: #ffffff
}

footer .sep {
  opacity: .4
}

.status-panel {
  position: fixed;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  color: #111827;
  padding: 1rem 1.25rem;
  width: 420px;
  max-width: 90%;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .2);
  z-index: 1000;
}

.status-panel h3 {
  margin-top: 0;
  font-size: 1.1rem;
}

.status-panel pre {
  background: #f9fafb;
  padding: .75rem;
  border-radius: 6px;
  max-height: 300px;
  overflow: auto;
  font-size: .75rem;
  line-height: 1.1;
  border: 1px solid var(--border);
}

.status-panel button {
  margin-top: .5rem;
}

/* Headings and paragraphs inside assistant answers */
.msg.assistant .bubble h2 {
  font-size: 1.25rem;
  margin: 0 0 .35rem 0;
  color: #0f172a
}

.msg.assistant .bubble h3 {
  font-size: 1.1rem;
  margin: .5rem 0 .25rem 0;
  color: #111827
}

.msg.assistant .bubble p {
  margin: .5rem 0
}

.msg.assistant .bubble p .sent {
  display: inline
}

.salutation {
  font-style: normal;
  font-weight: 500;
  color: #111827
}

/* Audio bar styling */
.audio-bar {
  margin-top: 14px;
  background: #fdf6d0;
  border: 1px solid #e2d29b;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.audio-bar .play-audio {
  background: #f5d780;
  color: #3f3010;
  border: 1px solid #d8b95e;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.audio-bar .play-audio:hover {
  background: #f3c95c
}

html.theme-dark .audio-bar {
  background: #4d3a12;
  border-color: #6b4f18;
}

html.theme-dark .audio-bar .play-audio {
  background: #6b4f18;
  color: #f8e8be;
  border-color: #8c641f;
}

html.theme-dark .audio-bar .play-audio:hover {
  background: #805c22
}

/* Fixed bottom composer */
:root {
  --composer-pad: 92px;
}

#messages {
  padding-bottom: var(--composer-pad);
}

.chat-strip-header.collapsed {
  height: 0;
  padding: 0;
  border-bottom: none;
  overflow: hidden;
  transition: height .25s ease, padding .25s ease;
}

.chat-strip-header {
  transition: height .25s ease, padding .25s ease;
}

#chat-form.composer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  z-index: 500
}

.composer-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0
}

.input-wrap {
  flex: 1 1 auto;
  display: flex
}

.input-wrap {
  position: relative;
  align-items: center;
  gap: 10px
}

.input-left-icon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff
}

@media (max-width:640px) {
  .input-left-icon {
    display: none
  }

  .actions-right {
    gap: 4px
  }

  .icon-square {
    width: 40px;
    height: 40px
  }

  #question {
    font-size: 16px;
    padding: 10px 12px
  }
}

.input-left-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover
}

.input-left-icon img.dark {
  display: none
}

html.theme-dark .input-left-icon {
  background: #1e293b;
  border-color: #334155
}

html.theme-dark .input-left-icon img.light {
  display: none
}

html.theme-dark .input-left-icon img.dark {
  display: block
}

#question {
  resize: none;
  width: 100%;
  min-height: 44px;
  max-height: 132px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: #111827;
  font-size: 18px;
  overflow: auto
}

/* Search popover */
.search-popover {
  position: fixed;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.search-popover-inner {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  height: 100%;
  max-width: none;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .22);
  padding: 12px;
  display: flex;
  flex-direction: column;
}

/* Unified menu styling */
.menu-sections {
  flex: 1 1 auto;
  overflow: auto;
  padding-right: 4px;
}

.menu-sections section {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .04)
}

html.theme-dark .menu-sections section {
  background: #162133;
  border-color: #334155;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .35)
}

.menu-sections section h4 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  gap: 6px
}

.menu-sections section h4::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-2)
}

html.theme-dark .menu-sections section h4::before {
  background: var(--accent)
}

.menu-sections label {
  font-size: 13px;
  color: var(--muted);
}

html.theme-dark .menu-sections label {
  color: #94a3b8
}

.menu-sections input[type=text],
.menu-sections select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 14px
}

html.theme-dark .menu-sections input[type=text],
html.theme-dark .menu-sections select {
  background: #0f172a;
  color: #e2e8f0;
  border-color: #334155
}

.menu-sections button {
  background: #f3f4f6;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease
}

.menu-sections button:hover {
  background: #e5e7eb
}

html.theme-dark .menu-sections button {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155
}

html.theme-dark .menu-sections button:hover {
  background: #334155
}

.settings-section .setting-row.check-row {
  justify-content: flex-start;
  padding-left: 0;
}

.settings-section .setting-row.check-row:first-of-type {
  margin-top: 2px;
}

.settings-section .setting-row.check-row label.check-line {
  width: 100%;
}

.settings-section .setting-row.check-row input[type=checkbox] {
  transform: translateY(-1px);
}

.menu-sections .toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 12px
}

.menu-sections .toggle-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px
}

.menu-sections .divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
  opacity: .6
}

html.theme-dark .menu-sections .divider {
  background: #334155
}

.search-actions button {
  padding: 6px 10px;
  font-size: 12px
}

.search-results {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 8px;
  padding: 6px;
}

html.theme-dark .search-results {
  background: #1e293b;
  border-color: #334155
}

.menu-sections pre {
  font-size: 11px;
  line-height: 1.3;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

html.theme-dark .menu-sections pre {
  background: #0f172a;
  border-color: #334155
}

.menu-sections ::-webkit-scrollbar {
  width: 10px
}

.menu-sections ::-webkit-scrollbar-track {
  background: transparent
}

.menu-sections ::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 6px
}

html.theme-dark .menu-sections ::-webkit-scrollbar-thumb {
  background: #334155
}

.search-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px
}

.search-popover input[type=text] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: #111827
}

.search-actions {
  display: flex;
  gap: 8px;
  margin: 8px 0
}

.search-results {
  max-height: 40vh;
  overflow: auto;
  border-top: 1px dashed var(--border);
  padding-top: 6px
}

.search-item {
  cursor: pointer;
  border-bottom: 1px dashed var(--border);
}

.search-item:hover {
  background: #f1f5f9
}

html.theme-dark .search-item:hover {
  background: #1e293b
}

.search-item mark {
  background: #fcd34d;
  color: #111827;
  padding: 0 2px;
  border-radius: 3px
}

html.theme-dark .search-item mark {
  background: #fbbf24;
  color: #0f172a
}

.msg.jump-flash {
  animation: flash-bg 2s ease-in-out 1
}

@keyframes flash-bg {
  0% {
    box-shadow: 0 0 0 0 rgba(234, 179, 8, .8)
  }

  50% {
    box-shadow: 0 0 0 6px rgba(234, 179, 8, .25)
  }

  100% {
    box-shadow: none
  }
}

html.theme-dark .search-popover-inner {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0
}

html.theme-dark .search-popover input {
  background: #0f172a;
  color: #e2e8f0;
  border-color: #334155
}

#question::placeholder {
  color: #9ca3af;
  font-size: 17px
}

.icon-square {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  color: #111827;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer
}

.icon-square.primary {
  background: #e5e7eb;
  color: #111827;
  border-color: #cbd5e1
}

.icon-square.detailed-mode {
  background: #111827;
  color: #ffffff;
  border-color: #111827
}

html.theme-dark .icon-square.detailed-mode {
  background: #e2e8f0;
  color: #0f172a;
  border-color: #e2e8f0
}

.icon-square.recording {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, .15) inset
}

/* Recording visual: mic button turns red background, keeps icon */
#btn-mic.recording {
  background: #ef4444;
  color: #ffffff;
  border-color: #dc2626;
}

html.theme-dark #btn-mic.recording {
  background: #dc2626;
  color: #ffffff;
  border-color: #b91c1c;
}

/* Hide mic while user is typing/focused */
.mic-hidden {
  display: none !important;
}

.actions-right {
  display: flex;
  align-items: center;
  gap: 8px
}

/* Small text option */
html.text-small body {
  font-size: 15px;
}

html.text-small #question {
  font-size: 16px;
}

html.text-small header h1 {
  font-size: 20px;
}

html.text-small .msg .avatar {
  font-size: 13px;
}

/* Dark theme */
html.theme-dark {
  --bg: #0b1020;
  --panel: #0f172a;
  --muted: #9ca3af;
  --text: #e5e7eb;
  --accent: #22c55e;
  --accent-2: #38bdf8;
  --danger: #ef4444;
  --border: #1f2937;
}

html.theme-dark body {
  background: var(--bg);
  color: var(--text);
}

html.theme-dark header,
html.theme-dark footer {
  background: var(--panel);
  border-color: var(--border);
}

html.theme-dark #chat-section {
  background: var(--panel);
}

/* Dark mode component overrides */
html.theme-dark .msg .bubble {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

html.theme-dark .msg.assistant .bubble {
  background: #162133;
}

html.theme-dark .msg .avatar {
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
}

html.theme-dark .msg.user .avatar {
  background: #065f46;
  color: #dcfce7;
}

html.theme-dark .history-toolbar input {
  background: #0f172a;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark .history-toolbar button {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark .citation {
  background: #24354d;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark .passage {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

html.theme-dark .passage .src {
  color: #94a3b8;
}

html.theme-dark #question {
  background: #0f172a;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark #question::placeholder {
  color: #64748b;
}

html.theme-dark .icon-square {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark .icon-square.primary {
  background: #334155;
  color: #e2e8f0;
  border-color: #475569;
}

html.theme-dark .spinner-box {
  background: #162133;
  border-color: #334155;
}

html.theme-dark .spinner {
  border-color: #334155;
  border-top-color: #38bdf8;
}

html.theme-dark .spinner-status {
  color: #e2e8f0;
}

html.theme-dark .spinner-details h4 {
  color: #94a3b8;
}

html.theme-dark .toast {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark .settings-popover {
  background: #1e293b;
  border-color: #334155;
}

html.theme-dark .settings-popover input,
html.theme-dark .settings-popover select {
  background: #0f172a;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark .settings-popover label {
  color: #94a3b8;
}

html.theme-dark #chat-form.composer {
  background: #162133;
  border-color: #334155;
}

html.theme-dark .msg.assistant .bubble h2 {
  color: #f1f5f9;
}

html.theme-dark .msg.assistant .bubble h3 {
  color: #e2e8f0;
}

html.theme-dark .salutation {
  color: #cbd5e1;
}

/* Language chip next to speaker */
.lang-chip {
  font-size: 11.5px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  margin-left: 6px;
  line-height: 1.1;
  opacity: .95
}

html.theme-dark .lang-chip {
  color: #94a3b8;
  border-color: #334155
}

/* Sticky play icon for full commentary audio */
.audio-fab {
  position: sticky;
  bottom: 6px;
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 20px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  opacity: 0.92;
  transition: background .2s ease, transform .15s ease, opacity .2s ease;
  z-index: 2;
}

.audio-fab:hover {
  background: var(--accent-2);
  opacity: 1;
}

.audio-fab:active {
  transform: scale(.96);
}

.audio-fab .icon {
  font-size: 18px;
  line-height: 1;
}

html.theme-dark .audio-fab {
  background: var(--accent);
  color: #0b1020;
}

/* Global audio bar (slides above composer) */
#global-audio-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 64px;
  background: #fdf6d0;
  border-top: 1px solid #e2d29b;
  padding: 8px 12px;
  display: block;
  z-index: 600;
  box-shadow: 0 -2px 4px rgba(0, 0, 0, .08);
  transform: translateY(110%);
  opacity: 0;
  transition: transform .3s ease, opacity .3s ease;
}

#global-audio-bar.visible {
  transform: translateY(0);
  opacity: 1;
}

#global-audio-bar .ga-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}

#global-audio-bar audio {
  flex: 1;
  max-width: 720px;
}

#global-audio-bar #ga-close,
#global-audio-bar #ga-replay {
  background: #f3f4f6;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 600;
}

#global-audio-bar #ga-close:hover,
#global-audio-bar #ga-replay:hover {
  background: #e5e7eb
}

/* Loading indicator */
#global-audio-bar .ga-loading {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px
}

#global-audio-bar .ga-loading .ga-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #e5e7eb;
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin .9s linear infinite;
  display: inline-block
}

html.theme-dark #global-audio-bar {
  background: #4d3a12;
  border-color: #6b4f18;
  box-shadow: 0 -2px 4px rgba(0, 0, 0, .4);
}

html.theme-dark #global-audio-bar #ga-close,
html.theme-dark #global-audio-bar #ga-replay {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark #global-audio-bar #ga-close:hover,
html.theme-dark #global-audio-bar #ga-replay:hover {
  background: #334155
}

/* Speaker buttons (answer and passages) */
.speaker-btn {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}

.speaker-btn:hover {
  background: #fafafa;
}

.speaker-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}

html.theme-dark .speaker-btn {
  background: #0b1020;
  color: #e2e8f0;
  border-color: #334155;
}

html.theme-dark .speaker-btn:hover {
  background: #111a2b;
}

/* Disabled badge inside speaker buttons for long text */
.speaker-btn[disabled] {
  opacity: .55;
  cursor: not-allowed;
  position: relative;
}

.audio-disabled-badge {
  display: inline-block;
  background: #f87171;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .3px;
  padding: 2px 6px;
  border-radius: 10px;
  line-height: 1;
  margin-left: 4px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .04);
}

html.theme-dark .audio-disabled-badge {
  background: #dc2626;
  color: #fff;
}

/* Tiny inline spinner for buttons */
.mini-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid #e5e7eb;
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin .9s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* Answer controls container top-right */
.answer-controls {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.answer-controls .speaker-btn {
  position: static;
}

/* Language chip redesigned as a compact rectangular tag/button */
.lang-chip {
  font-size: 11px;
  color: #0f172a;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  line-height: 1;
  opacity: .95;
  background: #f3f4f6;
  font-weight: 600;
}

html.theme-dark .lang-chip {
  color: #e2e8f0;
  background: #1f2937;
  border-color: #334155
}

.lang-chip.answer {
  position: static;
  margin: 0;
}

.answer-controls .lang-chip {
  order: -1;
  margin-right: 4px;
}

/* desktop: chip left of button */
@media (max-width:640px) {
  .answer-controls {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }

  .answer-controls .lang-chip {
    order: initial;
    margin: 0;
    align-self: flex-end;
  }
}

/* Ensure answer text clears the absolute-positioned controls at the top-right */
.msg.assistant .bubble .answer-body {
  margin-top: 28px;
}

/* Give space at top of each passage box for its inline speaker */
.passage {
  padding-top: 28px;
}

/* Add margin below speaker buttons to avoid overlap with subsequent text blocks */
.passage .speaker-btn {
  margin-bottom: 4px;
}

.speaker-answer-btn {
  margin-bottom: 6px;
}

/* Verse block for full commentary */
.verse-block {
  background: #f6f7fb;
  color: #374151;
  border-left: 3px solid var(--accent-2);
  padding: 8px 12px;
  margin: 8px 0 12px;
  border-radius: 6px;
  font-style: italic;
}

html.theme-dark .verse-block {
  background: #0f172a;
  color: #e2e8f0;
  border-color: #64748b;
}

.verse-block .translit {
  color: #6b7280;
}

/* --- Mobile message header bar & metadata chip additions (appended) --- */
/* Compact mobile header bar (appears above content on small screens) */
.msg .msg-header {
  display: none;
  align-items: center;
  gap: 10px;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.msg .msg-header .mh-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.msg .msg-header .mini-avatar {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  background: #e5e7eb;
  color: #374151;
}

.msg.assistant .msg-header .mini-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msg .msg-header .mh-right {
  margin-left: auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  flex-direction: column;
}

html.theme-dark .msg .msg-header {
  background: #0f172a;
  border-color: #334155;
}

html.theme-dark .msg .msg-header .mini-avatar {
  background: #1e293b;
  color: #e2e8f0;
}

@media (max-width: 700px) {
  .msg .avatar {
    display: none;
  }

  .msg .msg-header {
    display: flex;
  }

  /* Hide answer controls on mobile per spec */
  .answer-controls {
    display: none !important;
  }

  /* Hide bubble-top question chip when header is visible to avoid duplication */
  .msg.user .bubble .lang-chip.question {
    display: none;
  }
}

/* Passage metadata chip (date • location) */
.passage {
  padding-bottom: 30px;
}

.passage .meta-chip {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 12.5px;
  color: #374151;
  background: #eef2ff;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  padding: 4px 10px;
  line-height: 1.15;
  opacity: .97;
  font-weight: 600;
  letter-spacing: .2px;
}

html.theme-dark .passage .meta-chip {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}

/* Mobile: place meta chip as centered footer with margin */
@media (max-width: 700px) {
  .passage .meta-chip {
    position: static;
    display: block;
    margin: 8px auto 0;
    left: auto;
    right: auto;
    bottom: auto;
    text-align: center;
  }
}

/* Welcome panel */
.welcome-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: left;
}

.welcome-inner {
  display: flex;
  flex-direction: row;
  gap: 40px;
  max-width: 960px;
  width: 100%;
}

.welcome-visual {
  flex: 0 0 280px;
}

.welcome-image {
  width: 100%;
  border-radius: 18px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
  object-fit: cover;
}

.welcome-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome-text h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: .5px;
}

.welcome-text p {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
}

.welcome-instruction {
  font-weight: 600;
  font-size: 16px;
}

.welcome-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 2px 0 6px;
}

.welcome-record-btn {
  background: #ffffff;
  color: #111827;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 400;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

html.theme-dark .welcome-record-btn {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #334155;
}

.welcome-record-btn:hover {
  background: #f3f4f6;
}

html.theme-dark .welcome-record-btn:hover {
  background: #334155;
}

.welcome-write-btn {
  background: #2563eb;
  color: #ffffff;
  border: 1px solid #1d4ed8;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 400;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  box-shadow: 0 2px 10px rgba(37, 99, 235, .25);
}

html.theme-dark .welcome-write-btn {
  background: #3b82f6;
  border-color: #2563eb;
}

.welcome-write-btn:hover {
  filter: brightness(1.05);
}

.welcome-quotes {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.welcome-quotes li {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-style: italic;
  position: relative;
}

html.theme-dark .welcome-quotes li {
  background: #162133;
  border-color: #334155;
}

.welcome-tip {
  font-size: 13px;
  color: var(--muted);
}

@media (max-width:840px) {
  .welcome-inner {
    flex-direction: column;
    gap: 24px;
  }

  .welcome-visual {
    flex: 0 0 auto;
  }

  .welcome-image {
    max-width: 360px;
    margin: 0 auto;
  }
}

@media (max-width:640px) {
  .welcome-panel {
    padding: 28px 16px;
  }

  .welcome-text h2 {
    font-size: 24px;
  }

  .welcome-image {
    max-width: 300px;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    object-position: top center;
  }
}

/* Restore mic and speaker visibility */
#btn-mic {
  display: inline-flex;
}

#btn-speaker {
  display: none !important;
}

/* Smoothly adapt textarea width when actions change (mic removed) */
#question {
  transition: width .25s ease, flex .25s ease, box-shadow .25s ease;
}