/* ==========================================================================
   SUT Danışmanı — Modern CSS Design System (SGK Institutional Theme)
   Zero external dependencies, CSP compliant, native system typography
   ========================================================================== */

/* ==========================================================================
   Material Design 3 Theme System (Seed: Healthcare Calm Teal #006A60)
   Default: Light Theme. Supported: Dark Theme. Zero CDNs, CSP Compliant.
   ========================================================================== */

:root,
html[data-theme="light"] {
  /* Color Scheme Identification */
  color-scheme: light;

  /* Primary Tonal Palette (Calm Institutional Teal) */
  --md-sys-color-primary: #006a60;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #cce8e2;
  --md-sys-color-on-primary-container: #05201c;

  /* Secondary Tonal Palette (Neutral Slate Teal) */
  --md-sys-color-secondary: #4a635f;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #cce8e2;
  --md-sys-color-on-secondary-container: #05201c;

  /* Tertiary Tonal Palette (Calm Slate Blue) */
  --md-sys-color-tertiary: #456179;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #cce5ff;
  --md-sys-color-on-tertiary-container: #001e31;

  /* Error Tonal Palette */
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;

  /* Surfaces & Backgrounds (Soft Fresh Light Neutral) */
  --md-sys-color-background: #f4fbf8;
  --md-sys-color-on-background: #161d1b;
  --md-sys-color-surface: #f4fbf8;
  --md-sys-color-on-surface: #161d1b;
  --md-sys-color-surface-variant: #dae5e1;
  --md-sys-color-on-surface-variant: #3f4946;

  /* Surface Container Levels (M3 Elevation via Tonal Color) */
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #eef5f2;
  --md-sys-color-surface-container: #e8efec;
  --md-sys-color-surface-container-high: #e2eae6;
  --md-sys-color-surface-container-highest: #dce4e0;

  /* Outlines & Borders */
  --md-sys-color-outline: #6f7976;
  --md-sys-color-outline-variant: #bec9c5;

  /* Inverse Roles */
  --md-sys-color-inverse-surface: #2b3230;
  --md-sys-color-inverse-on-surface: #ecf2ef;
  --md-sys-color-inverse-primary: #53dbc9;

  /* Source Viewer Highlight Accents (Light) */
  --md-sys-color-highlight-bg: #fef3c7;
  --md-sys-color-highlight-border: #b45309;
  --md-sys-color-highlight-text: #78350f;
  --md-sys-color-backdrop: rgba(22, 29, 27, 0.45);

  /* Legacy Variable Bridges for Complete Compatibility */
  --bg-app: var(--md-sys-color-background);
  --bg-surface: var(--md-sys-color-surface-container-lowest);
  --bg-surface-elevated: var(--md-sys-color-surface-container-low);
  --bg-input: var(--md-sys-color-surface-container-lowest);
  --border-subtle: var(--md-sys-color-outline-variant);
  --border-medium: var(--md-sys-color-outline);
  --border-focus: var(--md-sys-color-primary);
  --text-main: var(--md-sys-color-on-surface);
  --text-muted: var(--md-sys-color-on-surface-variant);
  --text-dim: var(--md-sys-color-on-surface-variant);
  --sgk-blue: var(--md-sys-color-primary);
  --sgk-blue-hover: #005048;
  --sgk-blue-light: #53dbc9;
  --sgk-teal: var(--md-sys-color-secondary);
  --sgk-teal-light: #74f8e5;
  --sgk-emerald: #0f766e;
  --sgk-rose: var(--md-sys-color-error);
  --sgk-amber: #d97706;
  --user-bubble-bg: var(--md-sys-color-primary);
  --assistant-bubble-bg: var(--md-sys-color-surface-container-lowest);
  --assistant-bubble-border: var(--md-sys-color-outline-variant);
  --citation-bg: var(--md-sys-color-surface-container-low);
  --citation-border: var(--md-sys-color-outline-variant);
  --citation-accent: var(--md-sys-color-primary);

  /* Typography */
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* M3 Shape System */
  --md-shape-none: 0;
  --md-shape-xs: 4px;
  --md-shape-sm: 8px;
  --md-shape-md: 12px;
  --md-shape-lg: 16px;
  --md-shape-xl: 28px;
  --md-shape-full: 9999px;

  --radius-sm: var(--md-shape-xs);
  --radius-md: var(--md-shape-sm);
  --radius-lg: var(--md-shape-lg);
  --radius-full: var(--md-shape-full);

  /* M3 Elevation Shadows */
  --md-elevation-1: 0 1px 3px 1px rgba(0, 0, 0, 0.08), 0 1px 2px 0 rgba(0, 0, 0, 0.12);
  --md-elevation-2: 0 2px 6px 2px rgba(0, 0, 0, 0.10), 0 1px 2px 0 rgba(0, 0, 0, 0.14);
  --md-elevation-3: 0 4px 8px 3px rgba(0, 0, 0, 0.12), 0 1px 3px 0 rgba(0, 0, 0, 0.16);
  --md-elevation-4: 0 6px 12px 4px rgba(0, 0, 0, 0.14), 0 2px 4px 0 rgba(0, 0, 0, 0.18);
  --md-elevation-5: 0 8px 16px 6px rgba(0, 0, 0, 0.16), 0 4px 6px 0 rgba(0, 0, 0, 0.20);

  --shadow-sm: var(--md-elevation-1);
  --shadow-md: var(--md-elevation-2);
  --shadow-lg: var(--md-elevation-4);

  /* M3 Motion */
  --md-motion-standard: cubic-bezier(0.2, 0, 0, 1);
  --md-duration-short: 150ms;
  --md-duration-medium: 250ms;
  --md-duration-long: 350ms;
}

