@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg-base:        #f4f7f9;
  --bg-panel:       #ffffff;
  --bg-card:        #ffffff;
  --bg-card-hover:  #f8fafc;
  --bg-input:       #f1f5f9;
  --accent:         #2563eb;
  --accent-2:       #0ea5e9;
  --accent-glow:    rgba(37, 99, 235, 0.15);
  --success:        #059669;
  --warning:        #d97706;
  --danger:         #dc2626;
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #64748b;
  --border:         #e2e8f0;
  --border-light:   #f1f5f9;
  --shadow-sm:      0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow:         0 8px 30px rgba(15, 23, 42, 0.08);
  --shadow-hover:   0 12px 40px rgba(37, 99, 235, 0.12);
  --radius:         16px;
  --radius-sm:      10px;
  --radius-lg:      24px;
  --transition:     0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  --bounce:         0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

html, body {
  height: 100%;
  font-family: 'Outfit', 'Inter', -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Focus ── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Layout ── */
#app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-base);
  container-type: inline-size;
}

/* ── Header ── */
.ai-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.ai-header-logo {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-size: 16px; flex-shrink: 0;
  box-shadow: 0 4px 12px var(--accent-glow);
  transform: rotate(-3deg);
  transition: var(--bounce);
}
.ai-header-logo:hover {
  transform: rotate(3deg) scale(1.05);
}

.ai-header-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: clamp(14px, 4cqi, 16px);
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.ai-header-sub {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Nav Tabs ── */
.ai-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-tab {
  flex: 1;
  padding: 10px 6px;
  text-align: center;
  font-size: clamp(11px, 3cqi, 12px);
  font-weight: 600;
  font-family: 'Outfit', sans-serif;
  color: var(--text-muted);
  border: none;
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: var(--transition);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.ai-tab::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 50%; width: 0; height: 3px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  transition: var(--bounce);
  transform: translateX(-50%);
}
.ai-tab:hover  { color: var(--text-primary); background: var(--bg-base); }
.ai-tab.active { color: var(--accent); background: var(--bg-card); }
.ai-tab.active::after { width: 80%; }
.ai-tab i { display: block; font-size: 16px; margin-bottom: 4px; transition: var(--bounce); }
.ai-tab:hover i { transform: translateY(-2px); }

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--accent);
  color: #fff;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  margin-left: 4px;
  vertical-align: middle;
}
.tab-badge:empty { display: none; }

/* ── Tab Content ── */
.ai-tab-content {
  flex: 1;
  overflow: hidden;
  display: none;
  flex-direction: column;
  background: var(--bg-base);
}
.ai-tab-content.active {
  display: flex;
  animation: fadeIn 0.35s ease;
}

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

/* ── Chat Panel ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  position: relative;
}
.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  animation: slideUpFade 0.4s var(--bounce) both;
}
.chat-msg.bot  { flex-direction: row; }
.chat-msg.user { flex-direction: row-reverse; }

@keyframes slideUpFade {
  from { opacity: 0; transform: translateY(15px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; color: white;
  box-shadow: var(--shadow-sm);
}
.msg-avatar.bot  { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.msg-avatar.user { background: linear-gradient(135deg, var(--text-primary), var(--text-muted)); }

.msg-body { max-width: 85%; display: flex; flex-direction: column; gap: 6px; }
.chat-msg.user .msg-body { align-items: flex-end; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
}
.chat-msg.bot .msg-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}
.chat-msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  border-bottom-right-radius: 4px;
  color: #fff;
  box-shadow: 0 4px 15px var(--accent-glow);
}
.msg-meta {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.msg-actions { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.msg-action-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 11px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}
.msg-action-btn:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.msg-hint {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
}

/* Typing indicator */
.typing-dots { display: flex; align-items: center; gap: 5px; padding: 14px 16px; }
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingPulse 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingPulse {
  0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}
.typing-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  display: none;
  width: fit-content;
  box-shadow: var(--shadow-sm);
}
.typing-bubble.active { display: block; }

/* ── Chat Input ── */
.chat-input-area {
  padding: 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.02);
}
.chat-input-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition: var(--transition);
}
.chat-input-row:focus-within {
  background: var(--bg-card);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}
#chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  resize: none;
  max-height: 100px;
  line-height: 1.5;
  padding: 8px 4px;
}
#chat-input::placeholder { color: var(--text-muted); font-weight: 400; }
.chat-send-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  transition: var(--bounce);
  box-shadow: 0 4px 12px var(--accent-glow);
  margin-bottom: 2px;
  position: relative;
  overflow: hidden;
}
.chat-send-btn:hover { transform: scale(1.1) rotate(-10deg); }
.chat-send-btn:active { transform: scale(0.95); }
.chat-send-btn:disabled { background: #cbd5e1; box-shadow: none; cursor: not-allowed; transform: none; }

/* ── Review Panel ── */
.review-panel { padding: 16px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; scroll-behavior: smooth; position: relative; }

.review-config-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.review-config-title {
  font-family: 'Outfit', sans-serif;
  font-size: 15px; font-weight: 600; color: var(--text-primary);
  margin-bottom: 16px; display: flex; align-items: center; gap: 8px;
}
.review-config-title i { color: var(--accent); background: var(--accent-glow); padding: 6px; border-radius: 8px; }

/* Party selector */
.party-selector {
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  width: 100%;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
}
.party-selector:focus { outline: none; background: var(--bg-card); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-glow); }

.selected-party-text { flex: 1; text-align: left; }

.party-dropdown { position: relative; width: 100%; }
.party-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px); left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  z-index: 100;
  display: none;
  max-height: 200px;
  overflow-y: auto;
  padding: 6px;
}
.party-dropdown-menu.open { display: block; animation: slideUpFade 0.2s ease-out; }

.party-search-wrap { padding: 8px 10px; }
.party-search-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: 12px;
  width: 100%;
  font-family: inherit;
  transition: var(--transition);
}
.party-search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.party-dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text-primary);
  font-weight: 500;
  font-size: 13px;
  border-radius: 8px;
  transition: var(--transition);
}
.party-dropdown-item:hover { background: var(--bg-input); color: var(--accent); padding-left: 18px; }

/* Review form row */
.review-form-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* Scope selector (Review scope dropdown) */
.scope-selector {
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
}
.scope-selector:hover { background: var(--bg-card); border-color: var(--text-muted); }
.scope-selector:focus { outline: none; background: var(--bg-card); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-glow); }
.scope-selector[aria-expanded="true"] { border-color: var(--accent); background: var(--bg-card); }

.selected-scope-text { flex: 1; text-align: left; }

.scope-dropdown { position: relative; }
.scope-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px); left: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  z-index: 100;
  display: none;
  min-width: 100%;
  padding: 6px;
}
.scope-dropdown-menu.open { display: block; animation: slideUpFade 0.2s ease-out; }

.scope-dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text-primary);
  font-weight: 500;
  font-size: 13px;
  border-radius: 8px;
  transition: var(--transition);
}
.scope-dropdown-item:hover { background: var(--bg-input); color: var(--accent); padding-left: 18px; }

.form-row { display: flex; gap: 12px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.form-row select, .form-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}
.form-row select:focus, .form-row input:focus { outline: none; background: var(--bg-card); border-color: var(--accent); }

/* Review loading */
.review-loading-indicator {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px;
}
.review-loading-indicator.active { display: flex; }
.review-loading-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.review-loading-text {
  font-size: 12px;
  color: var(--text-muted);
}

/* Review toolbar */
.review-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
}
.review-toolbar:empty { display: none; }
.review-count {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

/* ── Buttons ── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; border-radius: var(--radius-lg);
  color: #fff; font-family: 'Outfit', sans-serif; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: var(--bounce);
  box-shadow: 0 4px 12px var(--accent-glow);
  position: relative;
  overflow: hidden;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { background: #cbd5e1; box-shadow: none; cursor: not-allowed; transform: none; }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-secondary); font-family: 'Outfit', sans-serif; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: var(--transition);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--bg-input); color: var(--text-primary); border-color: var(--text-muted); transform: translateY(-2px); }

.btn-secondary.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-danger-sm {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-lg);
  color: var(--danger); font-weight: 600; font-size: 11px;
  cursor: pointer; transition: var(--transition);
}
.btn-danger-sm:hover { background: #fee2e2; border-color: #fca5a5; }

.btn-success-sm {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-lg);
  color: var(--success); font-weight: 600; font-size: 11px;
  cursor: pointer; transition: var(--transition);
}
.btn-success-sm:hover { background: #d1fae5; border-color: #6ee7b7; }

/* ── Review Result Cards ── */
.review-result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: var(--bounce);
  animation: slideUpFade 0.4s both;
  box-shadow: var(--shadow-sm);
}
.review-result-card:hover { border-color: #cbd5e1; box-shadow: var(--shadow); transform: translateY(-3px); }

.review-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
  gap: 8px;
}
.review-card-header:hover { background: #e2e8f0; }
.review-card-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 600; font-size: 14px; color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
  flex: 1;
  min-width: 0;
}
.review-card-title .badge {
  font-family: 'Inter', sans-serif; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 12px;
  background: var(--accent-glow); color: var(--accent); border: 1px solid rgba(37,99,235,0.2);
  white-space: nowrap;
}
.review-card-actions { display: flex; gap: 8px; flex-shrink: 0; }
.review-card-chevron {
  color: var(--text-muted);
  transition: transform 0.3s ease;
  flex-shrink: 0;
}
.review-card-chevron.expanded { transform: rotate(180deg); }

