/* ==========================================================================
   SeminarLens — Minimalistischer W-Seminar KI-Reader & Editor
   Design System: Warm Editorial Academic Reader
   ========================================================================== */

:root {
  /* Color Palette - Warm Editorial Light */
  --bg-app: hsl(38, 33%, 97%);
  --bg-surface: hsl(0, 0%, 100%);
  --bg-elevated: hsl(36, 25%, 95%);
  --bg-subtle: hsl(35, 20%, 92%);
  --bg-glass: hsla(0, 0%, 100%, 0.92);

  --text-primary: hsl(240, 10%, 10%);
  --text-secondary: hsl(240, 5%, 36%);
  --text-muted: hsl(240, 4%, 54%);

  --border-subtle: hsl(35, 16%, 88%);
  --border-strong: hsl(35, 14%, 78%);

  /* Functional Accents */
  --accent-primary: hsl(215, 78%, 42%);
  --accent-primary-hover: hsl(215, 82%, 35%);
  --accent-primary-soft: hsl(215, 85%, 95%);

  /* Highlight / Annotation Colors */
  --mark-bg: hsla(43, 96%, 56%, 0.24);
  --mark-bg-hover: hsla(43, 96%, 56%, 0.44);
  --mark-border: hsl(38, 92%, 45%);
  --mark-active-bg: hsla(215, 88%, 55%, 0.22);

  /* Question Focus Color */
  --question-bg: hsl(215, 90%, 97%);
  --question-border: hsl(215, 75%, 82%);
  --question-text: hsl(215, 80%, 24%);

  /* Status Colors */
  --status-ok: hsl(152, 68%, 34%);
  --status-ok-bg: hsl(152, 65%, 94%);
  --status-warn: hsl(36, 90%, 42%);
  --status-warn-bg: hsl(38, 92%, 94%);
  --status-err: hsl(0, 72%, 48%);
  --status-err-bg: hsl(0, 80%, 95%);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(15, 18, 24, 0.05), 0 1px 2px rgba(15, 18, 24, 0.03);
  --shadow-md: 0 8px 24px -4px rgba(15, 18, 24, 0.08), 0 2px 6px -1px rgba(15, 18, 24, 0.04);
  --shadow-popover: 0 18px 42px -6px rgba(15, 18, 28, 0.18), 0 4px 12px -2px rgba(15, 18, 28, 0.08);

  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Layout */
  --header-height: 60px;
  --sidebar-width: 310px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg-app: hsl(228, 12%, 9%);
  --bg-surface: hsl(228, 12%, 13%);
  --bg-elevated: hsl(228, 11%, 17%);
  --bg-subtle: hsl(228, 10%, 21%);
  --bg-glass: hsla(228, 12%, 14%, 0.94);

  --text-primary: hsl(40, 20%, 94%);
  --text-secondary: hsl(225, 8%, 70%);
  --text-muted: hsl(225, 6%, 50%);

  --border-subtle: hsl(228, 10%, 20%);
  --border-strong: hsl(228, 10%, 28%);

  --accent-primary: hsl(212, 92%, 62%);
  --accent-primary-hover: hsl(212, 95%, 68%);
  --accent-primary-soft: hsla(212, 90%, 60%, 0.15);

  --mark-bg: hsla(43, 92%, 52%, 0.22);
  --mark-bg-hover: hsla(43, 92%, 52%, 0.38);
  --mark-border: hsl(42, 90%, 55%);
  --mark-active-bg: hsla(212, 90%, 60%, 0.28);

  --question-bg: hsla(212, 85%, 55%, 0.14);
  --question-border: hsla(212, 80%, 60%, 0.35);
  --question-text: hsl(212, 90%, 82%);

  --status-ok: hsl(152, 65%, 52%);
  --status-ok-bg: hsla(152, 65%, 45%, 0.15);
  --status-warn: hsl(38, 92%, 60%);
  --status-warn-bg: hsla(38, 92%, 50%, 0.15);
  --status-err: hsl(0, 82%, 66%);
  --status-err-bg: hsla(0, 80%, 55%, 0.15);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 28px -4px rgba(0, 0, 0, 0.45);
  --shadow-popover: 0 20px 48px -6px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.07);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ==========================================================================
   Top Navigation Bar
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-height);
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
}

.doc-title-input {
  border: 1px solid transparent;
  background: transparent;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--text-primary);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  width: 100%;
  max-width: 440px;
  text-overflow: ellipsis;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.doc-title-input:hover {
  background: var(--bg-elevated);
}

.doc-title-input:focus {
  outline: none;
  background: var(--bg-surface);
  border-color: var(--accent-primary);
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.mode-tab {
  border: none;
  background: transparent;
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.mode-tab:hover {
  color: var(--text-primary);
}

.mode-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
}

/* Instant Explain Toggle Pill */
.instant-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.instant-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.instant-toggle.active {
  background: var(--accent-primary-soft);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  font-weight: 600;
}

.instant-toggle input {
  display: none;
}

.toggle-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.15s ease;
}