html[data-theme="dark"] {
  /* Color Scheme Identification */
  color-scheme: dark;

  /* Primary Tonal Palette (Luminous Mint/Teal) */
  --md-sys-color-primary: #53dbc9;
  --md-sys-color-on-primary: #003731;
  --md-sys-color-primary-container: #005048;
  --md-sys-color-on-primary-container: #74f8e5;

  /* Secondary Tonal Palette */
  --md-sys-color-secondary: #b1ccc6;
  --md-sys-color-on-secondary: #1c3531;
  --md-sys-color-secondary-container: #334b47;
  --md-sys-color-on-secondary-container: #cce8e2;

  /* Tertiary Tonal Palette */
  --md-sys-color-tertiary: #adcae6;
  --md-sys-color-on-tertiary: #153349;
  --md-sys-color-tertiary-container: #2d4a60;
  --md-sys-color-on-tertiary-container: #cce5ff;

  /* Error Tonal Palette */
  --md-sys-color-error: #ffb4ab;
  --md-sys-color-on-error: #690005;
  --md-sys-color-error-container: #93000a;
  --md-sys-color-on-error-container: #ffdad6;

  /* Surfaces & Backgrounds (Deep Calm Neutral Dark) */
  --md-sys-color-background: #0e1514;
  --md-sys-color-on-background: #dee4e1;
  --md-sys-color-surface: #0e1514;
  --md-sys-color-on-surface: #dee4e1;
  --md-sys-color-surface-variant: #3f4946;
  --md-sys-color-on-surface-variant: #bec9c5;

  /* Surface Container Levels (Dark) */
  --md-sys-color-surface-container-lowest: #090f0e;
  --md-sys-color-surface-container-low: #161d1c;
  --md-sys-color-surface-container: #1a2120;
  --md-sys-color-surface-container-high: #252c2a;
  --md-sys-color-surface-container-highest: #2f3635;

  /* Outlines & Borders */
  --md-sys-color-outline: #899390;
  --md-sys-color-outline-variant: #3f4946;

  /* Inverse Roles */
  --md-sys-color-inverse-surface: #dee4e1;
  --md-sys-color-inverse-on-surface: #2b3230;
  --md-sys-color-inverse-primary: #006a60;

  /* Source Viewer Highlight Accents (Dark) */
  --md-sys-color-highlight-bg: rgba(245, 158, 11, 0.18);
  --md-sys-color-highlight-border: #f59e0b;
  --md-sys-color-highlight-text: #fef3c7;
  --md-sys-color-backdrop: rgba(0, 0, 0, 0.65);

  /* Legacy Variable Bridges */
  --bg-app: var(--md-sys-color-background);
  --bg-surface: var(--md-sys-color-surface-container-lowest);
  --bg-surface-elevated: var(--md-sys-color-surface-container-low);
  --bg-input: var(--md-sys-color-surface-container-low);
  --border-subtle: var(--md-sys-color-outline-variant);
  --border-medium: var(--md-sys-color-outline);
  --border-focus: var(--md-sys-color-primary);
  --text-main: var(--md-sys-color-on-surface);
  --text-muted: var(--md-sys-color-on-surface-variant);
  --text-dim: var(--md-sys-color-on-surface-variant);
  --sgk-blue: var(--md-sys-color-primary);
  --sgk-blue-hover: #74f8e5;
  --sgk-blue-light: #53dbc9;
  --sgk-teal: var(--md-sys-color-secondary);
  --sgk-teal-light: #cce8e2;
  --sgk-emerald: #53dbc9;
  --sgk-rose: var(--md-sys-color-error);
  --sgk-amber: #f59e0b;
  --user-bubble-bg: var(--md-sys-color-primary-container);
  --assistant-bubble-bg: var(--md-sys-color-surface-container-low);
  --assistant-bubble-border: var(--md-sys-color-outline-variant);
  --citation-bg: var(--md-sys-color-surface-container-low);
  --citation-border: var(--md-sys-color-outline-variant);
  --citation-accent: var(--md-sys-color-primary);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.7);
}

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

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