.review-card-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease;
  opacity: 0;
  background: var(--bg-card);
}
.review-card-body.expanded {
  max-height: 600px;
  opacity: 1;
}
.review-card-body-inner {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.review-section-label {
  font-family: 'Inter', sans-serif;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--text-muted); letter-spacing: 0.8px; margin-bottom: 6px; display: block;
}
.review-desc {
  font-family: 'Inter', sans-serif;
  font-size: 13px; color: var(--text-secondary);
  background: var(--bg-input); border-radius: var(--radius-sm);
  padding: 12px; line-height: 1.6; border: 1px solid var(--border);
}
.review-suggestion {
  font-family: 'Inter', sans-serif;
  font-size: 13px; color: var(--text-primary);
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  padding: 14px; line-height: 1.7;
}

/* ── Insights ── */
.insights-panel { padding: 16px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; scroll-behavior: smooth; position: relative; }

.insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.insights-header-title {
  font-family: 'Outfit', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.insights-empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}

.insight-stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.insight-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: var(--bounce);
  box-shadow: var(--shadow-sm);
}
.insight-stat:hover { border-color: var(--accent); transform: translateY(-4px); box-shadow: var(--shadow); }
.insight-stat-value { font-family: 'Outfit', sans-serif; font-size: 32px; font-weight: 700; line-height: 1; }
.insight-stat-label { font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-top: 8px; text-transform: uppercase; letter-spacing: 0.5px;}
.stat-purple { color: var(--accent); }
.stat-green  { color: var(--success); }
.stat-yellow { color: var(--warning); }
.stat-red    { color: var(--danger); }

.insight-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.insight-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg-card);
}
.insight-card-header:hover { background: var(--bg-input); }
.insight-card-title { font-family: 'Outfit', sans-serif; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 10px; color: var(--text-primary); }
.insight-progress-wrap { padding: 0 16px 14px; }
.insight-progress-bar {
  height: 6px; background: var(--bg-input); border-radius: 6px; overflow: hidden;
}
.insight-progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 6px; transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}
.insight-card-body { padding: 0 16px 16px; display: none; }
.insight-card-body.open { display: block; animation: slideUpFade 0.3s ease-out; }

/* ── Config / Patent Tab ── */
.config-panel { padding: 16px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; scroll-behavior: smooth; position: relative; }

.config-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.config-section-title {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 16px;
}
.config-section-title-row {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
}
.config-chevron {
  transition: transform 0.3s ease;
}
.config-chevron.expanded { transform: rotate(180deg); }

.config-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease, margin-top 0.3s ease, padding-top 0.3s ease;
  opacity: 0;
  margin-top: 0;
  border-top: 1px solid transparent;
  padding-top: 0;
}
.config-body.expanded {
  max-height: 500px;
  opacity: 1;
  margin-top: 16px;
  border-top-color: var(--border);
  padding-top: 16px;
}

.config-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.form-group { margin-bottom: 14px; }
.form-label { font-family: 'Inter', sans-serif; font-weight: 600; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; display: block; }
.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  transition: var(--transition);
}
.form-control:focus { outline: none; background: var(--bg-card); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-glow); }

/* Toggle switch */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.toggle-label { font-family: 'Inter', sans-serif; font-weight: 500; font-size: 13px; color: var(--text-primary); }
.toggle-switch { position: relative; width: 44px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: #cbd5e1;
  border-radius: 24px;
  cursor: pointer;
  transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Loading overlay ── */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
  gap: 20px;
}
.loading-overlay.active {
  display: flex;
  animation: fadeIn 0.3s ease;
}

