/* НормПоиск — Design System v3 */

/* ── Google Fonts ──────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Geologica:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Playfair+Display:wght@700&display=swap');

/* ── CSS Variables — Light Theme ───────────── */
:root {
  --bg: #f5f3ef;
  --bg-2: #eeece7;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --border: #e0dcd4;
  --border-dark: #c8c3ba;
  --accent: #0B2545;
  --accent-mid: #1a4a7a;
  --accent-light: #2D7DD2;
  --accent-pale: #e8f0fa;
  --text-primary: #1a1814;
  --text-secondary: #5a544a;
  --text-muted: #9a9088;
  --tag-bg: #edf3fb;
  --success: #166534;
  --success-bg: #dcfce7;
  --rule-color: #d4cfc7;

  --nav-h: 52px;
  --sidebar-w: 240px;
  --panel-w: 400px;

  --shadow-sm: 0 1px 4px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.04);
  --radius: 9px;
  --radius-sm: 6px;

  /* compat aliases for older templates */
  --text: var(--text-primary);
  --bg-card: var(--surface);
  --bg-input: var(--bg-2);
  --accent-hover: var(--accent-mid);
  --border-light: var(--border);
}

/* ── Dark Theme ─────────────────────────────── */
[data-theme="dark"] {
  --bg: #0c1220;
  --bg-2: #0f1929;
  --surface: #14203a;
  --surface-2: #111c30;
  --border: #1e3050;
  --border-dark: #2a4070;
  --accent: #0B2545;
  --accent-mid: #1a4a7a;
  --accent-light: #4DA3E8;
  --accent-pale: #1a2d48;
  --text-primary: #e8edf5;
  --text-secondary: #8fa5c0;
  --text-muted: #4a6a8a;
  --tag-bg: #1a2d48;
  --success: #4ade80;
  --success-bg: #14532d;
  --rule-color: #2a4060;

  /* compat aliases */
  --text: var(--text-primary);
  --bg-card: var(--surface);
  --bg-input: var(--bg-2);
  --accent-hover: var(--accent-mid);
  --border-light: var(--border);
}

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

/* ── Base ───────────────────────────────────── */
body {
  font-family: 'Geologica', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* subtle paper texture — light only */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Crect width='4' height='4' fill='%23f5f3ef'/%3E%3Ccircle cx='1' cy='1' r='0.4' fill='%23e8e4de' opacity='0.5'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 0;
}
[data-theme="dark"] body::before { display: none; }

a { color: inherit; }

