:root {
  --bg-dark: #070a12;
  --bg-card: rgba(15, 22, 37, 0.75);
  --bg-card-hover: rgba(22, 32, 54, 0.85);
  --bg-input: #0f172a;
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-focus: #6366f1;
  --accent-indigo: #6366f1;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-purple: #8b5cf6;
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* ---- Design tokens (light theme overrides the colour ones below) ---- */
  /* Spacing: 4px base */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Type scale */
  --fs-caption: 11px;   /* uppercase labels, meta */
  --fs-label: 12px;     /* buttons, captions, table headers */
  --fs-body: 13px;      /* table cells, secondary text */
  --fs-body-lg: 14px;   /* summary / primary reading text */
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --lh-tight: 1.25;
  --lh-body: 1.55;

  /* Radii */
  --radius-xs: 6px;
  --radius-sm: 8px;     /* buttons, inputs, tables, inner panels */
  --radius-md: 12px;    /* cards */
  --radius-lg: 16px;    /* large containers */
  --radius-pill: 999px;

  /* Elevation */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.25), 0 6px 20px rgba(0, 0, 0, 0.22);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.3), 0 14px 36px rgba(0, 0, 0, 0.38);

  /* Borders & surfaces */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-accent: rgba(99, 102, 241, 0.5);
  --surface-raised: rgba(255, 255, 255, 0.03);
  --surface-hover: rgba(99, 102, 241, 0.1);
  --surface-active: rgba(99, 102, 241, 0.18);
  --surface-sunken: rgba(10, 15, 26, 0.45);
  --surface-menu: #121a2c;
  --focus-ring: 0 0 0 2px var(--bg-dark), 0 0 0 4px rgba(129, 140, 248, 0.85);

  /* Data table */
  --table-cell-px: 12px;   /* shared by th AND td so columns line up */
  --table-cell-py: 8px;
  --table-head-bg: #111a2e;
  --table-head-fg: #a5b4fc;
  --table-row-border: rgba(255, 255, 255, 0.06);
  --table-row-hover: rgba(99, 102, 241, 0.08);

  /* Scrollbars (native controls follow color-scheme; custom thumbs use these) */
  color-scheme: dark;
  --scroll-thumb: rgba(148, 163, 184, 0.28);
  --scroll-thumb-hover: rgba(148, 163, 184, 0.45);
  /* Opaque background for sticky table cells (the Actions column) */
  --table-sticky-bg: #0e1526;

  /* Result card */
  --ai-avatar-size: 32px;
  --ai-actions-width: 148px;
  --control-h: 32px;
}

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

body {
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.12) 0px, transparent 50%),
    radial-gradient(at 50% 50%, rgba(139, 92, 246, 0.08) 0px, transparent 50%);
  color: var(--text-main);
  font-family: var(--font-sans);
  /* Fixed-height app shell: header + sidebar stay put, only inner regions scroll */
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Glassmorphism panel helper */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border-glass);
  background: rgba(7, 10, 18, 0.85);
  backdrop-filter: blur(24px);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand-logo-img {
  height: 38px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
  background: #ffffff;
  padding: 4px 10px;
  border-radius: 10px;
  box-shadow: 0 0 15px rgba(245, 158, 11, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.brand-logo-img:hover {
  transform: scale(1.04);
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.4);
}

.brand-name {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tag {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.35);
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* Navigation Controls */
.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.db-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  padding: 6px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-glass);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}

.db-selector-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.db-select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}

.db-select option {
  background: #121826;
  color: #fff;
}

/* App Layout */
.app-container {
  display: flex;
  flex: 1;
  min-height: 0; /* allow the flex child to shrink below its content height */
  overflow: hidden;
}

/* Sidebar Navigation Tabs */
.sidebar-tabs {
  width: 260px;
  min-width: 260px;
  padding: 16px 12px;
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  background: rgba(10, 15, 26, 0.85);
  backdrop-filter: blur(20px);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s ease;
  user-select: none;
  min-height: 0; /* sidebar matches the viewport height; its history list scrolls internally */
  overflow: hidden;
}

.sidebar-top-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.btn-new-chat {
  flex: 1;
  border-radius: 10px;
  justify-content: center;
  font-weight: 700;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
  transition: all 0.2s ease;
}

.btn-new-chat:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.sidebar-collapse-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  color: var(--text-muted);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

/* Sidebar History (Scrollable ChatGPT style) */
.sidebar-history-container {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-right: 4px;
  margin-bottom: 12px;
}

.sidebar-history-container::-webkit-scrollbar {
  width: 4px;
}

.sidebar-history-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.chat-section-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-section-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.6px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chat-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.chat-history-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}

.chat-history-item.active {
  background: rgba(99, 102, 241, 0.18);
  border-left-color: var(--accent-indigo);
  color: #fff;
  font-weight: 600;
}

.chat-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

.chat-title-span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

/* ChatGPT Style Inline Rename Input */
.chat-inline-rename-input {
  background: var(--bg-input);
  border: 1px solid var(--accent-indigo);
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 2px 6px;
  outline: none;
  width: 140px;
  font-family: inherit;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

.chat-header-rename-input {
  background: var(--bg-input);
  border: 1px solid var(--accent-indigo);
  border-radius: 6px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 4px 10px;
  outline: none;
  font-family: inherit;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

.chat-item-actions {
  display: none;
  align-items: center;
  gap: 4px;
}

.chat-history-item:hover .chat-item-actions,
.chat-history-item.active .chat-item-actions {
  display: flex;
}

.chat-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 5px;
  font-size: 11px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.chat-action-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

/* Sidebar Bottom Tools Section */
.sidebar-bottom-tools {
  border-top: 1px solid var(--border-glass);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: auto;
}

.sidebar-tools-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  transition: background 0.2s ease;
}

.sidebar-tools-header:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

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

.sidebar-tools-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.3s ease;
}

.sidebar-tools-menu.tools-collapsed {
  display: none;
}

.sidebar-collapse-bar {
  padding-top: 6px;
  border-top: 1px dashed var(--border-glass);
  margin-top: 4px;
}

.sidebar-collapse-bar-btn {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.sidebar-collapse-bar-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

/* Collapsed Sidebar Mode */
.sidebar-tabs.collapsed {
  width: 64px;
  min-width: 64px;
  padding: 16px 8px;
}

.sidebar-tabs.collapsed .btn-new-chat span,
.sidebar-tabs.collapsed .chat-section-header span,
.sidebar-tabs.collapsed .chat-title-span,
.sidebar-tabs.collapsed .chat-item-actions,
.sidebar-tabs.collapsed .tools-header-label span,
.sidebar-tabs.collapsed .toggle-icon,
.sidebar-tabs.collapsed .nav-tab-btn span,
.sidebar-tabs.collapsed .sidebar-collapse-bar-btn span {
  display: none !important;
}

.sidebar-tabs.collapsed .btn-new-chat {
  padding: 10px;
  justify-content: center;
}

.sidebar-tabs.collapsed .chat-section-header {
  justify-content: center;
}

.sidebar-tabs.collapsed .chat-history-item {
  justify-content: center;
  padding: 8px 0;
}

.sidebar-tabs.collapsed .nav-tab-btn {
  justify-content: center;
  padding: 10px 0;
}

.sidebar-tabs.collapsed .sidebar-collapse-btn #sidebar-toggle-icon,
.sidebar-tabs.collapsed .sidebar-collapse-bar-btn #collapse-bar-icon {
  transform: rotate(180deg);
}

.nav-tab-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.nav-tab-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.nav-tab-btn.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(6, 182, 212, 0.18));
  border-color: rgba(99, 102, 241, 0.45);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.nav-tab-btn i {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* Main Viewport */
.main-viewport {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

.tab-pane.active {
  display: flex;
}

/* Section Titles */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-main);
  border: 1px solid var(--border-glass);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  color: #f43f5e;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.btn-danger:hover {
  background: rgba(244, 63, 94, 0.25);
}

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

/* Input Fields */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border-glass);
  color: #fff;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Chat & Data Studio */
.query-box-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 22px;
  background: var(--bg-card);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  margin-top: auto;
}

/* Suggested questions: equal-width grid cells, one line each, full text in the title tooltip */
.sample-prompts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: var(--space-2);
}
.sample-prompts:empty { display: none; }

.prompt-chip {
  min-width: 0;
  height: var(--control-h);
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--surface-raised);
  border: 1px solid var(--border-glass);
  font: var(--fw-medium) var(--fs-label) / 1 var(--font-sans);
  color: #a5b4fc;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.prompt-chip-icon { flex-shrink: 0; font-size: var(--fs-caption); color: var(--accent-amber); }
.prompt-chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.prompt-chip:hover {
  background: var(--surface-hover);
  border-color: var(--border-accent);
  color: var(--text-main);
  box-shadow: var(--shadow-1);
}

.prompt-chip:active {
  background: var(--surface-active);
  box-shadow: none;
}

.input-row {
  display: flex;
  gap: 12px;
}

.nlp-input {
  flex: 1;
  padding: 14px 20px;
  font-size: 14px;
  border-radius: 12px;
  background: rgba(10, 15, 26, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
}

.nlp-input:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25), inset 0 2px 4px rgba(0,0,0,0.3);
}

/* Output Console & Result Tabs */
.results-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Conversational Chat Thread Layout */
.chat-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.chat-header-title-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.2px;
}

.icon-btn-sm {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.icon-btn-sm:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

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

.chat-messages-container {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 12px 4px;
  min-height: 380px;
  max-height: calc(100vh - 270px);
}

.chat-messages-container::-webkit-scrollbar {
  width: 6px;
}

.chat-messages-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
}

.chat-messages-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Individual Chat Message Turn */
.chat-turn {
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadeInTurn 0.3s ease;
}

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

.user-turn-bubble {
  align-self: flex-end;
  max-width: 82%;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.28), rgba(139, 92, 246, 0.22));
  border: 1px solid rgba(99, 102, 241, 0.45);
  border-radius: 18px 18px 4px 18px;
  padding: 14px 20px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  line-height: 1.5;
}

.user-turn-avatar {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #fff;
  flex-shrink: 0;
  margin-top: 1px;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

.ai-turn-card {
  align-self: flex-start;
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-top: 2px solid var(--accent-indigo);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

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

.ai-turn-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #a5b4fc;
}

.chat-welcome-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  gap: 16px;
}

.chat-welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(6, 182, 212, 0.25));
  border: 1px solid rgba(99, 102, 241, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: #818cf8;
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.3);
}

.chat-welcome-title {
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.3px;
}

.chat-welcome-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 480px;
  line-height: 1.6;
}

.results-header-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-glass);
  padding-bottom: 10px;
}

/* Modern Segment Control Pills */
.tab-pill-group {
  display: flex;
  gap: 6px;
  background: rgba(10, 15, 26, 0.6);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border-glass);
}

