/* Floating AI Jena - isolated from ScholarAI and sspimgAI. */
.ai-chat-launcher {
  position: fixed;
  right: 22px;
  bottom: 76px;
  z-index: 2147483640;
  display: none;
  align-items: center;
  gap: 8px;
  min-width: 68px;
  height: 42px;
  padding: 0 15px 0 9px;
  border: 1px solid #7aa2ef;
  border-radius: 999px;
  background: linear-gradient(145deg, #5267e8, #7456e8);
  color: #fff;
  box-shadow: 0 12px 32px rgba(22, 33, 76, 0.42);
  font: 700 14px/1 system-ui, sans-serif;
  cursor: pointer;
  touch-action: none;
}

.ai-chat-launcher.enabled { display: inline-flex; }
.ai-chat-launcher:hover { transform: translateY(-2px); filter: brightness(1.08); }
.ai-chat-launcher.dragging { cursor: grabbing; transform: none; filter: brightness(1.08); user-select: none; }
.ai-chat-launcher.active { opacity: 0; pointer-events: none; }
.ai-chat-launcher-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  font-size: 12px;
}

.ai-chat-panel {
  --chat-bg: #1b2638;
  --chat-surface: #223149;
  --chat-field: #26364f;
  --chat-border: #4d668d;
  --chat-text: #edf4ff;
  --chat-muted: #aebdd3;
  position: fixed;
  left: auto;
  right: 20px;
  bottom: 20px;
  z-index: 2147483647;
  display: none;
  flex-direction: column;
  width: min(520px, calc(100vw - 40px));
  height: min(1080px, calc(100dvh - 36px));
  min-width: min(280px, calc(100vw - 12px));
  min-height: min(320px, calc(100vh - 12px));
  overflow: hidden;
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  background: var(--chat-bg);
  color: var(--chat-text);
  box-shadow: 0 24px 70px rgba(0,0,0,0.48);
  font: 14px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

.ai-chat-panel.open { display: flex; animation: ai-chat-open 150ms ease-out; }
.ai-chat-panel:popover-open {
  display: flex;
  margin: 0;
}
.ai-chat-panel::backdrop {
  background: transparent;
  pointer-events: none;
}
.ai-chat-panel.layout-popup { resize: none; }
.ai-chat-panel.layout-popup.dragging { user-select: none; }
.ai-chat-panel.layout-popup.resizing { user-select: none; }
.ai-chat-resize-handle {
  position: absolute;
  z-index: 45;
  display: none;
  touch-action: none;
}
.ai-chat-panel.layout-popup .ai-chat-resize-handle { display: block; }
.ai-chat-resize-handle.is-n,
.ai-chat-resize-handle.is-s { left: 14px; right: 14px; height: 8px; }
.ai-chat-resize-handle.is-e,
.ai-chat-resize-handle.is-w { top: 14px; bottom: 14px; width: 8px; }
.ai-chat-resize-handle.is-n { top: 0; cursor: n-resize; background: linear-gradient(to bottom, rgba(45,212,191,.7), transparent 2px); }
.ai-chat-resize-handle.is-s { bottom: 0; cursor: s-resize; background: linear-gradient(to top, rgba(45,212,191,.7), transparent 2px); }
.ai-chat-resize-handle.is-w { left: 0; cursor: w-resize; background: linear-gradient(to right, rgba(45,212,191,.7), transparent 2px); }
.ai-chat-resize-handle.is-e { right: 0; cursor: e-resize; background: linear-gradient(to left, rgba(45,212,191,.7), transparent 2px); }
.ai-chat-resize-handle.is-ne,
.ai-chat-resize-handle.is-se,
.ai-chat-resize-handle.is-sw,
.ai-chat-resize-handle.is-nw { width: 16px; height: 16px; }
.ai-chat-resize-handle.is-ne { top: 0; right: 0; cursor: ne-resize; border-top: 2px solid #2dd4bf; border-right: 2px solid #2dd4bf; }
.ai-chat-resize-handle.is-se { right: 0; bottom: 0; cursor: se-resize; border-right: 2px solid #2dd4bf; border-bottom: 2px solid #2dd4bf; }
.ai-chat-resize-handle.is-sw { bottom: 0; left: 0; cursor: sw-resize; border-bottom: 2px solid #2dd4bf; border-left: 2px solid #2dd4bf; }
.ai-chat-resize-handle.is-nw { top: 0; left: 0; cursor: nw-resize; border-top: 2px solid #2dd4bf; border-left: 2px solid #2dd4bf; }
.ai-chat-resize-handle:hover { filter: brightness(1.45); }
body.ai-chat-popup-resizing { cursor: default; user-select: none; }
@keyframes ai-chat-open { from { opacity: 0; transform: translateX(-18px) scale(.98); } to { opacity: 1; transform: none; } }

.ai-chat-dock-slot {
  box-sizing: border-box;
  position: fixed;
  z-index: 2147483646;
  top: 0;
  right: 0;
  bottom: 0;
  display: none;
  width: min(380px, calc(100vw - 24px));
  min-width: min(340px, calc(100vw - 24px));
  height: 100vh;
  overflow: visible;
  border: 0;
  border-left: 1px solid #3d5273;
  background: #182234;
}
.ai-chat-dock-slot.active { display: block; }
.ai-chat-dock-slot:popover-open {
  inset: 0 0 0 auto;
  display: block;
  margin: 0;
  padding: 0;
  height: 100dvh;
  outline: 0;
}
.ai-chat-dock-slot::backdrop {
  background: transparent;
  pointer-events: none;
}
.ai-chat-dock-resizer {
  position: absolute;
  z-index: 4;
  top: 0;
  bottom: 0;
  left: -5px;
  width: 9px;
  background: linear-gradient(90deg, #182234 0 5px, transparent 5px);
  cursor: col-resize;
}
.ai-chat-dock-resizer:hover::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 2px;
  background: #7aa2ef;
}
.ai-chat-panel.layout-dock {
  position: relative;
  inset: auto;
  z-index: 1;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  resize: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.ai-chat-panel.layout-dock #ai-chat-header-model { display: block; }
.ai-chat-panel.layout-dock .ai-chat-header strong { font-size: 14px; white-space: nowrap; }
.ai-chat-panel.layout-fullscreen {
  position: fixed;
  inset: 8px;
  z-index: 2147483645;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  resize: none;
  border-radius: 13px;
}
body.ai-chat-fullscreen-open { overflow: hidden; }

/* Only right Dock reserves page space. Popup/fullscreen live in the browser top layer. */
html.ai-chat-page-pushed body {
  width: calc(100vw - var(--ai-chat-page-push, 0px)) !important;
  min-width: 0 !important;
  background-color: #111827 !important;
  transition: width 160ms ease;
}
html.ai-chat-page-pushed {
  background-color: #111827 !important;
}
html.ai-chat-page-pushed body > :not(#ai-chat-panel):not(#ai-chat-launcher):not(#ai-chat-dock-slot) {
  max-width: calc(100vw - var(--ai-chat-page-push, 0px)) !important;
}
html.ai-chat-page-pushed .ai-chat-panel.layout-popup {
  right: 8px;
}

.ai-chat-shell { position: relative; display: flex; flex: 1; min-width: 0; min-height: 0; }
.ai-chat-main { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; }
.ai-chat-history-sidebar {
  position: relative;
  display: none;
  container-type: inline-size;
  container-name: ai-chat-history;
  width: min(var(--ai-chat-history-width, 270px), 82%);
  min-width: 140px;
  flex: 0 0 min(var(--ai-chat-history-width, 270px), 82%);
  flex-direction: column;
  border-right: 1px solid var(--chat-border);
  background: #172235;
}
.ai-chat-panel.layout-fullscreen .ai-chat-history-sidebar { display: flex; }
.ai-chat-panel.layout-dock.dock-history-visible .ai-chat-history-sidebar {
  display: flex;
  width: min(var(--ai-chat-history-width, 270px), calc(100% - 180px));
  min-width: 140px;
  flex-basis: min(var(--ai-chat-history-width, 270px), calc(100% - 180px));
}
.ai-chat-panel.history-force-open .ai-chat-history-sidebar { display: flex !important; }
.ai-chat-panel.history-force-closed .ai-chat-history-sidebar { display: none !important; }
.ai-chat-panel.layout-popup.history-force-open .ai-chat-history-sidebar,
.ai-chat-panel.layout-dock.history-force-open:not(.dock-history-visible) .ai-chat-history-sidebar {
  position: relative;
  width: min(var(--ai-chat-history-width, 270px), calc(100% - 180px));
  min-width: 140px;
  flex-basis: min(var(--ai-chat-history-width, 270px), calc(100% - 180px));
  box-shadow: none;
}
.ai-chat-history-head { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-bottom: 1px solid var(--chat-border); }
.ai-chat-history-head strong { color: #e4edfb; font-size: 13px; }
.ai-chat-history-head button {
  width: 28px;
  height: 28px;
  border: 1px solid #58729a;
  border-radius: 7px;
  background: #2a3f5d;
  color: #fff;
  cursor: pointer;
}
.ai-chat-history-list { flex: 1; min-height: 0; overflow-y: auto; padding: 8px; }
.ai-chat-history-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 9px; border-top: 1px solid var(--chat-border); }
.ai-chat-history-footer button { min-height: 34px; border: 1px solid #58729a; border-radius: 7px; background: #2a3f5d; color: #e8f1ff; font-size: 10px; font-weight: 700; cursor: pointer; }
.ai-chat-history-footer button:hover { background: #365578; }
.ai-chat-history-footer button.danger:hover { border-color: #ef5b67; background: #8b2635; color: #fff; }
@container ai-chat-history (max-width: 235px) {
  .ai-chat-history-footer { grid-template-columns: 1fr; }
}
.ai-chat-history-empty { padding: 12px 5px; color: var(--chat-muted); font-size: 11px; text-align: center; }
.ai-chat-history-item {
  position: relative;
  display: grid;
  width: 100%;
  gap: 3px;
  margin-bottom: 5px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #d8e3f4;
  text-align: left;
  cursor: pointer;
}
.ai-chat-history-item:hover { background: #22324a; }
.ai-chat-history-item.active { border-color: #5f78aa; background: #293c59; }
.ai-chat-history-title { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.ai-chat-history-item small { color: #8fa3bf; font-size: 9px; }
.ai-chat-history-actions { display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.ai-chat-history-action { min-width: 25px; height: 24px; padding: 0 6px; border: 0; border-radius: 5px; background: transparent; color: #b7c6db; cursor: pointer; }
.ai-chat-history-action:hover { background: #344b69; color: #fff; }
.ai-chat-history-action svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.ai-chat-history-delete { margin-left: 0; color: #ffb0b7; font: normal 16px/1 sans-serif; }
.ai-chat-history-delete:hover { background: #b42336; color: #fff; }
.ai-chat-history-rename-form { display: grid; gap: 7px; margin-top: 6px; padding-top: 8px; border-top: 1px solid #49617f; cursor: default; }
.ai-chat-history-rename-form input { width: 100%; min-width: 0; height: 31px; padding: 5px 7px; border: 1px solid #6984aa; border-radius: 6px; background: #101a2a; color: #fff; box-sizing: border-box; }
.ai-chat-history-rename-form > div { display: flex; justify-content: flex-end; gap: 5px; }
.ai-chat-history-rename-form button { min-width: 48px; height: 27px; border: 1px solid #607ca5; border-radius: 5px; background: #31557c; color: #fff; cursor: pointer; }
.ai-chat-history-rename-form button.cancel { background: #334155; }

.ai-chat-header {
  position: relative;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--chat-border);
  background: linear-gradient(135deg, #283b59, #2d3559);
}
.ai-chat-panel.layout-popup .ai-chat-header { cursor: move; touch-action: none; }
.ai-chat-panel.layout-popup .ai-chat-header button { cursor: pointer; }
.ai-chat-header > div:first-child { min-width: 0; display: flex; flex-direction: column; }
.ai-chat-header strong { font-size: 16px; color: #fff; }
.ai-chat-header-model { display: block; }
#ai-chat-header-model { overflow: hidden; color: #b9c9e0; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.ai-chat-header-actions { display: flex; gap: 5px; }
.ai-chat-header-actions:not(.menu-open) > :not(#ai-chat-header-menu-toggle):not(#ai-chat-close):not(#ai-chat-mobile-expand) { display: none !important; }
#ai-chat-header-menu-toggle[aria-expanded="true"] { border-color: #5eead4; background: #0d5967; }
.ai-chat-header .ai-chat-icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 32px;
  min-width: 32px;
  padding: 4px 6px;
}
.ai-chat-header .ai-chat-icon-action.active { border-color: #8faeff; background: #50698f; color: #fff; }
.ai-chat-icon-action svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ai-chat-action-label,
.ai-chat-menu-caret { display: none; }
.ai-chat-panel.layout-fullscreen .ai-chat-header .ai-chat-icon-action { width: auto; min-width: 34px; padding: 4px 9px; }
.ai-chat-panel.layout-fullscreen .ai-chat-action-label,
.ai-chat-panel.layout-fullscreen .ai-chat-menu-caret { display: inline; }
.ai-chat-layout-menu-wrap { position: relative; }
.ai-chat-layout-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  right: 0;
  display: none;
  width: 270px;
  gap: 5px;
  padding: 8px;
  border: 1px solid #617aa3;
  border-radius: 9px;
  background: #1e2c43;
  box-shadow: 0 12px 28px rgba(0,0,0,.42);
}
.ai-chat-layout-menu.open { display: grid; }
.ai-chat-layout-menu-hint {
  padding: 4px 8px 2px;
  color: #9eb0cc;
  font-size: 11px;
  line-height: 1.35;
}
.ai-chat-layout-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
}
.ai-chat-layout-label { min-width: 0; }
.ai-chat-start-badge {
  flex-shrink: 0;
  min-width: 52px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid #5b7196;
  background: #24344f;
  color: #9eb0cc;
  font-size: 10px;
  font-weight: 800;
  text-align: center;
}
.ai-chat-start-badge.on {
  border-color: #5eead4;
  background: rgba(45, 212, 191, 0.16);
  color: #5eead4;
}
.ai-chat-layout-menu button.start-on {
  box-shadow: inset 0 0 0 1px rgba(94, 234, 212, 0.35);
}
.ai-chat-set-start-layout {
  margin-top: 2px;
  border-top: 1px solid #3d5477 !important;
  border-radius: 0 0 8px 8px !important;
  color: #c7d7f2 !important;
  font-weight: 700 !important;
}
.ai-chat-layout-menu kbd {
  flex: 0 0 auto;
  padding: 1px 5px;
  border: 1px solid rgba(174, 193, 222, .45);
  border-radius: 4px;
  background: rgba(9, 16, 29, .35);
  color: #c9d7ea;
  font: 700 10px/1.5 system-ui, sans-serif;
}
.ai-chat-layout-menu button.active { background: #5364cc; color: #fff; }
.ai-chat-answer-font-size {
  display: grid;
  gap: 7px;
  padding: 9px 10px;
  border: 1px solid #3d5477;
  border-radius: 8px;
  background: rgba(20, 34, 56, .55);
  color: #c7d7f2;
  font-size: 11px;
  font-weight: 700;
}
.ai-chat-answer-font-head { display: flex; align-items: center; justify-content: space-between; min-width: 0; }
.ai-chat-answer-font-head span { white-space: nowrap; }
.ai-chat-answer-font-controls { display: grid; grid-template-columns: 30px minmax(0, 1fr) 30px; align-items: center; gap: 9px; min-width: 0; }
.ai-chat-answer-font-size input { width: 100%; min-width: 0; margin: 0; accent-color: #5eead4; cursor: pointer; }
.ai-chat-answer-font-size .ai-chat-font-size-step {
  width: 30px;
  min-width: 30px;
  min-height: 30px;
  padding: 0;
  border-color: #5c769e;
  border-radius: 5px;
  background: #263c59;
  color: #dce9fb;
  font-size: 16px;
  line-height: 1;
}
.ai-chat-answer-font-size .ai-chat-font-size-step:hover { border-color: #5eead4; color: #5eead4; }
.ai-chat-answer-font-size output { min-width: 38px; color: #5eead4; font-variant-numeric: tabular-nums; text-align: right; }
.ai-chat-header button,
.ai-chat-provider-row button,
.ai-chat-compose-actions button,
.ai-chat-question-actions button,
.ai-chat-message-actions button,
.ai-chat-insert-wrap > summary {
  border: 1px solid #627ca5;
  border-radius: 7px;
  background: #304663;
  color: #eaf2ff;
  cursor: pointer;
}
.ai-chat-header button { min-height: 29px; padding: 4px 8px; font-size: 12px; }
#ai-chat-close { min-width: 30px; font-size: 19px; line-height: 1; }
.ai-chat-header button:hover,
.ai-chat-provider-row button:hover,
.ai-chat-compose-actions button:hover,
.ai-chat-question-actions button:hover,
.ai-chat-message-actions button:hover,
.ai-chat-insert-wrap > summary:hover { background: #3c587e; }

.ai-chat-provider-row {
  display: grid;
  grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr) 34px;
  gap: 7px;
  align-items: end;
  padding: 10px 11px 7px;
  background: var(--chat-surface);
}
.ai-chat-provider-toggle {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 32px;
  gap: 7px;
  padding: 6px 11px;
  border: 0;
  border-bottom: 1px solid rgba(77,102,141,.55);
  background: #1f2e45;
  color: #c7d5e8;
  text-align: left;
  cursor: pointer;
}
.ai-chat-provider-toggle:hover { background: #293c58; }
.ai-chat-provider-toggle > span:first-child { flex: 0 0 10px; color: #88aaf0; }
#ai-chat-provider-summary { min-width: 0; flex: 1; overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.ai-chat-provider-toggle small { flex: 0 0 auto; color: #8fa5c2; font-size: 9px; }
.ai-chat-fast-limits {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 5px 8px;
  border-bottom: 1px solid rgba(77,102,141,.55);
  background: #142238;
  color: #9fb2cd;
  font-size: 10px;
  font-weight: 700;
}
.ai-chat-fast-limits label { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.ai-chat-fast-limits input {
  width: 62px;
  height: 24px;
  padding: 2px 5px;
  border: 1px solid #456184;
  border-radius: 4px;
  background: #0d1727;
  color: #f1f5f9;
  font: 700 11px/1 system-ui, sans-serif;
  text-align: right;
}
.ai-chat-fast-limits input:focus { outline: 2px solid #4f8cff; outline-offset: 1px; }
.ai-chat-layout-fast-limits {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding: 9px 10px;
  border: 1px solid #3d5477;
  border-radius: 7px;
  background: rgba(20, 34, 56, .55);
}
.ai-chat-layout-fast-limits label { display: grid; grid-template-columns: 1fr; align-items: stretch; gap: 5px; min-width: 0; }
.ai-chat-layout-fast-limits input { width: 100%; height: 30px; box-sizing: border-box; }
.ai-chat-layout-fast-limits label:last-child { position: relative; }
.ai-chat-layout-fast-limits label:last-child span { position: absolute; right: 7px; bottom: 7px; color: #8fa3bf; }
.ai-chat-layout-fast-limits label:last-child input { padding-right: 20px; }
.ai-chat-provider-controls.collapsed { display: none; }
.ai-chat-provider-row label { min-width: 0; color: var(--chat-muted); font-size: 11px; }
.ai-chat-provider-row select {
  display: block;
  width: 100%;
  height: 34px;
  margin-top: 3px;
  padding: 4px 7px;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  border-radius: 7px;
  background: var(--chat-field);
  color: var(--chat-text);
  font-size: 12px;
  text-overflow: ellipsis;
}
.ai-chat-provider-row select:disabled { opacity: 1; color: #cfe0fa; -webkit-text-fill-color: #cfe0fa; }
.ai-chat-provider-row button { width: 34px; height: 34px; padding: 0; font-size: 18px; }
.ai-chat-writing-style-row {
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, 170px) auto auto;
  gap: 10px;
  align-items: end;
  justify-content: start;
  padding: 3px 11px 10px;
  background: var(--chat-surface);
}
.ai-chat-insert-expand-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 7px;
  color: var(--chat-muted);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.ai-chat-insert-expand-toggle input { margin: 0; accent-color: var(--chat-accent, #6366f1); }
.ai-chat-writing-style-row label { min-width: 0; color: var(--chat-muted); font-size: 11px; }
.ai-chat-writing-style-row select {
  display: block;
  width: 100%;
  height: 34px;
  margin-top: 3px;
  padding: 4px 7px;
  border: 1px solid var(--chat-border);
  border-radius: 7px;
  background: var(--chat-field);
  color: var(--chat-text);
  font-size: 12px;
}
.ai-chat-compatible-generation-settings {
  margin: 0 11px 10px;
  padding: 8px;
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  background: var(--chat-field);
  color: var(--chat-muted);
  font-size: 11px;
}
.ai-chat-compatible-generation-settings summary { cursor: pointer; font-weight: 800; color: var(--chat-text); }
.ai-chat-compatible-generation-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 105px), 1fr)); gap: 7px; margin-top: 8px; }
.ai-chat-compatible-generation-grid label { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.ai-chat-compatible-generation-grid input {
  width: 100%; min-width: 0; max-width: 100%; height: 30px; box-sizing: border-box; padding: 4px 6px;
  border: 1px solid var(--chat-border); border-radius: 6px; background: var(--chat-surface); color: var(--chat-text);
}
.ai-chat-compatible-generation-grid small { color: var(--chat-muted); font-size: 9px; }
#ai-chat-compatible-generation-save {
  width: 100%; min-height: 31px; margin-top: 8px; border: 1px solid #4f8cff; border-radius: 7px;
  background: #164e86; color: #fff; font-size: 11px; font-weight: 800; cursor: pointer;
}
@media (max-width: 700px) { .ai-chat-compatible-generation-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.ai-chat-mode-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 8px 1px 1px;
  background: transparent;
}
.ai-chat-mode-row > span { color: var(--chat-muted); font-size: 11px; white-space: nowrap; }
.ai-chat-mode-row button {
  min-height: 29px;
  padding: 4px 9px;
  border: 1px solid #536b91;
  border-radius: 7px;
  background: #293b55;
  color: #c9d7ea;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.ai-chat-mode-row button:hover { background: #344b6c; }
.ai-chat-mode-row button:disabled { opacity: .55; cursor: default; }
.ai-chat-mode-row button.active {
  border-color: #849cff;
  background: #4f5fc5;
  color: #fff;
  box-shadow: 0 0 0 2px rgba(113,135,255,.16);
}
.ai-chat-reasoning-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 29px;
  padding: 3px 8px;
  border: 1px solid #536b91;
  border-radius: 7px;
  background: #22334b;
  color: #c9d7ea;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.ai-chat-reasoning-toggle:hover { background: #2d4260; }
.ai-chat-reasoning-toggle input { margin: 0; accent-color: #778cff; }
.ai-chat-reasoning-toggle:has(input:checked) {
  border-color: #849cff;
  background: #35447f;
  color: #fff;
}
.ai-chat-reasoning-toggle:has(input:disabled) { opacity: .55; cursor: default; }
.ai-chat-fast-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 29px;
  padding: 3px 8px;
  border: 1px solid #536b91;
  border-radius: 7px;
  background: #172c3a;
  color: #bdeef2;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}
.ai-chat-history-head-tools { display: flex; align-items: center; gap: 6px; }
.ai-chat-history-head .ai-chat-history-close { font-size: 19px; line-height: 1; }
.ai-chat-history-head .ai-chat-history-close:hover { border-color: #d87882; background: #63323d; }
.ai-chat-history-resizer {
  position: absolute;
  z-index: 3;
  top: 0;
  right: -4px;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  touch-action: none;
}
.ai-chat-history-resizer::after {
  position: absolute;
  top: 0;
  right: 3px;
  bottom: 0;
  width: 2px;
  background: transparent;
  content: '';
}
.ai-chat-history-resizer:hover::after,
.ai-chat-history-resizer.dragging::after { background: #60a5fa; }
body.ai-chat-history-resizing { cursor: ew-resize !important; user-select: none !important; }
.ai-chat-fast-toggle input { margin: 0; accent-color: #14b8a6; }
.ai-chat-fast-toggle:has(input:checked) { border-color: #2dd4bf; background: #0f5e5a; color: #fff; box-shadow: 0 0 0 2px rgba(45,212,191,.16); }
.ai-chat-fast-toggle:has(input:disabled) { opacity: .55; cursor: default; }
.ai-chat-mode-row .ai-chat-academic-toggle.active {
  border-color: #55c7a0;
  background: #236751;
  color: #e4fff6;
  box-shadow: 0 0 0 2px rgba(85,199,160,.15);
}
.ai-chat-reasoning-toggle:not(:has(span)) { width: 29px; padding: 0; }
.ai-chat-mode-row .ai-chat-internet-toggle.active {
  border-color: #54b9e8;
  background: #17658a;
  color: #effaff;
  box-shadow: 0 0 0 2px rgba(84,185,232,.16);
}
.ai-chat-academic-count-wrap {
  display: none;
  align-items: center;
  gap: 4px;
  color: var(--chat-muted);
  cursor: default;
  font-size: 10px;
  white-space: nowrap;
}
.ai-chat-academic-count-wrap.visible { display: inline-flex; }
.ai-chat-academic-count-wrap select,
.ai-chat-academic-count-wrap input {
  height: 28px;
  padding: 2px 4px;
  border: 1px solid #536b91;
  border-radius: 6px;
  background: var(--chat-field);
  color: var(--chat-text);
  font-size: 10px;
}
.ai-chat-academic-count-wrap input {
  width: 58px;
  box-sizing: border-box;
  text-align: center;
}
.ai-chat-academic-count-wrap.editing select { display: none; }
.ai-chat-academic-count-wrap input[hidden] { display: none; }
.ai-chat-mode-row small {
  flex: 1 1 100%;
  width: 100%;
  min-width: 0;
  margin: 1px 0 0;
  color: #9dafc7;
  font-size: 9px;
  text-align: right;
}

.ai-chat-composer .ai-chat-mode-row { border: 0; }
.ai-chat-document-write-row { display: inline-flex; align-items: center; gap: 7px; }
.ai-chat-document-write-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-width: 58px; min-height: 30px; padding: 4px 7px; border: 1px solid #367b78; border-radius: 8px; background: #123c3c; color: #bff7ef; font-size: 17px; line-height: 1; cursor: pointer; }
.ai-chat-document-write-toggle input { width: 15px; height: 15px; margin: 0; accent-color: #14b8a6; cursor: pointer; }
.ai-chat-document-write-toggle:has(input:checked) { border-color: #2dd4bf; background: #0f766e; color: #fff; box-shadow: 0 0 0 2px rgba(45,212,191,.15); }
.ai-chat-document-write-row select { width: 48px; min-height: 30px; padding: 4px 5px; border: 1px solid #47647b; border-radius: 7px; background: #172b3b; color: #d9edf3; font-size: 16px; font-weight: 800; text-align: center; cursor: pointer; }
.ai-chat-sentence-only { width: 17px; height: 17px; margin: 0; accent-color: #14b8a6; cursor: pointer; }
body.theme-light .ai-chat-document-write-toggle { border-color: #48484a; background: #2c2c2e; color: #d1d1d6; box-shadow: none; }
body.theme-light .ai-chat-document-write-toggle:hover { background: #3a3a3c; }
body.theme-light .ai-chat-document-write-toggle:has(input:checked) { border-color: #2dd4bf; background: #0f766e; color: #fff; box-shadow: 0 0 0 2px rgba(45,212,191,.18); }
body.theme-light .ai-chat-document-write-row select { border-color: #48484a; background: #2c2c2e; color: #f5f5f7; }
.ai-chat-document-answer-record { margin-top: 7px; border: 1px solid #315e60; border-radius: 9px; background: rgba(15,118,110,.12); }
.ai-chat-document-answer-record > summary { padding: 9px 11px; color: #9de9df; font-size: 11px; font-weight: 700; cursor: pointer; }
.ai-chat-document-answer-record[open] > summary { border-bottom: 1px solid #315e60; }
.ai-chat-document-answer-record > .ai-chat-message-content { margin: 8px; }
body.theme-light .ai-chat-document-answer-record { border-color: #9bc9c4; background: #f0faf8; }
body.theme-light .ai-chat-document-answer-record > summary { color: #0f766e; }

.ai-chat-status {
  min-height: 25px;
  padding: 4px 12px 6px;
  border-bottom: 1px solid rgba(77,102,141,.65);
  background: var(--chat-surface);
  color: var(--chat-muted);
  font-size: 11px;
}
.ai-chat-status.ok {
  overflow: hidden;
  color: #76e0b3;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-chat-status.error { color: #ff9da5; }
.ai-chat-status.loading { color: #a9c8ff; }

.ai-chat-lemonade-load-progress {
  padding: 6px 12px 8px;
  border-bottom: 1px solid rgba(77,102,141,.65);
  background: var(--chat-surface);
  color: #cfe1ff;
}
.ai-chat-lemonade-load-progress[hidden] { display: none; }
.ai-chat-lemonade-load-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  font-size: 11px;
  font-weight: 700;
}
.ai-chat-lemonade-load-progress-head strong { color: #8fc5ff; font-variant-numeric: tabular-nums; }
.ai-chat-lemonade-load-progress-actions { display: inline-flex; align-items: center; gap: 7px; }
.ai-chat-lemonade-load-progress-actions button {
  min-height: 22px;
  padding: 2px 7px;
  border: 1px solid #e17878;
  border-radius: 6px;
  background: #722f3a;
  color: #fff1f2;
  font: inherit;
  cursor: pointer;
}
.ai-chat-lemonade-load-progress-actions button:disabled { opacity: .55; cursor: default; }
.ai-chat-lemonade-load-progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(8,18,34,.75);
  box-shadow: inset 0 0 0 1px rgba(126,165,224,.25);
}
.ai-chat-lemonade-load-progress-track > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3b82f6, #22d3ee, #60a5fa);
  background-size: 180% 100%;
  transition: width 450ms ease;
  animation: ai-chat-lemonade-progress-shimmer 1.4s linear infinite;
}
@keyframes ai-chat-lemonade-progress-shimmer { to { background-position: -180% 0; } }

.ai-chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px;
  background: radial-gradient(circle at top right, rgba(82,103,232,.12), transparent 38%), var(--chat-bg);
}
.ai-chat-empty { display: grid; place-items: center; align-content: center; height: 100%; color: var(--chat-muted); text-align: center; }
.ai-chat-empty strong { color: #dce8fa; font-size: 17px; }
.ai-chat-empty span { margin-top: 5px; font-size: 12px; }
.ai-chat-message { width: fit-content; max-width: 88%; margin: 0 0 12px; }
.ai-chat-message.user { margin-left: auto; }
.ai-chat-message-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 8px; margin: 0 3px 3px; color: var(--chat-muted); font-size: 11px; }
.ai-chat-message-actions {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  width: 100%;
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px solid rgba(87,111,148,.45);
}
.ai-chat-message-actions > button,
.ai-chat-insert-wrap > summary {
  min-height: 27px;
  padding: 3px 7px;
  border-color: transparent;
  background: transparent;
  color: #a9c8ff;
  font-size: 10px;
  line-height: 1.2;
}
.ai-chat-raw-view-group { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 5px; }
.ai-chat-raw-view-group > button {
  min-height: 27px;
  padding: 3px 7px;
  border-color: transparent;
  background: transparent;
  color: #a9c8ff;
  font-size: 10px;
  line-height: 1.2;
}
.ai-chat-message-actions .ai-chat-markdown-toggle { display: inline-grid; place-items: center; width: 27px; padding: 3px; }
.ai-chat-message-actions .ai-chat-markdown-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.ai-chat-message-actions .ai-chat-markdown-toggle[aria-pressed="true"] { border-color: #6f94ca; background: #314966; color: #fff; }
.ai-chat-message-actions > .ai-chat-answer-delete { color: #ffabb5; }
.ai-chat-message-actions > .ai-chat-answer-delete:hover { border-color: #9a5360; background: #4b303b; color: #ffdce0; }
.ai-chat-insert-control { position: relative; display: inline-flex; flex: 0 0 auto; align-items: stretch; }
.ai-chat-insert-wrap { position: static; display: inline-flex; align-items: stretch; }
.ai-chat-insert-wrap > summary {
  display: flex;
  align-items: center;
  min-height: 25px;
  padding: 2px 7px;
  border-radius: 7px 0 0 7px;
  color: #7ee2b6;
  font-size: 10px;
  list-style: none;
  cursor: pointer;
}
.ai-chat-insert-wrap > summary::-webkit-details-marker { display: none; }
.ai-chat-insert-control > .ai-chat-cursor-insert {
  display: inline-grid;
  place-items: center;
  width: 24px;
  min-height: 25px;
  padding: 2px;
  border: 1px solid #55749b;
  border-left-color: rgba(126,226,182,.55);
  border-radius: 0 7px 7px 0;
  background: #29445e;
  color: #7ee2b6;
  opacity: 1;
  visibility: visible;
}
.ai-chat-insert-control > .ai-chat-cursor-insert svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ai-chat-insert-expanded {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
}
.ai-chat-insert-expanded-label {
  font-size: 10px;
  font-weight: 800;
  color: #7ee2b6;
  margin-right: 2px;
  white-space: nowrap;
}
.ai-chat-message-actions.insert-actions-expanded {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
}
.ai-chat-message-actions.insert-actions-expanded .ai-chat-actions-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  width: 100%;
}
.ai-chat-message-actions.insert-actions-expanded .ai-chat-actions-row > button,
.ai-chat-message-actions.insert-actions-expanded .ai-chat-insert-expanded button {
  min-height: 27px;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: #a9c8ff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
}
.ai-chat-insert-expanded button:hover {
  border-color: #536b91;
  background: rgba(60, 88, 126, 0.45);
}
.ai-chat-insert-menu {
  position: absolute;
  z-index: 12;
  right: 0;
  bottom: calc(100% + 5px);
  display: grid;
  width: 132px;
  padding: 4px;
  border: 1px solid #617aa3;
  border-radius: 8px;
  background: #1b2a40;
  box-shadow: 0 10px 24px rgba(0,0,0,.42);
}
.ai-chat-insert-menu button {
  width: 100%;
  min-height: 25px;
  padding: 4px 6px;
  border-color: transparent;
  background: transparent;
  color: #dce9fa;
  font-size: 10px;
  line-height: 1.25;
  text-align: left;
}
.ai-chat-insert-menu button:hover { background: #344d70; }
.ai-chat-message-content {
  padding: 9px 11px;
  border: 1px solid #465e82;
  border-radius: 11px 11px 11px 3px;
  background: #253650;
  color: #f0f5fd;
  line-height: 1.58;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.ai-chat-message.assistant .ai-chat-message-content { font-size: var(--ai-chat-answer-font-size, 14px); }
.ai-chat-message-content.markdown-rendered { white-space: normal; }
.ai-chat-message-content.markdown-rendered > :first-child { margin-top: 0; }
.ai-chat-message-content.markdown-rendered > :last-child { margin-bottom: 0; }
.ai-chat-message-content.markdown-rendered p,
.ai-chat-message-content.markdown-rendered ul,
.ai-chat-message-content.markdown-rendered ol,
.ai-chat-message-content.markdown-rendered blockquote,
.ai-chat-message-content.markdown-rendered pre { margin: .55em 0; }
.ai-chat-message-content.markdown-rendered blockquote { padding-left: .85em; border-left: 3px solid currentColor; opacity: .88; }
.ai-chat-message-content.markdown-rendered pre {
  overflow-x: hidden;
  padding: 8px;
  border-radius: 6px;
  background: rgba(8,16,30,.38);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ai-chat-message-content.markdown-rendered code,
.ai-chat-message-content.markdown-source { font-family: Consolas, "Courier New", monospace; }
.ai-chat-message.user .ai-chat-message-content { border-color: #6f73e5; border-radius: 11px 11px 3px 11px; background: #5055b7; color: #fff; }
.ai-chat-panel.answer-plain-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content {
  border-color: #cbd5e1;
  background: #fff;
  color: #000;
}
.ai-chat-panel.answer-plain-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content.markdown-source {
  border-color: #365173;
  background: #091321;
  color: #e8f0ff;
  box-shadow: inset 0 0 0 1px rgba(111, 148, 202, .12);
}
.ai-chat-message.user.failed .ai-chat-message-content { border-style: dashed; opacity: .72; }
.ai-chat-continuation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  padding: 8px 9px;
  border: 1px solid #8a6d3b;
  border-radius: 8px;
  background: #3a3021;
  color: #ffe4aa;
  font-size: 10px;
}
.ai-chat-continuation > span { flex: 1 1 190px; }
.ai-chat-continuation-suggestion-label {
  flex: 1 1 100%;
  color: #ffd889;
  font-size: 10px;
}
.ai-chat-auto-continue {
  display: inline-flex;
  flex: 1 1 100%;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  color: #fff0bd;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}
.ai-chat-auto-continue input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: #e3a72f;
}
.ai-chat-auto-continue input:disabled { cursor: not-allowed; opacity: .6; }
.ai-chat-continuation-directive {
  flex: 1 1 100%;
  min-width: 0;
  min-height: 48px;
  box-sizing: border-box;
  resize: vertical;
  padding: 7px 8px;
  border: 1px solid #8b6b2f;
  border-radius: 7px;
  background: rgba(12,24,42,.82);
  color: #eef5ff;
  font: inherit;
  line-height: 1.4;
}
.ai-chat-continuation-directive::placeholder { color: #a9b5c8; }
.ai-chat-continuation button {
  min-height: 27px;
  padding: 4px 8px;
  border: 1px solid #d6a84d;
  border-radius: 6px;
  background: #9a6820;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}
.ai-chat-continuation button.secondary { border-color: #6b7890; background: #33445d; color: #dce7f8; }
.ai-chat-continuation button:disabled { opacity: .55; cursor: not-allowed; }
.ai-chat-response-notice {
  display: grid;
  gap: 4px;
  margin-top: 7px;
  padding: 9px 10px;
  border: 1px solid #657b9b;
  border-radius: 8px;
  background: #202f44;
  color: #cbd8ea;
  font-size: 10px;
  line-height: 1.5;
}
.ai-chat-response-notice strong { color: #9fc5ff; font-size: 11px; }
.ai-chat-message.user.has-academic-sources { width: 100%; max-width: 100%; }
.ai-chat-message.user.has-academic-sources > .ai-chat-message-content { width: fit-content; max-width: 88%; margin-left: auto; }
.ai-chat-question-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 5px;
}
.ai-chat-question-actions button {
  min-height: 25px;
  padding: 3px 7px;
  border-color: transparent;
  background: transparent;
  color: #b7cbec;
  font-size: 10px;
}
.ai-chat-question-actions button:disabled { opacity: .45; cursor: default; }
.ai-chat-question-actions .ai-chat-question-delete { color: #ffabb5; }
.ai-chat-question-actions .ai-chat-question-delete:hover { border-color: #9a5360; background: #4b303b; color: #ffdce0; }
.ai-chat-failed-label { margin-left: auto; color: #ffb4bd; font-size: 9px; }
.ai-chat-message.error .ai-chat-message-content { border-color: #a75361; background: #4b2c38; color: #ffd9dc; }
.ai-chat-answer-label { margin: 1px 3px 4px; color: #b8c9e1; font-size: 10px; font-weight: 700; }
.ai-chat-response-stats {
  margin: 5px 3px 0;
  color: #8fb6aa;
  font-size: 9px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.ai-chat-checklist {
  margin: 0 0 7px;
  overflow: hidden;
  border: 1px solid #5376a8;
  border-radius: 9px;
  background: #1d2c42;
}
.ai-chat-checklist > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 9px; background: #2a405f; }
.ai-chat-checklist strong { color: #cbe0ff; font-size: 11px; }
.ai-chat-checklist button { border: 0; background: transparent; color: #9fc5ff; font-size: 10px; cursor: pointer; }
.ai-chat-checklist > div:last-child { max-height: 210px; overflow: auto; padding: 9px; color: #d3dfef; font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; white-space: pre-wrap; }

.ai-chat-explanation {
  margin: 0 0 7px;
  overflow: hidden;
  border: 1px solid #526b77;
  border-radius: 9px;
  background: #1b2930;
}
.ai-chat-explanation > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 9px; background: #263b44; }
.ai-chat-explanation strong { color: #c8e7ee; font-size: 11px; }
.ai-chat-explanation button { border: 0; background: transparent; color: #9ed7e2; font-size: 10px; cursor: pointer; }
.ai-chat-explanation > div:last-child { padding: 9px; color: #d5e4e8; font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; white-space: pre-wrap; }

.ai-chat-academic-results {
  width: 100%;
  margin-top: 8px;
  overflow: visible;
  border: 1px solid #4f7599;
  border-radius: 9px;
  background: #17273b;
  color: #dce9f8;
}
.ai-chat-academic-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border-bottom: 1px solid #466887;
  background: #213a55;
}
.ai-chat-academic-head strong { color: #d9f8ed; font-size: 11px; }
.ai-chat-academic-head button {
  padding: 3px 7px;
  border: 1px solid #6683a7;
  border-radius: 6px;
  background: #2c4868;
  color: #dceaff;
  font-size: 10px;
  cursor: pointer;
}
.ai-chat-academic-results > p { margin: 0; padding: 6px 9px 0; color: #9fb5cf; font-size: 9px; line-height: 1.45; }
.ai-chat-academic-results > p.ai-chat-academic-warning { color: #ffc978; }
.ai-chat-academic-list { max-height: 270px; overflow-y: auto; padding: 5px 9px 9px; }
.ai-chat-academic-list article { padding: 7px 0; border-bottom: 1px solid rgba(91,119,153,.45); }
.ai-chat-academic-list article:last-child { border-bottom: 0; }
.ai-chat-academic-list article > a,
.ai-chat-academic-list article > strong { display: block; color: #cfe4ff; font-size: 11px; font-weight: 700; line-height: 1.4; }
.ai-chat-academic-list article > a:hover { color: #8fc5ff; text-decoration: underline; }
.ai-chat-academic-list article > span { display: block; margin-top: 3px; color: #91a8c3; font-size: 9px; line-height: 1.4; overflow-wrap: anywhere; }
.ai-chat-academic-list details { margin-top: 4px; }
.ai-chat-academic-list summary { color: #78dbb9; font-size: 9px; cursor: pointer; }
.ai-chat-academic-list details p { max-height: 150px; margin: 5px 0 0; overflow-y: auto; color: #d0dceb; font-size: 10px; line-height: 1.5; white-space: pre-wrap; }
.ai-chat-academic-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  padding: 7px 9px;
  border-top: 1px solid #466887;
  background: #1d3149;
}
.ai-chat-academic-footer > span {
  margin-right: auto;
  color: #a9bdd4;
  font-size: 10px;
  font-weight: 700;
}
.ai-chat-academic-footer button {
  min-height: 27px;
  padding: 4px 7px;
  border: 1px solid #5d789d;
  border-radius: 6px;
  background: #294765;
  color: #dceaff;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}
.ai-chat-academic-footer button:hover { border-color: #72cfaf; background: #285c51; color: #effff9; }

.ai-chat-image-gallery { display: grid; gap: 9px; margin-top: 7px; }
#ai-chat-keep-face-wrap { padding: 5px 0; font-size: 11px; }
#ai-chat-keep-face-wrap[hidden] { display: none; }
.ai-chat-image-gallery figure { margin: 0; overflow: hidden; border: 1px solid #526d96; border-radius: 10px; background: #172337; }
.ai-chat-image-gallery img { display: block; width: auto; height: auto; max-width: 100%; max-height: 520px; margin: 0 auto; object-fit: contain; background: #0d1522; }
.ai-chat-image-dimensions { padding: 7px 9px; color: #beddff; font-size: 11px; text-align: center; }
#ai-chat-lemonade-image-settings { max-height: 320px; overflow-y: auto; overflow-x: hidden; }
#ai-chat-lemonade-image-settings .ai-chat-compatible-generation-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#ai-chat-lemonade-image-settings label { min-width: 0; }
#ai-chat-lemonade-image-settings label:first-child,
#ai-chat-lemonade-image-settings label:last-child { grid-column: 1 / -1; }
#ai-chat-lemonade-image-settings input,
#ai-chat-lemonade-image-settings select { width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; }
.ai-chat-image-action-details > summary { padding: 7px 9px; border-top: 1px solid #526d96; background: #203650; color: #beddff; font-size: 11px; font-weight: 700; cursor: pointer; }
.ai-chat-image-action-details > summary:focus-visible { outline: 2px solid #60a5fa; outline-offset: -2px; }
.ai-chat-generated-image-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ai-chat-image-gallery button, .ai-chat-message-attachments .ai-chat-generated-image-actions button { width: 100%; padding: 7px 9px; border: 0; border-top: 1px solid #526d96; background: #29415f; color: #beddff; font-size: 11px; font-weight: 700; cursor: pointer; }
.ai-chat-generated-image-actions button:nth-child(even) { border-left: 1px solid #526d96; }
.ai-chat-image-gallery button:hover, .ai-chat-message-attachments .ai-chat-generated-image-actions button:hover { background: #365678; }
.ai-chat-image-gallery button:disabled, .ai-chat-message-attachments .ai-chat-generated-image-actions button:disabled { opacity: .55; cursor: wait; }
.ai-chat-panel.image-model-selected .ai-chat-mode-row { border-color: #7b6a34; background: #2b2d3b; }
.ai-chat-panel.image-model-selected .ai-chat-mode-row > span { color: #f2cd71; }

.ai-chat-reasoning {
  margin: 0 0 6px;
  overflow: hidden;
  border: 1px solid #596f94;
  border-radius: 9px;
  background: #1d2b40;
  color: #c4d3e8;
}
.ai-chat-reasoning summary {
  padding: 7px 9px;
  background: #2a3b55;
  color: #b9d2ff;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}
.ai-chat-reasoning-content {
  max-height: 230px;
  overflow: auto;
  padding: 9px;
  border-top: 1px solid rgba(89,111,148,.7);
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.ai-chat-reasoning-content.markdown-rendered { white-space: normal; }
.ai-chat-reasoning-actions {
  box-sizing: border-box;
  margin: 0;
  padding: 7px 8px;
  border-top-color: rgba(89,111,148,.7);
}

.ai-chat-thinking {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 12px;
  padding: 10px 11px;
  border: 1px solid #536d95;
  border-radius: 11px 11px 11px 3px;
  background: linear-gradient(145deg, #243650, #202f47);
  box-shadow: 0 7px 18px rgba(4,10,24,.2);
}
.ai-chat-thinking-head { display: flex; align-items: center; gap: 7px; min-width: 0; }
.ai-chat-thinking-head strong { min-width: 0; color: #dce9ff; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-chat-thinking-orb {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: #8aabff;
  box-shadow: 0 0 0 0 rgba(138,171,255,.55);
  animation: ai-chat-pulse 1.5s ease-out infinite;
}
.ai-chat-thinking-dots { display: inline-flex; align-items: center; gap: 3px; }
.ai-chat-thinking-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #9ab8ed;
  animation: ai-chat-dot 1.1s ease-in-out infinite;
}
.ai-chat-thinking-dots i:nth-child(2) { animation-delay: .16s; }
.ai-chat-thinking-dots i:nth-child(3) { animation-delay: .32s; }
.ai-chat-thinking-elapsed { margin-left: auto; color: #aabbd3; font-size: 10px; font-variant-numeric: tabular-nums; }
.ai-chat-thinking-track {
  height: 6px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #152238;
}
.ai-chat-thinking-track > span {
  position: relative;
  display: block;
  height: 100%;
  min-width: 8%;
  overflow: hidden;
  border-radius: inherit;
  background: linear-gradient(90deg, #6574e8, #8e7bed, #68a8ff);
  transition: width .35s ease;
}
.ai-chat-thinking-track > span::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  animation: ai-chat-shimmer 1.25s linear infinite;
}
.ai-chat-thinking-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 8px;
  margin-top: 7px;
  color: #aebed5;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}
.ai-chat-thinking-metrics span { min-width: 0; overflow-wrap: anywhere; }
.ai-chat-thinking-metrics span:first-child { grid-column: 1 / -1; }
.ai-chat-thinking-metrics span:nth-child(even) { color: #c6b8ff; }
.ai-chat-thinking-metrics span:nth-child(odd):not(:first-child) { text-align: right; color: #9ac8ff; }
.ai-chat-thinking-metrics span:last-child { text-align: right; color: #8fd8bd; }
.ai-chat-live-stream {
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid #536f98;
  border-radius: 8px;
  background: rgba(16,29,48,.72);
}
.ai-chat-live-stream[hidden] { display: none; }
.ai-chat-live-stream > strong {
  display: block;
  padding: 5px 7px;
  border-bottom: 1px solid rgba(83,111,152,.7);
  background: rgba(52,75,110,.6);
  color: #bcd2f4;
  font-size: 10px;
}
.ai-chat-live-stream > div {
  max-height: 190px;
  overflow: auto;
  overflow-anchor: none;
  overscroll-behavior-y: auto;
  scrollbar-gutter: stable;
  padding: 7px;
  color: #cbd8ea;
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.ai-chat-live-stream > div.waiting { color: #91a3bd; font-style: italic; }
.ai-chat-live-stream.answer { border-color: #4c846f; }
.ai-chat-live-stream.answer > strong { border-color: rgba(76,132,111,.75); background: rgba(39,91,72,.62); color: #baf2dd; }
.ai-chat-live-stream.answer > div { color: #e5f4ee; }
.ai-chat-live-stream.answer > div.waiting { color: #91a3bd; }
.ai-chat-thinking small { display: block; margin-top: 6px; color: #91a3bd; font-size: 9px; }
@keyframes ai-chat-pulse { 70% { box-shadow: 0 0 0 7px rgba(138,171,255,0); } 100% { box-shadow: 0 0 0 0 rgba(138,171,255,0); } }
@keyframes ai-chat-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-3px); opacity: 1; } }
@keyframes ai-chat-shimmer { to { transform: translateX(100%); } }

.ai-chat-composer { flex-shrink: 0; padding: 10px; border-top: 1px solid var(--chat-border); background: var(--chat-surface); }
.ai-chat-composer.drag-over { box-shadow: inset 0 0 0 2px #7aa2ef; }
.ai-chat-attachments { display: none; max-height: 220px; margin-bottom: 7px; overflow-y: auto; gap: 7px; }
.ai-chat-attachments.has-items { display: flex; flex-wrap: wrap; }
.ai-chat-attachment-chip { display: flex; align-items: center; gap: 5px; max-width: 100%; padding: 4px 6px; border: 1px solid #58729a; border-radius: 7px; background: #1d2c42; color: #dce8f8; font-size: 10px; }
.ai-chat-attachment-chip.is-image { position: relative; flex: 1 1 150px; flex-direction: column; align-items: stretch; padding: 6px; }
.ai-chat-attachment-chip.is-image img { width: 100%; height: 120px; border-radius: 6px; object-fit: contain; background: #0f1726; cursor: zoom-in; }
.ai-chat-attachment-chip.is-image .ai-chat-attachment-name { max-width: 100%; }
.ai-chat-attachment-chip.is-image button { position: absolute; top: 8px; right: 8px; border-radius: 50%; background: rgba(15,23,38,.82); }
.ai-chat-message.has-attachments { width: min(460px, 96%); max-width: 96%; }
.ai-chat-message-attachments { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 7px; margin: 0 0 7px; }
.ai-chat-message-attachments figure { min-width: 0; margin: 0; overflow: hidden; border: 1px solid #647da4; border-radius: 9px; background: #142035; }
.ai-chat-message-attachments img { display: block; width: 100%; max-height: 320px; min-height: 130px; object-fit: contain; background: #0d1627; cursor: zoom-in; }
.ai-chat-message-attachments figcaption { padding: 5px 7px; overflow: hidden; color: #c9d7eb; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.ai-chat-message-file { padding: 8px 10px; border: 1px solid #647da4; border-radius: 8px; background: #1c2b43; color: #dce8f8; font-size: 11px; }
.ai-chat-attachment-name { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-chat-attachment-chip.is-csv .ai-chat-attachment-name { color: #8dd9ff; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.ai-chat-attachment-chip.is-csv .ai-chat-attachment-name:focus-visible,
.ai-chat-message-file.is-csv:focus-visible { outline: 2px solid #38bdf8; outline-offset: 2px; }
.ai-chat-message-file.is-csv { width: 100%; border: 1px solid #647da4; border-radius: 7px; background: #1d2c42; color: #dce8f8; cursor: pointer; text-align: left; }
.ai-chat-message-file.is-csv:hover { border-color: #38bdf8; background: #243a58; }
.ai-chat-attachment-chip button { width: 20px; height: 20px; padding: 0; border: 0; background: transparent; color: #ffb4bd; font-size: 17px; line-height: 1; cursor: pointer; }
.ai-chat-composer textarea {
  width: 100%;
  min-height: 70px;
  max-height: 180px;
  padding: 9px 10px;
  resize: vertical;
  border: 1px solid #6680a9;
  border-radius: 9px;
  outline: none;
  background: var(--chat-field);
  color: var(--chat-text);
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  box-sizing: border-box;
}
.ai-chat-composer textarea:focus { border-color: #8aabff; box-shadow: 0 0 0 2px rgba(102,139,255,.2); }
.ai-chat-composer textarea::placeholder { color: #9baac0; }
.ai-chat-storage-note { margin-top: 7px; color: var(--chat-muted); font-size: 10px; }
.ai-chat-compose-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 7px; }
.ai-chat-compose-actions span { flex: 1; color: var(--chat-muted); font-size: 10px; }
.ai-chat-compose-actions button { min-width: 52px; min-height: 31px; padding: 5px 10px; font-size: 12px; font-weight: 700; }
.ai-chat-compose-actions button:disabled { opacity: .45; cursor: default; }
.ai-chat-compose-actions .ai-chat-send { border-color: #6e80ff; background: #5965dc; color: #fff; }
.ai-chat-compose-actions .ai-chat-stop { border-color: #8b5360; background: #4b3440; color: #ffccd2; }
.ai-chat-compose-actions .ai-chat-attach { border-color: #6d719c; background: #363a67; color: #e1e4ff; }
.ai-chat-compose-actions .ai-chat-image-gen { border-color: #a869d8; background: #54306f; color: #f2dcff; }
.ai-chat-compose-actions .ai-chat-image-gen:hover { background: #673a88; }
.ai-chat-compose-actions .ai-chat-image-gen.active { border-color: #e3a8ff; background: #8b3fba; color: #fff; box-shadow: 0 0 0 2px rgba(200, 116, 255, .2); }
.ai-chat-compose-actions .ai-chat-import-selection { position: relative; min-width: 96px; border-color: #527b96; background: #29465d; color: #c8ebff; }
.ai-chat-compose-actions .ai-chat-import-selection:hover { background: #355c78; }
.ai-chat-import-selection::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 30;
  right: 0;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: 250px;
  padding: 7px 9px;
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  border: 1px solid #607ca2;
  border-radius: 7px;
  background: #17263a;
  color: #e7f2ff;
  box-shadow: 0 8px 22px rgba(0,0,0,.38);
  font-size: 10px;
  font-weight: 500;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  transform: translateY(4px);
  transition: opacity 110ms ease, transform 110ms ease, visibility 110ms ease;
}
.ai-chat-import-selection:hover::after,
.ai-chat-import-selection:focus-visible::after { visibility: visible; opacity: 1; transform: translateY(0); }

body.theme-light .ai-chat-panel {
  --chat-bg: #f5f7fb;
  --chat-surface: #ffffff;
  --chat-field: #f8fafc;
  --chat-border: #b6c3d6;
  --chat-text: #172033;
  --chat-muted: #64748b;
  color-scheme: light;
  box-shadow: 0 22px 60px rgba(32,46,78,.24);
}
body.theme-light .ai-chat-header { background: linear-gradient(135deg, #e9edff, #f3ecff); }
body.theme-light .ai-chat-header strong { color: #303a8c; }
body.theme-light #ai-chat-header-model { color: #64748b; }
body.theme-light .ai-chat-header button,
body.theme-light .ai-chat-provider-row button,
body.theme-light .ai-chat-compose-actions button,
body.theme-light .ai-chat-question-actions button,
body.theme-light .ai-chat-message-actions > button,
body.theme-light .ai-chat-insert-wrap > summary { background: #eef2ff; border-color: #a5b4fc; color: #3730a3; }
body.theme-light .ai-chat-header .ai-chat-icon-action.active { border-color: #6366f1; background: #4f46c8; color: #fff; }
body.theme-light .ai-chat-import-selection::after { border-color: #aabbd0; background: #fff; color: #334155; box-shadow: 0 8px 22px rgba(30,41,59,.2); }
body.theme-light .ai-chat-insert-menu { border-color: #a8b6cb; background: #fff; box-shadow: 0 10px 24px rgba(30,41,59,.2); }
body.theme-light .ai-chat-insert-menu button { background: transparent; color: #334155; }
body.theme-light .ai-chat-insert-menu button:hover { background: #eef2ff; }
body.theme-light .ai-chat-mode-row button { background: #f8fafc; border-color: #b7c2d4; color: #475569; }
body.theme-light .ai-chat-mode-row button.active { background: #4f46c8; border-color: #4338ca; color: #fff; }
body.theme-light .ai-chat-reasoning-toggle { border-color: #b7c2d4; background: #f8fafc; color: #475569; }
body.theme-light .ai-chat-reasoning-toggle:has(input:checked) { border-color: #6366f1; background: #e0e7ff; color: #3730a3; }
body.theme-light .ai-chat-fast-toggle { border-color: #48484a; background: #2c2c2e; color: #d1d1d6; box-shadow: none; }
body.theme-light .ai-chat-fast-toggle:hover { background: #3a3a3c; }
body.theme-light .ai-chat-fast-toggle:has(input:checked) { border-color: #2dd4bf; background: #0f5e5a; color: #fff; box-shadow: 0 0 0 2px rgba(45,212,191,.18); }
body.theme-light .ai-chat-mode-row .ai-chat-academic-toggle.active { border-color: #0f9f75; background: #0f8a68; color: #fff; }
body.theme-light .ai-chat-mode-row .ai-chat-internet-toggle.active { border-color: #087eb6; background: #087eb6; color: #fff; }
body.theme-light .ai-chat-academic-count-wrap select,
body.theme-light .ai-chat-academic-count-wrap input { border-color: #b7c2d4; background: #fff; color: #334155; }
body.theme-light .ai-chat-mode-row small { color: #64748b; }
body.theme-light .ai-chat-provider-row select,
body.theme-light .ai-chat-writing-style-row select,
body.theme-light .ai-chat-composer textarea { background: #fff; color: #172033; }
body.theme-light .ai-chat-attachment-chip { border-color: #c4cfdf; background: #f3f6fb; color: #27364d; }
body.theme-light .ai-chat-attachment-chip.is-csv .ai-chat-attachment-name { color: #0369a1; }
body.theme-light .ai-chat-message-file.is-csv { border-color: #c4cfdf; background: #f3f6fb; color: #27364d; }
body.theme-light .ai-chat-message-file.is-csv:hover { border-color: #0284c7; background: #e7eef8; }
body.theme-light .ai-chat-message-attachments figure,
body.theme-light .ai-chat-message-file { border-color: #c4cfdf; background: #f3f6fb; color: #27364d; }
body.theme-light .ai-chat-message-attachments figcaption { color: #475569; }
body.theme-light .ai-chat-insert-expand-toggle { color: #475569; }
body.theme-light .ai-chat-insert-expanded-label { color: #0f766e; }
body.theme-light .ai-chat-insert-expanded button { color: #3730a3; }
body.theme-light .ai-chat-insert-expanded button:hover { background: #eef2ff; border-color: #a5b4fc; }
body.theme-light .ai-chat-provider-toggle { border-color: #cbd5e1; background: #f1f5f9; color: #475569; }
body.theme-light .ai-chat-provider-toggle:hover { background: #e2e8f0; }
body.theme-light .ai-chat-message-content { background: #fff; color: #1e293b; border-color: #cbd5e1; }
body.theme-light .ai-chat-message.user .ai-chat-message-content { background: #5b5bd6; color: #fff; border-color: #4f46c8; }
body.theme-light .ai-chat-continuation { border-color: #e0b35d; background: #fff8e8; color: #7a4b00; }
body.theme-light .ai-chat-continuation-suggestion-label { color: #8a5500; }
body.theme-light .ai-chat-continuation-directive { border-color: #d2a34c; background: #fff; color: #334155; }
body.theme-light .ai-chat-continuation-directive::placeholder { color: #64748b; }
body.theme-light .ai-chat-continuation button { border-color: #b7791f; background: #b7791f; color: #fff; }
body.theme-light .ai-chat-continuation button.secondary { border-color: #94a3b8; background: #e2e8f0; color: #334155; }
body.theme-light .ai-chat-response-notice { border-color: #a9bad0; background: #f1f5f9; color: #475569; }
body.theme-light .ai-chat-response-notice strong { color: #3f51b5; }
body.theme-light .ai-chat-response-stats { color: #25705d; }
body.theme-light .ai-chat-question-actions .ai-chat-question-delete { color: #b4233b; }
body.theme-light .ai-chat-question-actions .ai-chat-question-delete:hover { border-color: #e6a5af; background: #fff0f2; color: #981b31; }
body.theme-light .ai-chat-message-actions > .ai-chat-answer-delete { color: #b4233b; }
body.theme-light .ai-chat-message-actions > .ai-chat-answer-delete:hover { border-color: #e6a5af; background: #fff0f2; color: #981b31; }
body.theme-light .ai-chat-empty strong { color: #334155; }
body.theme-light .ai-chat-reasoning { background: #f8fafc; border-color: #b8c5d8; color: #334155; }
body.theme-light .ai-chat-reasoning summary { background: #eef2ff; color: #3730a3; }
body.theme-light .ai-chat-reasoning-content { border-color: #cbd5e1; }
body.theme-light .ai-chat-thinking { background: linear-gradient(145deg, #fff, #f2f5ff); border-color: #aabce0; }
body.theme-light .ai-chat-thinking-head strong { color: #334155; }
body.theme-light .ai-chat-thinking-track { background: #dbe4f2; }
body.theme-light .ai-chat-thinking small,
body.theme-light .ai-chat-thinking-elapsed { color: #64748b; }
body.theme-light .ai-chat-thinking-metrics { color: #64748b; }
body.theme-light .ai-chat-thinking-metrics span:nth-child(even) { color: #5b43a9; }
body.theme-light .ai-chat-thinking-metrics span:nth-child(odd):not(:first-child) { color: #2f5f9c; }
body.theme-light .ai-chat-thinking-metrics span:last-child { color: #08775d; }
body.theme-light .ai-chat-live-stream { border-color: #b3c2dc; background: #f8fafc; }
body.theme-light .ai-chat-live-stream > strong { border-color: #c5d1e4; background: #e8eef8; color: #334155; }
body.theme-light .ai-chat-live-stream > div { color: #334155; }
body.theme-light .ai-chat-live-stream.answer { border-color: #9ccdbd; }
body.theme-light .ai-chat-live-stream.answer > strong { border-color: #acd8c9; background: #e5f5ef; color: #116149; }
body.theme-light .ai-chat-live-stream.answer > div { color: #1f4036; }
body.theme-light .ai-chat-live-stream > div.waiting,
body.theme-light .ai-chat-live-stream.answer > div.waiting { color: #64748b; }
body.theme-light .ai-chat-history-sidebar { background: #f1f5f9; }
body.theme-light .ai-chat-history-head strong { color: #334155; }
body.theme-light .ai-chat-history-item { color: #334155; }
body.theme-light .ai-chat-history-item:hover { background: #e2e8f0; }
body.theme-light .ai-chat-history-item.active { border-color: #818cf8; background: #e0e7ff; }
body.theme-light .ai-chat-layout-menu { border-color: #a5b4fc; background: #fff; }
body.theme-light .ai-chat-checklist { border-color: #a8bce0; background: #f8fafc; }
body.theme-light .ai-chat-checklist > div:first-child { background: #eef2ff; }
body.theme-light .ai-chat-checklist strong { color: #3730a3; }
body.theme-light .ai-chat-checklist > div:last-child { color: #334155; }
body.theme-light .ai-chat-explanation { border-color: #9bb8c1; background: #f8fbfc; }
body.theme-light .ai-chat-explanation > div:first-child { background: #e8f2f5; }
body.theme-light .ai-chat-explanation strong { color: #155e75; }
body.theme-light .ai-chat-explanation > div:last-child { color: #334155; }
body.theme-light .ai-chat-academic-results { border-color: #9ab5d2; background: #f8fafc; color: #334155; }
body.theme-light .ai-chat-academic-head { border-color: #b5c7dd; background: #eaf2fb; }
body.theme-light .ai-chat-academic-head strong { color: #145b4b; }
body.theme-light .ai-chat-academic-head button { border-color: #a7b9cf; background: #fff; color: #334155; }
body.theme-light .ai-chat-academic-results > p { color: #64748b; }
body.theme-light .ai-chat-academic-results > p.ai-chat-academic-warning { color: #9a5b00; }
body.theme-light .ai-chat-academic-list article { border-color: #d5deea; }
body.theme-light .ai-chat-academic-list article > a,
body.theme-light .ai-chat-academic-list article > strong { color: #1e4f82; }
body.theme-light .ai-chat-academic-list article > span { color: #64748b; }
body.theme-light .ai-chat-academic-list summary { color: #08785d; }
body.theme-light .ai-chat-academic-list details p { color: #334155; }
body.theme-light .ai-chat-academic-footer { border-color: #b5c7dd; background: #eef4fa; }
body.theme-light .ai-chat-academic-footer > span { color: #52657b; }
body.theme-light .ai-chat-academic-footer button { border-color: #a5b4c8; background: #fff; color: #334155; }
body.theme-light .ai-chat-academic-footer button:hover { border-color: #0f9f75; background: #e3f7f0; color: #09664e; }
body.theme-light .ai-chat-image-gallery figure { border-color: #a8bce0; background: #fff; }
body.theme-light .ai-chat-image-gallery img { background: #eef2f7; }
body.theme-light .ai-chat-image-gallery button { border-color: #a8bce0; background: #eef2ff; color: #3730a3; }
body.theme-light .ai-chat-panel.image-model-selected .ai-chat-mode-row { background: #fff8df; }

/* Light app theme: keep Jena's answers light, while the surrounding chrome uses
   a restrained Apple-inspired graphite palette. */
body.theme-light .ai-chat-panel {
  --chat-bg: #1c1c1e;
  --chat-surface: #242426;
  --chat-field: #2c2c2e;
  --chat-border: #3a3a3c;
  --chat-text: #f5f5f7;
  --chat-muted: #a1a1a6;
  color-scheme: dark;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .38), 0 0 0 .5px rgba(255, 255, 255, .08);
}
body.theme-light .ai-chat-dock-slot { border-left-color: #3a3a3c; background: #1c1c1e; }
body.theme-light .ai-chat-dock-resizer { background: linear-gradient(90deg, #1c1c1e 0 5px, transparent 5px); }
body.theme-light .ai-chat-header { background: rgba(44, 44, 46, .96); backdrop-filter: saturate(180%) blur(18px); }
body.theme-light .ai-chat-header strong { color: #f5f5f7; letter-spacing: -.01em; }
body.theme-light #ai-chat-header-model,
body.theme-light .ai-chat-mode-row small { color: #98989d; }
body.theme-light .ai-chat-header button,
body.theme-light .ai-chat-provider-row button,
body.theme-light .ai-chat-compose-actions button,
body.theme-light .ai-chat-question-actions button,
body.theme-light .ai-chat-message-actions > button,
body.theme-light .ai-chat-insert-wrap > summary {
  border-color: #48484a;
  background: #323234;
  color: #e5e5ea;
}
body.theme-light .ai-chat-header button:hover,
body.theme-light .ai-chat-provider-row button:hover,
body.theme-light .ai-chat-compose-actions button:hover,
body.theme-light .ai-chat-question-actions button:hover,
body.theme-light .ai-chat-message-actions > button:hover,
body.theme-light .ai-chat-insert-wrap > summary:hover { background: #3a3a3c; }
body.theme-light .ai-chat-header .ai-chat-icon-action.active,
body.theme-light .ai-chat-mode-row button.active { border-color: #409cff; background: #0a84ff; color: #fff; }
body.theme-light .ai-chat-provider-toggle { border-color: #3a3a3c; background: #202022; color: #d1d1d6; }
body.theme-light .ai-chat-provider-toggle:hover { background: #2c2c2e; }
body.theme-light .ai-chat-provider-row select,
body.theme-light .ai-chat-writing-style-row select,
body.theme-light .ai-chat-composer textarea,
body.theme-light .ai-chat-academic-count-wrap select,
body.theme-light .ai-chat-academic-count-wrap input {
  border-color: #48484a;
  background: #2c2c2e;
  color: #f5f5f7;
}
body.theme-light .ai-chat-composer textarea:focus { border-color: #0a84ff; box-shadow: 0 0 0 3px rgba(10,132,255,.18); }
body.theme-light .ai-chat-mode-row button,
body.theme-light .ai-chat-reasoning-toggle { border-color: #48484a; background: #2c2c2e; color: #d1d1d6; }
body.theme-light .ai-chat-reasoning-toggle:has(input:checked) { border-color: #409cff; background: rgba(10,132,255,.22); color: #fff; }
body.theme-light .ai-chat-insert-menu,
body.theme-light .ai-chat-layout-menu { border-color: #48484a; background: #2c2c2e; box-shadow: 0 16px 40px rgba(0,0,0,.4); }
body.theme-light .ai-chat-insert-menu button { color: #e5e5ea; }
body.theme-light .ai-chat-insert-menu button:hover { background: #3a3a3c; }
body.theme-light .ai-chat-import-selection::after { border-color: #48484a; background: #2c2c2e; color: #f5f5f7; box-shadow: 0 12px 30px rgba(0,0,0,.38); }
body.theme-light .ai-chat-messages { background: radial-gradient(circle at top right, rgba(10,132,255,.07), transparent 38%), #1c1c1e; }
body.theme-light .ai-chat-empty strong { color: #f5f5f7; }
body.theme-light .ai-chat-history-sidebar { background: #202022; }
body.theme-light .ai-chat-history-head strong,
body.theme-light .ai-chat-history-item { color: #e5e5ea; }
body.theme-light .ai-chat-history-item:hover { background: #2c2c2e; }
body.theme-light .ai-chat-history-item.active { border-color: #0a84ff; background: rgba(10,132,255,.16); }
body.theme-light .ai-chat-attachment-chip,
body.theme-light .ai-chat-message-attachments figure,
body.theme-light .ai-chat-message-file { border-color: #48484a; background: #2c2c2e; color: #e5e5ea; }
body.theme-light .ai-chat-message-attachments figcaption,
body.theme-light .ai-chat-insert-expand-toggle { color: #a1a1a6; }
body.theme-light .ai-chat-message.user .ai-chat-message-content { border-color: #2997ff; background: #0a84ff; color: #fff; }

/* The assistant answer is intentionally unchanged from the original light mode. */
body.theme-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content {
  border-color: #cbd5e1;
  background: #fff;
  color: #1e293b;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
body.theme-light .ai-chat-reasoning,
body.theme-light .ai-chat-thinking,
body.theme-light .ai-chat-live-stream,
body.theme-light .ai-chat-checklist { border-color: #48484a; background: #242426; color: #d1d1d6; }
body.theme-light .ai-chat-reasoning summary,
body.theme-light .ai-chat-live-stream > strong,
body.theme-light .ai-chat-checklist > div:first-child { border-color: #48484a; background: #2c2c2e; color: #e5e5ea; }
body.theme-light .ai-chat-thinking-head strong,
body.theme-light .ai-chat-checklist strong { color: #e5e5ea; }
body.theme-light .ai-chat-thinking-track { background: #3a3a3c; }
body.theme-light .ai-chat-live-stream > div { color: #d1d1d6; }
body.theme-light .ai-chat-response-notice { border-color: #48484a; background: #2c2c2e; color: #a1a1a6; }
body.theme-light .ai-chat-image-gallery figure { border-color: #48484a; background: #242426; }
body.theme-light .ai-chat-image-gallery img { background: #1c1c1e; }
body.theme-light .ai-chat-image-gallery button { border-color: #48484a; background: #2c2c2e; color: #64d2ff; }
body.theme-light .ai-chat-panel.image-model-selected .ai-chat-mode-row { background: rgba(255,214,10,.08); }

/* Keep Jena's thought/reasoning surface on the clearer dark-blue palette in
   both app themes. The rest of the light-theme answer styling stays intact. */
body.theme-light .ai-chat-reasoning {
  border-color: #596f94;
  background: #1d2b40;
  color: #c4d3e8;
}
body.theme-light .ai-chat-reasoning summary {
  border-color: #596f94;
  background: #2a3b55;
  color: #b9d2ff;
}
body.theme-light .ai-chat-reasoning-content,
body.theme-light .ai-chat-reasoning-actions { border-color: rgba(89,111,148,.7); }
body.theme-light .ai-chat-thinking {
  border-color: #536d95;
  background: linear-gradient(145deg, #243650, #202f47);
  color: #c4d3e8;
}
body.theme-light .ai-chat-thinking-head strong { color: #dce9ff; }
body.theme-light .ai-chat-thinking-elapsed { color: #aabbd3; }
body.theme-light .ai-chat-thinking-track { background: #152238; }
body.theme-light .ai-chat-thinking-metrics { color: #aebed5; }
body.theme-light .ai-chat-thinking-metrics span:nth-child(even) { color: #c6b8ff; }
body.theme-light .ai-chat-thinking-metrics span:nth-child(odd):not(:first-child) { color: #9ac8ff; }
body.theme-light .ai-chat-thinking-metrics span:last-child { color: #8fd8bd; }
body.theme-light .ai-chat-thinking small { color: #91a3bd; }
body.theme-light .ai-chat-live-stream.reasoning {
  border-color: #536f98;
  background: rgba(16,29,48,.72);
}
body.theme-light .ai-chat-live-stream.reasoning > strong {
  border-color: rgba(83,111,152,.7);
  background: rgba(52,75,110,.6);
  color: #bcd2f4;
}
body.theme-light .ai-chat-live-stream.reasoning > div { color: #cbd8ea; }
body.theme-light .ai-chat-live-stream.reasoning > div.waiting { color: #91a3bd; }

@media (prefers-reduced-motion: reduce) {
  .ai-chat-thinking-orb,
  .ai-chat-thinking-dots i,
  .ai-chat-thinking-track > span::after { animation: none; }
}

@media (max-width: 560px) {
  .ai-chat-launcher { right: 12px; bottom: 14px; }
  .ai-chat-panel.layout-popup { right: 8px; bottom: 8px; width: min(320px, calc(100vw - 16px)); height: min(480px, calc(100dvh - 16px)); min-width: min(270px, calc(100vw - 16px)); min-height: 300px; border-radius: 12px; }
  .ai-chat-provider-row { grid-template-columns: minmax(0, 1fr) 34px; }
  .ai-chat-provider-row label:first-child { grid-column: 1 / -1; }
  .ai-chat-writing-style-row { grid-template-columns: minmax(0, 1fr); }
  .ai-chat-insert-expand-toggle { margin-bottom: 0; }
  .ai-chat-mode-row { flex-wrap: wrap; }
  .ai-chat-mode-row small { width: 100%; text-align: left; }
  .ai-chat-panel.layout-fullscreen { inset: 2px; border-radius: 8px; }
  .ai-chat-panel.layout-fullscreen .ai-chat-history-sidebar { position: absolute; z-index: 8; top: 0; bottom: 0; left: 0; width: min(var(--ai-chat-history-width, 270px), 82vw); box-shadow: 8px 0 24px rgba(0,0,0,.4); }
  .ai-chat-dock-slot { min-width: min(360px, 100vw); width: min(360px, 100vw); }
}

/* Mobile Dock is a dedicated bottom pane. It does not cover the document. */
@media (max-width: 700px) {
  .ai-chat-dock-slot,
  .ai-chat-dock-slot:popover-open {
    inset: auto 0 0 0;
    width: 100vw !important;
    min-width: 0;
    height: clamp(300px, 46dvh, 520px);
    border-top: 1px solid #22a7b8;
    border-left: 0;
  }
  .ai-chat-dock-resizer {
    top: -6px;
    right: 0;
    bottom: auto;
    left: 0;
    width: 100%;
    height: 11px;
    background: linear-gradient(180deg, transparent 0 5px, #176b79 5px 7px, transparent 7px);
    cursor: row-resize;
  }
  .ai-chat-dock-resizer:hover::after {
    top: 4px;
    right: 0;
    bottom: auto;
    left: 0;
    width: 100%;
    height: 2px;
  }
  html.ai-chat-mobile-bottom-docked body {
    height: calc(100dvh - var(--ai-chat-mobile-bottom-height, 46dvh)) !important;
    max-height: calc(100dvh - var(--ai-chat-mobile-bottom-height, 46dvh)) !important;
    overflow: auto !important;
  }
  html.ai-chat-mobile-bottom-docked body > :not(#ai-chat-panel):not(#ai-chat-launcher):not(#ai-chat-dock-slot) {
    max-height: calc(100dvh - var(--ai-chat-mobile-bottom-height, 46dvh)) !important;
  }
  .ai-chat-panel.layout-dock { border-radius: 0; }
}

@media print {
  .ai-chat-launcher,
  .ai-chat-panel { display: none !important; }
}

/* AI Jena phone-inspired visual system: deep blue hardware, teal accents, black chat canvas. */
.ai-chat-launcher {
  border-color: #2dd4bf;
  background: linear-gradient(135deg, #082f49 0%, #0c4a6e 52%, #0f766e 100%);
  box-shadow: 0 12px 32px rgba(2, 12, 27, .52), 0 0 0 1px rgba(45, 212, 191, .12);
}

.ai-chat-launcher-icon {
  background: rgba(4, 15, 28, .48);
  box-shadow: inset 0 0 0 1px rgba(153, 246, 228, .24);
}

.ai-chat-panel,
body.theme-light .ai-chat-panel {
  --chat-bg: #000;
  --chat-surface: #07111e;
  --chat-field: #0a1624;
  --chat-border: #176b79;
  --chat-text: #edfafa;
  --chat-muted: #8ba8b5;
  border: 1px solid #22a7b8;
  border-radius: 24px;
  background: #000;
  color: var(--chat-text);
  color-scheme: dark;
  box-shadow:
    0 28px 80px rgba(0, 0, 0, .64),
    0 0 0 3px rgba(4, 18, 31, .92),
    inset 0 0 0 1px rgba(103, 232, 249, .08);
  backdrop-filter: blur(18px) saturate(112%);
}

.ai-chat-panel.layout-popup {
  border-color: rgba(45, 212, 191, .82);
  box-shadow:
    0 30px 90px rgba(0, 0, 0, .68),
    0 0 0 3px rgba(3, 16, 28, .94),
    0 0 34px rgba(13, 148, 136, .13),
    inset 0 0 0 1px rgba(153, 246, 228, .08);
}

.ai-chat-panel::after {
  content: "";
  position: absolute;
  z-index: 30;
  top: 7px;
  left: 50%;
  width: 54px;
  height: 5px;
  border-radius: 999px;
  background: #04111d;
  box-shadow: inset 0 0 0 1px rgba(103, 232, 249, .18), 0 1px 4px rgba(0, 0, 0, .65);
  transform: translateX(-50%);
  pointer-events: none;
}

.ai-chat-panel.layout-dock::after,
.ai-chat-panel.layout-fullscreen::after { display: none; }

.ai-chat-header,
body.theme-light .ai-chat-header {
  padding-top: 18px;
  border-bottom-color: rgba(34, 167, 184, .52);
  background:
    radial-gradient(circle at 85% -60%, rgba(45, 212, 191, .24), transparent 48%),
    linear-gradient(125deg, #071d33 0%, #0a3c58 58%, #0d5d64 100%);
}

.ai-chat-panel.layout-popup .ai-chat-header {
  min-height: 78px;
  padding-right: 18px;
  padding-left: 18px;
}

.ai-chat-header strong,
body.theme-light .ai-chat-header strong { color: #f3ffff; letter-spacing: .02em; }

#ai-chat-header-model,
body.theme-light #ai-chat-header-model { color: #9ed4db; }

.ai-chat-header button,
body.theme-light .ai-chat-header button {
  border-color: rgba(103, 232, 249, .38);
  border-radius: 10px;
  background: rgba(7, 31, 49, .76);
  color: #dcfbff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
}

.ai-chat-header button:hover,
body.theme-light .ai-chat-header button:hover {
  border-color: #5eead4;
  background: #0d5967;
}

.ai-chat-panel .ai-chat-messages,
body.theme-light .ai-chat-panel .ai-chat-messages {
  background:
    radial-gradient(circle at 100% 0%, rgba(8, 74, 92, .13), transparent 34%),
    #000;
}

.ai-chat-provider-toggle,
body.theme-light .ai-chat-provider-toggle,
.ai-chat-provider-row,
.ai-chat-status,
.ai-chat-composer,
body.theme-light .ai-chat-composer {
  border-color: rgba(23, 107, 121, .62);
  background: #07111e;
}

.ai-chat-composer textarea,
body.theme-light .ai-chat-composer textarea {
  border-color: #1d6271;
  border-radius: 13px;
  background: #02070d;
  color: #eefcfc;
  box-shadow: inset 0 1px 8px rgba(0, 0, 0, .48);
}

.ai-chat-composer textarea:focus,
body.theme-light .ai-chat-composer textarea:focus {
  border-color: #2dd4bf;
  box-shadow: 0 0 0 3px rgba(45, 212, 191, .14), inset 0 1px 8px rgba(0, 0, 0, .48);
}

.ai-chat-panel.layout-popup .ai-chat-composer {
  padding: 14px 15px 15px;
  background: linear-gradient(180deg, rgba(7, 17, 30, .98), #06101c);
  box-shadow: 0 -14px 34px rgba(0, 0, 0, .18);
}

.ai-chat-panel.layout-popup .ai-chat-composer textarea {
  min-height: 112px;
  padding: 12px 14px;
  border-radius: 17px;
}

.ai-chat-compose-actions .ai-chat-send,
body.theme-light .ai-chat-compose-actions .ai-chat-send {
  border-color: #2dd4bf;
  background: linear-gradient(135deg, #075985, #0f766e);
  color: #fff;
}

.ai-chat-message.user .ai-chat-message-content,
body.theme-light .ai-chat-message.user .ai-chat-message-content {
  border-color: #1496a8;
  background: linear-gradient(135deg, #083b59, #0b6670);
  color: #fff;
}

.ai-chat-message.assistant:not(.error) .ai-chat-message-content {
  border-color: #183b4a;
  background: #08111b;
  color: #e8f4f5;
}

/* The light app theme keeps Jena's shell dark. Give the live answer an
   explicitly bright reading color so earlier light-theme rules cannot make
   streamed text disappear against that shell. */
body.theme-light .ai-chat-live-stream.answer > div {
  color: #ecfff9;
  font-family: system-ui, "Segoe UI", "Malgun Gothic", sans-serif;
  font-weight: 500;
}

/* Answers use the same dark reading surface in both app themes. */
.ai-chat-panel.answer-plain-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content,
body.theme-light .ai-chat-panel.answer-plain-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content,
body.theme-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content {
  border-color: #183b4a;
  background: #08111b;
  color: #e8f4f5;
  box-shadow: inset 0 0 0 1px rgba(111, 148, 202, .08);
}

/* The response theme is independent from the application's chrome theme. */
.ai-chat-panel.answer-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content,
body.theme-light .ai-chat-panel.answer-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content {
  border-color: #cbd5e1;
  background: #fff;
  color: #172033;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.ai-chat-panel.answer-dark .ai-chat-message.assistant:not(.error) .ai-chat-message-content,
body.theme-light .ai-chat-panel.answer-dark .ai-chat-message.assistant:not(.error) .ai-chat-message-content {
  border-color: #183b4a;
  background: #08111b;
  color: #e8f4f5;
  box-shadow: inset 0 0 0 1px rgba(111,148,202,.08);
}

body.theme-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content.markdown-rendered pre {
  border: 1px solid #28495b;
  background: #030a12;
  color: #d7e7ef;
}

body.theme-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content.markdown-rendered code {
  color: #b9d8e8;
  font-family: Consolas, "Courier New", monospace;
}

body.theme-light .ai-chat-panel.answer-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content.markdown-rendered pre {
  border-color: #d6deea;
  background: #f1f5f9;
  color: #172033;
}
body.theme-light .ai-chat-panel.answer-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content.markdown-rendered code {
  color: #334155;
}

body.theme-light .ai-chat-panel.answer-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content.markdown-rendered pre {
  border-color: #d6deea;
  background: #f1f5f9;
  color: #172033;
}
body.theme-light .ai-chat-panel.answer-light .ai-chat-message.assistant:not(.error) .ai-chat-message-content.markdown-rendered code {
  color: #334155;
}

body.theme-light .ai-chat-document-answer-record {
  border-color: #315e60;
  background: rgba(15,118,110,.12);
}
body.theme-light .ai-chat-document-answer-record > summary { color: #9de9df; }

body.theme-light .ai-chat-live-stream.answer {
  border-color: #4c846f;
  background: rgba(16,29,48,.72);
}
body.theme-light .ai-chat-live-stream.answer > strong {
  border-color: rgba(76,132,111,.75);
  background: rgba(39,91,72,.62);
  color: #baf2dd;
}
body.theme-light .ai-chat-live-stream.answer > div { color: #e5f4ee; }
body.theme-light .ai-chat-live-stream.answer > div.waiting { color: #91a3bd; }

.ai-chat-panel.layout-dock {
  border: 1px solid #22a7b8;
  border-radius: 24px;
}

@media (max-width: 560px) {
  .ai-chat-panel { border-radius: 22px; }
  .ai-chat-header { padding-top: 19px; }
  .ai-chat-panel.layout-popup .ai-chat-composer { padding: 10px; }
  .ai-chat-panel.layout-popup .ai-chat-composer textarea { min-height: 86px; }
}

.ai-chat-answer-plan { margin: 8px 0; padding: 8px; border: 1px solid var(--chat-border); border-radius: 8px; }
.ai-chat-answer-plan summary { cursor: pointer; font-weight: 700; }
.ai-chat-answer-plan div { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 6px; }

#ai-chat-mobile-expand { display: none; }
.ai-chat-litertlm-auth { margin: 0; padding: 6px 11px 10px; color: var(--chat-muted); font-size: 12px; }
.ai-chat-litertlm-auth[hidden] { display: none; }
.ai-chat-litertlm-auth > div { display: flex; gap: 8px; margin: 5px 0; }
.ai-chat-litertlm-auth input { flex: 1; width: 0; min-width: 0; padding: 8px; border: 1px solid var(--chat-border); border-radius: 7px; background: var(--chat-field); color: var(--chat-text); }
.ai-chat-litertlm-auth button { flex: none; padding: 8px; border: 1px solid #5eead4; border-radius: 7px; background: #145366; color: #fff; }
.ai-chat-litertlm-auth small { display: block; overflow-wrap: anywhere; }

/* A short mobile pane must scroll as a whole: settings and composer cannot
   consume all flex space and strand the send buttons outside its bounds. */
@media (max-width: 700px) {
  .ai-chat-panel, .ai-chat-panel * { box-sizing: border-box; }
  .ai-chat-panel.layout-dock { min-height: 0; min-width: 0; }
  .ai-chat-panel.layout-popup,
  .ai-chat-panel.layout-fullscreen {
    top: calc(var(--ai-chat-viewport-top, 0px) + 4px) !important;
    left: 4px !important;
    right: auto !important;
    bottom: auto !important;
    width: calc(100vw - 8px) !important;
    height: calc(var(--ai-chat-viewport-height, 100dvh) - 8px) !important;
    min-width: 0; min-height: 0; max-height: none;
  }
  .ai-chat-dock-slot, .ai-chat-dock-slot:popover-open {
    height: min(56dvh, var(--ai-chat-viewport-height, 100dvh));
    max-height: var(--ai-chat-viewport-height, 100dvh);
    bottom: max(0px, calc(100dvh - var(--ai-chat-viewport-height, 100dvh) - var(--ai-chat-viewport-top, 0px)));
  }
  .ai-chat-panel .ai-chat-header { flex: none; min-height: 56px; padding: 6px 10px; gap: 6px; }
  .ai-chat-panel .ai-chat-header-actions { flex: none; gap: 4px; }
  .ai-chat-header-actions:not(.menu-open) > #ai-chat-mobile-expand { display: block !important; }
  #ai-chat-mobile-expand { display: block; }
  .ai-chat-panel .ai-chat-header button { min-width: 44px; min-height: 44px; }
  .ai-chat-header-actions.menu-open { flex-wrap: wrap; justify-content: flex-end; max-width: 70%; }
  .ai-chat-panel.layout-fullscreen .ai-chat-action-label { display: none; }
  .ai-chat-panel .ai-chat-shell { overflow: hidden; }
  .ai-chat-panel .ai-chat-main { overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .ai-chat-main > * { flex-shrink: 0; }
  .ai-chat-panel .ai-chat-messages { flex: 1 0 140px; min-height: 140px; overflow: visible; }
  .ai-chat-panel .ai-chat-provider-row { grid-template-columns: minmax(0, 1fr) 44px; }
  .ai-chat-provider-row label:first-child { grid-column: 1 / -1; }
  .ai-chat-panel .ai-chat-provider-row button { width: 44px; height: 44px; }
  #ai-chat-ollama-load { width: auto; grid-column: 1 / -1; }
  .ai-chat-panel .ai-chat-writing-style-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .ai-chat-panel select, .ai-chat-panel textarea, .ai-chat-litertlm-auth input { font-size: 16px; }
  .ai-chat-panel .ai-chat-provider-row select, .ai-chat-panel .ai-chat-writing-style-row select { height: 44px; }
  .ai-chat-insert-expand-toggle { min-height: 44px; white-space: normal; margin: 0; }
  .ai-chat-panel .ai-chat-composer { padding: 8px 10px max(10px, env(safe-area-inset-bottom)); }
  .ai-chat-panel.layout-popup .ai-chat-composer textarea, .ai-chat-panel .ai-chat-composer textarea { min-height: 72px; max-height: 160px; }
  .ai-chat-compose-actions, .ai-chat-mode-row { flex-wrap: wrap; gap: 6px; }
  .ai-chat-panel .ai-chat-compose-actions button, .ai-chat-panel .ai-chat-mode-row > button, .ai-chat-mode-row > label { min-height: 44px; }
  .ai-chat-panel .ai-chat-layout-menu { position: fixed; top: calc(var(--ai-chat-viewport-top, 0px) + 64px); right: 10px; max-width: calc(100vw - 20px); max-height: calc(var(--ai-chat-viewport-height, 100dvh) - 80px); overflow: auto; }
  .ai-chat-panel.layout-popup .ai-chat-resize-handle { display: none; }
  .ai-chat-dock-resizer { height: 22px; top: -11px; touch-action: none; }
}

/* Jena settings: panel-width layout and a shared type/control scale. */
.ai-chat-main { container-type: inline-size; container-name: jena-settings; }
.ai-chat-panel .ai-chat-provider-controls {
  background: var(--chat-surface);
  border-bottom: 1px solid var(--chat-border);
  padding: 12px;
}
.ai-chat-panel .ai-chat-provider-row {
  grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr) 36px;
  gap: 8px;
  padding: 0 0 12px;
  background: transparent;
}
.ai-chat-panel .ai-chat-provider-row label:first-child { grid-column: auto; }
.ai-chat-panel .ai-chat-writing-style-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--chat-border);
  background: transparent;
}
.ai-chat-panel .ai-chat-provider-row label,
.ai-chat-panel .ai-chat-writing-style-row label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font: 500 12px/1.4 system-ui, sans-serif;
  color: var(--chat-muted);
}
.ai-chat-panel .ai-chat-provider-controls select,
.ai-chat-panel .ai-chat-provider-controls button {
  box-sizing: border-box;
  min-width: 0;
  height: 36px;
  margin: 0;
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  background: var(--chat-field);
  color: var(--chat-text);
  font: 500 13px/1.4 system-ui, sans-serif;
}
.ai-chat-panel .ai-chat-provider-controls select { padding: 6px 8px; }
.ai-chat-panel .ai-chat-provider-row button { width: 36px; padding: 0; }
.ai-chat-panel #ai-chat-refresh-model { font-size: 19px; }
.ai-chat-panel #ai-chat-ollama-load {
  grid-column: 1 / -1;
  justify-self: end;
  width: auto;
  height: 30px;
  padding: 0 12px;
  white-space: nowrap;
  color: #93e5dc;
  border-color: #28646a;
  background: #0d303b;
}
.ai-chat-preference-toggles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 8px;
  padding-top: 10px;
  border-top: 1px solid var(--chat-border);
}
.ai-chat-panel .ai-chat-preference-toggles label {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 32px;
  margin: 0;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--chat-text);
  font: 500 12px/1.4 system-ui, sans-serif;
}
.ai-chat-panel .ai-chat-preference-toggles label:first-child { flex-direction: row; justify-content: flex-start; }
.ai-chat-preference-toggles label:hover { background: rgba(100, 180, 190, .08); }
.ai-chat-panel .ai-chat-preference-toggles input { flex: 0 0 14px; width: 14px; height: 14px; margin: 0; accent-color: #27b8ac; }
.ai-chat-panel .ai-chat-provider-controls :is(select, button, input):focus-visible {
  outline: 2px solid #5eead4;
  outline-offset: 2px;
}
.ai-chat-panel .ai-chat-provider-toggle { min-height: 36px; }
.ai-chat-panel #ai-chat-provider-summary { font-size: 12px; font-weight: 500; }
.ai-chat-panel .ai-chat-provider-toggle small { font-size: 11px; }
.ai-chat-panel .ai-chat-status { font-size: 12px; line-height: 1.5; padding: 8px 12px; }
@container jena-settings (max-width: 340px) {
  .ai-chat-panel .ai-chat-provider-row { grid-template-columns: minmax(0, 1fr) 36px; }
  .ai-chat-panel .ai-chat-provider-row label:first-child { grid-column: 1 / -1; }
}
@media (max-width: 600px), (pointer: coarse) {
  .ai-chat-panel .ai-chat-provider-controls select { height: 44px; font-size: 16px; }
  .ai-chat-panel .ai-chat-provider-row { grid-template-columns: minmax(0, 1fr) 44px; }
  .ai-chat-panel .ai-chat-provider-row label:first-child { grid-column: 1 / -1; }
  .ai-chat-panel .ai-chat-provider-row button { width: 44px; height: 44px; }
  .ai-chat-panel #ai-chat-ollama-load { width: auto; height: 44px; }
  .ai-chat-panel .ai-chat-preference-toggles label { min-height: 44px; }
}

/* Compact Think Level control, kept in the existing composer flow. */
#ai-chat-reasoning-settings-slot { min-width:0; max-width:100%; }
.ai-chat-reasoning-settings { display:inline-flex; position:relative; max-width:100%; align-items:center; font-size:12px; vertical-align:middle; }
.ai-chat-reasoning-settings[hidden], .ai-chat-reasoning-settings-body [hidden] { display:none; }
.ai-chat-reasoning-settings summary { display:inline-flex; align-items:center; justify-content:center; box-sizing:border-box; list-style:none; cursor:pointer; padding:3px 7px; min-height:28px; border:1px solid var(--chat-border, #64748b); border-radius:6px; font-size:11px; font-weight:700; }
.ai-chat-reasoning-settings summary::-webkit-details-marker { display:none; }
.ai-chat-reasoning-settings summary:focus-visible { outline:2px solid #818cf8; outline-offset:2px; }
.ai-chat-reasoning-settings[open] { display:inline-flex; flex-wrap:wrap; gap:4px; }
.ai-chat-reasoning-settings:not([open]) .ai-chat-reasoning-settings-body { display:none; }
.ai-chat-reasoning-settings-body { display:inline-flex; align-items:center; gap:4px; max-width:100%; padding:0; white-space:normal; }
.ai-chat-reasoning-settings-body select, .ai-chat-reasoning-settings-body input { box-sizing:border-box; min-width:0; max-width:130px; min-height:28px; font-size:12px; color:inherit; background:var(--chat-bg, #172539); border:1px solid #64748b; border-radius:6px; padding:3px 5px; }
.ai-chat-reasoning-settings-body input { width:90px; }
.ai-chat-reasoning-settings-body small { max-width:180px; overflow-wrap:anywhere; }
.ai-chat-panel .ai-chat-compose-actions .ai-chat-image-gen { flex:0 0 auto; padding:5px 8px; min-width:0; font-size:12px; white-space:nowrap; }
@media (pointer:coarse) { .ai-chat-reasoning-settings summary, .ai-chat-reasoning-settings-body select, .ai-chat-reasoning-settings-body input { min-height:44px; } }

/* Citation lookup shares the JENA window and wraps with the existing mode row. */
.ai-chat-mode-row .ai-chat-citation-toggle.active,
body.theme-light .ai-chat-mode-row .ai-chat-citation-toggle.active {
  background: #7c3aed; border-color: #a78bfa; color: #fff;
}
.ai-chat-mode-row .ai-chat-citation-toggle:focus-visible { outline: 2px solid #c4b5fd; outline-offset: 2px; }
@media (max-width: 700px) {
  .ai-chat-mode-row #ai-chat-citation-toggle { min-height: 44px; min-width: 44px; }
  .ai-chat-mode-row .ai-chat-search-pair button { min-height: 44px; }
}

.ai-chat-search-pair { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; }