/* ── NAV ────────────────────────────────────── */
nav.site-nav {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 200; height: var(--nav-h);
  display: flex; align-items: center;
  padding: 0 20px;
  background: rgba(245, 243, 239, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
[data-theme="dark"] nav.site-nav {
  background: rgba(12, 18, 32, 0.97);
}

.nav-toggle {
  width: 30px; height: 30px;
  background: transparent;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; transition: all .12s; flex-shrink: 0;
}
.nav-toggle:hover { border-color: var(--border-dark); color: var(--text-primary); }

.nav-logo {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none; flex-shrink: 0;
}
.state-home .nav-logo { display: none; }

/* ── CHAT TOP LOGO ──────────────────────────── */
.chat-top-logo {
  display: none;
  justify-content: center;
  padding: 20px 0 4px;
  flex-shrink: 0;
}
.state-chat .chat-top-logo { display: flex; }
.chat-logo-link {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none;
}
.logo-icon {
  width: 30px; height: 30px;
  background: var(--accent); border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-icon svg { width: 15px; height: 15px; }
.logo-wordmark {
  font-family: 'Geologica', sans-serif;
  font-size: 15px; letter-spacing: -0.2px;
}
.logo-wordmark .bold { font-weight: 700; color: var(--accent); font-family: 'Geologica', sans-serif; }
.logo-wordmark .light { font-weight: 300; color: var(--accent-light); font-family: 'Geologica', sans-serif; }
[data-theme="dark"] .logo-wordmark .bold { color: #c8daf4; }

.nav-links {
  margin-left: auto;
  display: flex; align-items: center; gap: 2px;
}
.nav-link {
  font-size: 13px; font-weight: 400;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 5px 11px; border-radius: var(--radius-sm);
  transition: all 0.12s; white-space: nowrap;
}
.nav-link:hover { background: var(--bg-2); color: var(--text-primary); }
.nav-link.active { color: var(--accent-light); font-weight: 500; }

.nav-divider { width: 1px; height: 18px; background: var(--border); margin: 0 6px; }
.nav-feedback-icon { display: none; font-size: 15px; }

.theme-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-muted);
  width: 30px; height: 30px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: all 0.12s;
}
.theme-btn:hover { border-color: var(--border-dark); color: var(--text-primary); }

/* ── APP LAYOUT ─────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  padding-top: var(--nav-h);
  position: relative; z-index: 1;
}

/* ── SIDEBAR (history) ─────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width .22s cubic-bezier(.4,0,.2,1),
              opacity .18s ease,
              transform .22s cubic-bezier(.4,0,.2,1);
}
.sidebar.collapsed {
  width: 0; opacity: 0; transform: translateX(-8px); pointer-events: none;
}

.sidebar-header {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.new-chat-btn {
  width: 100%; background: var(--accent); color: white;
  border: none; border-radius: 7px; padding: 8px 12px;
  font-size: 12.5px; font-weight: 500; cursor: pointer;
  display: flex; align-items: center; gap: 7px;
  font-family: 'Geologica', sans-serif; transition: all 0.12s;
  white-space: nowrap;
}
.new-chat-btn:hover { background: var(--accent-mid); }

.sidebar-body {
  flex: 1; overflow-y: auto; overflow-x: hidden;
}
.sidebar-body::-webkit-scrollbar { width: 3px; }
.sidebar-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sidebar-section { padding: 10px 6px 4px; }
.sidebar-section-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px; font-weight: 500;
  color: var(--text-muted); letter-spacing: 1.5px;
  text-transform: uppercase; padding: 0 8px; margin-bottom: 3px;
}
.chat-item {
  padding: 7px 9px; border-radius: 5px;
  cursor: pointer; display: flex; align-items: flex-start; gap: 8px;
  transition: all 0.1s;
}
.chat-item:hover { background: var(--bg-2); }
.chat-item.active { background: var(--accent-pale); }
.chat-item-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--rule-color); margin-top: 5px; flex-shrink: 0;
}
.chat-item.active .chat-item-dot { background: var(--accent-light); }
.chat-item-text {
  font-size: 12px; color: var(--text-secondary); line-height: 1.4;
  overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.chat-item.active .chat-item-text { color: var(--accent-light); font-weight: 500; }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: 10.5px; color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0;
}
.sidebar-footer span { color: var(--accent-light); font-weight: 500; }

/* ── MAIN ───────────────────────────────────── */
.main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

/* ── HOME STATE ─────────────────────────────── */
.home-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 24px; gap: 28px;
  overflow-y: auto;
}

.home-hero { text-align: center; }

.home-eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: var(--text-muted);
  letter-spacing: 2px; text-transform: uppercase;
  margin-bottom: 16px;
}
.eyebrow-line { width: 24px; height: 1px; background: var(--rule-color); }

.home-title {
  font-family: 'Geologica', sans-serif;
  font-size: 52px; font-weight: 700;
  color: var(--accent); letter-spacing: -1.5px; line-height: 1;
  margin-bottom: 12px;
}
[data-theme="dark"] .home-title { color: #c8daf4; }

.home-title .accent-word {
  color: var(--accent-light);
}
.home-subtitle {
  font-size: 14px; color: var(--text-secondary);
  font-weight: 300; letter-spacing: 0.3px;
}

/* ── SEARCH BOX ─────────────────────────────── */
.search-container { width: 100%; max-width: 660px; }

.search-box {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  transition: all 0.2s;
  box-shadow: var(--shadow);
}
.search-box:focus-within {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(45,125,210,0.12), var(--shadow);
}

.search-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text-primary); font-size: 14.5px;
  font-family: 'Geologica', sans-serif; font-weight: 400;
  resize: none; min-height: 22px; max-height: 120px; line-height: 1.5;
}
.search-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px; height: 36px; background: var(--accent);
  border: none; border-radius: 7px; color: white;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.12s; flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-mid); transform: scale(1.04); }