.tab-pill {
  padding: 6px 14px;
  border-radius: 7px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tab-pill:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

.tab-pill.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(139, 92, 246, 0.25));
  color: #fff;
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.execution-badge {
  font-size: 12px;
  color: var(--accent-emerald);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  background: rgba(16, 185, 129, 0.12);
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

/* Data Grid Table */
.data-grid-wrapper {
  max-height: 420px;
  overflow: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
  background: var(--surface-sunken);
}

/* separate + 0 spacing (not collapse) so the sticky header keeps its bottom border while the body scrolls */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-body);
  line-height: 1.45;
  text-align: left;
}

/* th and td share the SAME padding tokens so every column edge lines up */
.data-table th,
.data-table td {
  padding: var(--table-cell-py) var(--table-cell-px);
  vertical-align: middle;
  text-align: left;
}

.data-table th {
  background: var(--table-head-bg);
  color: var(--table-head-fg);
  font-size: var(--fs-label);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.2px;
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--border-strong);
}

.data-table td {
  border-bottom: 1px solid var(--table-row-border);
  color: var(--text-main);
  white-space: nowrap;
}

.data-table tbody tr:last-child td { border-bottom: 0; }

.data-table tbody tr { transition: background-color 0.12s ease; }
.data-table tbody tr:hover { background: var(--table-row-hover); }

/* Numeric columns: right-aligned, fixed-width digits (applied by renderTableHead/BodyHtml via isNumericColumn) */
.data-table th.num,
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.cell-null { color: var(--text-dim); }

/* Chart Canvas Wrapper */
.chart-wrapper {
  padding: 24px;
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-card {
  text-align: center;
  padding: 40px;
}

.kpi-value {
  font-size: 48px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-indigo));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.kpi-label {
  font-size: 16px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* SQL Code Block */
.sql-editor-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sql-code-area {
  background: #0d1321;
  font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 14px;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
  color: #a5b4fc;
  min-height: 120px;
  resize: vertical;
}

/* Power BI Relationship Manager Table */
.rel-table-container {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
}

/* Data Studio: fixed-height page. Header bar and prompt box always stay on screen; only the message
   list scrolls and takes whatever height is left (replaces the old 100vh-based max-height guess) */
#tab-studio {
  flex: 1;
  min-height: 0;
}
#tab-studio .chat-header-bar,
#tab-studio .query-box-container { flex-shrink: 0; }
#tab-studio .chat-messages-container {
  flex: 1 1 auto;
  min-height: 120px;
  max-height: none;
  overscroll-behavior: contain;
}

/* Short windows (laptops, zoomed browsers): give the height to the messages, not the chrome around them */
@media (max-height: 800px) {
  .main-viewport { padding: var(--space-4) var(--space-6); }
  #tab-studio { gap: var(--space-3); }
  #tab-studio .chat-header-bar { margin-bottom: 0; padding-top: var(--space-2); padding-bottom: var(--space-2); }
  #tab-studio .query-box-container { gap: var(--space-3); padding: var(--space-3) var(--space-4); }
  /* chips: one side-scrolling row instead of a multi-row grid */
  .sample-prompts { display: flex; flex-wrap: nowrap; overflow-x: auto; padding: var(--space-1); margin: calc(-1 * var(--space-1)); scrollbar-width: none; }
  .sample-prompts::-webkit-scrollbar { display: none; }
  .sample-prompts .prompt-chip { flex: 0 0 auto; max-width: 300px; }
}

/* Relationship Designer: fixed-height page, only the relationships list scrolls */
#tab-relationships {
  flex: 1;
  min-height: 0;
}

#tab-relationships .section-header {
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 0;
}

#tab-relationships .section-header > div:last-child {
  flex-wrap: wrap;
}

#tab-relationships .rel-table-container {
  flex: 1 1 auto;
  min-height: 220px; /* stays usable on short screens; the viewport scrolls only below this */
  overflow: auto;
  overscroll-behavior: contain;
}

#tab-relationships .rel-table-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#tab-relationships .rel-table-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

@media (max-width: 900px) {
  #tab-relationships .section-header > div:last-child {
    width: 100%;
  }
  #tab-relationships .section-header .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}

.badge-auto {
  background: rgba(6, 182, 212, 0.15);
  color: #06b6d4;
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.badge-manual {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.badge-cardinality {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #334155;
  transition: .2s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
}

input:checked+.slider {
  background-color: var(--accent-indigo);
}

input:checked+.slider:before {
  transform: translateX(16px);
}

/* ER Diagram Visual Canvas */
.er-canvas-container {
  width: 100%;
  height: 650px;
  border-radius: var(--radius-md);
  position: relative;
  overflow: auto;
  background: #090d16;
  background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 0);
  background-size: 24px 24px;
}

.er-svg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.er-tables-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
}

.er-table-card {
  position: absolute;
  width: 210px;
  background: rgba(18, 24, 38, 0.95);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px);
  cursor: move;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.er-table-card:hover,
.er-table-card.selected {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.4);
}

.er-table-header {
  padding: 10px 14px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(6, 182, 212, 0.15));
  border-bottom: 1px solid var(--border-glass);
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top-left-radius: var(--radius-sm);
  border-top-right-radius: var(--radius-sm);
}

.er-table-cols {
  padding: 8px 0;
  max-height: 220px;
  overflow-y: auto;
}

.er-col-item {
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.er-col-name {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-main);
  font-weight: 500;
}

.er-col-type {
  font-size: 10px;
  color: var(--text-dim);
}

.icon-pk {
  color: #f59e0b;
}

.icon-fk {
  color: var(--accent-cyan);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-backdrop.active {
  display: flex;
}

.modal-box {
  width: 90%;
  max-width: 520px;
  padding: 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.auth-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  filter: brightness(1.1);
}

/* ChatGPT-Style Voice Mic Controls & Speech Engine Selector */
.voice-engine-select {
  max-width: 220px;
  padding: 10px 12px;
  font-size: 13px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.2s ease;
}

.voice-engine-select:focus, .voice-engine-select:hover {
  border-color: #6366f1;
  background: rgba(30, 41, 59, 0.95);
}

.voice-control-wrapper {
  display: flex;
  align-items: center;
}

.voice-mic-btn {
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 16px;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
}

.voice-mic-btn:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: #38bdf8;
  color: #fff;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

/* ChatGPT-Style Rounded Action Pill */
.voice-action-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px;
  border-radius: 30px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  animation: pillFadeIn 0.25s ease-out;
}

@keyframes pillFadeIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.voice-recording-pulse {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #f43f5e;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f43f5e;
  box-shadow: 0 0 8px #f43f5e;
  animation: dotPulse 1.2s infinite ease-in-out;
}

@keyframes dotPulse {
  0% { transform: scale(0.85); opacity: 0.7; }
  50% { transform: scale(1.3); opacity: 1; box-shadow: 0 0 14px #f43f5e; }
  100% { transform: scale(0.85); opacity: 0.7; }
}

.voice-pill-divider {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.2);
}

.voice-pill-btn {
  background: transparent;
  border: none;
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.voice-cancel-btn {
  color: #94a3b8;
}

.voice-cancel-btn:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
  transform: scale(1.1);
}

.voice-confirm-btn {
  color: #38bdf8;
}

.voice-confirm-btn:hover {
  color: #10b981;
  background: rgba(16, 185, 129, 0.2);
  transform: scale(1.1);
}

/* =====================================================================
   LIGHT THEME
   Dark theme = the original rules above (untouched).
   Light theme = palette variable overrides + targeted overrides for the
   few hard-coded dark colours and inline template styles.
   ===================================================================== */
.theme-toggle-btn {
  min-width: 78px;
  justify-content: center;
}

[data-theme="light"] {
  color-scheme: light;
  --bg-dark: #f3f5fa;
  --bg-card: rgba(255, 255, 255, 0.94);
  --bg-card-hover: #ffffff;
  --bg-input: #ffffff;
  --border-glass: rgba(15, 23, 42, 0.12);
  --border-focus: #4f46e5;
  --accent-cyan: #0891b2;
  --accent-emerald: #059669;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
  --lt-strong: #0f172a;
  --lt-hover: rgba(15, 23, 42, 0.05);
  --lt-hover-strong: rgba(15, 23, 42, 0.09);
  --lt-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --lt-soft-accent: #4f46e5;
  --lt-scroll-thumb: rgba(15, 23, 42, 0.22);

  /* Design tokens (light) */
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.07);
  --shadow-2: 0 2px 6px rgba(15, 23, 42, 0.08), 0 12px 28px rgba(15, 23, 42, 0.14);
  --border-subtle: rgba(15, 23, 42, 0.07);
  --border-strong: rgba(15, 23, 42, 0.18);
  --border-accent: rgba(79, 70, 229, 0.45);
  --surface-raised: #ffffff;
  --surface-hover: rgba(99, 102, 241, 0.07);
  --surface-active: rgba(99, 102, 241, 0.12);
  --surface-sunken: rgba(15, 23, 42, 0.025);
  --surface-menu: #ffffff;
  --focus-ring: 0 0 0 2px #ffffff, 0 0 0 4px rgba(79, 70, 229, 0.75);
  --table-head-bg: #f1f4fb;
  --table-head-fg: #3730a3;
  --table-row-border: rgba(15, 23, 42, 0.07);
  --table-row-hover: rgba(99, 102, 241, 0.05);
  --scroll-thumb: rgba(15, 23, 42, 0.22);
  --scroll-thumb-hover: rgba(15, 23, 42, 0.36);
  --table-sticky-bg: #ffffff;
}

[data-theme="light"] body {
  background-image:
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.07) 0px, transparent 50%);
}

/* Header & brand */
[data-theme="light"] .app-header { background: rgba(255, 255, 255, 0.92); }
[data-theme="light"] .brand-name { background: linear-gradient(135deg, #1e1b4b, #6366f1); -webkit-background-clip: text; }
[data-theme="light"] .brand-tag { color: var(--lt-soft-accent); background: rgba(99, 102, 241, 0.1); }
[data-theme="light"] .brand-logo-img { border-color: rgba(15, 23, 42, 0.1); }
[data-theme="light"] .db-selector-wrapper { box-shadow: none; }
[data-theme="light"] .db-select option { background: #ffffff; color: var(--text-main); }

/* Sidebar */
[data-theme="light"] .sidebar-tabs { background: rgba(255, 255, 255, 0.88); }
[data-theme="light"] .nav-tab-btn.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.14), rgba(6, 182, 212, 0.1));
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: var(--lt-shadow);
}
[data-theme="light"] .chat-history-item.active { background: rgba(99, 102, 241, 0.12); }

