:root {
  --accent: #0d6efd;
  --accent-dark: #0b5ed7;
  --sidebar-bg: #0f172a;
  --sidebar-bg-2: #1a2540;
  --sidebar-text: #cbd5e1;
  --sidebar-text-muted: #7c8aa5;
  --sidebar-active-bg: rgba(255, 255, 255, 0.08);
  --page-bg: #f4f6fb;
  --card-border: rgba(15, 23, 42, 0.08);
  --radius-lg: 1rem;
  --radius-md: 0.75rem;
  --shadow-soft: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-hover: 0 12px 24px -8px rgba(15, 23, 42, 0.18);
}

body {
  background-color: var(--page-bg);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1e293b;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ---------- App shell: dark sidebar + light content ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.25rem 1.25rem 1rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand img {
  height: 44px;
  width: auto;
  max-width: 176px;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
  padding: 3px 6px;
}

.sidebar-brand .accent-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
}

.sidebar-nav .nav-link {
  color: var(--sidebar-text);
  border-radius: 0.6rem;
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.15rem;
  font-size: 0.92rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-nav .nav-link i {
  font-size: 1.05rem;
  width: 1.2rem;
  text-align: center;
  opacity: 0.85;
}

.sidebar-nav .nav-link:hover {
  background: var(--sidebar-active-bg);
  color: #fff;
}

.sidebar-nav .nav-link.active {
  background: var(--accent);
  color: #fff;
}

.sidebar-nav .nav-link.active i {
  opacity: 1;
}

/* ---------- Sidebar nav categories (collapsible groups) ---------- */

.nav-category {
  margin-top: 0.5rem;
}

.nav-category-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  background: none;
  border: none;
  color: var(--sidebar-text-muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
}

.nav-category-toggle i:first-child {
  font-size: 0.95rem;
}

.nav-category-toggle .bi-chevron-down {
  margin-left: auto;
  font-size: 0.7rem;
  transition: transform 0.15s ease;
}

.nav-category-toggle[aria-expanded="false"] .bi-chevron-down {
  transform: rotate(-90deg);
}

.nav-category-toggle:hover {
  color: var(--sidebar-text);
}

.sidebar-footer {
  padding: 0.9rem 1.1rem 1.1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  color: var(--sidebar-text-muted);
}

.viewing-as-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255, 193, 7, 0.15);
  border: 1px solid rgba(255, 193, 7, 0.35);
  color: #ffd867;
  border-radius: 0.6rem;
  padding: 0.5rem 0.7rem;
  font-size: 0.78rem;
  margin: 0 0.75rem 0.75rem;
}

.viewing-as-chip a {
  color: #ffd867;
  margin-left: auto;
}

.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--card-border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .search-box {
  max-width: 340px;
}

.topbar .search-box input {
  border-radius: 999px;
  padding-left: 1rem;
  background: var(--page-bg);
  border: 1px solid var(--card-border);
}