.send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* ── CHIPS ──────────────────────────────────── */
.quick-examples {
  display: flex; flex-wrap: wrap; gap: 7px;
  justify-content: center; max-width: 660px;
}
.quick-chip {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 11px;
  font-size: 11.5px; color: var(--text-secondary);
  cursor: pointer; transition: all 0.12s;
  font-family: 'JetBrains Mono', monospace;
}
.quick-chip:hover {
  border-color: var(--accent-light); color: var(--accent-light);
  background: var(--tag-bg);
}

/* ── CHAT LAYOUT ────────────────────────────── */
.chat-layout {
  flex: 1; display: flex; overflow: hidden; min-height: 0;
}

.chat-left {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

.chat-state {
  flex: 1; overflow-y: auto;
  padding: 28px 32px;
  display: flex; flex-direction: column; gap: 28px;
}
.chat-state::-webkit-scrollbar { width: 4px; }
.chat-state::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── MESSAGES ───────────────────────────────── */
.msg-user {
  align-self: flex-end;
  background: var(--accent); color: white;
  border-radius: 11px 11px 2px 11px;
  padding: 11px 15px; max-width: 72%;
  font-size: 14px; line-height: 1.5; font-weight: 400;
}

.msg-ai {
  display: flex; flex-direction: column; gap: 14px;
}

.ai-header {
  display: flex; align-items: center; gap: 8px;
}
.ai-icon {
  width: 26px; height: 26px;
  background: var(--accent); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ai-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: var(--text-muted);
  letter-spacing: 1.2px; text-transform: uppercase;
}

.ai-answer {
  font-size: 14px; line-height: 1.75;
  color: var(--text-primary); font-weight: 300;
}
.ai-answer strong { font-weight: 600; }

.clause-link {
  color: var(--accent-light); text-decoration: none;
  border-bottom: 1px dotted var(--accent-light);
  transition: all 0.1s;
}
.clause-link:hover { border-bottom-style: solid; }

/* ── ANSWER SECTIONS ────────────────────────── */
.answer-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.answer-section-header {
  padding: 9px 14px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px; font-weight: 500;
  color: var(--text-muted); letter-spacing: 1.5px;
  text-transform: uppercase; background: var(--surface-2);
  display: flex; align-items: center; gap: 7px;
  cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.answer-section-header:hover { background: var(--bg-2); }
.section-chevron { margin-left: auto; font-size: 10px; }

.answer-section-body {
  padding: 14px;
  overflow: hidden;
}
.answer-section-body.hidden { display: none; }

/* ── PARAMS TABLE ───────────────────────────── */
.params-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.params-table tr { border-bottom: 1px solid var(--border); }
.params-table tr:last-child { border-bottom: none; }
.params-table td { padding: 8px 12px; vertical-align: middle; }
.params-table td:first-child { color: var(--text-secondary); width: 52%; }
.params-table td:last-child {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent-light); font-weight: 500;
}
.params-table tr:hover { background: var(--bg); }

/* exception / related box */
.exception-box {
  font-size: 13px; line-height: 1.65;
  color: var(--text-secondary);
  background: #fffbeb; border-radius: 6px; padding: 10px 12px;
}
[data-theme="dark"] .exception-box {
  background: #2a1f05; color: var(--text-secondary);
}
.related-box {
  font-size: 13px; line-height: 1.65;
  color: var(--text-secondary);
  background: var(--tag-bg); border-radius: 6px; padding: 10px 12px;
}

/* loading animation */
.msg-loading {
  display: flex; align-items: center; gap: 10px;
  padding: 14px; color: var(--text-muted); font-size: 13px;
}
.loading-dots { display: flex; gap: 4px; }
.loading-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-light);
  animation: pulse 1.2s infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* irrelevant / error */