.instant-toggle.active .toggle-indicator {
  background: var(--accent-primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.btn-primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
  color: #ffffff;
}

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
}

/* Cloud Sync Status Pill */
.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--status-ok-bg);
  color: var(--status-ok);
  white-space: nowrap;
}

.sync-pill.syncing {
  background: var(--status-warn-bg);
  color: var(--status-warn);
}

.sync-pill.error {
  background: var(--status-err-bg);
  color: var(--status-err);
}

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ==========================================================================
   Main Workspace Layout
   ========================================================================== */

.workspace {
  display: flex;
  min-height: calc(100vh - var(--header-height));
  position: relative;
}

/* Left Sidebar: Saved Explanations & Outline */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
  flex-shrink: 0;
  transition: margin-left 0.22s ease, opacity 0.2s ease;
}

.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-width));
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-elevated);
  padding: 3px;
  border-radius: var(--radius-sm);
}

.sidebar-tab {
  border: none;
  background: transparent;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
}

.sidebar-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.sidebar-search {
  width: 100%;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  font-size: 12.5px;
}

.sidebar-search:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.annotation-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  cursor: pointer;
  transition: all 0.14s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.annotation-item:hover {
  border-color: var(--accent-primary);
  background: var(--bg-surface);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.annotation-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.annotation-term {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.annotation-delete-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 12px;
  line-height: 1;
}

.annotation-delete-btn:hover {
  color: var(--status-err);
  background: var(--status-err-bg);
}

.annotation-preview {
  font-size: 12.5px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.annotation-question-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-primary);
  background: var(--accent-primary-soft);
  padding: 2px 6px;
  border-radius: 4px;
  align-self: flex-start;
  margin-top: 2px;
}

