﻿/* -- CSS Variables / Theming ------------------------------- */
:root {
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;

  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  --sidebar-bg: #0f172a;
  --sidebar-text: #e2e8f0;
  --sidebar-text-muted: #64748b;
  --sidebar-hover: #1e293b;
  --sidebar-active: #1e293b;
  --sidebar-border: #1e293b;

  --user-bubble: #6366f1;
  --user-text: #ffffff;
  --bot-bubble: #f8fafc;
  --bot-border: #e2e8f0;
  --bot-text: #0f172a;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  --sidebar-width: 260px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --surface: #1e293b;
  --surface-hover: #334155;
  --border: #334155;
  --border-light: #1e293b;

  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --sidebar-bg: #020617;
  --sidebar-text: #e2e8f0;
  --sidebar-text-muted: #475569;
  --sidebar-hover: #0f172a;
  --sidebar-active: #1e293b;
  --sidebar-border: #1e293b;

  --bot-bubble: #1e293b;
  --bot-border: #334155;
  --bot-text: #f1f5f9;
}

[data-theme="dark"] #hljs-theme { display: none; }

/* -- Reset ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  transition: background 0.2s, color 0.2s;
}

/* App shell is the sole flex child of body */
#app-shell {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;        /* always flex row; visibility controlled by JS display:none */
  flex-direction: row;
}

/* -- Sidebar ----------------------------------------------- */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.25s ease, transform 0.25s ease;
  overflow: hidden;
  z-index: 100;
  position: relative; /* anchor for the resize handle */
}

/* Sidebar drag-to-resize handle */
#sidebar-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 110;
  background: transparent;
  transition: background 0.15s;
}
#sidebar-resize-handle:hover,
#sidebar-resize-handle.dragging {
  background: var(--accent);
  opacity: 0.5;
}

#sidebar.collapsed {
  width: 56px;
}
#sidebar.collapsed .logo-titles { display: none; }
#sidebar.collapsed .logo { overflow: hidden; width: 0; margin: 0; padding: 0; }
#sidebar.collapsed .sidebar-header { justify-content: center; }
#sidebar.collapsed .history-label { display: none; }
#sidebar.collapsed #history-list { display: none; }
#sidebar.collapsed .btn-label { display: none; }
#sidebar.collapsed .new-chat-btn { justify-content: center; padding: 9px; margin: 8px auto; width: auto; }
#sidebar.collapsed .icon-btn { justify-content: center; padding: 8px; }

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.logo-titles {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}

.logo-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo-tagline {
  font-size: 10px;
  color: var(--sidebar-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sidebar-toggle {
  background: transparent;
  border: none;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
#sidebar-toggle:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }

.new-chat-btn {
  margin: 12px;
  padding: 9px 14px;
  background: transparent;
  color: var(--sidebar-text);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.new-chat-btn:hover {
  background: var(--sidebar-hover);
  border-color: var(--sidebar-text-muted);
  color: var(--sidebar-text);
}

.history-label {
  padding: 8px 16px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-text-muted);
  white-space: nowrap;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 2px; }

.history-item {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--sidebar-text);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
}
.history-item:hover { background: var(--sidebar-hover); }
.history-item.active { background: var(--sidebar-active); }
.history-item-text { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.history-item-del {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 12px;
  transition: opacity 0.1s, color 0.1s;
  flex-shrink: 0;
}
.history-item:hover .history-item-del { opacity: 1; }
.history-item-del:hover { color: #ef4444; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
  width: 100%;
}
.icon-btn:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }
.icon-btn-active { color: var(--accent) !important; background: rgba(99,102,241,0.12) !important; }
.icon-btn-active:hover { color: var(--accent-hover) !important; background: rgba(99,102,241,0.18) !important; }

/* -- Product filter pill bar ------------------------------- */
#product-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 900px;
  margin: 10px auto 0;
  padding: 0 2px;
}
.product-filter-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.product-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.product-pill {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.product-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
.product-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.product-pill:disabled {
  cursor: default;
  opacity: 0.85;
}
.product-pill:disabled:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* -- Main -------------------------------------------------- */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

/* -- Topbar ------------------------------------------------ */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

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

#chat-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn-sm {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
}
.icon-btn-sm:hover { color: var(--text); background: var(--bg-tertiary); }

#mobile-menu-btn { display: none; }

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}
.status-dot.online { background: #22c55e; }
.status-dot.offline { background: #ef4444; }
.status-dot.loading { background: #f59e0b; animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.btn-ghost:hover { background: var(--bg-secondary); color: var(--text); }

/* -- Welcome Screen ---------------------------------------- */
#welcome-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Input inside welcome-wrap has no border separator */
#welcome-wrap #input-area {
  border-top: none;
  width: 100%;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}
#chat-messages::-webkit-scrollbar { width: 5px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message-row {
  display: flex;
  padding: 6px 24px;
  gap: 12px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  animation: fadeInUp 0.2s ease;
}

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

.message-row.user { flex-direction: row-reverse; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 2px;
}
.avatar.user { background: var(--accent); color: white; }
.avatar.bot  { background: var(--bg-secondary); color: var(--text-secondary); border: 1px solid var(--border); }

.message-content { flex: 1; min-width: 0; }

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  font-size: 14px;
  max-width: 100%;
  word-break: break-word;
}