/* Hover surfaces that were white-on-dark tints */
[data-theme="light"] .sidebar-collapse-btn,
[data-theme="light"] .chat-history-item:hover,
[data-theme="light"] .sidebar-tools-header:hover,
[data-theme="light"] .nav-tab-btn:hover,
[data-theme="light"] .sidebar-collapse-bar-btn:hover,
[data-theme="light"] .tab-pill:hover,
[data-theme="light"] .btn-secondary { background: var(--lt-hover); }
[data-theme="light"] .sidebar-collapse-btn:hover,
[data-theme="light"] .chat-action-btn:hover,
[data-theme="light"] .icon-btn-sm:hover,
[data-theme="light"] .btn-secondary:hover { background: var(--lt-hover-strong); }

/* Text that was hard-coded white */
[data-theme="light"] .sidebar-collapse-btn:hover,
[data-theme="light"] .chat-history-item.active,
[data-theme="light"] .chat-inline-rename-input,
[data-theme="light"] .chat-header-rename-input,
[data-theme="light"] .chat-action-btn:hover,
[data-theme="light"] .sidebar-collapse-bar-btn:hover,
[data-theme="light"] .nav-tab-btn.active,
[data-theme="light"] .section-title,
[data-theme="light"] .form-input,
[data-theme="light"] .form-select,
[data-theme="light"] .form-textarea,
[data-theme="light"] .nlp-input,
[data-theme="light"] .chat-header-title,
[data-theme="light"] .icon-btn-sm:hover,
[data-theme="light"] .user-turn-bubble,
[data-theme="light"] .chat-welcome-title,
[data-theme="light"] .tab-pill:hover,
[data-theme="light"] .tab-pill.active,
[data-theme="light"] .er-table-header,
[data-theme="light"] .modal-title { color: var(--lt-strong); }

/* Soft accent text (was light indigo) */
[data-theme="light"] .prompt-chip,
[data-theme="light"] .ai-turn-title { color: var(--lt-soft-accent); }
[data-theme="light"] .prompt-chip:hover { color: var(--lt-strong); }

/* Cards, panels & shadows */
[data-theme="light"] .glass-panel,
[data-theme="light"] .query-box-container,
[data-theme="light"] .chat-header-bar,
[data-theme="light"] .ai-turn-card,
[data-theme="light"] .user-turn-bubble,
[data-theme="light"] .er-table-card { box-shadow: var(--lt-shadow); }
[data-theme="light"] .auth-card:hover { box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12); filter: none; }

/* Chat */
[data-theme="light"] .user-turn-bubble {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(139, 92, 246, 0.09));
  border-color: rgba(99, 102, 241, 0.35);
}
[data-theme="light"] .nlp-input {
  background: #ffffff;
  border-color: rgba(15, 23, 42, 0.15);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
}
[data-theme="light"] .nlp-input:focus { box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18); }
[data-theme="light"] .tab-pill-group { background: rgba(15, 23, 42, 0.04); }
[data-theme="light"] .tab-pill.active { background: linear-gradient(135deg, rgba(99, 102, 241, 0.16), rgba(139, 92, 246, 0.12)); }
[data-theme="light"] .form-input::placeholder,
[data-theme="light"] .nlp-input::placeholder { color: #94a3b8; }

/* Tables: colours come from the --table-* tokens overridden in [data-theme="light"] above */
[data-theme="light"] .data-grid-wrapper { background: #ffffff; }

/* SQL editor */
[data-theme="light"] .sql-code-area { background: #f8fafc; color: #3730a3; }

/* Badges & toggles */
[data-theme="light"] .badge-auto { color: #0e7490; }
[data-theme="light"] .badge-manual { color: #6d28d9; }
[data-theme="light"] .badge-cardinality { color: #047857; }
[data-theme="light"] .slider { background-color: #cbd5e1; }

/* ER diagram */
[data-theme="light"] .er-canvas-container {
  background: #f8fafc;
  background-image: radial-gradient(rgba(15, 23, 42, 0.09) 1px, transparent 0);
  background-size: 24px 24px;
}
[data-theme="light"] .er-table-card { background: #ffffff; }
[data-theme="light"] .er-table-header { background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(6, 182, 212, 0.1)); }

/* Modals */
[data-theme="light"] .modal-backdrop { background: rgba(15, 23, 42, 0.35); }
[data-theme="light"] .modal-box { background: #ffffff; }

/* Voice controls */
[data-theme="light"] .voice-engine-select { background: #ffffff; border-color: rgba(15, 23, 42, 0.15); color: var(--text-main); }
[data-theme="light"] .voice-engine-select:focus,
[data-theme="light"] .voice-engine-select:hover { background: #f8fafc; }
[data-theme="light"] .voice-mic-btn { color: #0284c7; }
[data-theme="light"] .voice-mic-btn:hover { color: #075985; }
[data-theme="light"] .voice-action-pill { background: #ffffff; border-color: rgba(15, 23, 42, 0.15); box-shadow: var(--lt-shadow); }
[data-theme="light"] .voice-pill-divider { background: rgba(15, 23, 42, 0.15); }

/* Scrollbars */
[data-theme="light"] .sidebar-history-container::-webkit-scrollbar-thumb,
[data-theme="light"] .chat-messages-container::-webkit-scrollbar-thumb,
[data-theme="light"] #tab-relationships .rel-table-container::-webkit-scrollbar-thumb { background: var(--lt-scroll-thumb); }

/* Inline template styles in index.html / app.js (white text, dark insets, pale accents) */
[data-theme="light"] [style*="color: #fff"]:not(.btn),
[data-theme="light"] [style*="color:#fff"]:not(.btn) { color: var(--lt-strong) !important; }
[data-theme="light"] [style*="color: rgba(255,255,255,0.6)"] { color: var(--text-dim) !important; }
[data-theme="light"] [style*="background: rgba(0, 0, 0, 0.3)"],
[data-theme="light"] [style*="background: rgba(0,0,0,0.3)"],
[data-theme="light"] [style*="background: rgba(0, 0, 0, 0.25)"] { background: rgba(15, 23, 42, 0.04) !important; }
[data-theme="light"] [style*="background: #121826"] { background: #ffffff !important; }
[data-theme="light"] [style*="rgba(255,255,255,0.08)"],
[data-theme="light"] [style*="rgba(255,255,255,0.1)"],
[data-theme="light"] [style*="rgba(255,255,255,0.03)"] { border-color: rgba(15, 23, 42, 0.1) !important; }
[data-theme="light"] [style*="color: #34d399"], [data-theme="light"] [style*="color:#34d399"],
[data-theme="light"] [style*="color: rgb(52, 211, 153)"] { color: #047857 !important; }
[data-theme="light"] [style*="color: #06b6d4"], [data-theme="light"] [style*="color:#06b6d4"],
[data-theme="light"] [style*="color: rgb(6, 182, 212)"] { color: #0e7490 !important; }
[data-theme="light"] [style*="color: #a5b4fc"], [data-theme="light"] [style*="color:#a5b4fc"] { color: #4338ca !important; }
[data-theme="light"] [style*="color: #c084fc"] { color: #7c3aed !important; }
[data-theme="light"] [style*="color: #fbbf24"], [data-theme="light"] [style*="color: rgb(251, 191, 36)"] { color: #b45309 !important; }
[data-theme="light"] [style*="color: #f87171"], [data-theme="light"] [style*="color:#f87171"] { color: #dc2626 !important; }


/* =====================================================================
   DATABASE INSIGHTS
   ===================================================================== */
#tab-insights {
  flex: 1;
  min-height: 0;
}

#tab-insights .section-header {
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 0;
}

.insights-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.insights-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.insights-status {
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  border: 1px solid var(--border-glass);
  background: var(--bg-card);
}

.insights-status-running { border-color: rgba(99, 102, 241, 0.4); }
.insights-status-error { border-color: rgba(244, 63, 94, 0.45); color: var(--accent-rose); }

.insights-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.insights-status-pct {
  margin-left: auto;
  font-weight: 700;
  color: var(--accent-indigo);
}

.insights-progress {
  margin-top: 8px;
  height: 4px;
  border-radius: 4px;
  background: var(--border-glass);
  overflow: hidden;
}

.insights-progress > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-indigo), var(--accent-cyan));
  transition: width 0.4s ease;
}

.insights-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-right: 4px;
}

.insights-body::-webkit-scrollbar { width: 8px; }
.insights-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 4px; }
[data-theme="light"] .insights-body::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.22); }

.insights-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.insights-empty > i { font-size: 32px; color: var(--accent-indigo); }
.insights-empty-title { font-size: 17px; font-weight: 700; color: var(--text-main); }
.insights-empty-text { font-size: 13px; color: var(--text-muted); }

/* KPI strip */
.insight-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.insight-kpi {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
}

.insight-kpi > i {
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-indigo);
  background: rgba(99, 102, 241, 0.14);
}

.insight-kpi-value { font-size: 20px; font-weight: 800; color: var(--text-main); line-height: 1.1; }
.insight-kpi-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }

/* Summary */
.insight-summary { padding: 16px 20px; }
.insight-summary p { font-size: 14px; line-height: 1.6; color: var(--text-main); margin: 8px 0; }

.insight-summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-purple);
}

.insight-domain {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  color: var(--accent-cyan);
  border: 1px solid var(--border-glass);
  background: rgba(6, 182, 212, 0.1);
}

.insight-footnote { font-size: 11px; color: var(--text-dim); line-height: 1.5; }

.insight-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.insight-section-title > i { color: var(--accent-amber); }

/* Category filters */
.insight-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: -6px;
}

.insight-filter-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-glass);
  transition: all 0.2s ease;
}

.insight-filter-chip span { opacity: 0.7; margin-left: 2px; }
.insight-filter-chip:hover { color: var(--text-main); border-color: rgba(99, 102, 241, 0.45); }
.insight-filter-chip.active { color: var(--text-main); background: rgba(99, 102, 241, 0.16); border-color: rgba(99, 102, 241, 0.5); }

/* Cards */
.insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.insight-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 3px solid var(--insight-color, var(--accent-indigo));
  min-width: 0;
}

.insight-card-highlight { box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.35), 0 8px 24px rgba(0, 0, 0, 0.25); }

.insight-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.insight-card-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--insight-color, var(--accent-indigo));
  background: color-mix(in srgb, var(--insight-color, #6366f1) 16%, transparent);
}

.insight-card-cat {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}

.insight-card-title { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-top: 4px; }

.insight-card-value {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.insight-card-detail { font-size: 13px; line-height: 1.5; color: var(--text-main); opacity: 0.9; word-break: break-word; }

.insight-card-why {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
  font-style: italic;
  border-top: 1px dashed var(--border-glass);
  padding-top: 6px;
  margin-top: 2px;
}

.insight-bars { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }

.insight-bar-row {
  display: grid;
  grid-template-columns: minmax(60px, 38%) 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.insight-bar-label { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insight-bar-track { height: 6px; border-radius: 4px; background: var(--border-glass); overflow: hidden; }
.insight-bar-track > span { display: block; height: 100%; border-radius: 4px; }
.insight-bar-value { color: var(--text-main); font-weight: 600; }

.insight-spark {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 46px;
  margin-top: 8px;
}

.insight-spark > span { flex: 1; border-radius: 2px 2px 0 0; opacity: 0.85; min-width: 3px; }
.insight-spark-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--text-dim); }

/* Suggested questions */
.insight-questions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  padding-bottom: 8px;
}

.insight-question {
  text-align: left;
  font-size: 13px;
  line-height: 1.4;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-main);
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  display: flex;
  gap: 10px;
  align-items: flex-start;
  transition: all 0.2s ease;
}

.insight-question > i { color: var(--accent-indigo); margin-top: 2px; }
.insight-question:hover { border-color: rgba(99, 102, 241, 0.5); background: rgba(99, 102, 241, 0.1); transform: translateY(-1px); }

[data-theme="light"] .insight-card-highlight { box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.3), var(--lt-shadow); }