/* App Wrapper */
.app-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 1024px;
  margin: 0 auto;
  position: relative;
  background-color: var(--md-sys-color-surface);
  border-left: 1px solid var(--md-sys-color-outline-variant);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: var(--md-elevation-2);
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background-color: var(--md-sys-color-surface-container-low);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  flex-shrink: 0;
  z-index: 20;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.brand-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--md-shape-md);
  background-color: var(--md-sys-color-primary-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-primary-container);
}

.brand-meta {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--md-sys-color-on-surface);
}

.brand-subtitle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--md-sys-color-on-surface-variant);
}

.version-badge {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  padding: 1px 6px;
  border-radius: var(--md-shape-xs);
  font-weight: 600;
  font-size: 0.72rem;
  border: 1px solid var(--md-sys-color-outline-variant);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--md-sys-color-primary);
  animation: pulse-dot 2s infinite ease-in-out;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.9); }
}

.status-text {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.btn-new-chat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-full);
  color: var(--md-sys-color-on-surface);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--md-duration-short) var(--md-motion-standard);
}

.btn-new-chat:hover {
  background-color: var(--md-sys-color-surface-container-highest);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
}

.btn-new-chat:focus-visible,
#new-chat-button:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* Toast Banner */
.toast-banner {
  position: absolute;
  top: 70px;
  left: 20px;
  right: 20px;
  z-index: 50;
  background-color: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-sm);
  padding: 12px 16px;
  box-shadow: var(--md-elevation-3);
  transition: opacity var(--md-duration-short) var(--md-motion-standard),
              transform var(--md-duration-short) var(--md-motion-standard);
}

.toast-banner.toast-error {
  background-color: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  border-color: var(--md-sys-color-error);
}

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

.toast-message {
  font-size: 0.88rem;
  color: inherit;
}

.toast-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.8;
}

.toast-close:hover {
  opacity: 1;
}

.toast-close:focus-visible,
#toast-close:focus-visible {
  outline: 2px solid var(--md-sys-color-inverse-primary);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

/* Chat Area */
.chat-container {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}

.messages-container {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: auto;
  min-height: 100%;
}

/* Welcome Card */
.welcome-card {
  margin: auto;
  max-width: 600px;
  text-align: center;
  padding: 32px 24px;
  background-color: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-lg);
  box-shadow: var(--md-elevation-1);
}