.loading-spinner {
  width: 50px; height: 50px;
  border: 4px solid var(--bg-input);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s cubic-bezier(0.6, 0.2, 0.4, 0.8) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-family: 'Outfit', sans-serif; font-weight: 600; color: var(--text-primary); font-size: 16px; letter-spacing: 0.5px; }

.loading-stop {
  padding: 8px 24px;
  background: #fff;
  border: 1.5px solid #fecaca;
  border-radius: var(--radius-lg);
  color: var(--danger); font-weight: 600; font-size: 13px; font-family: 'Outfit', sans-serif;
  cursor: pointer; transition: var(--bounce);
  box-shadow: var(--shadow-sm);
}
.loading-stop:hover { background: #fef2f2; transform: translateY(-2px); box-shadow: 0 4px 12px rgba(220, 38, 38, 0.15); }

/* ── Alert ── */
.alert {
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif; font-weight: 500; font-size: 13px; display: none;
  animation: slideUpFade 0.3s ease;
}
.alert.show { display: flex; align-items: center; gap: 8px; }
.alert-danger { background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); }
.alert-success { background: #ecfdf5; border: 1px solid #a7f3d0; color: var(--success); }

/* ── File Manager Modal ── */
.file-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(244, 247, 249, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
}
.file-modal.active {
  display: flex;
  animation: modalBackdropIn 0.25s ease;
}
@keyframes modalBackdropIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.file-modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 380px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-hover);
  animation: modalSlideIn 0.3s var(--bounce);
}
@keyframes modalSlideIn {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.file-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.file-modal-title {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
}
.file-modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
  padding: 4px;
  border-radius: 6px;
}
.file-modal-close:hover { color: var(--danger); }