.message-row.user .message-bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
  margin-left: auto;
  max-width: 75%;
}

.message-row.bot .message-bubble {
  background: var(--bot-bubble);
  color: var(--bot-text);
  border: 1px solid var(--bot-border);
  border-bottom-left-radius: 4px;
}

.message-row.bot .message-bubble.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

[data-theme="dark"] .message-row.bot .message-bubble.error {
  background: #450a0a;
  border-color: #7f1d1d;
  color: #fca5a5;
}

/* Markdown content */
.message-bubble p { margin-bottom: 12px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble h1, .message-bubble h2, .message-bubble h3 { margin: 16px 0 8px; font-weight: 600; }
.message-bubble h1 { font-size: 18px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 15px; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; margin-bottom: 12px; }
.message-bubble li { margin-bottom: 4px; }
.message-bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(99,102,241,0.1);
  padding: 2px 6px;
  border-radius: 4px;
}
.message-row.user .message-bubble code { background: rgba(255,255,255,0.2); }
.message-bubble pre {
  background: #1e293b;
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 12px 0;
}
.message-bubble pre code { background: transparent; padding: 0; color: #e2e8f0; font-size: 13px; }
.message-bubble table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13px; }
.message-bubble th, .message-bubble td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.message-bubble th { background: var(--bg-secondary); font-weight: 600; }
.message-bubble blockquote { border-left: 3px solid var(--accent); padding-left: 12px; margin: 12px 0; color: var(--text-secondary); }