.topbar-clock {
  font-variant-numeric: tabular-nums;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.role-badge {
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 0.3em 0.65em;
}

.role-badge-superadmin { background: #1e1b4b; color: #c7d2fe; }
.role-badge-staff { background: #134e4a; color: #99f6e4; }
.role-badge-admin { background: #4c1d95; color: #e9d5ff; }
.role-badge-manager { background: #0c4a6e; color: #bae6fd; }
.role-badge-user { background: #374151; color: #d1d5db; }

.content-area {
  padding: 1.75rem;
  flex: 1;
}

/* ---------- Cards ---------- */

.card {
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.card-clickable {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card-clickable:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.airline-logo-bubble {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fff;
  overflow: hidden;
}

.airline-logo-bubble img {
  max-width: 80%;
  max-height: 80%;
  object-fit: contain;
}

.stat-card {
  border-radius: var(--radius-lg);
  border-left: 4px solid var(--accent);
  position: relative;
  overflow: hidden;
}

.stat-card .stat-icon {
  position: absolute;
  right: 1rem;
  top: 1rem;
  font-size: 2rem;
  opacity: 0.12;
}

.stat-card.stat-success { border-left-color: #198754; }
.stat-card.stat-warning { border-left-color: #ffc107; }
.stat-card.stat-info { border-left-color: #0dcaf0; }

.autofill-banner {
  background: linear-gradient(120deg, rgba(13, 110, 253, 0.08), rgba(13, 110, 253, 0.02));
  border: 1px dashed rgba(13, 110, 253, 0.35) !important;
  border-radius: var(--radius-lg);
}

.autofill-logo-preview {
  height: 48px;
  max-width: 96px;
  object-fit: contain;
  background: #fff;
  border-radius: 0.5rem;
  padding: 4px;
  border: 1px solid var(--card-border);
}

/* ---------- Buttons ---------- */

.btn {
  border-radius: 0.6rem;
  font-weight: 500;
}

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

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

/* ---------- Article content ---------- */

.article-content {
  font-size: 1rem;
  line-height: 1.55;
}

/* Heading scale inside article bodies. The global h1-h6 rule leaves these
   at Bootstrap's defaults (H1 2.5rem, H2 2rem, H3 1.75rem), which dwarfs the
   card title and body text on pages that stack many articles. */
.article-content h1 { font-size: 1.4rem; }
.article-content h2 { font-size: 1.15rem; }
.article-content h3 { font-size: 1rem; }
.article-content h4 { font-size: 0.95rem; }
.article-content h5,
.article-content h6 { font-size: 0.9rem; }

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4,
.article-content h5,
.article-content h6 {
  line-height: 1.3;
  margin: 1rem 0 0.4rem;
}

.article-content > :first-child { margin-top: 0; }
.article-content > :last-child { margin-bottom: 0; }

.article-content p,
.article-content ul,
.article-content ol,
.article-content blockquote,
.article-content pre,
.article-content dl {
  margin-bottom: 0.6rem;
}

.article-content ul,
.article-content ol {
  padding-left: 1.4rem;
}

.article-content li > ul,
.article-content li > ol {
  margin-bottom: 0;
}

.article-content hr {
  margin: 0.8rem 0;
}

.article-content blockquote {
  padding-left: 0.8rem;
  border-left: 3px solid #ced4da;
  color: #475569;
}

[data-bs-theme="dark"] .article-content blockquote {
  border-left-color: var(--card-border);
  color: #94a3b8;
}

.article-content img {
  max-width: 100%;
}

/* Tables sit in a .kb-table-wrap (added by kb.rendering) so a wide table
   scrolls inside its own box instead of stretching the page. */
.kb-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 0.6rem 0;
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  font-size: 0.95em;
  line-height: 1.45;
}

.article-content table th,
.article-content table td {
  border: 1px solid #ced4da;
  padding: 0.35rem 0.6rem;
  vertical-align: top;
}

.article-content table th {
  background: #f1f3f5;
  font-weight: 700;
  text-align: left;
}

.article-content table.kb-table-firstcol td:first-child {
  background: #f1f3f5;
}

.kb-panel .kb-table-wrap {
  margin: 0.4rem 0;
}

[data-bs-theme="dark"] .article-content table th,
[data-bs-theme="dark"] .article-content table td {
  border-color: var(--card-border);
}

[data-bs-theme="dark"] .article-content table th,
[data-bs-theme="dark"] .article-content table.kb-table-firstcol td:first-child {
  background: rgba(148, 163, 184, 0.14);
}

/* ---------- Article panels (:::info ... :::) ---------- */

.kb-panel {
  --kb-c: #6b7280;
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin: 0.6rem 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid color-mix(in srgb, var(--kb-c) 35%, transparent);
  border-radius: 0.4rem;
  background: color-mix(in srgb, var(--kb-c) 11%, transparent);
  line-height: 1.5;
}

/* Info follows the agency's accent color; the other types keep a fixed
   hue so their meaning does not change with the theme. */
.kb-panel-info { --kb-c: var(--accent, #0d6efd); }
.kb-panel-note { --kb-c: #7c3aed; }
.kb-panel-warning { --kb-c: #d97706; }
.kb-panel-error { --kb-c: #dc2626; }
.kb-panel-success { --kb-c: #16a34a; }

[data-bs-theme="dark"] .kb-panel-note { --kb-c: #a78bfa; }
[data-bs-theme="dark"] .kb-panel-warning { --kb-c: #fbbf24; }
[data-bs-theme="dark"] .kb-panel-error { --kb-c: #f87171; }
[data-bs-theme="dark"] .kb-panel-success { --kb-c: #4ade80; }

.kb-panel-icon {
  flex: 0 0 auto;
  color: var(--kb-c);
  font-size: 1rem;
  line-height: 1.5;
}

.kb-panel-body {
  flex: 1 1 auto;
  min-width: 0;
}

.kb-panel-body > :first-child { margin-top: 0; }
.kb-panel-body > :last-child { margin-bottom: 0; }

.kb-panel-body p,
.kb-panel-body ul,
.kb-panel-body ol {
  margin-bottom: 0.3rem;
}

.kb-panel-body ul,
.kb-panel-body ol {
  padding-left: 1.2rem;
}

.kb-panel-title {
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.kb-panel .kb-panel {
  margin: 0.4rem 0;
}

/* ---------- Article link cards (:::card URL Title ... :::) ---------- */

.kb-linkcard {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin: 0.5rem 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ced4da;
  border-radius: 0.4rem;
  background: color-mix(in srgb, var(--accent, #0d6efd) 5%, transparent);
  color: inherit;
  text-decoration: none;
  line-height: 1.4;
}

.kb-linkcard:hover {
  border-color: var(--accent, #0d6efd);
  background: color-mix(in srgb, var(--accent, #0d6efd) 11%, transparent);
  color: inherit;
}

.kb-linkcard-icon {
  flex: 0 0 auto;
  color: var(--accent, #0d6efd);
  line-height: 1.4;
}

.kb-linkcard-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.kb-linkcard-title {
  font-weight: 700;
  color: var(--accent, #0d6efd);
  overflow-wrap: anywhere;
}

.kb-linkcard-host {
  font-size: 0.8rem;
  color: #64748b;
  overflow-wrap: anywhere;
}

.kb-linkcard-desc {
  margin-top: 0.15rem;
  font-size: 0.92em;
}

[data-bs-theme="dark"] .kb-linkcard {
  border-color: var(--card-border);
}

[data-bs-theme="dark"] .kb-linkcard-host {
  color: #94a3b8;
}

.kb-panel .kb-linkcard {
  margin: 0.4rem 0;
}

/* ---------- Attachment chips (under an article) ---------- */

.kb-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.kb-chip {
  --kb-c: #6b7280;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: 100%;
  padding: 0.3rem 0.65rem;
  border: 1px solid color-mix(in srgb, var(--kb-c) 35%, transparent);
  border-radius: 0.4rem;
  background: color-mix(in srgb, var(--kb-c) 9%, transparent);
  color: inherit;
  text-decoration: none;
  line-height: 1.3;
}

.kb-chip:hover {
  background: color-mix(in srgb, var(--kb-c) 18%, transparent);
  color: inherit;
}

.kb-chip-pdf { --kb-c: #dc2626; }
.kb-chip-word { --kb-c: #2563eb; }
.kb-chip-excel { --kb-c: #16a34a; }
.kb-chip-slides { --kb-c: #d97706; }
.kb-chip-image { --kb-c: #7c3aed; }

[data-bs-theme="dark"] .kb-chip-pdf { --kb-c: #f87171; }
[data-bs-theme="dark"] .kb-chip-word { --kb-c: #60a5fa; }
[data-bs-theme="dark"] .kb-chip-excel { --kb-c: #4ade80; }
[data-bs-theme="dark"] .kb-chip-slides { --kb-c: #fbbf24; }
[data-bs-theme="dark"] .kb-chip-image { --kb-c: #a78bfa; }

.kb-chip-icon {
  flex: 0 0 auto;
  color: var(--kb-c);
  font-size: 1.1rem;
}

.kb-chip-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.kb-chip-meta {
  flex: 0 0 auto;
  font-size: 0.75rem;
  color: #64748b;
  white-space: nowrap;
}

[data-bs-theme="dark"] .kb-chip-meta { color: #94a3b8; }

/* Rendered article text on the review pages (Content Updates, suggestions). */
.review-preview {
  max-height: 420px;
  overflow: auto;
  padding: 0.5rem 0.75rem;
  border: 1px solid #dee2e6;
  border-radius: 0.4rem;
}

[data-bs-theme="dark"] .review-preview {
  border-color: var(--card-border);
}

/* ---------- Login page ---------- */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #1e3a8a 0%, #0f172a 55%, #0b1120 100%);
  padding: 1.5rem;
}

.login-card {
  max-width: 400px;
  width: 100%;
  background: rgba(255, 255, 255, 0.97);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.4);
  overflow: hidden;
}

.login-card .login-header {
  background: linear-gradient(135deg, var(--accent), #6610f2);
  color: #fff;
  padding: 1.75rem 2rem 1.25rem;
  text-align: center;
}

.login-card .login-body {
  padding: 1.75rem 2rem 2rem;
}

/* ---------- Markdown editor ---------- */

/* Textarea and live preview sit side by side when the editor is wide enough
   (container query on the editor's parent, set by markdown-toolbar.js), and
   stack when it is not. */
.kb-editor-host { container-type: inline-size; }

.markdownx {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.75rem 0.75rem;
}

@container (min-width: 640px) {
  .markdownx { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

.markdownx .markdown-toolbar { grid-column: 1 / -1; margin-bottom: -0.75rem; }

.markdownx textarea {
  width: 100%;
  min-height: 420px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  border: 1px solid #ced4da;
  border-radius: 0.5rem;
  padding: 0.6rem;
}

.markdownx-preview {
  min-height: 420px;
  max-height: 70vh;
  overflow: auto;
  padding: 0.6rem 0.9rem;
  border: 1px solid #ced4da;
  border-radius: 0.5rem;
  border-top-left-radius: 0;
  background: #fff;
}

[data-bs-theme="dark"] .markdownx-preview {
  background: #111827;
  border-color: var(--card-border);
}

/* ---------- Tag chip inputs (hubs, subsidiaries, article tags) ---------- */

.tags-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid #ced4da;
  border-radius: 0.375rem;
  background-color: #fff;
  cursor: text;
}

.tags-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.15);
}

.tags-input-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 1rem;
  background-color: #eef2ff;
  color: #3730a3;
  border: 1px solid #dbe0fb;
  font-size: 0.85rem;
  line-height: 1.3;
  white-space: nowrap;
}

.tag-chip button {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  line-height: 1;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  font-size: 0.95rem;
}

.tag-chip button:hover {
  opacity: 1;
}

.tags-input-text {
  flex: 1 1 140px;
  min-width: 140px;
  border: none;
  outline: none;
  background: transparent;
  padding: 0.15rem 0.15rem;
  font-size: 0.95rem;
}

/* ---------- Tag checkbox picker (airline edit form) ---------- */

.tag-checkbox-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-checkbox-list li {
  display: block;
}

.tag-checkbox-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  margin: 0;
}

.tag-checkbox-option input[type="checkbox"] {
  margin: 0;
}

/* ---------- Markdown editor toolbar (article content) ---------- */

.markdown-toolbar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem;
  border: 1px solid #ced4da;
  border-bottom: none;
  border-radius: 0.375rem 0.375rem 0 0;
  background-color: #f8f9fa;
}

.markdown-toolbar .btn {
  min-width: 2.1rem;
  padding: 0.15rem 0.45rem;
}

.markdown-toolbar .btn:disabled {
  opacity: 0.35;
}

.kb-editor-sep {
  width: 1px;
  align-self: stretch;
  margin: 0.15rem 0.2rem;
  background: #ced4da;
}

.kb-editor-pop {
  position: absolute;
  z-index: 20;
  padding: 0.5rem;
  background: #fff;
  color: #1e293b;
  border: 1px solid #ced4da;
  border-radius: 0.4rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 11rem;
}

.kb-editor-pop-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 0.3rem;
  background: transparent;
  color: inherit;
  text-align: left;
}

.kb-editor-pop-item:hover { background: rgba(100, 116, 139, 0.14); }
.kb-editor-pop-item .bi { color: var(--kb-c, #6b7280); }

.kb-editor-pop-label { font-size: 0.8rem; color: #64748b; }

.kb-editor-grid {
  display: grid;
  grid-template-columns: repeat(8, 1.35rem);
  gap: 2px;
}

.kb-editor-grid-cell {
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1px solid #ced4da;
  border-radius: 2px;
  background: #fff;
}

.kb-editor-grid-cell.on {
  background: var(--accent, #0d6efd);
  border-color: var(--accent-dark, #0a58ca);
}

.kb-editor-nums {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.kb-editor-num {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
}

.kb-editor-num input { width: 3.6rem; }

.kb-editor-emoji {
  display: grid;
  grid-template-columns: repeat(12, 1.9rem);
  gap: 2px;
}

.kb-editor-emoji-item {
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  border: 0;
  border-radius: 0.3rem;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
}

.kb-editor-emoji-item:hover { background: rgba(100, 116, 139, 0.2); }

.markdownx-editor {
  border-top-left-radius: 0 !important;
  border-top-right-radius: 0 !important;
}

/* ---------- Article source citation bubble ---------- */

.citation-bubble {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border-radius: 1rem;
  background-color: var(--page-bg);
  border: 1px solid var(--card-border);
  color: #495057;
  font-size: 0.8rem;
  text-decoration: none;
}

.citation-bubble:hover {
  background-color: #eef2f7;
  color: #212529;
}

/* ---------- Responsive: collapse sidebar on small screens ---------- */

/* ---------- Dark mode ----------
   A personal per-user toggle (accounts.User.dark_mode), independent of
   an agency's chosen color theme - see templates/base.html for the
   `data-bs-theme` attribute this hangs off of. Bootstrap 5.3's own
   components (cards, tables, forms, alerts, badges, the dropdown menu)
   already re-theme themselves under [data-bs-theme="dark"]; everything
   below is just this app's own classes that use a hardcoded color
   instead of a Bootstrap variable, plus the couple of custom variables
   (--page-bg, --card-border) this stylesheet defines itself. The sidebar
   is deliberately left alone - it's always dark regardless of this
   toggle, by design. */

[data-bs-theme="dark"] {
  --page-bg: #0b1220;
  --card-border: rgba(255, 255, 255, 0.09);
}

[data-bs-theme="dark"] body {
  color: #e2e8f0;
}

[data-bs-theme="dark"] .topbar {
  background: #111827;
}

/* Bootstrap's `.bg-white` utility is *literally* white by design, not
   theme-aware - this app uses it all over (card/card-header/card-footer/
   stat-card/table) purely to get a clean surface color in LIGHT mode. In
   dark mode that hardcoded white stayed white while the text inside it
   (`.text-muted`, `<strong>`) re-themed to a light color, so headers like
   "NDC" or "Fleet" turned into near-unreadable light-gray-on-white bars -
   this is the fix. Falling back to Bootstrap's own --bs-card-bg (already
   dark-theme-aware) makes a `bg-white` card/header/table look exactly
   like an un-classed one in dark mode, which is what was actually wanted
   here all along - `bg-white` was never meant as "stay white no matter
   what", just "look like a normal card surface". */
[data-bs-theme="dark"] .bg-white {
  background-color: var(--bs-card-bg) !important;
}

[data-bs-theme="dark"] .role-badge-user {
  background: #1f2937;
}

[data-bs-theme="dark"] .autofill-banner {
  background: linear-gradient(120deg, rgba(13, 110, 253, 0.16), rgba(13, 110, 253, 0.04));
}

[data-bs-theme="dark"] .autofill-logo-preview,
[data-bs-theme="dark"] .tags-input,
[data-bs-theme="dark"] .markdown-toolbar {
  background-color: #111827;
  border-color: var(--card-border);
}

[data-bs-theme="dark"] .kb-editor-pop {
  background: #1e293b;
  color: #e2e8f0;
  border-color: var(--card-border);
}

[data-bs-theme="dark"] .kb-editor-grid-cell { background: #0f172a; border-color: var(--card-border); }
[data-bs-theme="dark"] .kb-editor-sep { background: var(--card-border); }

[data-bs-theme="dark"] .tags-input-text {
  color: #e2e8f0;
}

[data-bs-theme="dark"] .tag-chip {
  background-color: rgba(99, 102, 241, 0.18);
  color: #c7d2fe;
  border-color: rgba(99, 102, 241, 0.35);
}

[data-bs-theme="dark"] .markdownx textarea {
  background-color: #111827;
  color: #e2e8f0;
  border-color: var(--card-border);
}

[data-bs-theme="dark"] .citation-bubble {
  color: #cbd5e1;
}

[data-bs-theme="dark"] .citation-bubble:hover {
  background-color: #1e293b;
  color: #f1f5f9;
}

[data-bs-theme="dark"] .tag-checkbox-option {
  color: #e2e8f0;
}

@media (max-width: 991.98px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .sidebar-nav {
    display: flex;
    overflow-x: auto;
    padding: 0.5rem;
  }
  .sidebar-nav .nav-link {
    white-space: nowrap;
  }
  .sidebar-footer, .viewing-as-chip {
    display: none;
  }
}
