: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: 1.02rem;
  line-height: 1.7;
}

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

.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

.article-content table th,
.article-content table td {
  border: 1px solid #dee2e6;
  padding: 0.5rem;
}

/* ---------- 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 ---------- */

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

/* ---------- 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 {
  display: flex;
  flex-wrap: wrap;
  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 button {
  min-width: 2.25rem;
}

.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"] .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"] .article-content table th,
[data-bs-theme="dark"] .article-content table td {
  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;
  }
}
