:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-secondary: #64748b;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --accent-hover: #1d4ed8;
  --green: #059669;
  --green-light: #d1fae5;
  --red: #dc2626;
  --red-light: #fee2e2;
  --orange: #d97706;
  --orange-light: #fef3c7;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* Dark mode */
.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent: #3b82f6;
  --accent-light: #1e3a5f;
  --accent-hover: #60a5fa;
  --green-light: #064e3b;
  --red-light: #450a0a;
  --orange-light: #451a03;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* ===== HEADER ===== */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

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

.logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon { font-size: 24px; }

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

.dark-mode-toggle {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background 0.15s;
}
.dark-mode-toggle:hover { background: var(--accent-light); }

.lang-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}

.nav-links {
  display: flex;
  gap: 4px;
}

.nav-links button {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-links button:hover,
.nav-links button.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ===== MAIN LAYOUT ===== */
.main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px;
  padding-bottom: 80px;
}

/* ===== VIEWS ===== */
.view { display: none; animation: fadeIn 0.2s ease; }
.view.active { display: block; }

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

/* ===== HERO / SEARCH ===== */
.hero {
  text-align: center;
  padding: 60px 0 40px;
}

.hero h1 {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
}

.hero p {
  color: var(--text-secondary);
  font-size: 16px;
  max-width: 500px;
  margin: 0 auto 32px;
}

.search-box {
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 16px 20px 16px 48px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  transition: all 0.2s;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 20px;
  pointer-events: none;
}

.search-hint {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.search-hint kbd {
  background: var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--mono);
}

/* Autocomplete */
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 300px;
  overflow-y: auto;
  display: none;
  z-index: 50;
}
.autocomplete-dropdown.show { display: block; }
.autocomplete-item {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.autocomplete-item:hover, .autocomplete-item.active {
  background: var(--accent-light);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item .ac-name { font-weight: 600; }
.autocomplete-item .ac-cat { font-size: 12px; color: var(--text-secondary); margin-left: 8px; }

/* ===== QUICK LINKS ===== */
.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 24px;
}

.quick-link {
  padding: 8px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
}

.quick-link:hover, .quick-link:active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* ===== STATS BAR ===== */
.stats-bar {
  display: flex;
  gap: 32px;
  justify-content: center;
  padding: 32px 0;
  margin: 24px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat { text-align: center; flex: 1; }

.stat-num {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 4px;
}

/* ===== FEATURE CARDS ===== */
.features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 24px 0;
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: all 0.2s;
}
.feature-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.feature-icon { font-size: 28px; margin-bottom: 8px; }
.feature-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.feature-desc { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }

/* ===== CATEGORY SECTION ===== */
.category-section {
  margin-top: 32px;
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 16px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}

.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.category-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.category-card .cat-icon { font-size: 28px; margin-bottom: 8px; }
.category-card .cat-name { font-size: 14px; font-weight: 500; }
.category-card .cat-count { font-size: 12px; color: var(--text-secondary); }

/* ===== SEARCH RESULTS ===== */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.results-count {
  font-size: 14px;
  color: var(--text-secondary);
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-user-select: none;
  user-select: none;
}

.result-card:hover, .result-card:active {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.result-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.result-meta {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.result-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

/* ===== DRUG DETAIL ===== */
.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: none;
  margin-bottom: 16px;
  -webkit-user-select: none;
  user-select: none;
}

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.detail-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.detail-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.badge-source { background: var(--accent-light); color: var(--accent); }
.badge-lang { background: var(--green-light); color: var(--green); }
.badge-alias { background: var(--orange-light, #fef3c7); color: var(--orange, #d97706); font-size: 12px; }
.badge-license { background: var(--orange-light); color: var(--orange); }
.badge-interaction { background: var(--red-light); color: var(--red); font-weight: 600; }

.detail-content {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
  overflow-wrap: break-word;
  word-break: break-word;
}

.detail-content h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 24px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.detail-content h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 20px 0 8px;
}

.detail-content ul, .detail-content ol {
  padding-left: 24px;
  margin: 8px 0;
}

.detail-content li { margin: 4px 0; }

.detail-content code {
  background: rgba(0,0,0,0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
}
.dark .detail-content code { background: rgba(255,255,255,0.1); }

.detail-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  margin: 12px 0;
  color: var(--text-secondary);
}

/* ===== AI CHAT ===== */
#chatView {
  display: none;
  flex-direction: column;
  height: calc(100vh - 120px);
  height: calc(100dvh - 120px);
}
#chatView.active {
  display: flex;
}

.chat-disclaimer {
  text-align: center;
  padding: 12px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--orange-light);
  border-radius: var(--radius);
  margin-bottom: 12px;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  animation: fadeIn 0.2s ease;
}