@media (max-width: 700px) {
  .insight-grid, .insight-questions { grid-template-columns: 1fr; }
}

/* Header: keep action buttons and brand tag on one line */
.header-actions { gap: 10px; }
.header-actions .btn,
.brand-tag,
.db-selector-label { white-space: nowrap; }
.db-select { max-width: 260px; text-overflow: ellipsis; }
/* ==========================================================================
   AI response in chat: summary -> result -> compact actions (no result tabs)
   ========================================================================== */
.ai-response {
  container-type: inline-size;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-1);
}
.ai-response [hidden] { display: none !important; }

/* Summary header: avatar | label + meta on one baseline, sentence wraps under the label */
.ai-summary { display: flex; align-items: flex-start; gap: var(--space-3); }
/* Divider between the summary and the result below it (only when a result follows) */
.ai-summary:not(:last-child) { padding-bottom: var(--space-4); border-bottom: 1px solid var(--border-subtle); }
.ai-avatar {
  width: var(--ai-avatar-size); height: var(--ai-avatar-size); flex-shrink: 0;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-body-lg); line-height: 1; color: #fff;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-cyan));
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.35);
}
.ai-summary-error .ai-avatar { background: linear-gradient(135deg, #e11d48, #f59e0b); box-shadow: 0 2px 10px rgba(225, 29, 72, 0.3); }
.ai-summary-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: var(--space-1); }
.ai-summary-label {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--space-1) var(--space-2);
  min-height: 16px;
  font-size: var(--fs-caption); font-weight: var(--fw-bold); line-height: 16px; letter-spacing: 0.6px; text-transform: uppercase;
  color: #a5b4fc;
}
.ai-summary-meta {
  font-size: var(--fs-caption); font-weight: var(--fw-medium); letter-spacing: 0; text-transform: none;
  color: var(--text-dim); font-variant-numeric: tabular-nums;
}
.ai-summary-meta::before { content: "\00B7"; margin-right: var(--space-2); }
.ai-summary-text {
  font-size: var(--fs-body-lg); line-height: var(--lh-body); color: var(--text-main);
  overflow-wrap: break-word; word-break: normal; max-width: 90ch;
}
.ai-summary-text strong { font-weight: 700; }
.ai-summary-text em { color: var(--text-muted); }
.ai-summary-error .ai-summary-label { color: #fb7185; }
.ai-inline-code { background: rgba(255, 255, 255, 0.08); padding: 1px 6px; border-radius: 4px; font-family: 'Fira Code', monospace; font-size: 0.9em; }

/* Result region: two explicit columns (result | actions). The caption lives in its own row above the
   result column only, so the action stack's top edge lines up with the table's top edge. */
.ai-result-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--ai-actions-width);
  grid-template-areas: "main actions";
  column-gap: var(--space-4);
  row-gap: var(--space-2);
  align-items: start;
  padding-left: calc(var(--ai-avatar-size) + var(--space-3)); /* result starts under the summary text, past the avatar */
}
.ai-result-layout.has-caption { grid-template-areas: "caption ." "main actions"; }
.ai-result-layout-actions-only { grid-template-columns: minmax(0, 1fr); grid-template-areas: "actions"; }
.ai-result-caption { grid-area: caption; }
.ai-result-main { grid-area: main; min-width: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.ai-result-actions { grid-area: actions; }

.ai-result-caption {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-1) var(--space-3);
  min-width: 0;
  font-size: var(--fs-label); font-weight: var(--fw-semibold); line-height: 20px; color: var(--text-muted);
}
.ai-result-caption-title { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text-main); }
.ai-result-caption i { color: var(--accent-indigo); font-size: var(--fs-label); }
.ai-result-count { font-weight: var(--fw-regular); color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* Table box hugs its columns (no lone ID column stretched across a huge width), but never narrower
   than a comfortable minimum and never wider than the column: wide results scroll inside the box */
.ai-result-table {
  max-height: 420px;
  width: fit-content;
  min-width: min(100%, 480px);
  max-width: 100%;
}
.ai-result-table .data-table th { white-space: nowrap; }

.ai-kpi {
  align-self: flex-start;
  min-width: 220px; max-width: 100%;
  padding: 16px 22px;
  border-radius: 12px;
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.14), rgba(6, 182, 212, 0.08));
}
.ai-kpi-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.ai-kpi-value {
  font-size: 34px; font-weight: 800; line-height: 1.2; margin-top: 2px;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-indigo));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  overflow-wrap: anywhere;
}