.irrelevant-notice, .error-notice {
  font-size: 13.5px; color: var(--text-secondary);
  padding: 12px; background: var(--surface-2);
  border-radius: var(--radius); border: 1px solid var(--border);
}
.error-notice { color: #dc2626; }

/* feedback row */
.feedback-row {
  display: flex; align-items: center; gap: 7px; margin-top: 4px;
}
.feedback-label {
  font-size: 10.5px; color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}
.feedback-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 8px;
  font-size: 11px; color: var(--text-muted);
  cursor: pointer; transition: all 0.1s; font-family: 'Geologica', sans-serif;
}
.feedback-btn:hover { border-color: var(--border-dark); color: var(--text-primary); }

/* ── SOURCES COLUMN ─────────────────────────── */
.chat-sources {
  width: 310px; flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--surface-2);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.chat-sources-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px; font-weight: 500;
  color: var(--text-muted); letter-spacing: 1.5px;
  text-transform: uppercase;
  display: flex; align-items: center; gap: 7px;
  flex-shrink: 0;
}
.sources-count-badge {
  background: var(--accent-light); color: white;
  border-radius: 10px; padding: 1px 7px;
  font-size: 9px; font-weight: 500;
}
.chat-sources-body {
  flex: 1; overflow-y: auto; padding: 10px;
}
.chat-sources-body::-webkit-scrollbar { width: 3px; }
.chat-sources-body::-webkit-scrollbar-thumb { background: var(--border); }

.source-group { margin-bottom: 14px; }
.source-group-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; font-weight: 500;
  color: var(--accent-light); letter-spacing: 0.5px;
  margin-bottom: 6px; padding: 0 2px;
}
.source-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 10px 12px;
  cursor: pointer; transition: all 0.12s;
  margin-bottom: 6px;
}
.source-card:hover {
  border-color: var(--accent-light);
  background: var(--tag-bg);
  transform: translateX(2px);
}
.source-card-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 500;
  color: var(--accent-light); margin-bottom: 3px;
}
.source-card-text {
  font-size: 11.5px; line-height: 1.4; color: var(--text-secondary);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ── CHAT INPUT FOOTER ──────────────────────── */
.chat-input-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: rgba(245, 243, 239, 0.97);
  backdrop-filter: blur(10px);
  display: flex; justify-content: center;
  gap: 10px; align-items: center;
  flex-shrink: 0;
}
[data-theme="dark"] .chat-input-footer {
  background: rgba(12, 18, 32, 0.97);
}
.chat-input-inner { flex: 1; max-width: 700px; }

.clear-chat-btn {
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 12px;
  font-size: 12px; color: var(--text-muted);
  cursor: pointer; transition: all 0.12s; white-space: nowrap;
  font-family: 'Geologica', sans-serif;
}
.clear-chat-btn:hover { border-color: var(--border-dark); color: var(--text-primary); }

/* ── SITE FOOTER ────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border); background: var(--surface-2);
  padding: 11px 28px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.sf-left { display: flex; align-items: center; gap: 14px; }
.sf-logo { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.sf-logo span { font-weight: 300; color: var(--accent-light); }
.sf-links { display: flex; gap: 2px; }
.sf-link {
  font-size: 11.5px; color: var(--text-muted); text-decoration: none;
  padding: 3px 8px; border-radius: 5px; transition: all .1s;
}
.sf-link:hover { color: var(--text-secondary); background: var(--bg-2); }
.sf-right {
  font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--text-muted);
}
.sf-right span { color: var(--accent-light); }

/* ── OVERLAY (mobile sidebar) ───────────────── */
.sb-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.35); z-index: 140;
  top: var(--nav-h);
}
.sb-overlay.visible { display: block; }