.chat-msg.user { flex-direction: row-reverse; }

.chat-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.chat-msg.ai .chat-avatar { background: var(--accent-light); }
.chat-msg.user .chat-avatar { background: rgba(0,0,0,0.06); }
.dark .chat-msg.user .chat-avatar { background: rgba(255,255,255,0.1); }

.chat-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: break-word;
  word-break: break-word;
}

.chat-msg.ai .chat-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
}

.chat-msg.user .chat-bubble {
  background: var(--accent);
  color: white;
}

.chat-bubble p { margin: 8px 0; }
.chat-bubble p:first-child { margin-top: 0; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul, .chat-bubble ol { padding-left: 20px; }
.chat-bubble li { margin: 4px 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble code {
  background: rgba(0,0,0,0.06);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 13px;
}
.dark .chat-bubble code { background: rgba(255,255,255,0.1); }

.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 12px 0 0;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  outline: none;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  transition: border-color 0.2s;
}

.chat-input:focus { border-color: var(--accent); }

.chat-send {
  padding: 12px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  align-self: flex-end;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-send:hover { background: var(--accent-hover); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== WELCOME CHAT ===== */
.chat-welcome {
  text-align: center;
  padding: 40px 16px;
}

.chat-welcome h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.chat-welcome p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.chat-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-width: 500px;
  margin: 0 auto;
}

.chat-suggestion {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  -webkit-user-select: none;
  user-select: none;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-suggestion:hover, .chat-suggestion:active {
  border-color: var(--accent);
  color: var(--accent);
}

.chat-suggestion-icon { font-size: 18px; flex-shrink: 0; }

/* ===== SETTINGS PANEL ===== */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

.settings-card h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.form-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--mono);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: #cbd5e1; }
.dark .form-input::placeholder { color: #475569; }

.input-with-toggle {
  position: relative;
  display: flex;
}
.input-with-toggle .form-input { padding-right: 44px; }
.input-toggle-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggle-switch {
  position: relative;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border);
  border-radius: 26px;
  transition: 0.3s;
}
.toggle-slider:before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(22px); }

.btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 44px;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: rgba(0,0,0,0.05); color: var(--text); }
.dark .btn-secondary { background: rgba(255,255,255,0.1); }
.btn-secondary:hover { background: rgba(0,0,0,0.1); }

.settings-status {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 8px;
  display: none;
}

.settings-status.success {
  display: block;
  background: var(--green-light);
  color: var(--green);
}

.settings-status.error {
  display: block;
  background: var(--red-light);
  color: var(--red);
}

/* ===== LOADING ===== */
.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 20px 0;
}

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

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

.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-8px); }
}

/* ===== MOBILE BOTTOM TAB BAR ===== */
.mobile-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 6px 0;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.mobile-tabs-inner {
  display: flex;
  justify-content: space-around;
  max-width: 500px;
  margin: 0 auto;
}

.mobile-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s;
  min-width: 64px;
  -webkit-user-select: none;
  user-select: none;
}