/* Message actions */
.message-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.message-row:hover .message-actions { opacity: 1; }
.action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.action-btn:hover { background: var(--bg-secondary); color: var(--text); }
.action-btn.copied { color: #22c55e; border-color: #22c55e; }
.feedback-sep { width: 1px; background: var(--border); margin: 2px 2px; align-self: stretch; }
.like-btn.fb-active-like     { color: #22c55e; border-color: #22c55e; background: #22c55e18; }
.dislike-btn.fb-active-dislike { color: #ef4444; border-color: #ef4444; background: #ef444418; }

/* Feedback inline form */
.feedback-form {
  margin-top: 8px;
  padding: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.feedback-field { display: flex; flex-direction: column; gap: 8px; }
.feedback-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.feedback-textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  font-family: inherit;
  box-sizing: border-box;
}
.feedback-textarea:focus { outline: none; border-color: var(--accent); }
.feedback-actions { display: flex; gap: 8px; margin-top: 4px; }
.feedback-submit-btn {
  padding: 5px 14px; font-size: 12px; font-weight: 600;
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius-sm); cursor: pointer;
}
.feedback-submit-btn:hover { opacity: 0.88; }
.feedback-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.feedback-cancel-btn {
  padding: 5px 12px; font-size: 12px;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
}
.feedback-cancel-btn:hover { background: var(--bg); color: var(--text); }
.feedback-submitted { font-size: 13px; color: #22c55e; font-weight: 500; }
.feedback-error { font-size: 12px; color: #ef4444; margin-top: 4px; }

/* Citations */
.citations-block {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.citations-toggle {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.1s;
}
.citations-toggle:hover { background: var(--bg-tertiary); }
.citations-body { display: none; padding: 8px; }
.citations-body.open { display: block; }
.citation-item {
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.1s;
}
.citation-item:hover { background: var(--bg-secondary); }
.citation-icon { color: var(--accent); flex-shrink: 0; }
.citation-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.citation-page {
  flex-shrink: 0;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* Cost / metadata */
.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  display: flex;
  gap: 12px;
}

/* Thinking indicator */
.thinking-indicator {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bot-bubble);
  border: 1px solid var(--bot-border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
}

/* Scrolling 'Thinking .........' text */
.thinking-text {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 13px;
}
.thinking-dots-scroll {
  display: inline-block;
  overflow: hidden;
  vertical-align: bottom;
  white-space: nowrap;
  width: 0;
  animation: thinking-reveal 2s steps(9, end) infinite;
}
@keyframes thinking-reveal {
  0%   { width: 0; }
  80%  { width: 9ch; }
  100% { width: 9ch; }
}

/* Inline thinking text appended during streaming */
.thinking-inline {
  font-style: italic;
  color: var(--text-secondary);
  font-size: 13px;
  margin-left: 4px;
}

/* Word-by-word reveal: blinking caret trailing the revealed text */
.reveal-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--accent, currentColor);
  opacity: 0.85;
  animation: reveal-caret-blink 1s steps(2, start) infinite;
}
@keyframes reveal-caret-blink {
  0%, 50% { opacity: 0.85; }
  50.01%, 100% { opacity: 0; }
}

/* Respect users who prefer reduced motion: no dot animation */
@media (prefers-reduced-motion: reduce) {
  .reveal-caret { display: none; }
  .thinking-dots-scroll { animation: none; width: 9ch; }
}

/* -- Welcome Screen ---------------------------------------- */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 24px 24px;
  gap: 8px;
  color: var(--text-secondary);
}
.welcome-icon { margin-bottom: 8px; }
.welcome-greeting {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  line-height: 1.2;
}
.welcome-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 2px;
  max-width: 380px;
  line-height: 1.5;
}
.welcome-suggestions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 720px;
}
.suggestion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: left;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
  width: 200px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.suggestion-card:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 2px 10px rgba(99,102,241,0.1);
}
.suggestion-icon { color: var(--accent); flex-shrink: 0; }
.suggestion-text { font-weight: 500; }
.example-question-label { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 8px; }
.examples-grid { display: flex; gap: 8px; margin-top: 4px; }
.example-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.example-btn:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }

/* -- Input Area -------------------------------------------- */
#input-area {
  padding: 16px 24px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
  max-width: 900px;
  margin: 0 auto;
  overflow: hidden;
}
.input-wrapper:focus-within { border-color: var(--accent); }

#question-input {
  flex: 1;
  padding: 14px 16px;
  background: transparent;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  resize: none;
  max-height: 91px;
  line-height: 1.5;
  overflow-y: auto;
}
#question-input::placeholder { color: var(--text-muted); }
#question-input::-webkit-scrollbar { width: 3px; }
#question-input::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.input-actions {
  display: flex;
  align-items: flex-end;
  padding: 10px 12px;
  gap: 8px;
}

.char-count { font-size: 11px; color: var(--text-muted); padding-bottom: 4px; }

#send-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:active { transform: scale(0.95); }
#send-btn:disabled { background: var(--text-muted); cursor: default; transform: none; }
#send-btn.loading { background: var(--accent); opacity: 0.7; cursor: default; }
#send-btn.loading:hover { background: var(--accent); opacity: 0.8; cursor: default; }

/* Hourglass rotation animation */
@keyframes hourglass-flip {
  0%   { transform: rotate(0deg); }
  25%  { transform: rotate(180deg); }
  50%  { transform: rotate(180deg); }
  75%  { transform: rotate(360deg); }
  100% { transform: rotate(360deg); }
}
#send-btn.loading .hourglass-icon {
  animation: hourglass-flip 2s ease-in-out infinite;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
  font-size: 11px;
  color: var(--text-muted);
}

kbd {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: var(--font-mono);
}

.badge {
  background: var(--accent-light);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
}

/* -- Modal ------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 480px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; color: var(--text); }

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

.setting-group { display: flex; flex-direction: column; gap: 6px; }
.setting-group label { font-size: 13px; font-weight: 500; color: var(--text); display: flex; align-items: center; gap: 10px; }
.setting-group small { font-size: 12px; color: var(--text-muted); }
.setting-group input[type="text"] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}
.setting-group input[type="text"]:focus { border-color: var(--accent); }

/* Toggle */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }

/* -- Responsive -------------------------------------------- */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    height: 100%;
    transform: translateX(-100%);
  }
  #sidebar.mobile-open {
    transform: translateX(0);
    width: var(--sidebar-width);
  }
  #mobile-menu-btn { display: flex; }
  .examples-grid { grid-template-columns: 1fr; }
  #chat-title { max-width: 200px; }
}

.form-select {
  width: 100%;
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a99' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

/* -- Product multi-checkbox dropdown --------------------------- */
.product-dropdown-wrap { position: relative; width: 100%; }

.product-dropdown-display {
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color 0.15s;
  position: relative;
}
.product-dropdown-display::after {
  content: '▾';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 12px;
}
.product-dropdown-display.open { border-color: var(--accent); }

.product-dropdown-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 200;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px 0;
}

.product-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.product-option:hover { background: var(--bg-secondary); }
.product-option input[type=checkbox] { accent-color: var(--accent); flex-shrink: 0; }

/* -- Login Screen ------------------------------------------ */
#login-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-top: 4px;
}

.login-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.login-field {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}

.login-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.login-input-wrap {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
}

.login-input-wrap input {
  flex: 1;
  min-width: 0;
  padding: 10px 42px 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-input-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

.eye-btn {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  align-items: center;
  line-height: 1;
  transition: color 0.15s;
}
.eye-btn:hover { color: var(--text-secondary); }

/* Hide Edge's built-in password reveal/clear icons so only our .eye-btn shows. */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear { display: none; }

.login-btn {
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.login-btn:hover:not(:disabled) { background: var(--accent-hover); }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.login-error {
  min-height: 18px;
  font-size: 12px;
  color: #ef4444;
  text-align: center;
}

/* Username/password login additions */
.login-pane { width: 100%; }
.login-links {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 10px;
}
.login-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12.5px;
  padding: 0;
  text-decoration: underline;
}
.login-link:hover { color: var(--accent-hover); }
.login-notice {
  width: 100%;
  margin-top: 10px;
  font-size: 12.5px;
  color: #1a7f37;
  background: rgba(26,127,55,0.08);
  border: 1px solid #1a7f37;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}
.login-pw-rules {
  width: 100%;
  list-style: none;
  margin: 4px 0 6px;
  padding: 0;
  font-size: 12px;
  color: var(--text-muted);
}
.login-pw-rules li { padding: 1px 0; }
.login-pw-rules li.ok { color: #1a7f37; }
/* Common-password line is a warning: hidden unless JS detects a common password. */
.login-pw-rules li[data-rule="common"] { display: none; color: #ef4444; font-weight: 600; }

/* Smooth enter animation when switching login panes */
@keyframes loginPaneIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.login-pane.pane-anim { animation: loginPaneIn 0.24s ease; }

/* Password strength meter (segmented) */
.pw-meter { width: 100%; display: flex; align-items: center; gap: 10px; margin: 2px 0 6px; }
.pw-bars { flex: 1; display: flex; gap: 4px; }
.pw-bars span { flex: 1; height: 5px; border-radius: 999px; background: var(--border); transition: background 0.2s ease; }
.pw-meter-label { font-size: 11px; font-weight: 600; min-width: 46px; text-align: right; color: var(--text-muted); }
.pw-meter[data-score="1"] .pw-bars span:nth-child(-n+1) { background: #ef4444; }
.pw-meter[data-score="2"] .pw-bars span:nth-child(-n+2) { background: #f59e0b; }
.pw-meter[data-score="3"] .pw-bars span:nth-child(-n+3) { background: #3b82f6; }
.pw-meter[data-score="4"] .pw-bars span:nth-child(-n+4) { background: #1a7f37; }
.pw-meter[data-score="1"] .pw-meter-label { color: #ef4444; }
.pw-meter[data-score="2"] .pw-meter-label { color: #b45309; }
.pw-meter[data-score="3"] .pw-meter-label { color: #3b82f6; }
.pw-meter[data-score="4"] .pw-meter-label { color: #1a7f37; }
/* Live confirm-password match */
.pw-match { width: 100%; font-size: 12px; color: #ef4444; min-height: 14px; margin: -2px 0 4px; }
.login-input-wrap input.match-ok { border-color: #1a7f37; }
.login-input-wrap input.match-bad { border-color: #ef4444; }
.login-caps {
  width: 100%;
  margin-top: 10px;
  font-size: 12.5px;
  color: #9a6700;
  background: rgba(154,103,0,0.08);
  border: 1px solid #d4a72c;
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  text-align: center;
}

/* Respect the OS "reduce motion" accessibility setting. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* -- Topbar user welcome ----------------------------------- */
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.topbar-welcome {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* -- Topbar avatar as button ------------------------------- */
button.topbar-avatar {
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, box-shadow 0.15s;
  padding: 0;
}
button.topbar-avatar:hover  { opacity: 0.85; box-shadow: 0 0 0 2px var(--accent); }
button.topbar-avatar:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.topbar-avatar[data-no-profile="true"] { cursor: default; }
button.topbar-avatar[data-no-profile="true"]:hover { opacity: 1; box-shadow: none; }

/* -- Profile popup ----------------------------------------- */
/* position:fixed so overflow:hidden on #main cannot clip it.
   top/right are set dynamically by JS openProfile(). */

.profile-popup {
  position: fixed;
  width: 272px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  padding: 16px;
  animation: profileFadeIn 0.12s ease;
}

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

.profile-popup-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.profile-popup-avatar {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.profile-popup-identity { overflow: hidden; }

.profile-popup-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-popup-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-divider {
  height: 1px;
  background: var(--border);
  margin-bottom: 12px;
}

.profile-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.profile-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-width: 60px;
  padding-top: 2px;
  flex-shrink: 0;
}

.profile-val {
  font-size: 13px;
  color: var(--text-secondary);
  word-break: break-all;
}

.profile-row-products { align-items: flex-start; }

.profile-products {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.profile-product-tag {
  font-size: 11px;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 4px;
  padding: 2px 7px;
}

/* -- Logout button ----------------------------------------- */
.icon-btn-logout:hover { color: #ef4444 !important; }

/* -- Admin Page -------------------------------------------- */
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

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

.admin-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.users-table-wrap {
  flex: 1;
  overflow: auto;
  padding: 24px;
}

.admin-loading, .admin-empty {
  color: var(--text-secondary);
  padding: 40px;
  text-align: center;
  font-size: 14px;
}

.admin-error {
  color: #ef4444;
  padding: 20px;
  text-align: center;
  font-size: 14px;
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.users-table th {
  background: var(--bg-secondary);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.users-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  vertical-align: middle;
}

.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: var(--bg-secondary); }

.badge-active {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: #dcfce7;
  color: #15803d;
}
[data-theme="dark"] .badge-active { background: #14532d; color: #86efac; }

.badge-inactive {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: #fee2e2;
  color: #b91c1c;
}
[data-theme="dark"] .badge-inactive { background: #450a0a; color: #fca5a5; }

/* Background access-sync status */
.sync-failed { margin-top: 4px; font-size: 11px; font-weight: 600; color: #b91c1c; cursor: help; }
[data-theme="dark"] .sync-failed { color: #fca5a5; }
.sync-pending { margin-top: 4px; font-size: 11px; font-weight: 600; color: #b45309; }
[data-theme="dark"] .sync-pending { color: #fcd34d; }
.sync-status-line { margin-left: 10px; font-size: 12px; font-weight: 600; vertical-align: middle; }
.sync-status-bad { color: #b91c1c; cursor: help; }
.sync-status-pending { color: #b45309; cursor: help; }
.sync-status-ok { color: var(--text-muted); font-weight: 500; }
[data-theme="dark"] .sync-status-bad { color: #fca5a5; }
[data-theme="dark"] .sync-status-pending { color: #fcd34d; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn-row {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.1s;
  white-space: nowrap;
}
.btn-row:hover { background: var(--bg-secondary); color: var(--text); }
.btn-row-warn:hover  { border-color: #f59e0b; color: #b45309; background: #fffbeb; }
.btn-row-ok:hover    { border-color: #22c55e; color: #15803d; background: #f0fdf4; }
.btn-row-danger:hover { border-color: #ef4444; color: #b91c1c; background: #fef2f2; }

/* -- Primary button ---------------------------------------- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #ef4444;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-danger:hover { background: #dc2626; }
.ui-confirm-msg { font-size: 13.5px; line-height: 1.5; color: var(--text-secondary); margin: 0; }

/* -- Modals ------------------------------------------------ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  animation: fadeInUp 0.18s ease;
}

.modal-card-sm { max-width: 460px; }

/* -- Sidebar chat search ----------------------------------- */
.history-search-wrap {
  position: relative;
  margin: 4px 12px 8px;
}
.history-search-ico {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--sidebar-text-muted);
  pointer-events: none;
}
.history-search {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px 8px 32px;
  background: var(--sidebar-hover);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.history-search::placeholder { color: var(--sidebar-text-muted); }
.history-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.25);
}
#sidebar.collapsed .history-search-wrap { display: none; }
.history-empty {
  padding: 14px 12px;
  color: var(--sidebar-text-muted);
  font-size: 12.5px;
  font-style: italic;
  text-align: center;
}

/* -- Settings modal ---------------------------------------- */
.settings-card { max-width: 480px; padding: 22px 24px; }
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.settings-head .modal-title { margin: 0; }
.settings-x {
  display: inline-flex;
  padding: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.settings-x:hover { background: var(--border); color: var(--text); }

.settings-account {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 2px 18px;
  border-bottom: 1px solid var(--border);
}
.settings-avatar {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.3px;
}
.settings-idblock { min-width: 0; }
.settings-appname { font-size: 13px; font-weight: 700; color: var(--text); }
.settings-ver { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-left: 4px; }
.settings-username { font-size: 14px; font-weight: 600; color: var(--text); margin-top: 2px; }
.settings-email { font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }

.settings-section { padding: 16px 0; border-bottom: 1px solid var(--border); }
.settings-section:last-child { border-bottom: none; padding-bottom: 2px; }
.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.settings-row-main { display: flex; flex-direction: column; min-width: 0; }
.settings-row-label { font-size: 13.5px; font-weight: 600; color: var(--text); }
.settings-row-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

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

.settings-pw-form { display: flex; flex-direction: column; gap: 8px; max-height: 0; opacity: 0; overflow: hidden; margin-top: 0; transition: max-height 0.3s ease, opacity 0.24s ease, margin-top 0.3s ease; }
.settings-pw-form.open { max-height: 520px; opacity: 1; margin-top: 12px; }
.settings-pw-field { position: relative; display: flex; align-items: center; }
.settings-pw-field input { width: 100%; box-sizing: border-box; padding-right: 40px; }
.settings-pw-field .eye-btn { position: absolute; right: 8px; background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; display: flex; }
.settings-pw-field .eye-btn:hover { color: var(--text); }
.settings-pw-field input.match-ok { border-color: #1a7f37; }
.settings-pw-field input.match-bad { border-color: #ef4444; }
.settings-pw-form input {
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.settings-pw-form input:focus { border-color: var(--accent); }
.settings-pw-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }
.settings-inline-msg { font-size: 12px; color: #b91c1c; min-height: 14px; }
.settings-inline-msg.ok { color: #15803d; }
.settings-inline-warn {
  margin-top: 10px;
  font-size: 12px;
  color: #b45309;
  background: rgba(245,158,11,0.12);
  border: 1px solid rgba(245,158,11,0.35);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.settings-inline-warn.error { color: #b91c1c; background: rgba(239,68,68,0.10); border-color: rgba(239,68,68,0.35); }

.settings-key-reveal { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.settings-key-reveal .key-display {
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-break: break-all;
}

.settings-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  cursor: pointer;
}
.settings-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}
.settings-toggle-label .ts-ico { color: var(--text-muted); }
[data-theme="dark"] .settings-toggle-label .ts-sun { display: none; }
[data-theme="light"] .settings-toggle-label .ts-moon { display: none; }

/* -- Toggle switch ----------------------------------------- */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.18s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform 0.18s;
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:focus-visible + .switch-slider { box-shadow: 0 0 0 2px rgba(99,102,241,0.4); }

/* -- Info tooltip (API key hint) --------------------------- */
.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 5px;
  color: var(--text-muted);
  cursor: help;
  vertical-align: middle;
  outline: none;
}
.info-tip-bubble {
  position: absolute;
  bottom: calc(100% + 9px);
  left: -8px;
  transform: translateY(4px);
  width: max-content;
  max-width: 230px;
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  text-align: left;
  padding: 9px 11px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 10;
}
.info-tip-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 13px;
  border: 5px solid transparent;
  border-top-color: var(--text);
}
.info-tip:hover .info-tip-bubble,
.info-tip:focus .info-tip-bubble,
.info-tip:focus-visible .info-tip-bubble {
  opacity: 1;
  transform: translateY(0);
}

/* -- API key animated reveal drawer ------------------------ */
.settings-key-drawer {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(-4px);
  transition: max-height 0.3s ease, opacity 0.24s ease, transform 0.3s ease;
}
.settings-key-drawer.open {
  max-height: 200px;
  opacity: 1;
  transform: translateY(0);
}
.btn-sm.copied { background: #15803d; }

@media (prefers-reduced-motion: reduce) {
  .settings-key-drawer,
  .info-tip-bubble,
  .switch-slider,
  .switch-slider::before { transition: none; }
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

/* -- User Form --------------------------------------------- */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

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

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="email"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}
.form-group input:disabled { opacity: 0.5; cursor: not-allowed; }
.form-group input.input-error { border-color: #ef4444; }
.form-group input.input-error:focus { border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,0.15); }

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}
.form-hint code {
  background: var(--bg-tertiary);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

.form-group-inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.form-group-inline input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.form-group-inline label { margin: 0; font-size: 13px; font-weight: 500; color: var(--text-secondary); }

.required { color: #ef4444; }

.form-error {
  min-height: 16px;
  font-size: 12px;
  color: #ef4444;
  margin-top: 4px;
}

/* -- Key display ------------------------------------------- */
.key-modal-intro {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.6;
}

.key-modal-warn {
  color: #d97706;
  font-weight: 500;
}

.key-modal-notice {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 3px solid #6366f1;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.key-display-wrap {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin-bottom: 4px;
}

.key-display {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  word-break: break-all;
  white-space: pre-wrap;
}

/* -- Toast notification ------------------------------------ */
.admin-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.admin-toast-show { opacity: 1; transform: translateY(0); }
.admin-toast-success { background: #f0fdf4; color: #15803d; border: 1px solid #86efac; }
.admin-toast-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fca5a5; }
.admin-toast-info    { background: var(--bg-secondary); color: var(--text); border: 1px solid var(--border); }
[data-theme="dark"] .admin-toast-success { background: #14532d; color: #86efac; border-color: #166534; }
[data-theme="dark"] .admin-toast-error   { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }

/* -- Feedback Analytics Page ------------------------------- */
.fb-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
@media (max-width: 700px) { .fb-stats-row { grid-template-columns: repeat(2, 1fr); } }

.fb-stat-card {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-align: center;
}
.fb-stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
}
.fb-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.fb-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}
.fb-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.fb-filters { display: flex; gap: 6px; }
.fb-filter-btn {
  padding: 4px 12px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.fb-filter-btn:hover { background: var(--bg-secondary); color: var(--text); }
.fb-filter-btn.fb-filter-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* -- List controls row (sentiment buttons + page size) -- */
.fb-list-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.fb-page-size-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.fb-page-size-sel {
  padding: 3px 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.fb-page-size-sel:focus { outline: none; border-color: var(--accent); }

/* -- Dimension dropdown filter row -- */
.fb-dropdown-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  align-items: flex-end;
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.fb-dd-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.fb-dd-select {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  min-width: 150px;
}
.fb-dd-select:focus { outline: none; border-color: var(--accent); }

/* -- Pagination -- */
.fb-pagination { margin-top: 12px; }
.fb-pag-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.fb-pag-info {
  font-size: 12px;
  color: var(--text-secondary);
}
.fb-pag-btns {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}
.fb-page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 32px;
}
.fb-page-btn:hover:not(:disabled) { background: var(--bg-secondary); }
.fb-page-btn:disabled { opacity: 0.35; cursor: default; }
.fb-page-btn.fb-page-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
}
.fb-pag-ellipsis {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 0 2px;
  line-height: 32px;
  user-select: none;
}

.fb-question-cell {
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
}
.fb-comment-cell {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  color: var(--text-secondary);
}

.fb-insights-card {
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
.fb-insights-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}
.fb-insights-sub {
  font-size: 12px;
  color: var(--text-muted);
}
.fb-insights-body {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}
.fb-insights-body h2 {
  font-size: 14px;
  font-weight: 700;
  margin: 14px 0 6px;
  color: var(--text);
}
.fb-insights-body ul, .fb-insights-body ol {
  padding-left: 20px;
  margin: 4px 0 10px;
}
.fb-insights-body li { margin-bottom: 4px; }
.fb-insights-body strong { font-weight: 600; }