.welcome-emblem {
  display: inline-flex;
  padding: 14px;
  border-radius: var(--md-shape-full);
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  margin-bottom: 14px;
}

.welcome-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--md-sys-color-on-surface);
}

.welcome-desc {
  font-size: 0.92rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.6;
  margin-bottom: 0;
}

.welcome-features {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--md-sys-color-on-surface);
}

.feature-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-size: 0.75rem;
  font-weight: bold;
}

/* Message Rows & Bubbles */
.chat-message, .message {
  display: flex;
  width: 100%;
}

.user-message, .message.self-end {
  justify-content: flex-end;
}

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

.message-bubble {
  max-width: 85%;
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  position: relative;
  word-wrap: break-word;
}

/* User Bubble */
.user-bubble {
  background: var(--user-bubble-bg);
  color: var(--md-sys-color-on-primary);
  border-bottom-right-radius: 4px;
  border: 1px solid transparent;
}

html[data-theme="dark"] .user-bubble {
  color: var(--md-sys-color-on-primary-container);
}

/* Assistant Bubble */
.assistant-bubble {
  background: var(--assistant-bubble-bg);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--assistant-bubble-border);
  border-bottom-left-radius: 4px;
}

.bubble-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.assistant-badge {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.badge-answer {
  background: rgba(16, 185, 129, 0.15);
  color: var(--sgk-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-clarify {
  background: rgba(245, 158, 11, 0.15);
  color: var(--sgk-amber);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-refusal {
  background: rgba(244, 63, 94, 0.15);
  color: var(--sgk-rose);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

/* Refusal Badge Banner */
.refusal-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(244, 63, 94, 0.12);
  border: 1px solid rgba(244, 63, 94, 0.3);
  color: var(--sgk-rose);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  font-size: 0.85rem;
  font-weight: 500;
}

/* Formatted Assistant Content */
.assistant-content {
  line-height: 1.65;
  font-size: 0.95rem;
}

.assistant-content p, .chat-paragraph {
  margin-bottom: 10px;
}

.assistant-content p:last-child, .chat-paragraph:last-child {
  margin-bottom: 0;
}

.assistant-content strong {
  color: var(--md-sys-color-on-surface);
  font-weight: 700;
}

.assistant-content em {
  font-style: italic;
  color: var(--md-sys-color-on-surface-variant);
}

.chat-list {
  margin-left: 20px;
  margin-bottom: 12px;
}

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

.chat-inline-code {
  font-family: var(--font-mono);
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  padding: 2px 6px;
  border-radius: var(--md-shape-xs);
  font-size: 0.88em;
  color: var(--md-sys-color-on-surface);
}

.chat-heading {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--md-sys-color-primary);
  margin-top: 14px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding-bottom: 4px;
}

/* Citations Component */
.citations-container {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border-medium);
}

.citations-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--md-sys-color-primary);
  margin-bottom: 8px;
}

.citations-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.open-all-citations-btn {
  appearance: none;
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-full);
  padding: 3px 10px;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  cursor: pointer;
  transition: all var(--md-duration-short) var(--md-motion-standard);
}

.open-all-citations-btn:hover {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.citation-cards-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.citation-card, .citation-pill, .citation {
  appearance: none;
  background-color: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-left: 4px solid var(--md-sys-color-primary);
  border-radius: var(--md-shape-sm);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--md-sys-color-on-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: all var(--md-duration-short) var(--md-motion-standard);
  box-shadow: var(--md-elevation-1);
}

.citation-card:hover {
  background-color: var(--md-sys-color-surface-container-high);
  border-color: var(--md-sys-color-primary);
  box-shadow: var(--md-elevation-2);
  transform: translateY(-1px);
}

.citation-card:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.citation-badge-section, .citation-section {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

.citation-badge-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.citation-badge-lines, .citation-lines {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  padding: 2px 8px;
  border-radius: var(--md-shape-full);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--md-sys-color-outline-variant);
  white-space: nowrap;
}

.citation-action-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-primary);
  opacity: 0.8;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.citation-card:hover .citation-action-icon {
  opacity: 1;
  transform: translateX(2px) translateY(-1px);
}