/* ── SOURCE PANEL (slide-in) ────────────────── */
.source-panel {
  position: fixed; top: var(--nav-h); right: 0; bottom: 0;
  width: var(--panel-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0,0,0,0.1);
  display: flex; flex-direction: column;
  z-index: 300;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.source-panel.open { transform: translateX(0); }

.source-panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.source-panel-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; font-weight: 500;
  color: var(--accent-light); flex: 1;
}
.source-panel-close {
  width: 26px; height: 26px; background: transparent;
  border: 1px solid var(--border); border-radius: 5px;
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; transition: all 0.1s;
}
.source-panel-close:hover { border-color: var(--border-dark); color: var(--text-primary); }

.source-panel-body {
  flex: 1; overflow-y: auto; padding: 18px 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.source-panel-body::-webkit-scrollbar { width: 4px; }
.source-panel-body::-webkit-scrollbar-thumb { background: var(--border); }

.panel-text {
  font-size: 13.5px; line-height: 1.75;
  color: var(--text-primary); font-weight: 300;
}
.panel-related { margin-top: 4px; }
.panel-related-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px; color: var(--text-muted);
  letter-spacing: 1.2px; text-transform: uppercase; margin-bottom: 7px;
}
.panel-related-links { display: flex; flex-wrap: wrap; gap: 6px; }
.panel-related-links a {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--accent-light);
  text-decoration: none; border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 8px; transition: all 0.1s;
}
.panel-related-links a:hover { border-color: var(--accent-light); }
.panel-lib-link {
  display: inline-block;
  font-size: 12px; color: var(--accent-light);
  text-decoration: none; border-bottom: 1px solid transparent;
  transition: border-color 0.1s; margin-top: 4px;
}
.panel-lib-link:hover { border-bottom-color: var(--accent-light); }

/* ── PANEL OVERLAY ──────────────────────────── */
.panel-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.25); z-index: 290;
}
.panel-overlay.active { display: block; }

/* ── ANIMATIONS ─────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-up { animation: fadeUp 0.3s ease forwards; }
.delay-1 { animation-delay: 0.05s; opacity: 0; }
.delay-2 { animation-delay: 0.1s; opacity: 0; }
.delay-3 { animation-delay: 0.15s; opacity: 0; }
.delay-4 { animation-delay: 0.2s; opacity: 0; }

/* ── LIBRARY PAGE ───────────────────────────── */
.lib-page {
  flex: 1; overflow-y: auto; padding: 32px 40px;
}
.lib-page::-webkit-scrollbar { width: 4px; }
.lib-page::-webkit-scrollbar-thumb { background: var(--border); }

.lib-page-header { margin-bottom: 28px; }
.lib-page-title {
  font-family: 'Geologica', sans-serif;
  font-size: 26px; font-weight: 600;
  color: var(--text-primary); margin-bottom: 6px;
}
.lib-page-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; color: var(--text-muted);
  letter-spacing: 0.5px;
}

.lib-category { margin-bottom: 32px; }
.lib-cat-title {
  font-size: 13px; font-weight: 600;
  color: var(--text-secondary); text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 10px;
  font-family: 'JetBrains Mono', monospace;
}

.lib-table {
  width: 100%; border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.lib-table thead tr {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.lib-table th {
  padding: 10px 14px;
  text-align: left; font-size: 11px; font-weight: 500;
  color: var(--text-muted); letter-spacing: 0.5px;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}
.lib-table th:last-child { text-align: center; }
.lib-row {
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.1s;
}
.lib-row:last-child { border-bottom: none; }
.lib-row:hover { background: var(--bg); }
.lib-row td { padding: 11px 14px; vertical-align: middle; }

.lib-row-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--text-muted);
  width: 36px;
}
.lib-row-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; font-weight: 500;
  color: var(--accent-light); width: 110px;
  white-space: nowrap;
}
.lib-row-title {
  font-size: 13px; color: var(--text-primary); font-weight: 400;
}
.lib-row-clauses {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; color: var(--text-muted);
  text-align: right; width: 80px;
}
.lib-row-status { text-align: center; width: 130px; }