.mobile-tab .tab-icon { font-size: 22px; }
.mobile-tab.active { color: var(--accent); }
.mobile-tab:active { transform: scale(0.95); }

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  padding: 32px 20px;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  margin-top: 48px;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .header { padding: 10px 16px; }
  .nav-links { display: none; }
  .main { padding: 16px 12px; padding-bottom: 90px; }
  .hero h1 { font-size: 26px; }
  .hero { padding: 32px 0 20px; }
  .hero p { font-size: 14px; margin-bottom: 20px; }
  .search-input { padding: 14px 16px 14px 44px; font-size: 16px; }
  .quick-links { gap: 6px; }
  .quick-link { padding: 8px 12px; font-size: 12px; }
  .stats-bar { gap: 16px; flex-wrap: wrap; padding: 24px 16px; }
  .stat-num { font-size: 22px; }
  .features { grid-template-columns: 1fr; gap: 8px; }
  .chat-suggestions { grid-template-columns: 1fr; }
  .detail-card { padding: 20px 16px; }
  .detail-title { font-size: 22px; }
  .detail-content { font-size: 14px; }
  .chat-bubble { max-width: 90%; font-size: 14px; }
  .chat-input { font-size: 16px; }
  .settings-card { padding: 16px; }
  .category-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .mobile-tabs { display: block; }

  /* Hide header right elements on very small screens */
  .lang-select { display: none; }
}

@media (max-width: 380px) {
  .hero h1 { font-size: 22px; }
  .quick-link { padding: 6px 10px; font-size: 11px; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.dark ::-webkit-scrollbar-thumb { background: #475569; }

/* Language buttons */
.btn-lang {
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.btn-lang:hover { border-color: var(--accent); background: var(--accent-light); }
.btn-lang.active { border-color: var(--accent); background: var(--accent-light); color: var(--accent); font-weight: 600; }

/* RTL support */
[dir="rtl"] .search-box { direction: rtl; }
[dir="rtl"] .search-input { text-align: right; }
[dir="rtl"] .result-meta { direction: rtl; }
[dir="rtl"] .header { flex-direction: row-reverse; }
[dir="rtl"] .nav-links { flex-direction: row-reverse; }
[dir="rtl"] .detail-content { direction: rtl; text-align: right; }

/* Homepage language selector */
.lang-selector {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 16px 0 8px;
  flex-wrap: wrap;
}
.lang-label { font-size: 16px; margin-right: 4px; }
.lang-btn {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 6px;
  background: var(--card-bg, #fff);
  color: var(--text-secondary, #64748b);
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
}
.lang-btn:hover {
  border-color: var(--accent, #2563eb);
  color: var(--accent, #2563eb);
}
.lang-btn.active {
  background: var(--accent, #2563eb);
  color: #fff;
  border-color: var(--accent, #2563eb);
}

/* ===== TABLE OF CONTENTS ===== */
.toc {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  position: sticky;
  top: 64px;
  z-index: 10;
}
.toc-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
  display: inline;
}
.toc-toggle {
  float: right;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 2px 6px;
  user-select: none;
}
.toc.collapsed .toc-list { display: none; }
.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 50vh;
  overflow-y: auto;
}
.toc-list li { margin: 2px 0; }
.toc-list li.toc-h3 { padding-left: 16px; }
.toc-list a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  padding: 3px 8px;
  border-radius: 4px;
  display: block;
  transition: all 0.15s;
}
.toc-list a:hover, .toc-list a.active {
  color: var(--accent);
  background: var(--accent-light);
}

/* ===== COPY BUTTON ===== */
.copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  float: right;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.copy-btn:hover { opacity: 1; background: var(--accent-light); }

/* ===== CHAT TOOLBAR ===== */
.chat-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 0 0 8px;
  flex-shrink: 0;
}
.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  min-height: 32px;
}

/* ===== SCROLL FAB ===== */
.scroll-fab {
  position: absolute;
  bottom: 80px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.scroll-fab.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}
.empty-state p {
  font-size: 16px;
}

/* ===== TABLES IN DETAIL CONTENT ===== */
.detail-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 14px;
}
.detail-content th, .detail-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.detail-content th {
  background: var(--accent-light);
  font-weight: 600;
}

/* ===== HORIZONTAL RULE ===== */
.detail-content hr, .chat-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ===== CHAT INPUT STICKY ===== */
.chat-input-area {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  z-index: 10;
}

/* ===== CHAT VIEW RELATIVE ===== */
#chatView {
  position: relative;
}