/* Thinking / Loading Bubble */
.thinking-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dots .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--md-sys-color-primary);
  animation: dot-bounce 1.4s infinite ease-in-out both;
}

.thinking-dots .dot:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

.thinking-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.blinking-cursor {
  animation: blink-cursor 1s step-end infinite;
  font-weight: bold;
  color: var(--md-sys-color-primary);
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* System Error Bubble */
.error-bubble {
  background-color: var(--md-sys-color-error-container);
  border: 1px solid var(--md-sys-color-error);
  color: var(--md-sys-color-on-error-container);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.retry-button {
  background-color: var(--md-sys-color-error);
  border: none;
  color: var(--md-sys-color-on-error);
  padding: 6px 12px;
  border-radius: var(--md-shape-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: filter var(--md-duration-short) var(--md-motion-standard);
  white-space: nowrap;
}

.retry-button:hover {
  filter: brightness(0.92);
}

.retry-button:focus-visible {
  outline: 2px solid var(--md-sys-color-error);
  outline-offset: 2px;
}

/* Footer & Controls */
.app-footer {
  flex-shrink: 0;
  background-color: var(--bg-surface-elevated);
  border-top: 1px solid var(--border-subtle);
  padding: 12px 20px 16px;
  z-index: 20;
}

/* Example Question Pills */
.example-pills-container {
  margin-bottom: 12px;
}

.pills-header {
  margin-bottom: 6px;
}

.pills-label {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.pills-wrapper {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-medium) transparent;
}

.example-pill, .example-question-btn {
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-full);
  color: var(--md-sys-color-on-surface);
  font-size: 0.82rem;
  padding: 6px 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--md-duration-short) var(--md-motion-standard);
  font-family: inherit;
  flex-shrink: 0;
}

.example-pill:hover, .example-question-btn:hover {
  background-color: var(--md-sys-color-surface-container-highest);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-primary);
}

.example-pill:focus-visible,
.example-question-btn:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.example-pill:disabled, .example-question-btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Input Form */
.chat-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  background-color: var(--bg-input);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-shape-md);
  padding: 6px 8px 6px 14px;
  transition: border-color var(--md-duration-short) var(--md-motion-standard),
              box-shadow var(--md-duration-short) var(--md-motion-standard);
}

.input-wrapper:focus-within {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}

.chat-textarea {
  flex: 1 1 auto;
  background: transparent;
  border: none;
  outline: none;
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 24px;
  resize: none;
  max-height: 120px;
  min-height: 24px;
  padding: 0;
  margin: 0;
  display: block;
  align-self: center;
}

.chat-textarea::placeholder {
  color: var(--md-sys-color-on-surface-variant);
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.char-counter {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
  user-select: none;
  white-space: nowrap;
}

.char-counter.char-warn {
  color: var(--sgk-amber);
}

.char-counter.char-danger {
  color: var(--sgk-rose);
  font-weight: 600;
}

.btn-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--md-shape-sm);
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  cursor: pointer;
  transition: all var(--md-duration-short) var(--md-motion-standard);
}

.btn-send:hover:not(:disabled) {
  background-color: var(--sgk-blue-hover);
  box-shadow: var(--md-elevation-1);
}

.btn-send:disabled {
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-outline);
  border: 1px solid var(--md-sys-color-outline-variant);
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-send:focus-visible,
#send-button:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.footer-disclaimer {
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 4px;
}

/* Responsive */
@media (max-width: 640px) {
  .app-header {
    padding: 10px 14px;
  }
  
  .brand-title {
    font-size: 1rem;
  }
  
  .version-badge {
    display: none;
  }
  
  .chat-container {
    padding: 14px 12px;
  }
  
  .message-bubble {
    max-width: 92%;
  }
  
  .app-footer {
    padding: 10px 14px 14px;
  }
}