.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500;
  color: var(--success);
  background: var(--success-bg);
  border-radius: 4px; padding: 3px 8px;
  white-space: nowrap;
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--success); flex-shrink: 0;
}

/* ── DOCUMENT PAGE ──────────────────────────── */
.doc-page {
  flex: 1; overflow-y: auto; padding: 28px 40px 60px;
}
.doc-page::-webkit-scrollbar { width: 4px; }
.doc-page::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.doc-breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 20px; flex-wrap: wrap;
}
.doc-breadcrumb a {
  color: var(--accent-light); text-decoration: none;
  transition: opacity 0.1s;
}
.doc-breadcrumb a:hover { opacity: 0.75; }
.doc-breadcrumb-sep { color: var(--rule-color); }

.doc-header { margin-bottom: 24px; }
.doc-code-badge {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 500;
  color: var(--accent-light);
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 5px; padding: 3px 9px; margin-bottom: 10px;
}
.doc-title {
  font-size: 22px; font-weight: 600;
  color: var(--text-primary); line-height: 1.3; margin-bottom: 8px;
}
.doc-meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}
.doc-meta-sep { color: var(--rule-color); }

/* TOC */
.doc-toc {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
}
.doc-toc-label {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px; font-weight: 500;
  color: var(--text-muted); letter-spacing: 1.5px;
  text-transform: uppercase; background: var(--surface-2);
  cursor: pointer; display: flex; align-items: center; justify-content: space-between;
}
.doc-toc-label:hover { background: var(--bg-2); }
.doc-toc-links {
  padding: 8px 6px;
  display: flex; flex-wrap: wrap; gap: 3px;
}
.doc-toc-links.hidden { display: none; }
.doc-toc-link {
  font-size: 12px; color: var(--text-secondary);
  text-decoration: none; padding: 4px 10px;
  border-radius: 5px; transition: all 0.1s;
  display: inline-flex; gap: 5px;
}
.doc-toc-link:hover { background: var(--bg-2); color: var(--accent-light); }
.doc-toc-link strong {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500; color: var(--accent-light);
}

/* Sections */
.doc-section { margin-bottom: 36px; }
.doc-section-title {
  font-size: 17px; font-weight: 600; color: var(--text-primary);
  border-left: 4px solid var(--accent-light);
  padding-left: 14px; margin-bottom: 16px; line-height: 1.4;
}
.doc-section-num {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent-light); margin-right: 8px;
}

.doc-clause {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.1s;
}
.doc-clause:hover { border-color: var(--border-dark); }
.doc-clause:target {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(45,125,210,0.1);
}

.doc-clause-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; font-weight: 500;
  color: var(--accent-light); margin-bottom: 7px;
}
.doc-clause-text {
  font-size: 13.5px; line-height: 1.75;
  color: var(--text-primary); font-weight: 300;
}

/* Back-to-top */
.back-to-top {
  position: fixed; bottom: 28px; right: 28px;
  width: 38px; height: 38px;
  background: var(--accent); color: white;
  border: none; border-radius: 50%; cursor: pointer;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); transition: all 0.2s;
  opacity: 0; pointer-events: none;
  z-index: 150;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; }
.back-to-top:hover { background: var(--accent-mid); transform: translateY(-2px); }