.file-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.file-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  transition: var(--transition);
}
.file-list-item:hover { background: #e8ecf1; }
.file-list-item > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list-item .file-remove {
  margin-left: auto;
  color: var(--danger);
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: var(--transition);
}
.file-list-item .file-remove:hover { background: #fef2f2; }

.file-modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.file-modal-actions .btn-secondary { flex: 1; justify-content: center; }

/* ── Toast Notifications ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10060; /* Above Bootstrap modal (1050) and backdrop (1040) */
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
  width: fit-content;
  max-width: 320px;
}
.toast {
  display: flex !important; /* Đảm bảo luôn sử dụng flex layout */
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  pointer-events: auto;
  border: 1px solid;
  
  /* CẬP NHẬT LUỒNG ANIMATION */
  animation: toastSlideIn 0.3s ease-out forwards; /* Thêm 'forwards' để giữ lại trạng thái cuối */
  
  /* ĐÈ TRIỆT ĐỂ BẤT KỲ THUỘC TÍNH ẨN NÀO CỦA BOOTSTRAP */
  opacity: 1 !important;        /* Ép buộc luôn hiển thị, không bị trả về 0 khi hết hiệu ứng */
  white-space: normal !important; /* Cho phép tự động xuống dòng khi chữ dài */
  max-width: 100% !important;     /* Không bị bó hẹp khung */
  flex-basis: auto !important;    /* Loại bỏ thuộc tính chia tỉ lệ của Bootstrap */
  line-height: 1.4;
}
.toast.removing {
  animation: toastSlideOut 0.25s ease forwards;
}
@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(100%); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastSlideOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(100%); }
}
.toast-success { background: #ecfdf5; border-color: #a7f3d0; color: var(--success); }
.toast-error   { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.toast-warning { background: #fffbeb; border-color: #fde68a; color: var(--warning); }
.toast-info    { background: #eff6ff; border-color: #bfdbfe; color: var(--accent); }

.toast-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  font-size: 16px;
  padding: 2px;
  line-height: 1;
}
.toast-close:hover { opacity: 1; }

/* ── Skeleton Loading ── */
.skeleton {
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.skeleton-bubble {
  height: 60px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.skeleton-card {
  height: 100px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.skeleton-stat {
  height: 90px;
  border-radius: var(--radius);
}

/* ── Scroll to top ── */
.scroll-top-btn {
  position: absolute;
  bottom: 80px;
  right: 20px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  z-index: 5;
}
.scroll-top-btn.visible { display: flex; }
.scroll-top-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); transform: translateY(-2px); }

/* ── Icon Utilities ── */
.icon-logo { width: 18px; height: 18px; stroke-width: 2.5; }
.icon-avatar { width: 16px; height: 16px; }
.icon-send { width: 18px; height: 18px; stroke-width: 2.5; }
.icon-chevron-sm { width: 14px; height: 14px; color: var(--text-muted); }
.icon-xs { width: 12px; height: 12px; }
.icon-btn { width: 14px; height: 14px; }
.icon-empty { width: 32px; height: 32px; opacity: 0.4; display: block; margin: 0 auto 12px; }
.icon-file { color: var(--accent); width: 16px; height: 16px; flex-shrink: 0; }
.icon-remove { width: 14px; height: 14px; }
.icon-review-title { color: var(--accent); background: var(--accent-glow); padding: 6px; border-radius: 8px; width: 16px; height: 16px; }

/* ── Misc ── */
del { text-decoration: line-through; color: var(--danger); opacity: 0.8; background: #fee2e2; padding: 0 2px; border-radius: 2px; }
strong, b { font-weight: 700; color: var(--accent); background: #eff6ff; padding: 0 2px; border-radius: 2px;}
a { color: var(--accent); text-decoration: none; font-weight: 600; transition: var(--transition); }
a:hover { color: var(--accent-2); text-decoration: underline; }

/* ══════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ══════════════════════════════════════════════════ */

@container (max-width: 300px) {
  .ai-header { padding: 12px 14px; gap: 10px; }
  .ai-header-logo { width: 28px; height: 28px; }
  .ai-header-sub { display: none; }
  .ai-tabs { padding: 8px 10px 0; gap: 4px; }
  .ai-tab { padding: 8px 4px; }
  .chat-messages { padding: 12px; gap: 12px; }
  .msg-body { max-width: 92%; }
  .msg-bubble { padding: 10px 12px; font-size: 12.5px; }
  .chat-input-area { padding: 10px; }
  .review-panel, .insights-panel, .config-panel { padding: 10px; }
  .review-config-card { padding: 14px; }
  .review-form-row { flex-direction: column; }
  .review-form-row .btn-primary,
  .review-form-row .btn-secondary { width: 100%; }
  .insight-stat-row { grid-template-columns: 1fr; }
  .insight-stat { padding: 14px; }
  .insight-stat-value { font-size: 26px; }
  .config-actions { flex-direction: column; }
  .config-actions .btn-primary,
  .config-actions .btn-secondary { width: 100%; }
  .btn-primary, .btn-secondary { width: 100%; justify-content: center; }
  .file-modal-dialog { padding: 18px; }
}

@container (min-width: 400px) {
  .ai-header { padding: 18px 24px; }
  .chat-messages { padding: 24px; }
  .msg-body { max-width: 80%; }
  .review-panel, .insights-panel, .config-panel { padding: 20px; }
  .review-form-row { flex-wrap: nowrap; }
  .insight-stat { padding: 24px; }
}

@container (min-width: 550px) {
  .ai-header { padding: 20px 28px; }
  .chat-messages { padding: 28px; gap: 20px; }
  .msg-body { max-width: 75%; }
  .review-panel, .insights-panel, .config-panel { padding: 24px; }
  .insight-stat-row { gap: 16px; }
}

/* ══════════════════════════════════════════════════
   REDUCED MOTION
   ══════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .chat-msg { animation: none; }
  .review-result-card { animation: none; }
  .ai-tab-content.active { animation: none; }
}

a { color: var(--accent); text-decoration: none; font-weight: 600; transition: var(--transition); }
a:hover { color: var(--accent-2); text-decoration: underline; }

/* ═══════════════════════════════════════
   RISK ANALYSIS
   ═══════════════════════════════════════ */

/* Risk button */
.btn-risk {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 9px 13px; font-size: 12px; font-weight: 600;
  border-radius: var(--radius-sm); border: 1.5px solid #f97316;
  background: #fff7ed; color: #c2410c;
  cursor: pointer; transition: var(--transition); font-family: inherit;
  white-space: nowrap;
}
.btn-risk:hover { background: #fed7aa; border-color: #ea580c; }
.btn-risk:disabled { opacity: 0.5; cursor: not-allowed; }

/* Ghost small button */
.btn-ghost-sm {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 7px 12px; font-size: 12px; font-weight: 500;
  border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: transparent; color: var(--text-muted);
  cursor: pointer; transition: var(--transition); font-family: inherit;
}
.btn-ghost-sm:hover { background: var(--bg-input); color: var(--text-primary); border-color: var(--border-strong); }

/* Risk header */
.risk-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  padding: 10px 0 8px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 10px;
}
.risk-header-title {
  font-family: 'Outfit', sans-serif; font-size: 14px; font-weight: 700;
  color: var(--text-primary); display: flex; align-items: center; gap: 8px;
}
.risk-count { font-size: 11px; font-weight: 500; color: var(--text-muted); }
.risk-summary-badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* Risk level badges */
.risk-badge {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 600;
}
.risk-badge.risk-red    { background: #fee2e2; color: #b91c1c; }
.risk-badge.risk-yellow { background: #fef9c3; color: #854d0e; }
.risk-badge.risk-green  { background: #dcfce7; color: #15803d; }

/* Risk cards */
.risk-card {
  border-radius: var(--radius-sm); margin-bottom: 8px;
  border: 1.5px solid var(--border); overflow: hidden;
  transition: box-shadow 0.2s ease;
}
.risk-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.risk-card-red    { border-left: 4px solid #ef4444; }
.risk-card-yellow { border-left: 4px solid #f59e0b; }
.risk-card-green  { border-left: 4px solid #22c55e; }

.risk-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; cursor: pointer;
  background: var(--bg-card);
  user-select: none;
}
.risk-card-left { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.risk-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.risk-dot-red    { background: #ef4444; }
.risk-dot-yellow { background: #f59e0b; }
.risk-dot-green  { background: #22c55e; }

.risk-card-title {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.risk-level-badge {
  display: inline-block; padding: 2px 8px;
  border-radius: 999px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; flex-shrink: 0;
}
.risk-level-red    { background: #fee2e2; color: #b91c1c; }
.risk-level-yellow { background: #fef9c3; color: #854d0e; }
.risk-level-green  { background: #dcfce7; color: #15803d; }

.risk-card-body {
  display: none; flex-direction: column; gap: 8px;
  padding: 0 12px 12px; background: var(--bg-card);
}
.risk-card-body.expanded { display: flex; }

.risk-explanation {
  font-size: 12px; color: var(--text-secondary); line-height: 1.55;
}

.risk-source-quote {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  background: #fffbeb; border: 1px solid #fde68a;
  font-size: 11px; color: #78350f; line-height: 1.5;
  cursor: pointer; transition: background 0.15s;
}
.risk-source-quote:hover { background: #fef3c7; }
.risk-source-quote span { flex: 1; word-break: break-word; }

/* ═══════════════════════════════════════
   AMENDMENT TRACER
   ═══════════════════════════════════════ */
.amendment-tracer-card {
  background: var(--bg-card); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px; margin-top: 10px;
}
.amendment-tracer-title {
  display: flex; align-items: center; gap: 6px;
  font-family: 'Outfit', sans-serif; font-size: 13px; font-weight: 700;
  color: var(--text-primary); margin-bottom: 12px;
}
.amendment-close-btn {
  margin-left: auto; background: none; border: none;
  font-size: 18px; color: var(--text-muted); cursor: pointer; line-height: 1;
  padding: 0 2px;
}
.amendment-close-btn:hover { color: var(--danger); }

.amendment-fields {
  display: flex; flex-direction: column; gap: 10px;
}
.amendment-field { display: flex; flex-direction: column; gap: 5px; }
.amendment-textarea {
  background: var(--bg-input); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px;
  color: var(--text-primary); font-size: 12px; font-family: inherit;
  resize: vertical; line-height: 1.5; transition: border-color 0.2s;
}
.amendment-textarea:focus { outline: none; border-color: var(--accent); }

/* Diff result */
.diff-result-card {
  background: var(--bg-input); border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.diff-result-summary {
  display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap;
}
.diff-summary-text { font-size: 12px; color: var(--text-secondary); line-height: 1.5; flex: 1; }
.diff-changes { display: flex; flex-direction: column; gap: 6px; }
.diff-change-item {
  padding: 7px 10px; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border-light);
}
.diff-change-desc { font-size: 12px; color: var(--text-primary); font-weight: 500; margin-bottom: 3px; }
.diff-change-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; color: var(--text-muted); }
.diff-favors { font-weight: 600; color: var(--accent); }
.diff-recommendation {
  font-size: 12px; color: var(--text-secondary); padding: 8px 10px;
  background: #eff6ff; border-radius: var(--radius-sm); border: 1px solid #bfdbfe;
  line-height: 1.5;
}