/* ========================================================
   Material 3 Top App Bar Theme Toggle Button
   ======================================================== */
.btn-theme-toggle, .theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--md-shape-full);
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  transition: all var(--md-duration-short) var(--md-motion-standard);
}

.btn-theme-toggle:hover, .theme-toggle-btn:hover {
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-primary);
  box-shadow: var(--md-elevation-1);
}

.btn-theme-toggle:focus-visible,
.theme-toggle-btn:focus-visible,
#theme-toggle-button:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

/* ========================================================
   Source Viewer Multi-Panel Workspace (Desktop & Mobile)
   ======================================================= */
.source-viewer-backdrop, .viewer-scrim {
  position: fixed;
  inset: 0;
  background-color: var(--md-sys-color-backdrop);
  backdrop-filter: blur(4px);
  z-index: 90;
  transition: opacity var(--md-duration-medium) var(--md-motion-standard);
}

.source-viewer-backdrop.hidden, .viewer-scrim.hidden {
  display: none !important;
}

.source-viewer-sheet, .source-viewer-drawer, .viewer-panel {
  position: fixed;
  background-color: transparent;
  color: var(--md-sys-color-on-surface);
  box-shadow: none;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: none;
  opacity: 1;
  transition: opacity var(--md-duration-medium) var(--md-motion-standard);
}

/* Workspace holding Fixed Left Source List + Right-Aligned Horizontally Scrollable Panels */
.source-viewer-workspace {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
  overflow: hidden;
  pointer-events: none;
}

/* Fixed Left-Side Source List Sidebar (Always Visible, Pinned to Left) */
.source-viewer-sidebar {
  flex: 0 0 280px;
  width: 280px;
  min-width: 280px;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--md-sys-color-surface-container);
  border-right: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: var(--md-elevation-3);
  z-index: 5;
  overflow: hidden;
  pointer-events: auto;
  transform: translateX(0);
  transition: transform var(--md-duration-medium) var(--md-motion-standard);
}

.source-sidebar-header {
  padding: 14px 14px 12px;
  background-color: var(--md-sys-color-surface-container-high);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

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

.source-sidebar-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

.source-sidebar-count {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--md-shape-full);
}

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

.source-open-all-btn {
  flex: 1 1 auto;
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border: none;
  border-radius: var(--md-shape-sm);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--md-duration-short) var(--md-motion-standard);
}

.source-open-all-btn:hover {
  filter: brightness(0.93);
}

.source-close-all-btn {
  background-color: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-sm);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--md-duration-short) var(--md-motion-standard);
}

.source-close-all-btn:hover {
  background-color: var(--md-sys-color-surface-container-highest);
}

.source-sidebar-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.source-message-group {
  background-color: var(--md-sys-color-surface-container-lowest);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.source-group-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.source-group-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.source-group-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--md-sys-color-primary);
}

.source-group-open-all-btn {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-full);
  padding: 2px 8px;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--md-duration-short) var(--md-motion-standard);
}

.source-group-open-all-btn:hover {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
}