/* ── MOBILE ─────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --nav-h: 48px;
    --sidebar-w: 80vw;
    --panel-w: 100vw;
  }

  nav.site-nav { padding: 0 14px; }

  /* hide text nav links on mobile, keep feedback icon */
  .nav-link:not(.active):not(.nav-feedback-link) { display: none; }
  .nav-feedback-label { display: none; }
  .nav-feedback-icon { display: inline !important; }
  .nav-divider { display: none; }

  /* sidebar becomes overlay on mobile */
  .sidebar {
    position: fixed; top: var(--nav-h); left: 0; bottom: 0;
    z-index: 150; width: var(--sidebar-w);
    box-shadow: 4px 0 20px rgba(0,0,0,.15);
    transform: translateX(0);
  }
  .sidebar.collapsed {
    transform: translateX(-100%); width: var(--sidebar-w); opacity: 1;
  }

  /* chat sources hidden on mobile */
  .chat-sources { display: none; }

  .home-state { padding: 24px 16px; gap: 20px; }
  .home-title { font-size: 38px; }
  .home-subtitle { font-size: 13px; }
  .search-container { max-width: 100%; }
  .search-input { font-size: 16px; }

  .quick-examples {
    flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
    max-width: 100%; padding-bottom: 4px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .quick-examples::-webkit-scrollbar { display: none; }
  .quick-chip { flex-shrink: 0; }

  .chat-state { padding: 16px 14px; }
  .msg-user { max-width: 90%; font-size: 13.5px; }
  .ai-answer { font-size: 13.5px; }
  .answer-section-body { overflow-x: auto; }
  .params-table { min-width: 300px; }

  .chat-input-footer { padding: 10px 14px; gap: 7px; }

  .lib-page { padding: 20px 16px; }
  .lib-page-title { font-size: 21px; }
  .lib-table th:nth-child(1),
  .lib-table td:nth-child(1) { display: none; }
  .lib-row-status .status-text { display: none; }

  .doc-page { padding: 20px 16px 60px; }
  .doc-title { font-size: 18px; }
  .doc-toc-links { flex-direction: column; }

  .site-footer { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px 16px; }
  .sf-links { flex-wrap: wrap; }
  .sf-right { display: none; }
}

/* ── Compat: clause page ────────────────────── */
.clause-page {
  max-width: 760px; margin: 0 auto; padding: 32px 24px;
}
.back-link-row { display: flex; gap: 14px; margin-bottom: 20px; }
.back-link {
  font-size: 13px; color: var(--accent-light); text-decoration: none;
}
.back-link:hover { text-decoration: underline; }
.clause-page-title {
  font-size: 20px; font-weight: 600; color: var(--text-primary);
  margin-bottom: 16px;
  font-family: 'JetBrains Mono', monospace;
}
.clause-full-text {
  font-size: 14px; line-height: 1.75; color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.clause-section { margin-top: 22px; }
.clause-section h3 {
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase; letter-spacing: 1.2px; margin-bottom: 10px;
}
.clause-tags { display: flex; flex-wrap: wrap; gap: 7px; }
.tag {
  background: var(--tag-bg); border: 1px solid var(--border);
  color: var(--accent-light); border-radius: 5px;
  padding: 4px 10px; font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
}
.clause-refs { display: flex; flex-wrap: wrap; gap: 7px; }
.clause-ref-link {
  font-size: 12px; color: var(--accent-light); text-decoration: none;
  border: 1px solid var(--border); border-radius: 4px; padding: 3px 9px;
}
.clause-ref-link:hover { border-color: var(--accent-light); }
.clause-not-found, .not-found {
  padding-top: 60px; text-align: center; color: var(--text-muted); font-size: 15px;
}
.not-found h2 { font-size: 20px; color: var(--text-primary); margin-bottom: 8px; }
.not-found p { margin-bottom: 16px; }
.btn {
  display: inline-block; background: var(--accent); color: white;
  padding: 8px 18px; border-radius: var(--radius-sm); text-decoration: none;
  font-size: 13px; font-weight: 500; transition: background 0.12s;
}
.btn:hover { background: var(--accent-mid); }

.tags-row { display: flex; flex-wrap: wrap; gap: 7px; }
.refs-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.refs-list li { font-size: 13.5px; }
.ref-link {
  color: var(--accent-light); text-decoration: none; font-weight: 500;
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
}
.ref-link:hover { text-decoration: underline; }
.ref-preview { color: var(--text-secondary); font-size: 12.5px; }
.clause-section-title {
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase; letter-spacing: 1.2px; margin-bottom: 10px;
}