/* Actions: equal-width, equal-height vertical stack beside the result, top-aligned with the table */
.ai-result-actions { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.ai-result-actions > .ai-action-btn,
.ai-action-menu-wrap { width: 100%; }
.ai-action-btn {
  width: 100%;
  height: var(--control-h);
  display: flex; align-items: center; gap: var(--space-2);
  padding: 0 var(--space-3);
  font: var(--fw-semibold) var(--fs-label) / 1 var(--font-sans);
  color: var(--text-muted);
  background: var(--surface-raised);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap; text-align: left;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
/* Fixed icon box so labels start at the same x in every button; line-height 1 keeps icon + text optically centred */
.ai-action-btn > i:first-child {
  flex: 0 0 16px; width: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1; color: var(--accent-indigo);
}
.ai-action-btn > span { line-height: 1; overflow: hidden; text-overflow: ellipsis; }
.ai-action-btn:hover:not(:disabled) { color: var(--text-main); border-color: var(--border-accent); background: var(--surface-hover); }
.ai-action-btn.active,
.ai-action-btn[aria-expanded="true"] { color: var(--text-main); border-color: var(--border-accent); background: var(--surface-active); }
.ai-action-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ai-action-btn.busy { opacity: 0.7; cursor: progress; }
.ai-action-btn.busy > i:first-child { animation: fa-spin 1s linear infinite; }
.ai-action-caret { margin-left: auto; font-size: 9px; line-height: 1; opacity: 0.7; transition: transform 0.15s ease; }
.ai-action-btn[aria-expanded="true"] .ai-action-caret { transform: rotate(180deg); }

.ai-action-menu-wrap { position: relative; }
.ai-action-menu {
  position: absolute; right: 0; top: calc(100% + var(--space-1)); z-index: 40;
  min-width: 170px; padding: var(--space-1);
  background: var(--surface-menu);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-2);
  display: flex; flex-direction: column; gap: 2px;
}
.ai-action-menu-title {
  padding: var(--space-1) var(--space-2) 6px; margin-bottom: 2px;
  font-size: var(--fs-caption); font-weight: var(--fw-bold); letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--text-dim); border-bottom: 1px solid var(--border-subtle);
}
.ai-action-menu button {
  display: flex; align-items: center; gap: var(--space-2);
  height: var(--control-h); padding: 0 var(--space-2); border: 0; border-radius: var(--radius-xs);
  background: transparent; color: var(--text-main);
  font: var(--fw-medium) var(--fs-body) / 1 var(--font-sans); text-align: left; cursor: pointer;
}
.ai-action-menu button:hover,
.ai-action-menu button:focus-visible { background: var(--surface-hover); }
.ai-action-menu button i { flex: 0 0 16px; width: 16px; text-align: center; line-height: 1; }
.ai-action-menu .fa-file-csv { color: #22c55e; }
.ai-action-menu .fa-file-excel { color: #16a34a; }
.ai-action-menu .fa-file-pdf { color: #ef4444; }
.ai-action-menu .fa-whatsapp { color: #25d366; }
.ai-action-menu .fa-envelope { color: var(--accent-cyan); }

/* Inline panels opened by Visualization / SQL (stay inside the answer) */
.ai-panel {
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}
.ai-panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; font-size: var(--fs-label); font-weight: var(--fw-bold); color: var(--text-muted); }
.ai-panel-head > span i { color: var(--accent-indigo); margin-right: var(--space-1); }
.ai-panel-tools { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.ai-panel-close { border: 0; background: transparent; color: var(--text-dim); cursor: pointer; padding: var(--space-1) 6px; border-radius: var(--radius-xs); font-size: 13px; }
.ai-panel-close:hover { color: var(--text-main); background: rgba(255, 255, 255, 0.06); }
.ai-chart-box { position: relative; height: 320px; }

.ai-sql-code {
  margin: 0; padding: 14px 16px;
  max-height: 320px; overflow: auto;
  font: 13px/1.6 'Fira Code', 'Courier New', monospace;
  white-space: pre; tab-size: 4;
  color: #cbd5e1; background: #0d1321;
  border: 1px solid var(--border-glass); border-radius: 8px;
}
.sql-kw { color: #c084fc; font-weight: 600; }
.sql-fn { color: #22d3ee; }
.sql-str { color: #34d399; }
.sql-num { color: #fbbf24; }
.sql-cm { color: #64748b; font-style: italic; }
.ai-sql-edit { display: flex; flex-direction: column; gap: 8px; }
.ai-sql-edit .sql-code-area { width: 100%; min-height: 140px; font-size: 13px; }
.ai-sql-edit-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* No table/KPI (e.g. error with SQL): actions sit in a row, same button width as the column */
.ai-result-layout-actions-only .ai-result-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--ai-actions-width)), var(--ai-actions-width)));
}

/* Narrow chat area (tablet / mobile / collapsed sidebar): one column, actions become a full-width
   equal-column row directly under the result. Queries the .ai-response container, not the viewport. */
@container (max-width: 700px) {
  .ai-result-layout,
  .ai-result-layout.has-caption {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "caption" "main" "actions";
    padding-left: 0;
  }
  .ai-result-layout:not(.has-caption) { grid-template-areas: "main" "actions"; }
  .ai-result-layout.ai-result-layout-actions-only { grid-template-areas: "actions"; }
  .ai-result-main + .ai-result-actions { margin-top: var(--space-1); } /* 12px under the table, caption stays 8px above it */
  .ai-result-actions,
  .ai-result-layout-actions-only .ai-result-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: var(--space-2);
  }
  /* A lone button (error + SQL) keeps the same column width instead of stretching */
  .ai-result-layout-actions-only .ai-result-actions { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  /* Menus span their trigger's width so the right-most one can't overflow the card */
  .ai-action-menu { left: 0; right: 0; min-width: 0; }
  .ai-result-table { min-width: 100%; }
  .ai-kpi { min-width: 0; width: 100%; }
  .ai-chart-box { height: 260px; }
}

/* Light theme (colours mostly come from tokens; these cover the remaining hard-coded values) */
[data-theme="light"] .ai-summary-label { color: #4f46e5; }
[data-theme="light"] .ai-summary-error .ai-summary-label { color: #e11d48; }
[data-theme="light"] .ai-inline-code { background: rgba(15, 23, 42, 0.06); }
[data-theme="light"] .ai-result-caption-title { color: var(--lt-strong); }
[data-theme="light"] .ai-action-btn.active,
[data-theme="light"] .ai-action-btn[aria-expanded="true"] { color: #3730a3; }
[data-theme="light"] .ai-action-btn > i:first-child,
[data-theme="light"] .ai-result-caption i { color: #4f46e5; }
[data-theme="light"] .ai-panel-close:hover { background: rgba(15, 23, 42, 0.06); }
[data-theme="light"] .ai-kpi { background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(6, 182, 212, 0.05)); border-color: rgba(99, 102, 241, 0.25); }
[data-theme="light"] .ai-sql-code { background: #f8fafc; color: #1e293b; }
[data-theme="light"] .sql-kw { color: #7c3aed; }
[data-theme="light"] .sql-fn { color: #0e7490; }
[data-theme="light"] .sql-str { color: #047857; }
[data-theme="light"] .sql-num { color: #b45309; }
[data-theme="light"] .sql-cm { color: #94a3b8; }


/* Phones: icon-rail sidebar, scrollable header, stacked prompt bar so the chat answer gets the width */
@media (max-width: 1100px) {
  .app-header { gap: 12px; overflow-x: auto; }
  .app-header::-webkit-scrollbar { display: none; }
}
@media (max-width: 760px) {
  .app-header { padding: 8px 12px; }
  .brand-tag { display: none; }
  .header-actions { gap: 8px; }

  .sidebar-tabs { width: 60px; min-width: 60px; padding: 12px 6px; }
  .sidebar-tabs .btn-new-chat span,
  .sidebar-tabs .chat-section-header span,
  .sidebar-tabs .chat-title-span,
  .sidebar-tabs .chat-item-actions,
  .sidebar-tabs .tools-header-label span,
  .sidebar-tabs .toggle-icon,
  .sidebar-tabs .nav-tab-btn span,
  .sidebar-tabs .sidebar-collapse-bar-btn span,
  .sidebar-tabs .sidebar-collapse-btn { display: none !important; }
  .sidebar-tabs .btn-new-chat { padding: 10px; justify-content: center; }
  .sidebar-tabs .chat-section-header { justify-content: center; }
  .sidebar-tabs .chat-history-item { justify-content: center; padding: 8px 0; }
  .sidebar-tabs .nav-tab-btn { justify-content: center; padding: 10px 0; }

  .main-viewport { padding: 10px; }
  .chat-header-bar { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .chat-header-right { gap: 8px; flex-wrap: wrap; }
  .chat-messages-container { min-height: 0; max-height: none; }
  .user-turn-bubble { max-width: 92%; padding: 10px 14px; }
  .ai-response { padding: var(--space-3); }

  .query-box-container { padding: 10px; gap: 8px; }
  /* Phones: chips become one horizontally scrollable row instead of a tall grid */
  .sample-prompts { display: flex; flex-wrap: nowrap; overflow-x: auto; padding: var(--space-1); scrollbar-width: none; } /* padding keeps the focus ring unclipped */
  .sample-prompts::-webkit-scrollbar { display: none; }
  .sample-prompts .prompt-chip { flex: 0 0 auto; max-width: 260px; }
  .input-row { flex-wrap: wrap; gap: 8px; }
  .input-row .voice-engine-select { flex: 1 1 100%; }
  .input-row .nlp-input { flex: 1 1 0; min-width: 0; padding: 12px 14px; }
}

/* Suggested questions: only verified ones are shown */
.insight-questions-note { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); margin: -4px 0 10px; }
.insight-questions-note i { color: var(--accent-indigo); }
.insight-question > span { flex: 1; }
.insight-question-verified { color: var(--accent-emerald); font-size: 12px; margin-left: 6px; flex-shrink: 0; }
/* Manual relationship check */
.rel-check-badge { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; padding: 2px 8px; border-radius: 10px; font: 700 11px var(--font-sans); cursor: pointer; border: 1px solid; background: transparent; }
.rel-check-badge.rel-check-warning { color: #fbbf24; border-color: rgba(245, 158, 11, 0.5); background: rgba(245, 158, 11, 0.12); }
.rel-check-badge.rel-check-error { color: #fb7185; border-color: rgba(244, 63, 94, 0.5); background: rgba(244, 63, 94, 0.12); }
.rel-check-list { display: flex; flex-direction: column; gap: 10px; max-height: 55vh; overflow-y: auto; padding-right: 4px; }
.rel-check-item { border: 1px solid var(--border-glass); border-left: 3px solid #f59e0b; border-radius: 10px; padding: 10px 12px; background: rgba(255, 255, 255, 0.02); }
.rel-check-item.rel-check-error { border-left-color: #f43f5e; }
.rel-check-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 13px; }
.rel-check-head code { font-size: 12px; }
.rel-check-level { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; padding: 2px 6px; border-radius: 6px; background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.rel-check-error .rel-check-level { background: rgba(244, 63, 94, 0.18); color: #fb7185; }
.rel-check-inactive { font-size: 11px; color: var(--text-dim); }
.rel-check-item ul { margin: 6px 0 0 18px; font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }
.rel-check-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
[data-theme="light"] .rel-check-badge.rel-check-warning, [data-theme="light"] .rel-check-level { color: #b45309; }
[data-theme="light"] .rel-check-badge.rel-check-error, [data-theme="light"] .rel-check-error .rel-check-level { color: #be123c; }
[data-theme="light"] .rel-check-item { background: #ffffff; }
/* Query cache: database name with its connection id underneath */
.cache-db-name { font-weight: 700; font-size: 12.5px; color: var(--text-main); white-space: nowrap; }
.cache-db-id { font-size: 10.5px; color: var(--text-dim); font-family: 'Fira Code', monospace; }
/* ==========================================================================
   Keyboard focus: one visible ring for every interactive control (mouse clicks don't show it)
   ========================================================================== */
:where(button, [role="button"], [role="menuitem"], a[href], select, summary, [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.ai-action-btn:focus-visible,
.prompt-chip:focus-visible,
.btn:focus-visible,
.tab-pill:focus-visible,
.nav-tab-btn:focus-visible,
.icon-btn-sm:focus-visible,
.ai-panel-close:focus-visible,
.voice-engine-select:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ai-action-menu button:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--border-accent); }
/* The DB <select> has no box of its own; ring its wrapper instead */
.db-selector-wrapper:has(.db-select:focus-visible) { box-shadow: var(--focus-ring); }

/* ==========================================================================
   UI audit fixes (2026-09-25)
   ========================================================================== */

/* Scrollbars: themed everywhere instead of bright native ones on dark cards (and dark ones in light mode) */
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background-color: var(--scroll-thumb-hover); }
*::-webkit-scrollbar-corner { background: transparent; }

/* Scrolling table boxes reserve a gutter so the scrollbar never sits on top of cell content */
.data-grid-wrapper,
.rel-table-container { scrollbar-gutter: stable; }

/* Actions column stays pinned to the right edge of wide tables, so Edit / Delete are always reachable */
.rel-table th:last-child, .rel-table td:last-child,
.cache-table th:last-child, .cache-table td:last-child {
  position: sticky;
  right: 0;
  background: var(--table-sticky-bg);
  box-shadow: -1px 0 0 var(--border-glass);
}
.rel-table td:last-child, .cache-table td:last-child { z-index: 2; white-space: nowrap; }
.rel-table th:last-child, .cache-table th:last-child { z-index: 6; background: var(--table-head-bg); }
.rel-table tbody tr:hover td:last-child,
.cache-table tbody tr:hover td:last-child { background: linear-gradient(var(--table-row-hover), var(--table-row-hover)), var(--table-sticky-bg); }

/* Relationship Designer: long detection-method badges truncate with an ellipsis (full text on hover) */
.rel-method-badge { max-width: 240px; min-width: 0; vertical-align: middle; }
.rel-method-badge > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Query Cache: question and SQL wrap instead of pushing the Delete button out of view */
.cache-table td { white-space: normal; }
.cache-table td:nth-child(2) { min-width: 200px; max-width: 360px; overflow-wrap: anywhere; }
.cache-table td:nth-child(4) { min-width: 180px; max-width: 320px; overflow-wrap: anywhere; }
.cache-table td:nth-child(5) { white-space: nowrap; }
.cache-table td:nth-child(6) { min-width: 90px; } /* date / time may break onto two lines */

/* DB Permissions: 7 privilege tiles in one even row (4 + 3 on tablets, 2-up on phones) */
.perm-flags-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-3); margin-bottom: var(--space-6); }
@media (max-width: 1000px) { .perm-flags-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 560px) {
  .perm-flags-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .perm-flags-grid > :last-child:nth-child(odd) { grid-column: 1 / -1; }
}

/* Database Insights KPIs: column count follows the card count and the space available, so rows are
   always full (5 across, or 3 + 2 / 2 + 2 on narrower panels, 2-up on phones) - never one orphan card */
.insights-body { container-type: inline-size; }
.insight-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); }
.insight-kpis:has(> .insight-kpi:nth-child(5)) { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.insight-kpi { min-width: 0; }
@container (max-width: 820px) {
  .insight-kpis,
  .insight-kpis:has(> .insight-kpi:nth-child(5)) { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .insight-kpi { grid-column: span 3; }                                                   /* 4 cards: 2 + 2 */
  .insight-kpis:has(> .insight-kpi:nth-child(5)) .insight-kpi { grid-column: span 2; }     /* 5 cards: 3 ... */
  .insight-kpis:has(> .insight-kpi:nth-child(5)) .insight-kpi:nth-child(n+4) { grid-column: span 3; } /* ... + 2 */
}
@container (max-width: 460px) {
  .insight-kpis:has(> .insight-kpi:nth-child(1)) .insight-kpi:nth-child(n) { grid-column: span 3; }
  .insight-kpis:has(> .insight-kpi:nth-child(1)) .insight-kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
.insight-kpi > div { min-width: 0; }
.insight-kpi-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Schema Inspector cards: column name and type never overlap; long names wrap */
#schema-inspector-grid .glass-panel { min-width: 0; }
#schema-inspector-grid .glass-panel > div > div { gap: var(--space-3); }
#schema-inspector-grid .glass-panel span { min-width: 0; overflow-wrap: anywhere; }

/* Tablets: slimmer speech-engine picker so the prompt input keeps its width */
@media (min-width: 761px) and (max-width: 1024px) {
  .input-row .voice-engine-select { max-width: 170px; }
}

/* Share dialog (email / WhatsApp): preview of exactly what is sent, then the ways to send it */
.share-modal-box { max-width: 760px; width: calc(100vw - 2 * var(--space-4)); display: flex; flex-direction: column; max-height: calc(100dvh - 2 * var(--space-6)); }
.share-modal-box .modal-title i { margin-right: var(--space-2); }
.share-modal-box .fa-whatsapp { color: #25d366; }
.share-modal-box .modal-title .fa-envelope { color: var(--accent-cyan); }
.share-preview {
  flex: 1 1 auto; min-height: 120px; overflow: auto;
  border: 1px solid var(--border-glass); border-radius: var(--radius-sm);
}
.share-preview-email { background: #ffffff; }            /* shows the email as the recipient sees it */
.share-paper { padding: var(--space-5); color: #0f172a; }
.share-preview-wa { background: #0b141a; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); align-items: flex-start; }
.share-wa-chart { max-width: min(100%, 480px); border-radius: var(--radius-sm); display: block; }
.share-wa-text {
  margin: 0; max-width: 100%; overflow-x: auto;
  padding: var(--space-3) var(--space-4); border-radius: 0 var(--radius-sm) var(--radius-sm) var(--radius-sm);
  background: #005c4b; color: #e9edef;
  font: 12.5px/1.5 Consolas, 'Courier New', monospace; white-space: pre-wrap; overflow-wrap: anywhere;
}
.share-loading { padding: var(--space-8); text-align: center; color: #64748b; font-size: var(--fs-body); }
.share-preview-wa .share-loading { color: #aebac1; }
.share-hint { margin: var(--space-3) 0; font-size: var(--fs-label); line-height: var(--lh-body); color: var(--text-muted); }
.share-hint kbd {
  font: 600 11px var(--font-sans); padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--border-strong); background: var(--surface-raised); color: var(--text-main);
}
/* Send row: recipients + actions (email), send buttons + target picker (WhatsApp) */
.share-controls { margin-top: var(--space-4); }
.share-send-row { display: flex; align-items: flex-end; flex-wrap: wrap; gap: var(--space-2) var(--space-3); }
.share-send-row .btn { height: 40px; justify-content: center; }
.share-to { flex: 1 1 280px; display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.share-to > span, .share-target > span { font-size: var(--fs-caption); font-weight: var(--fw-bold); letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-muted); }
.share-to .form-input { height: 40px; padding: 0 var(--space-3); }
.share-to .form-input:disabled { opacity: 0.55; cursor: not-allowed; }
.share-target { margin-left: auto; display: flex; flex-direction: column; gap: var(--space-1); }
.share-target .form-select { height: 40px; padding: 0 var(--space-3); min-width: 190px; }
.share-hint i { margin-right: 4px; }
.share-hint-ok { color: var(--accent-emerald); }
.share-hint-error { color: var(--accent-rose); }
.share-hint a { color: inherit; font-weight: var(--fw-semibold); }
@media (max-width: 560px) {
  .share-send-row .btn, .share-target { flex: 1 1 100%; margin-left: 0; }
  .share-target .form-select { width: 100%; }
}

/* Chat turn: which database the question ran on (each turn can use a different one) */
.user-turn-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-top: 6px; }
.user-turn-time { font-size: 10px; color: rgba(255, 255, 255, 0.6); font-variant-numeric: tabular-nums; }
.turn-db-tag {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%;
  height: 20px; padding: 0 8px; border-radius: var(--radius-pill);
  font-size: 10.5px; font-weight: var(--fw-semibold); line-height: 1;
  color: #a5f3fc; background: rgba(6, 182, 212, 0.14); border: 1px solid rgba(6, 182, 212, 0.35);
}
.turn-db-tag > i { font-size: 9px; opacity: 0.9; }
.turn-db-name { min-width: 0; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-db-type { font-size: 9px; font-weight: var(--fw-bold); letter-spacing: 0.4px; opacity: 0.75; padding-left: 5px; border-left: 1px solid rgba(165, 243, 252, 0.35); }
[data-theme="light"] .user-turn-time { color: var(--text-dim); }
[data-theme="light"] .turn-db-tag { color: #0e7490; background: rgba(8, 145, 178, 0.1); border-color: rgba(8, 145, 178, 0.3); }
[data-theme="light"] .turn-db-type { border-left-color: rgba(14, 116, 144, 0.3); }

/* ==========================================
   VALUE MAPPING (admin)
   ========================================== */
.vm-panel { padding: 20px 24px; }
.vm-scope-info { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }
.vm-scope-info b { color: var(--text-main); }
.vm-scan-status { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.vm-progress { height: 6px; border-radius: 3px; background: var(--surface-sunken); overflow: hidden; margin-top: 6px; max-width: 420px; }
.vm-progress > div { height: 100%; background: linear-gradient(90deg, var(--accent-indigo), var(--accent-purple)); transition: width 0.4s ease; }
.vm-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.vm-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.vm-filter {
  border: 1px solid var(--border-glass); background: var(--surface-raised); color: var(--text-muted);
  border-radius: 14px; padding: 4px 12px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.vm-filter.active { background: var(--surface-active); color: var(--text-main); border-color: var(--border-accent); }
.vm-filter .vm-count { margin-left: 4px; opacity: 0.8; }
.vm-search { max-width: 260px; }
.vm-table td { vertical-align: top; }
.vm-col-name { font-weight: 600; color: var(--text-main); }
.vm-col-table { font-size: 11px; color: var(--text-dim); }
.vm-samples { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vm-note { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.vm-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.vm-actions .btn { padding: 4px 8px; font-size: 11px; }
.badge-vm-auto { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-vm-confirmed { background: rgba(99, 102, 241, 0.15); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.3); }
.badge-vm-suggested { background: rgba(139, 92, 246, 0.15); color: #a78bfa; border: 1px solid rgba(139, 92, 246, 0.3); }
.badge-vm-pending { background: rgba(245, 158, 11, 0.15); color: #f59e0b; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-vm-ignored { background: rgba(148, 163, 184, 0.12); color: var(--text-muted); border: 1px solid rgba(148, 163, 184, 0.25); }
.badge-vm-list { background: rgba(6, 182, 212, 0.12); color: #06b6d4; border: 1px solid rgba(6, 182, 212, 0.3); margin-left: 6px; }
.vm-modal-samples { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.vm-mode-switch { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; font-size: 13px; color: var(--text-main); }
.vm-mode-switch label, .vm-inline-checks label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.vm-inline-checks { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-main); }
.vm-delim { width: 56px; padding: 4px 8px; text-align: center; }
.vm-labels-list { display: grid; grid-template-columns: minmax(60px, auto) 1fr; gap: 6px 10px; align-items: center; max-height: 260px; overflow-y: auto; margin: 6px 0 12px; }
.vm-labels-list code { font-size: 12px; color: var(--text-muted); }
.vm-preview { font-size: 13px; color: var(--text-muted); }
.vm-preview table { width: 100%; margin-top: 8px; }
.vm-preview .vm-miss { color: var(--accent-amber); }

/* ==========================================
   POWER BI DASHBOARDS
   ========================================== */
.bi-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.bi-tab {
  border: 1px solid var(--border-glass); background: var(--surface-raised); color: var(--text-muted);
  border-radius: 14px; padding: 5px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.bi-tab.active { background: var(--surface-active); color: var(--text-main); border-color: var(--border-accent); }
.bi-frame-wrap { padding: 0; overflow: hidden; height: calc(100vh - 230px); min-height: 480px; background: var(--bg-card); }
.bi-frame-wrap:fullscreen { height: 100vh; border-radius: 0; }
.bi-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.bi-empty { padding: 48px 24px; text-align: center; color: var(--text-muted); font-size: 14px; }
.bi-hint { font-size: 12px; color: var(--text-dim); margin-top: 8px; }
.bi-card-info { font-size: 12px; color: var(--accent-amber); margin: -8px 0 12px; }
.bi-card-info a { color: inherit; text-decoration: underline; }
.bi-field-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.bi-modal-list { margin-bottom: 8px; }
.bi-modal-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border-glass); border-radius: 8px; margin-bottom: 8px; }
.bi-modal-row-text { min-width: 0; }
.bi-modal-row-title { font-weight: 600; color: var(--text-main); font-size: 13px; }
.bi-modal-row-url { font-size: 11px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.bi-modal-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
@media (max-width: 640px) {
  .bi-frame-wrap { height: calc(100vh - 260px); min-height: 360px; }
  .bi-modal-row-url { max-width: 200px; }
}

/* Schema Inspector: tables hidden from the AI */
.schema-ai-summary { font-size: 13px; color: var(--text-muted); margin-bottom: 14px; }
.schema-card-hidden { opacity: 0.6; }
.schema-ai-badge { font-size: 11px; font-weight: 600; color: var(--accent-amber); margin: -4px 0 8px; }
.schema-ai-badge-shown { color: var(--accent-emerald); }
.schema-ai-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.schema-ai-actions:empty { display: none; }
.schema-ai-actions .btn { padding: 3px 8px; font-size: 11px; }

/* Login page (login.html): the sign-in box on its own page instead of a popup */
body.login-body { height: auto; min-height: 100vh; min-height: 100dvh; overflow: auto; }
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px 16px;
}
.login-brand { justify-content: center; }
.login-box { width: 100%; max-width: 560px; padding: 28px; }
@media (max-width: 560px) {
  .login-box { padding: 20px 16px; }
  .login-cards, .login-fields { grid-template-columns: 1fr !important; }
}

/* Alternative questions under an unclear / unanswered question (engine/question_recommender.py) */
.ai-recs { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-3); }
.ai-rec-btn {
  max-width: 100%;
  min-height: var(--control-h);
  padding: 6px var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  border: 1px solid var(--border-glass);
  font: var(--fw-medium) var(--fs-label) / 1.35 var(--font-sans);
  color: #a5b4fc;
  text-align: left;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.ai-rec-btn i { flex-shrink: 0; font-size: var(--fs-caption); color: var(--accent-amber); }
.ai-rec-btn:hover { background: var(--surface-hover); border-color: var(--border-accent); color: var(--text-main); box-shadow: var(--shadow-1); }
.ai-rec-btn:active { background: var(--surface-active); box-shadow: none; }
.ai-rec-btn:focus-visible { outline: 2px solid var(--accent-indigo); outline-offset: 2px; }
.ai-rec-btn:disabled { opacity: 0.55; cursor: progress; }
.ai-rec-btn.ai-rec-used { border-color: var(--accent-indigo); }
.ai-rec-btn.ai-rec-retype { color: var(--text-muted); background: transparent; border-style: dashed; }
.ai-rec-btn.ai-rec-retype i { color: var(--text-muted); }
[data-theme="light"] .ai-rec-btn { color: var(--lt-soft-accent); }
[data-theme="light"] .ai-rec-btn:hover { color: var(--lt-strong); }
[data-theme="light"] .ai-rec-btn.ai-rec-retype { color: var(--text-muted); }

/* Reports page (reports.html / js/reports.js) */
.rpt-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.rpt-layout[hidden], .rpt-notice[hidden] { display: none; }
.rpt-panel { padding: 18px 20px; }
.rpt-notice { color: var(--text-muted); font-size: var(--fs-body); }
.rpt-request-panel, .rpt-actions { grid-column: 1 / -1; }
.rpt-step { display: flex; align-items: center; gap: var(--space-2); font-weight: 700; font-size: 15px; margin-bottom: var(--space-3); color: var(--text-main); }
.rpt-step-no { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple)); color: #fff; }
.rpt-optional { font-size: var(--fs-caption); font-weight: 600; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
.rpt-request { width: 100%; resize: vertical; min-height: 72px; font-family: var(--font-sans); line-height: 1.45; }
.rpt-row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-top: var(--space-2); }
.rpt-help { font-size: var(--fs-label); color: var(--text-muted); font-weight: 400; }
.rpt-template-desc { margin: 8px 0 12px; }
.rpt-note { margin-top: var(--space-3); padding: 10px 12px; border-radius: var(--radius-sm); font-size: var(--fs-body);
  background: var(--surface-raised); border: 1px solid var(--border-glass); display: flex; flex-direction: column; gap: 6px; }
.rpt-note[hidden] { display: none; }
.rpt-note-na { color: var(--text-muted); }
.rpt-note-error { border-color: rgba(244, 63, 94, 0.45); color: var(--accent-rose); }
.rpt-note-warn { border-color: rgba(245, 158, 11, 0.45); margin: 0 0 12px; }
.rpt-subhead { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; font-size: var(--fs-body); margin-bottom: 8px; }
.rpt-subhead-actions { display: inline-flex; gap: 12px; }
.rpt-link { background: none; border: none; padding: 0; color: #a5b4fc; font: inherit; font-size: var(--fs-label); cursor: pointer; }
.rpt-link:hover { text-decoration: underline; }
.rpt-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; max-height: 340px; overflow-y: auto; padding-right: 4px; }
.rpt-field { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-xs); border: 1px solid var(--border-glass);
  background: var(--surface-raised); font-size: var(--fs-body); cursor: pointer; min-width: 0; }
.rpt-field span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-field:has(input:checked) { border-color: var(--border-accent); }
.rpt-field-na { opacity: 0.5; cursor: not-allowed; }
.rpt-field em { margin-left: auto; font-size: var(--fs-caption); color: var(--text-muted); font-style: normal; white-space: nowrap; }
.rpt-filters { display: flex; flex-direction: column; gap: 14px; }
.rpt-filter .form-label { display: block; margin-bottom: 6px; }
.rpt-required { color: var(--accent-rose); }
.rpt-multi-count { font-weight: 400; color: var(--text-muted); }
.rpt-multi-search { width: 100%; margin-bottom: 6px; }
.rpt-multi-list { max-height: 150px; overflow-y: auto; border: 1px solid var(--border-glass); border-radius: var(--radius-sm); padding: 4px 8px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 8px; background: var(--surface-raised); }
.rpt-multi-opt { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: var(--fs-body); cursor: pointer; }
.rpt-multi-opt[hidden] { display: none; }
.rpt-multi-clear { margin-top: 4px; }
.rpt-check { display: flex; align-items: center; gap: 8px; font-size: var(--fs-body); cursor: pointer; }
.rpt-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.rpt-downloads { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.rpt-preview-panel { margin-top: 16px; }
.rpt-preview-panel[hidden] { display: none; }
.rpt-preview-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.rpt-preview-title { font-weight: 700; font-size: 15px; color: var(--text-main); }
.rpt-preview-count { font-size: var(--fs-body); color: var(--text-muted); }
.rpt-table-wrap { max-height: 520px; overflow: auto; }
.rpt-table th { position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.rpt-table td { white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1100px) { .rpt-layout { grid-template-columns: minmax(0, 1fr); } }
[data-theme="light"] .rpt-link { color: var(--lt-soft-accent); }
[data-theme="light"] .rpt-step { color: var(--lt-strong); }

/* Cross-Database Insights (cross-database-insights.html / js/cross_db.js) */
#tab-crossdb .glass-panel.rpt-panel { margin-bottom: 16px; }
.xdb-toast { position: fixed; right: 24px; bottom: 24px; z-index: 5000; max-width: 520px; padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: var(--fs-body); background: var(--bg-card); border: 1px solid var(--border-glass); box-shadow: var(--shadow-1); backdrop-filter: blur(16px); }
.xdb-toast[hidden] { display: none; }
.xdb-toast-ok { border-color: rgba(16, 185, 129, 0.55); }
.xdb-toast-error { border-color: rgba(244, 63, 94, 0.6); color: var(--accent-rose); }
.xdb-config-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.xdb-config-bar .form-label { margin: 0; }
.xdb-config-select { width: auto; min-width: 280px; }
.xdb-config-name { width: 260px; }
.xdb-config-id { font-family: "Fira Code", monospace; font-size: var(--fs-label); color: var(--accent-cyan); }
.xdb-config-actions { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.xdb-manage[hidden] { display: none !important; }
.xdb-empty { display: flex; align-items: center; gap: 14px; color: var(--text-muted); font-size: var(--fs-body); }
.xdb-empty > i { font-size: 26px; color: var(--accent-purple); }
.xdb-empty[hidden], #xdb-body[hidden] { display: none; }
.xdb-section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.xdb-section-head .rpt-step { margin-bottom: 0; }
.xdb-db-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.xdb-db-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.xdb-db-head { display: flex; gap: 10px; align-items: flex-start; }
.xdb-alias { font-size: var(--fs-caption); font-weight: 700; padding: 3px 7px; border-radius: 6px; color: #fff;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple)); }
.xdb-db-name { font-weight: 700; color: var(--text-main); }
.xdb-status { font-size: var(--fs-body); font-weight: 600; color: var(--text-muted); }
.xdb-status-ok { color: var(--accent-emerald); }
.xdb-status-bad { color: var(--accent-rose); }
.xdb-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 12px; font-size: var(--fs-label); color: var(--text-muted); }
.xdb-facts b { color: var(--text-main); font-weight: 600; }
.xdb-db-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.xdb-add-card { align-items: center; justify-content: center; min-height: 120px; cursor: pointer; border-style: dashed; color: var(--text-muted);
  font: inherit; font-weight: 600; flex-direction: column; }
.xdb-add-card i { font-size: 20px; color: var(--accent-indigo); }
.xdb-add-card:hover { border-color: var(--border-accent); color: var(--text-main); }
.xdb-schema { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.xdb-schema-card { border: 1px solid var(--border-glass); border-radius: var(--radius-sm); padding: 8px 12px; background: var(--surface-raised); font-size: var(--fs-body); }
.xdb-schema-card summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.xdb-chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.xdb-chips span { font-size: var(--fs-caption); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border-glass); color: var(--text-muted); }
.xdb-table-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 12px; margin-top: 10px; max-height: 220px; overflow: auto; }
.xdb-table-item { font-size: var(--fs-label); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xdb-table-item em { color: var(--text-muted); font-style: normal; }
.xdb-rel-table-wrap { max-height: 460px; overflow: auto; }
.xdb-rel-table td { vertical-align: middle; }
.xdb-rel-table tr[data-rel-row] { cursor: pointer; }
.xdb-rel-selected td { background: rgba(99, 102, 241, 0.10); }
.xdb-rel-rejected td { opacity: 0.55; }
.xdb-rel-db { font-size: var(--fs-caption); font-weight: 700; color: var(--accent-cyan); margin-right: 4px; }
.xdb-arrow { color: var(--accent-indigo); text-align: center; }
.xdb-actions { white-space: nowrap; }
.xdb-actions .btn { padding: 3px 8px; font-size: 11px; }
.xdb-problem { font-size: var(--fs-caption); color: var(--accent-rose); margin-top: 3px; max-width: 280px; white-space: normal; }
.xdb-badge { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-caption); font-weight: 700; padding: 3px 8px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.xdb-badge-ok { color: #34d399; border-color: rgba(52, 211, 153, 0.55); background: rgba(16, 185, 129, 0.12); }
.xdb-badge-warn { color: #fbbf24; border-color: rgba(251, 191, 36, 0.5); background: rgba(245, 158, 11, 0.10); }
.xdb-badge-bad { color: #fb7185; border-color: rgba(251, 113, 133, 0.5); background: rgba(244, 63, 94, 0.10); }
.xdb-badge-info { color: #67e8f9; border-color: rgba(103, 232, 249, 0.5); background: rgba(6, 182, 212, 0.10); }
.xdb-rel-detail td { background: var(--surface-raised); }
.xdb-validation { padding: 6px 4px; display: flex; flex-direction: column; gap: 8px; font-size: var(--fs-body); white-space: normal; }
.xdb-validation-title { font-weight: 700; }
.xdb-validation-ok .xdb-validation-title { color: var(--accent-emerald); }
.xdb-validation-bad .xdb-validation-title { color: var(--accent-rose); }
.xdb-validation-grid, .xdb-plan-grid { display: grid; grid-template-columns: 170px 1fr; gap: 4px 14px; }
.xdb-validation-grid span, .xdb-plan-grid span { color: var(--text-muted); }
.xdb-validation-grid b, .xdb-plan-grid b { font-weight: 600; color: var(--text-main); }
.xdb-plan-grid em { color: var(--text-muted); font-style: normal; font-weight: 400; }
.xdb-problems { margin: 0; padding-left: 18px; color: var(--accent-rose); }
.xdb-two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; align-items: start; }
.xdb-overview-lead { font-weight: 600; margin-bottom: 8px; }
.xdb-overview-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: var(--fs-body); }
.xdb-overview-list li span { display: block; color: var(--text-muted); font-size: var(--fs-label); }
.xdb-overview-conf { color: var(--accent-emerald) !important; }
.xdb-zoom { display: inline-flex; gap: 6px; }
.xdb-graph-wrap { position: relative; border: 1px solid var(--border-glass); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-raised); }
.xdb-graph { width: 100%; display: block; cursor: grab; user-select: none; }
.xdb-graph.xdb-dragging { cursor: grabbing; }
.xdb-graph-empty { position: absolute; left: 16px; right: 16px; bottom: 12px; }
.xdb-graph-empty[hidden] { display: none; }
.xdb-g-db { fill: rgba(99, 102, 241, 0.06); stroke: rgba(99, 102, 241, 0.35); stroke-width: 1; }
.xdb-g-dbname { font: 700 13px var(--font-sans); }
.xdb-g-node { fill: var(--bg-card); stroke: rgba(148, 163, 184, 0.45); stroke-width: 1; }
.xdb-g-table { font: 500 12px "Fira Code", monospace; }
.xdb-g-line { fill: none; stroke-width: 2; }
.xdb-g-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
.xdb-g-edge-ok .xdb-g-line { stroke: #10b981; }
.xdb-g-edge-sug .xdb-g-line { stroke: #f59e0b; stroke-dasharray: 6 5; }
.xdb-g-edge-sel .xdb-g-line { stroke-width: 4; }
.xdb-g-edge { cursor: pointer; }
.xdb-g-label { font: 600 11px var(--font-sans); pointer-events: none; }
.xdb-examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.xdb-examples-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.xdb-answers-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 2px -4px; }
.xdb-answers-bar[hidden], #btn-xdb-more-ideas[hidden] { display: none; }
.xdb-answer-actions { margin-left: auto; display: inline-flex; gap: 6px; }
.xdb-answer-del:hover { color: var(--accent-rose); border-color: var(--accent-rose); }
.xdb-single-note { margin-top: 6px; }
.xdb-examples .prompt-chip { max-width: 100%; }
.xdb-answers { display: flex; flex-direction: column; gap: 14px; }
.xdb-answer { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.xdb-answer-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.xdb-answer-q { font-weight: 700; color: var(--text-main); }
.xdb-insight { font-size: var(--fs-body-lg); line-height: 1.5; }
.xdb-insight-cross { padding: 10px 12px; border-radius: var(--radius-sm); background: rgba(139, 92, 246, 0.08); border: 1px solid rgba(139, 92, 246, 0.3); }
.xdb-plan { border: 1px solid var(--border-glass); border-radius: var(--radius-sm); padding: 8px 12px; font-size: var(--fs-body); background: var(--surface-raised); }
.xdb-plan > summary { cursor: pointer; font-weight: 700; margin-bottom: 6px; }
.xdb-plan-grid { margin-bottom: 4px; }
.xdb-plan-db { color: var(--text-muted); font-weight: 500; }
.xdb-plan-reason { font-weight: 400 !important; line-height: var(--lh-body); }
.xdb-ok { color: var(--accent-emerald); font-size: 11px; margin-right: 2px; }
.xdb-steps-title { margin: 12px 0 6px; font-size: var(--fs-label); font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.xdb-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.xdb-step { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); background: var(--surface-sunken); }
.xdb-step-no { flex: 0 0 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; background: var(--accent-indigo); }
.xdb-step-main { flex: 1; min-width: 0; }
.xdb-step-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.xdb-step-db { font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: var(--radius-pill); border: 1px solid var(--border-strong); color: var(--text-main); white-space: nowrap; }
.xdb-step-text { flex: 1; min-width: 180px; color: var(--text-main); }
.xdb-step-meta { margin-left: auto; color: var(--text-muted); font-size: var(--fs-caption); white-space: nowrap; }
.xdb-step-warn { color: var(--accent-amber); }
.xdb-step-sql { margin-top: 4px; }
.xdb-step-sql > summary { cursor: pointer; font-size: var(--fs-caption); color: var(--accent-indigo); width: fit-content; }
.xdb-step-sql pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; overflow-x: hidden; }
.xdb-figures { display: flex; flex-wrap: wrap; gap: 12px; }
.xdb-figure { flex: 1 1 200px; max-width: 320px; padding: 14px 18px; border: 1px solid var(--border-glass); border-radius: var(--radius-md); background: var(--surface-raised); }
.xdb-figure-value { font-size: 28px; font-weight: 800; line-height: 1.1; color: var(--accent-indigo); font-variant-numeric: tabular-nums; }
.xdb-figure-text { font-size: 18px; color: var(--text-main); word-break: break-word; }
.xdb-figure-label { margin-top: 4px; font-size: var(--fs-caption); color: var(--text-muted); }
@media (max-width: 640px) { .xdb-plan-grid { grid-template-columns: 1fr; } .xdb-step-meta { margin-left: 0; } }
.xdb-result-tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.xdb-tool-buttons { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.xdb-result-table { max-height: 420px; overflow: auto; }
.xdb-chart[hidden] { display: none; }
.xdb-add-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow: auto; }
.xdb-pick { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--border-glass); border-radius: var(--radius-sm); cursor: pointer; font-size: var(--fs-body); }
.xdb-pick em { color: var(--text-muted); font-style: normal; }
.xdb-rel-form { display: grid; grid-template-columns: 1fr 40px 1fr; gap: 10px; align-items: center; }
.xdb-rel-form .form-label { margin: 8px 0 4px; }
.xdb-rel-form-arrow { text-align: center; color: var(--accent-indigo); font-size: 18px; }
@media (max-width: 1100px) { .xdb-two-col { grid-template-columns: minmax(0, 1fr); } }
[data-theme="light"] .xdb-badge-ok { color: #047857; }
[data-theme="light"] .xdb-badge-warn { color: #b45309; }
[data-theme="light"] .xdb-badge-bad { color: #be123c; }
[data-theme="light"] .xdb-badge-info { color: #0e7490; }
.xdb-warnings { margin: 0; padding-left: 18px; color: #fbbf24; }
[data-theme="light"] .xdb-warnings { color: #b45309; }
.xdb-meaning { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-weight: 400; }
.xdb-meaning-ok { color: var(--accent-emerald); }
.xdb-meaning-bad { color: var(--accent-rose); }
.xdb-rel-table td { white-space: normal; overflow-wrap: anywhere; }
.xdb-rel-table td.xdb-actions, .xdb-rel-table td.num, .xdb-rel-table td.xdb-arrow { white-space: nowrap; overflow-wrap: normal; }
.xdb-rel-table td:first-child, .xdb-rel-table td:nth-child(3) { min-width: 220px; }

/* Cross-database link types: same records / same list / key link */
.xdb-link { display: inline-block; margin-top: 3px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.xdb-link-rec { color: #7c3aed; background: rgba(124, 58, 237, 0.10); border-color: rgba(124, 58, 237, 0.35); }
.xdb-link-list { color: #0e7490; background: rgba(8, 145, 178, 0.10); border-color: rgba(8, 145, 178, 0.35); }
.xdb-link-key { color: #475569; background: rgba(100, 116, 139, 0.10); border-color: rgba(100, 116, 139, 0.35); }
:root[data-theme="dark"] .xdb-link-rec { color: #c4b5fd; }
:root[data-theme="dark"] .xdb-link-list { color: #67e8f9; }
:root[data-theme="dark"] .xdb-link-key { color: #cbd5e1; }

/* App-wide notices (showToast): top right, clear of the question box and its Run button */
#qx-toast { top: 76px; bottom: auto; }
#qx-toast[hidden] { display: none; }

/* Question in progress: a live card in the conversation (spinner, estimated step, elapsed time, Stop) */
.ai-pending { border: 1px solid var(--border-accent); background: linear-gradient(135deg, rgba(99, 102, 241, 0.10), rgba(6, 182, 212, 0.06)); }
.ai-pending-head { display: flex; align-items: center; gap: 14px; }
.ai-pending-spinner { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(99, 102, 241, 0.25);
  border-top-color: var(--accent-indigo); animation: qx-spin 0.9s linear infinite; }
.ai-pending-text { flex: 1; min-width: 0; }
.ai-pending-title { font-weight: 700; font-size: var(--fs-body-lg); color: var(--text-main); }
.ai-pending-step { margin-top: 2px; color: var(--accent-indigo); font-weight: 600; }
.ai-pending-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-muted); min-width: 48px; text-align: right; }
.ai-pending-bar { position: relative; height: 4px; margin: 14px 0 12px; border-radius: 999px; overflow: hidden; background: rgba(99, 102, 241, 0.15); }
.ai-pending-bar span { position: absolute; top: 0; bottom: 0; width: 35%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-indigo), var(--accent-cyan)); animation: qx-slide 1.4s ease-in-out infinite; }
.ai-pending-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: var(--fs-caption); color: var(--text-muted); }
.ai-pending-steps li { display: inline-flex; align-items: center; gap: 6px; }
.ai-pending-steps li i { font-size: 11px; }
.ai-pending-steps li.done { color: var(--accent-emerald); }
.ai-pending-steps li.active { color: var(--text-main); font-weight: 600; }
.ai-pending-steps li.active i { color: var(--accent-indigo); }
.ai-pending-note { margin-top: 10px; font-size: var(--fs-caption); color: var(--text-dim); }
@keyframes qx-spin { to { transform: rotate(360deg); } }
@keyframes qx-slide { 0% { left: -35%; } 100% { left: 100%; } }
@media (prefers-reduced-motion: reduce) {
  .ai-pending-spinner { animation-duration: 2.5s; }
  .ai-pending-bar span { animation: none; left: 0; width: 100%; opacity: 0.6; }
}
@media (max-width: 640px) { .ai-pending-head { flex-wrap: wrap; } .ai-pending-stop { margin-left: auto; } }

/* Answer confidence: checks against the data (green), notes (amber), not verified (red) */
.ai-quality { margin-top: 10px; font-size: var(--fs-caption); border-radius: var(--radius-sm); padding: 6px 10px; border: 1px solid var(--border-subtle); background: var(--surface-sunken); }
.ai-quality > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 6px; }
.ai-quality > summary::-webkit-details-marker { display: none; }
.ai-quality ul { list-style: none; margin: 6px 0 2px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.ai-quality li { display: flex; gap: 8px; align-items: baseline; color: var(--text-muted); line-height: var(--lh-body); }
.ai-quality li i { font-size: 11px; flex: 0 0 auto; }
.ai-quality-ok i { color: var(--accent-emerald); }
.ai-quality-warn { color: var(--text-main) !important; }
.ai-quality-warn i { color: var(--accent-amber); }
.ai-quality-count { font-weight: 500; color: var(--text-muted); }
.ai-quality-high > summary { color: var(--accent-emerald); }
.ai-quality-medium { border-color: rgba(245, 158, 11, 0.45); }
.ai-quality-medium > summary { color: var(--accent-amber); }
.ai-quality-low { border-color: rgba(244, 63, 94, 0.55); background: rgba(244, 63, 94, 0.06); }
.ai-quality-low > summary { color: var(--accent-rose); }

/* A question waiting in the queue (its turn comes after the user's earlier questions) */
.ai-pending-queued { border-style: dashed; background: var(--surface-sunken); }
.ai-pending-wait { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent-amber); background: rgba(245, 158, 11, 0.12); font-size: 15px; }
.ai-pending-queued .ai-pending-step { color: var(--accent-amber); }

/* A follow-up question and the complete question it was read as */
.ai-understood { margin: 2px 0 8px; font-size: var(--fs-caption); color: var(--text-muted); display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.ai-understood i { color: var(--accent-indigo); font-size: 11px; }
.ai-understood em { color: var(--text-main); font-style: normal; font-weight: 600; }