.outline-item {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.outline-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.outline-item.level-h1 {
  font-weight: 700;
  color: var(--text-primary);
}

.outline-item.level-h3 {
  padding-left: 22px;
  font-size: 12.5px;
}

.empty-sidebar-hint {
  text-align: center;
  padding: 28px 14px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ==========================================================================
   Main Reader & Editor Area
   ========================================================================== */

.main-stage {
  flex: 1;
  min-width: 0;
  padding: 28px 24px 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stage-container {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Helper / Hint Banner in Read Mode */
.reader-hint-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.reader-hint-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hint-kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.reader-stats {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Edit Mode Toolbar & Import Strip */
.editor-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.editor-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.format-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.fmt-btn {
  border: 1px solid transparent;
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 5px 9px;
  border-radius: 5px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.fmt-btn:hover {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.fmt-divider {
  width: 1px;
  height: 20px;
  background: var(--border-subtle);
  margin: 0 4px;
}

.import-dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  background: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  transition: all 0.15s ease;
}

.import-dropzone.dragover {
  border-color: var(--accent-primary);
  background: var(--accent-primary-soft);
}

.dropzone-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

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

/* Seminar Paper Canvas */
.paper-canvas {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 46px 56px;
  min-height: 620px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.paper-canvas.edit-mode-active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-soft), var(--shadow-md);
}

.seminar-content {
  font-family: 'Times New Roman', Times, serif;
  font-size: 19px;
  font-weight: 400;
  line-height: 1.78;
  color: var(--text-primary);
  outline: none;
  word-wrap: break-word;
}

.seminar-content p,
.seminar-content li {
  font-family: 'Times New Roman', Times, serif;
  font-weight: 400;
}

.seminar-content strong,
.seminar-content b {
  font-family: 'Plus Jakarta Sans', 'Times New Roman', sans-serif;
  font-weight: 700;
  font-size: 0.94em;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.seminar-content h1,
.seminar-content h2,
.seminar-content h3,
.seminar-content h4 {
  font-family: var(--font-sans);
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin-top: 1.6em;
  margin-bottom: 0.55em;
}

.seminar-content h1 strong,
.seminar-content h2 strong,
.seminar-content h3 strong,
.seminar-content h1 b,
.seminar-content h2 b,
.seminar-content h3 b {
  font-size: inherit;
  font-weight: inherit;
  font-family: inherit;
}

.seminar-content h1:first-child,
.seminar-content h2:first-child,
.seminar-content h3:first-child {
  margin-top: 0;
}

.seminar-content h1 {
  font-size: 1.65rem;
  font-weight: 800;
}

.seminar-content h2 {
  font-size: 1.32rem;
  font-weight: 700;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.seminar-content h3 {
  font-size: 1.12rem;
  font-weight: 700;
}

.seminar-content p {
  margin-bottom: 1.15em;
}

.seminar-content ul,
.seminar-content ol {
  margin: 0.6em 0 1.2em 1.5em;
}

.seminar-content li {
  margin-bottom: 0.35em;
}

.seminar-content blockquote {
  border-left: 3px solid var(--accent-primary);
  padding: 6px 18px;
  margin: 1.2em 0;
  color: var(--text-secondary);
  font-style: italic;
  background: var(--bg-app);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Highlighted / Annotated Words & Sentences in the Seminar Text */
mark.seminar-mark {
  background-color: var(--mark-bg);
  color: inherit;
  border-bottom: 2px solid var(--mark-border);
  border-radius: 3px;
  padding: 0 2px;
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

mark.seminar-mark:hover,
mark.seminar-mark.active-mark {
  background-color: var(--mark-bg-hover);
}

/* ==========================================================================
   Right-Hand AI Chat Sidebar & Minimal Selection Pill
   ========================================================================== */

.ai-chat-sidebar {
  width: 390px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height));
  position: sticky;
  top: var(--header-height);
  flex-shrink: 0;
}

.chat-sidebar-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-context-info {
  min-width: 0;
  flex: 1;
}

.chat-context-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.chat-selected-snippet {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-empty-state {
  margin: auto 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.55;
  padding: 24px 12px;
}

.chat-msg-user {
  align-self: flex-end;
  max-width: 86%;
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 9px 13px;
  border-radius: 12px 12px 3px 12px;
  font-size: 13.5px;
  line-height: 1.48;
}

.chat-msg-ai {
  align-self: flex-start;
  width: 100%;
  font-size: 14px;
  line-height: 1.62;
  color: var(--text-primary);
}

.chat-msg-ai p {
  margin-bottom: 10px;
}

.chat-msg-ai p:last-child {
  margin-bottom: 0;
}

.chat-msg-ai strong {
  font-weight: 700;
  color: var(--text-primary);
}

.chat-msg-ai ul,
.chat-msg-ai ol {
  margin: 6px 0 10px 18px;
}

.chat-msg-ai li {
  margin-bottom: 4px;
}

.chat-msg-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0;
}

.popover-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  color: var(--text-secondary);
  font-size: 13px;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

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

.chat-input-bar {
  padding: 12px 14px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-text-input {
  flex: 1;
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  color: var(--text-primary);
  min-width: 0;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.chat-text-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  background: var(--bg-surface);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent-primary);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.14s ease, opacity 0.14s ease;
}

.chat-send-btn:hover {
  background: var(--accent-primary-hover);
}

.chat-send-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.popover-close-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.popover-close-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

/* Minimal Floating Quick-Access Pill next to Text Selection */
.selection-mini-pill {
  position: fixed;
  z-index: 100;
  background: var(--text-primary);
  color: var(--bg-surface);
  border-radius: 999px;
  padding: 3px 5px;
  box-shadow: var(--shadow-md);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  animation: popoverFadeIn 0.12s ease;
}

.selection-mini-pill.hidden {
  display: none !important;
}

.mini-pill-sep {
  width: 1px;
  height: 14px;
  background: rgba(128, 128, 128, 0.35);
}

.mini-pill-btn {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease;
}

.mini-pill-btn:hover {
  background: rgba(128, 128, 128, 0.24);
}

/* Clickable Rewrite Suggestion Row inside Chat */
.rewrite-option-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  margin: 6px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  transition: border-color 0.14s ease;
}

.rewrite-option-row:hover {
  border-color: var(--accent-primary);
}

.rewrite-option-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-primary);
  flex: 1;
}

.rewrite-apply-btn {
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.12s ease;
}

.rewrite-apply-btn:hover {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

/* Minimal Confirmation Modal for Replacing Text */
.confirm-mini-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.confirm-mini-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.confirm-mini-preview {
  font-family: 'Times New Roman', Times, serif;
  font-size: 15.5px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  max-height: 180px;
  overflow-y: auto;
}

.confirm-mini-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

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

/* ==========================================================================
   Settings & Prompt Field Customizer Modal
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(10, 12, 18, 0.48);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-popover);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-section-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-section-desc {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: -4px;
}

.fields-editor-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-editor-item {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-editor-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field-index-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.field-label-input {
  flex: 1;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  font-weight: 600;
  font-size: 13px;
}

.field-prompt-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  font-size: 12.5px;
  resize: vertical;
  min-height: 52px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input, .form-select, .form-textarea {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  font-size: 13px;
}

.form-textarea {
  resize: vertical;
  min-height: 68px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--text-primary);
  color: var(--bg-surface);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: popoverFadeIn 0.18s ease;
}

/* Responsive Adjustments */
@media (max-width: 960px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    z-index: 50;
    box-shadow: var(--shadow-popover);
  }
  .paper-canvas {
    padding: 28px 24px;
  }
  .doc-title-input {
    max-width: 200px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 10px;
    gap: 6px;
  }
  .brand-badge span {
    display: none;
  }
  .instant-toggle span.toggle-text {
    display: none;
  }
  .paper-canvas {
    padding: 20px 16px;
  }
  .seminar-content {
    font-size: 17px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}