.source-group-question {
  font-size: 0.76rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.source-group-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.source-list-item {
  appearance: none;
  width: 100%;
  text-align: left;
  background-color: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-left: 3px solid transparent;
  border-radius: var(--md-shape-sm);
  padding: 7px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  cursor: pointer;
  font-family: inherit;
  color: var(--md-sys-color-on-surface);
  transition: all var(--md-duration-short) var(--md-motion-standard);
}

.source-list-item:hover {
  background-color: var(--md-sys-color-surface-container-high);
  border-color: var(--md-sys-color-primary);
}

.source-list-item.is-open {
  border-left-color: var(--md-sys-color-secondary);
  background-color: var(--md-sys-color-surface-container);
}

.source-list-item.is-focused {
  border-left-color: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.source-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.source-item-section {
  font-size: 0.8rem;
  font-weight: 600;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-item-lines {
  font-family: var(--font-mono);
  font-size: 0.71rem;
  color: var(--md-sys-color-on-surface-variant);
}

.source-list-item.is-focused .source-item-lines {
  color: var(--md-sys-color-on-primary-container);
}

.source-item-status {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--md-shape-full);
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
  flex-shrink: 0;
}

.source-list-item.is-open .source-item-status {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.source-list-item.is-focused .source-item-status {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

/* Horizontally Scrollable Source Panels Track (Aligned to Right) */
.source-panels-track {
  flex: 1 1 auto;
  height: 100%;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 12px;
  padding: 0;
  background-color: transparent;
  scroll-behavior: smooth;
  pointer-events: auto;
  transform: translateX(0);
  transition: transform var(--md-duration-medium) var(--md-motion-standard);
}

/* Individual Source Panel inside Horizontal Track — pushed to right when space permits */
.source-panel {
  position: relative;
  width: 480px;
  min-width: 440px;
  flex: 0 0 480px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  border-left: 1px solid var(--md-sys-color-outline-variant);
  border-top: 3px solid transparent;
  box-shadow: var(--md-elevation-4);
  pointer-events: auto;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.source-panel.hidden {
  display: none !important;
}

.source-panel:first-child,
.source-panel.is-first-visible {
  margin-left: auto;
}

.source-panel.is-first-visible ~ .source-panel {
  margin-left: 0;
}

.source-panel.is-focused {
  border-top-color: var(--md-sys-color-primary);
  box-shadow: var(--md-elevation-4);
}

.source-panel.panel-focus-pulse {
  animation: pulse-panel-focus 0.9s ease-out;
}

@keyframes pulse-panel-focus {
  0% { box-shadow: 0 0 0 0 var(--md-sys-color-primary); }
  50% { box-shadow: 0 0 0 4px var(--md-sys-color-primary); }
  100% { box-shadow: var(--md-elevation-4); }
}

/* Desktop: Left Source List on Left, Source Panels Aligned to Right */
@media (min-width: 769px) {
  .source-viewer-sheet, .source-viewer-drawer, .viewer-panel {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
  }

  .source-panel {
    width: 480px;
  }

  .source-viewer-sheet.hidden, .source-viewer-drawer.hidden, .viewer-panel.hidden {
    opacity: 0;
    display: flex !important;
    pointer-events: none;
    visibility: hidden;
  }

  .source-viewer-sheet.hidden .source-viewer-sidebar {
    transform: translateX(-100%);
  }

  .source-viewer-sheet.hidden .source-panels-track {
    transform: translateX(40px);
  }

  .sheet-drag-handle {
    display: none;
  }
}

/* Mobile: Modal Bottom Sheet sliding from bottom */
@media (max-width: 768px) {
  .source-viewer-sheet, .source-viewer-drawer, .viewer-panel {
    left: 0;
    right: 0;
    bottom: 0;
    height: 85vh;
    max-height: 90vh;
    border-radius: var(--md-shape-xl) var(--md-shape-xl) 0 0;
    border-top: 1px solid var(--md-sys-color-outline-variant);
    transform: translateY(0);
  }

  .source-viewer-sidebar {
    flex: 0 0 150px;
    width: 150px;
    min-width: 150px;
  }

  .source-panel {
    width: 310px;
    min-width: 280px;
    flex: 0 0 310px;
  }

  .source-viewer-sheet.hidden, .source-viewer-drawer.hidden, .viewer-panel.hidden {
    transform: translateY(100%);
    display: flex !important;
    pointer-events: none;
    visibility: hidden;
  }

  .sheet-drag-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background-color: var(--md-sys-color-outline-variant);
    margin: 8px auto 4px;
    flex-shrink: 0;
  }
}

/* Sheet Header */
.sheet-header, .viewer-header {
  padding: 16px 20px 12px;
  background-color: var(--md-sys-color-surface-container-low);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.sheet-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sheet-title-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--md-sys-color-primary);
  font-weight: 700;
  font-size: 1.1rem;
}

.sheet-lines-badge, .source-viewer-range {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--md-shape-full);
}

.sheet-close-btn, .btn-close {
  background: transparent;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: var(--md-shape-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background-color var(--md-duration-short) var(--md-motion-standard);
}

.sheet-close-btn:hover, .btn-close:hover {
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

.sheet-close-btn:focus-visible,
.btn-close:focus-visible,
#source-viewer-close:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.sheet-header-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sheet-section-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  line-height: 1.35;
}

.sheet-meta-links {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
}

.sheet-annex-badge {
  background-color: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  padding: 2px 7px;
  border-radius: var(--md-shape-xs);
  font-size: 0.72rem;
  font-weight: 600;
}

.sheet-official-link, .official-source-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--md-sys-color-primary);
  text-decoration: none;
  font-weight: 500;
}

.sheet-official-link:hover, .official-source-link:hover {
  text-decoration: underline;
}

.sheet-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
}

.sheet-btn-tonal, .btn-full-section {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--md-shape-full);
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border: none;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--md-duration-short) var(--md-motion-standard);
}

.sheet-btn-tonal:hover, .btn-full-section:hover {
  box-shadow: var(--md-elevation-1);
  filter: brightness(0.96);
}

.sheet-btn-tonal:focus-visible,
.btn-full-section:focus-visible,
#source-viewer-full-section-btn:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.sheet-btn-text:focus-visible,
#source-load-prev-btn:focus-visible,
#source-load-next-btn:focus-visible,
#source-viewer-retry-btn:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.sheet-range-status {
  font-size: 0.72rem;
  color: var(--md-sys-color-on-surface-variant);
}

/* Sheet Content & Lines Table */
.sheet-content {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 0;
  background-color: var(--md-sys-color-surface);
}

.sheet-pagination-control {
  display: flex;
  justify-content: center;
  padding: 6px 16px;
}

.sheet-btn-text {
  background: transparent;
  border: 1px dashed var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-primary);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 6px 14px;
  border-radius: var(--md-shape-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.2s ease;
}

.sheet-btn-text:hover {
  background-color: var(--md-sys-color-surface-container-high);
}

.source-lines-table, .viewer-lines-container {
  display: flex;
  flex-direction: column;
}

.source-line, .viewer-line {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 4px 18px;
  font-family: var(--font-stack);
  font-size: 0.88rem;
  line-height: 1.6;
  transition: background-color 0.15s ease;
}

.source-line:hover, .viewer-line:hover {
  background-color: var(--md-sys-color-surface-container-low);
}

.source-line-number, .line-number {
  flex-shrink: 0;
  width: 44px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--md-sys-color-on-surface-variant);
  user-select: none;
}

.source-line-text, .line-text {
  flex: 1 1 auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--md-sys-color-on-surface);
}

/* Prominently Highlighted Cited Lines */
.source-line-cited, .highlighted-line, .is-cited {
  background-color: var(--md-sys-color-highlight-bg) !important;
  border-left: 4px solid var(--md-sys-color-highlight-border);
  padding-left: 14px;
  font-weight: 500;
}

.source-line-cited .source-line-number, .highlighted-line .line-number {
  color: var(--md-sys-color-highlight-text);
  font-weight: 700;
}

.source-line-cited .source-line-text, .highlighted-line .line-text {
  color: var(--md-sys-color-highlight-text);
}

/* Subtle Animation Pulse on Scroll Target */
.highlight-pulse {
  animation: pulse-line 1.2s ease-in-out;
}

@keyframes pulse-line {
  0% { transform: scale(1); filter: brightness(1.2); }
  50% { transform: scale(1.01); filter: brightness(1.4); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* Context lines subtle dimming */
.source-line-context .source-line-text, .context-line .line-text {
  color: var(--md-sys-color-on-surface-variant);
}

/* Overlays */
.sheet-state-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(244, 251, 248, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 10;
}

html[data-theme="dark"] .sheet-state-overlay {
  background-color: rgba(14, 21, 20, 0.88);
}

.sheet-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--md-sys-color-outline-variant);
  border-top-color: var(--md-sys-color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

body.modal-open {
  overflow: hidden;
}
