:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --text: #101828;
  --text-soft: #344054;
  --muted: #667085;
  --muted-2: #98a2b3;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --success: #067647;
  --danger: #b42318;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

html[data-theme="dark"] {
  color-scheme: dark;
  /* Dash 4 controls and portalled menus inherit these from the document. */
  --Dash-Fill-Inverse-Strong: #151f30;
  --Dash-Fill-Inverse-strong: #151f30;
  --Dash-Fill-Interactive-Strong: #a5bacb;
  --Dash-Fill-Interactive-Weak: #263449;
  --Dash-Fill-Primary-Hover: #243247;
  --Dash-Fill-Primary-Active: #304159;
  --Dash-Fill-Disabled: #263244;
  --Dash-Stroke-Strong: #56667e;
  --Dash-Stroke-Weak: #354359;
  --Dash-Text-Primary: #e6edf5;
  --Dash-Text-Strong: #e6edf5;
  --Dash-Text-Weak: #b3bfd0;
  --Dash-Text-Disabled: #9aa8bd;
  --Dash-Shading-Strong: rgba(0, 0, 0, .45);
  --Dash-Shading-Weak: rgba(0, 0, 0, .25);
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #172033;
  --surface-3: #202b3d;
  --text: #f3f4f6;
  --text-soft: #d1d5db;
  --muted: #9ca3af;
  --muted-2: #6b7280;
  --border: #273244;
  --border-strong: #374151;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-soft: rgba(96, 165, 250, 0.12);
  --success: #34d399;
  --danger: #f87171;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28), 0 2px 8px rgba(0, 0, 0, 0.18);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.28);
  --focus: 0 0 0 3px rgba(96, 165, 250, 0.18);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.app-shell {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(18px, 3vw, 38px);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}
.brand-mark img { display: block; width: 100%; height: 100%; }
.brand-title { margin: 0; font-size: 18px; line-height: 1.2; letter-spacing: -0.02em; }
.brand-subtitle { margin-top: 2px; color: var(--muted); font-size: 12px; }

.topbar-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.nav-links { display: flex; align-items: center; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.nav-link {
  padding: 7px 11px;
  border-radius: 9px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  transition: background .16s ease, color .16s ease;
}
.nav-link:hover { background: var(--surface); color: var(--text); }

.theme-control { display: flex; align-items: center; gap: 8px; }
.theme-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.theme-picker > div {
  display: inline-flex !important;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
}
.theme-picker label {
  display: inline-flex !important;
  align-items: center;
  margin: 0 !important;
  padding: 5px 9px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}
.theme-picker label:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.theme-picker input { position: absolute; opacity: 0; pointer-events: none; }

.page-content {
  width: min(1580px, 100%);
  margin: 0 auto;
  padding: 22px clamp(16px, 2.4vw, 34px) 48px;
}

h1, h2, h3, h4 { color: var(--text); letter-spacing: -0.015em; }
h2 { font-size: 22px; }
h3 { font-size: 16px; }
code {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.muted { color: var(--muted) !important; }
.small { font-size: 12px !important; }
.tiny { font-size: 11px !important; }
.helper-text { line-height: 1.45; }
.source-line { overflow-wrap: anywhere; }
.section-copy { margin-top: 0; max-width: 980px; line-height: 1.55; }

.snapshot-card { position: relative; overflow: hidden; }
.snapshot-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: linear-gradient(180deg, var(--accent), #7c3aed);
}

.filter-panel {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.filter-panel label,
.investigation-selector label,
.page-content label { display: block; margin-bottom: 6px; color: var(--text-soft); font-size: 12px; font-weight: 650; }

.investigation-selector { border-color: color-mix(in srgb, var(--accent) 34%, var(--border)) !important; }
.investigation-panel {
  margin-bottom: 22px;
  padding: clamp(16px, 2vw, 24px);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--border));
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.kpi-card {
  position: relative;
  min-height: 106px;
  overflow: hidden;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.kpi-card::after {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(90deg, var(--accent), #7c3aed);
  opacity: .75;
}
.kpi-card[title] { cursor: help; }
@media (hover:hover) and (pointer:fine) {
  .kpi-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); border-color: var(--border-strong) !important; }
}
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { margin-top: 6px; color: var(--text); font-size: 28px; line-height: 1.1; font-weight: 720; letter-spacing: -0.035em; }
.kpi-note { margin-top: 6px; color: var(--muted-2); font-size: 11px; }

/* Plotly cards */
.dash-graph {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.js-plotly-plot .plotly .modebar { opacity: .25; transition: opacity .15s ease; }
.js-plotly-plot:hover .plotly .modebar { opacity: .8; }

/* Dash inputs and react-select */
input[type="text"], input[type="number"], textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { line-height: 1.45; resize: vertical; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--focus); }

.Select-control,
.Select-menu-outer,
.Select-menu,
.Select-value,
.Select-input,
.Select-input > input,
.Select-placeholder,
.VirtualizedSelectOption,
.VirtualizedSelectFocusedOption {
  background: var(--surface) !important;
  color: var(--text) !important;
}
.Select-control { min-height: 40px !important; border: 1px solid var(--border-strong) !important; border-radius: 10px !important; box-shadow: none !important; }
.is-focused:not(.is-open) > .Select-control { border-color: var(--accent) !important; box-shadow: var(--focus) !important; }
.Select-menu-outer { border: 1px solid var(--border) !important; border-radius: 10px !important; overflow: hidden; box-shadow: var(--shadow-md) !important; z-index: 1100 !important; }
.VirtualizedSelectFocusedOption { background: var(--accent-soft) !important; }
.Select-value-label { color: var(--text) !important; }
.Select-arrow { border-top-color: var(--muted) !important; }
.Select-clear-zone { color: var(--muted) !important; }

.primary-button {
  min-height: 40px;
  padding: 9px 15px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
}
.primary-button:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }
.primary-button:active { transform: translateY(1px); }
.primary-button:focus-visible { outline: none; box-shadow: var(--focus); }

/* DataTable polish */
.dash-table-container { border-radius: 12px; overflow: hidden; }
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner td,
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner th { border-color: var(--border) !important; }
.dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner input {
  background: var(--surface-2) !important;
  color: var(--text) !important;
}
.dash-table-container .previous-next-container button,
.dash-table-container .page-number { color: var(--text) !important; }

summary { color: var(--text-soft); }
hr { border: 0; border-top: 1px solid var(--border); }

@media (max-width: 820px) {
  .topbar { position: static; align-items: flex-start; }
  .topbar, .topbar-actions { flex-direction: column; width: 100%; }
  .topbar-actions { align-items: stretch; }
  .nav-links { width: 100%; }
  .nav-link { flex: 1; text-align: center; }
  .theme-control { justify-content: space-between; }
  .page-content { padding-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}


/* Dark-mode form hardening -------------------------------------------------
   Dash/React Select and browser-native form internals can ship with light
   component styles that outrank generic theme rules. Keep these overrides
   presentation-only and scoped to dark mode. */
html[data-theme="dark"] .dash-dropdown,
html[data-theme="dark"] .dash-dropdown-content,
html[data-theme="dark"] .dash-input-container,
html[data-theme="dark"] select {
  background: var(--Dash-Fill-Inverse-Strong);
  color: var(--Dash-Text-Strong);
  border-color: var(--Dash-Stroke-Strong);
  color-scheme: dark;
}
html[data-theme="dark"] .dash-dropdown-search,
html[data-theme="dark"] .dash-input-element {
  color: var(--Dash-Text-Strong);
  caret-color: var(--Dash-Text-Strong);
}
html[data-theme="dark"] .dash-dropdown-placeholder {
  color: var(--Dash-Text-Disabled);
}
html[data-theme="dark"] .dash-dropdown-option:hover,
html[data-theme="dark"] .dash-dropdown-option:focus-within {
  background: var(--Dash-Fill-Primary-Hover);
  color: var(--Dash-Text-Strong);
}
html[data-theme="dark"] .dash-dropdown-option:has(input:checked) {
  background: var(--Dash-Fill-Primary-Active);
  color: #f3f6fa;
}
html[data-theme="dark"] .dash-dropdown:disabled,
html[data-theme="dark"] .dash-input-container:has(input:disabled) {
  background: #1b2535;
  color: var(--Dash-Text-Disabled);
  opacity: 1;
}
html[data-theme="dark"] .dash-dropdown:disabled .dash-dropdown-value,
html[data-theme="dark"] .dash-input-element:disabled {
  color: var(--Dash-Text-Disabled) !important;
  -webkit-text-fill-color: var(--Dash-Text-Disabled) !important;
}
html[data-theme="dark"] .primary-button,
html[data-theme="dark"] .admin-page button:not([class]) {
  background: #33475b;
  color: #f3f6fa;
  border-color: #56667e;
}
html[data-theme="dark"] .primary-button:hover,
html[data-theme="dark"] .admin-page button:not([class]):hover {
  background: #40576d;
}
html[data-theme="dark"] .admin-page button:focus-visible {
  outline: 2px solid #a5bacb;
  outline-offset: 2px;
}
html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] textarea {
  background: #111827 !important;
  color: #e5e7eb !important;
  border-color: #465166 !important;
  caret-color: #e5e7eb;
  -webkit-text-fill-color: #e5e7eb;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #7f8a9d !important;
  opacity: 1;
  -webkit-text-fill-color: #7f8a9d;
}
html[data-theme="dark"] textarea:focus,
html[data-theme="dark"] input:focus {
  background: #121c2d !important;
  border-color: #7693a2 !important;
  box-shadow: 0 0 0 3px rgba(118, 147, 162, .18) !important;
}

html[data-theme="dark"] .Select,
html[data-theme="dark"] .Select div,
html[data-theme="dark"] .Select span {
  color: #e5e7eb;
}
html[data-theme="dark"] .Select-control,
html[data-theme="dark"] .Select.is-open > .Select-control,
html[data-theme="dark"] .Select.is-focused > .Select-control {
  background-color: #111827 !important;
  border-color: #465166 !important;
  color: #e5e7eb !important;
}
html[data-theme="dark"] .Select-value,
html[data-theme="dark"] .Select-value-label,
html[data-theme="dark"] .Select-placeholder,
html[data-theme="dark"] .Select-input,
html[data-theme="dark"] .Select-input input {
  color: #e5e7eb !important;
  -webkit-text-fill-color: #e5e7eb !important;
}
html[data-theme="dark"] .Select-placeholder { color: #7f8a9d !important; }
html[data-theme="dark"] .Select-input input { background: transparent !important; }
html[data-theme="dark"] .Select-arrow-zone,
html[data-theme="dark"] .Select-clear-zone { color: #9ca7b8 !important; }
html[data-theme="dark"] .Select-arrow { border-top-color: #9ca7b8 !important; }
html[data-theme="dark"] .Select-menu-outer,
html[data-theme="dark"] .Select-menu,
html[data-theme="dark"] .VirtualizedSelectOption {
  background-color: #111827 !important;
  color: #e5e7eb !important;
  border-color: #465166 !important;
}
html[data-theme="dark"] .VirtualizedSelectFocusedOption,
html[data-theme="dark"] .Select-option.is-focused {
  background-color: #202b3d !important;
  color: #f3f4f6 !important;
}
html[data-theme="dark"] .Select-option.is-selected {
  background-color: #273447 !important;
  color: #f3f4f6 !important;
}

/* Dash v2+ dropdown class variants. */
html[data-theme="dark"] .dash-dropdown,
html[data-theme="dark"] .dash-dropdown .Select-control,
html[data-theme="dark"] div[class*="-control"] {
  --select-bg: #111827;
}

/* Native number steppers are intentionally subdued in dark mode. */
html[data-theme="dark"] input[type="number"] { color-scheme: dark; }
html[data-theme="dark"] input[type="number"]::-webkit-inner-spin-button,
html[data-theme="dark"] input[type="number"]::-webkit-outer-spin-button {
  opacity: .55;
}

/* Checkboxes/radios follow the quieter application accent. */
html[data-theme="dark"] input[type="checkbox"],
html[data-theme="dark"] input[type="radio"] {
  accent-color: #7896a0;
}

/* Dark-mode dropdown menu contrast -----------------------------------------
   Cover both the legacy React-Select classes used by older Dash releases and
   the generated react-select class names used by newer dcc.Dropdown builds.
   These selectors are intentionally scoped to dropdown menus only. */
html[data-theme="dark"] .Select-menu-outer,
html[data-theme="dark"] .Select-menu-outer .Select-menu,
html[data-theme="dark"] .dash-dropdown [class*="-menu"] {
  background: #151e2e !important;
  background-color: #151e2e !important;
  border-color: #3d4a60 !important;
  color: #e6eaf0 !important;
}

html[data-theme="dark"] .Select-menu-outer .VirtualizedSelectOption,
html[data-theme="dark"] .Select-menu-outer .Select-option,
html[data-theme="dark"] .dash-dropdown [class*="-option"] {
  background: #151e2e !important;
  background-color: #151e2e !important;
  color: #d8dee9 !important;
  -webkit-text-fill-color: #d8dee9 !important;
  border-color: #273449 !important;
}

html[data-theme="dark"] .Select-menu-outer .VirtualizedSelectFocusedOption,
html[data-theme="dark"] .Select-menu-outer .Select-option.is-focused,
html[data-theme="dark"] .dash-dropdown [class*="-option"]:hover,
html[data-theme="dark"] .dash-dropdown [class*="-option"][aria-selected="true"] {
  background: #243247 !important;
  background-color: #243247 !important;
  color: #f8fafc !important;
  -webkit-text-fill-color: #f8fafc !important;
}

html[data-theme="dark"] .Select-menu-outer .Select-option.is-selected {
  background: #2c3b50 !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}

/* The searchable company dropdown renders a separate search field in some
   Dash versions. Keep it dark and visibly separated from the results list. */
html[data-theme="dark"] .dash-dropdown [class*="-menu"] input,
html[data-theme="dark"] .Select-menu-outer input,
html[data-theme="dark"] .dash-dropdown input[type="text"] {
  background: #0f1827 !important;
  color: #f3f4f6 !important;
  -webkit-text-fill-color: #f3f4f6 !important;
  caret-color: #f3f4f6 !important;
}
html[data-theme="dark"] .dash-dropdown [class*="-menu"] input::placeholder,
html[data-theme="dark"] .Select-menu-outer input::placeholder {
  color: #91a0b5 !important;
  -webkit-text-fill-color: #91a0b5 !important;
  opacity: 1 !important;
}

/* Make disabled dropdowns clearly disabled without making their text vanish. */
html[data-theme="dark"] .Select.is-disabled > .Select-control,
html[data-theme="dark"] .dash-dropdown[aria-disabled="true"] [class*="-control"] {
  background: #161f2f !important;
  color: #8996a8 !important;
  opacity: .78;
}

/* AG Grid Community data tables -------------------------------------------
   Shared table treatment: compact toolbars, quick search, floating filters,
   pagination and readable light/dark theme variables. */
.grid-shell {
  width: 100%;
  min-width: 0;
}
.grid-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}
.grid-search {
  flex: 1 1 240px;
  min-width: 180px;
  max-width: 440px;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  outline: none;
}
.grid-search::placeholder { color: var(--muted); opacity: 1; }
.grid-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.grid-export-button {
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.grid-export-button:hover {
  border-color: var(--accent);
  background: var(--surface-3, var(--surface-2));
}
.grid-export-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.fqa-ag-grid {
  --ag-font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ag-font-size: 13px;
  --ag-background-color: #ffffff;
  --ag-foreground-color: #344054;
  --ag-header-background-color: #f8fafc;
  --ag-header-foreground-color: #344054;
  --ag-odd-row-background-color: #fbfcfd;
  --ag-row-hover-color: #f2f6f7;
  --ag-selected-row-background-color: #e8f0f1;
  --ag-border-color: #e4e7ec;
  --ag-secondary-border-color: #eef1f4;
  --ag-input-border-color: #d0d5dd;
  --ag-input-focus-border-color: #607d86;
  --ag-input-focus-box-shadow: 0 0 0 2px rgba(96,125,134,.14);
  --ag-control-panel-background-color: #ffffff;
  --ag-subheader-background-color: #f8fafc;
  --ag-chip-background-color: #eef3f4;
  --ag-range-selection-border-color: #607d86;
  --ag-checkbox-checked-color: #607d86;
  --ag-row-border-color: #eef1f4;
  --ag-wrapper-border-radius: 10px;
  --ag-grid-size: 6px;
  --ag-list-item-height: 32px;
}
.fqa-ag-grid .ag-root-wrapper {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.fqa-ag-grid .ag-header-cell-label { font-weight: 650; }
.fqa-ag-grid .ag-floating-filter-input input,
.fqa-ag-grid .ag-input-field-input {
  font-size: 12px;
}
.fqa-ag-grid .ag-paging-panel {
  min-height: 44px;
  border-top-color: var(--border);
}
.fqa-ag-grid .ag-cell { line-height: 1.35; }

html[data-theme="dark"] .fqa-ag-grid {
  --ag-background-color: #111827;
  --ag-foreground-color: #d8dee9;
  --ag-header-background-color: #182235;
  --ag-header-foreground-color: #edf1f6;
  --ag-odd-row-background-color: #131c2b;
  --ag-row-hover-color: #1e2b3d;
  --ag-selected-row-background-color: #263647;
  --ag-border-color: #334155;
  --ag-secondary-border-color: #263244;
  --ag-input-border-color: #465166;
  --ag-input-focus-border-color: #88a096;
  --ag-input-focus-box-shadow: 0 0 0 2px rgba(136,160,150,.16);
  --ag-control-panel-background-color: #111827;
  --ag-subheader-background-color: #151f30;
  --ag-chip-background-color: #243247;
  --ag-range-selection-border-color: #88a096;
  --ag-checkbox-checked-color: #88a096;
  --ag-row-border-color: #263244;
  color-scheme: dark;
}
html[data-theme="dark"] .fqa-ag-grid .ag-root-wrapper,
html[data-theme="dark"] .fqa-ag-grid .ag-header,
html[data-theme="dark"] .fqa-ag-grid .ag-paging-panel,
html[data-theme="dark"] .fqa-ag-grid .ag-menu,
html[data-theme="dark"] .fqa-ag-grid .ag-popup-child {
  background-color: #111827;
  color: #d8dee9;
  border-color: #334155;
}
html[data-theme="dark"] .fqa-ag-grid input,
html[data-theme="dark"] .fqa-ag-grid select,
html[data-theme="dark"] .fqa-ag-grid .ag-picker-field-wrapper {
  background-color: #0f1827 !important;
  color: #f3f4f6 !important;
  border-color: #465166 !important;
}
html[data-theme="dark"] .fqa-ag-grid input::placeholder { color: #8e9caf; opacity: 1; }
html[data-theme="dark"] .grid-search,
html[data-theme="dark"] .grid-export-button {
  background: #151f30;
  color: #e5e7eb;
  border-color: #3d4a60;
}
html[data-theme="dark"] .grid-export-button:hover { background: #202c3f; }

@media (max-width: 640px) {
  .grid-toolbar { align-items: stretch; }
  .grid-search { max-width: none; width: 100%; flex-basis: 100%; }
  .grid-export-button { width: 100%; }
}

/* Logical dashboard pages keep their callback components mounted. */
.workspace-layout { display: grid; grid-template-columns: 228px minmax(0, 1fr); align-items: start; }
.sidebar {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 78px);
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 78px);
  overflow-y: auto;
  padding: 26px 14px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.sidebar-heading { padding: 0 12px 14px; font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 5px; }
.sidebar-link { display: block; padding: 11px 12px; border-radius: 9px; color: var(--text-soft); font-size: 13px; font-weight: 600; text-decoration: none; }
.sidebar-link:hover { background: var(--surface-2); color: var(--text); }
.sidebar-link[aria-current="page"] { background: var(--surface-2); color: var(--accent); box-shadow: inset 3px 0 var(--accent); }
.sidebar-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sidebar-admin { margin-top: 16px; border-top: 1px solid var(--border); }
.sidebar > * { flex-shrink: 0; }
.sidebar-status { margin-top: auto; padding: 16px 12px 0; color: var(--muted); font-size: 11px; line-height: 1.6; overflow-wrap: anywhere; }
.sidebar-status-label { border-top: 1px solid var(--border); padding-top: 12px; margin-bottom: 4px; font-weight: 650; }
.sidebar-status strong { color: var(--text-soft); font-size: 12px; }
.sidebar-status time, .sidebar-status a { display: block; }
.workspace-layout .page-content { min-width: 0; }
.dashboard-page-title { margin: 0 0 18px; }
.dashboard-panel { display: none; min-width: 0; }
.view-overview [data-dashboard-page="overview"],
.view-quota [data-dashboard-page="quota"],
.view-landings [data-dashboard-page="landings"],
.view-ownership [data-dashboard-page="ownership"],
.view-companies [data-dashboard-page="companies"],
.view-governance [data-dashboard-page="governance"],
.view-quality [data-dashboard-page="quality"] { display: grid; }
/* These pages have independent controls, rather than the shared FQA filters. */
.view-landings .filter-panel, .view-companies .filter-panel, .view-quality .filter-panel { display: none !important; }
.dashboard-panel > div { max-width: 100%; }
@media (max-width: 1100px) {
  .workspace-layout { grid-template-columns: 195px minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .workspace-layout { display: block; }
  .sidebar { position: static; height: auto; max-height: none; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-status { padding: 8px 10px 0; }
  .sidebar-heading { padding: 0 0 8px; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .sidebar-link { padding: 8px 10px; }
  .sidebar-admin { margin-top: 0; border-top: 0; }
}

/* Shared spacing: sections 24px, components 16px, field contents 8px.
   Scope layout rules to our wrappers, never Plotly or AG Grid internals. */
.dashboard-page, .admin-page, .investigation-panel {
  display: grid;
  gap: var(--space-6);
  min-width: 0;
}
.dashboard-panel { gap: var(--space-6); }
.dashboard-page > *, .dashboard-panel > *, .admin-page > *, .investigation-panel > * {
  margin-block: 0 !important;
  min-width: 0;
}
.content-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}
.content-card > * { margin-block: 0 !important; min-width: 0; }
.content-card > button { align-self: flex-start; }
.content-card > div:empty, .dashboard-panel > div:empty { display: none; }
details.content-card { display: block; }
details.content-card[open] > :not(summary) { margin-top: var(--space-4) !important; }
.layout-grid { gap: var(--space-4) !important; }
.layout-grid > * { min-width: 0; }
.form-field { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.page-content .form-field > label { margin: 0; line-height: 1.5; }
.form-field .helper-text { margin: 0; }
.page-content .dash-options-list-option { display: flex; align-items: center; gap: var(--space-2); margin: 0; }
.page-content .dash-options-list-option-checkbox { margin: 0; }
.form-field > div > .helper-text { margin-top: var(--space-2); }
.page-content :is(h2, h3, h4) { line-height: 1.3; }
.page-content p { line-height: 1.55; }
.section-copy > :first-child { margin-top: 0; }
.section-copy > :last-child { margin-bottom: 0; }
.section-copy > * + * { margin-top: var(--space-3); }
.section-copy li + li { margin-top: var(--space-1); }
.page-content details > summary { padding-block: var(--space-2); cursor: pointer; }
.page-content details[open] > :not(summary) { margin-top: var(--space-4); }
.page-content .dash-dropdown { min-height: 40px; }
.page-content .dash-dropdown-trigger { min-height: 38px; }
.page-content .dash-input-container { height: 40px; }
.page-content .dash-input-container .dash-input-element {
  min-height: 0;
  height: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none !important;
}
.grid-toolbar { gap: var(--space-3); margin-bottom: var(--space-3); }
.admin-page button:not([class]) {
  appearance: none;
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
}
.admin-page button:not([class]):hover { background: var(--surface-3); box-shadow: var(--shadow-md); }
.admin-page button:not([class]):active { transform: translateY(1px); }
.admin-page button:not([class]):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.admin-page .content-card > div:has(> button) { flex-wrap: wrap; align-items: center; }
@media (max-width: 640px) {
  .page-content { padding-inline: var(--space-4); }
  .content-card { padding: var(--space-4) !important; }
  .investigation-panel { padding: var(--space-4); }
}

/* Account forms share dashboard colours and control sizing. */
.account-body { margin: 0; padding: var(--space-5); background: var(--bg); color: var(--text); font-family: Inter, system-ui, sans-serif; }
.account-panel { max-width: 1100px; margin: 0 auto; }
.account-panel form { display: grid; gap: var(--space-4); margin: var(--space-4) 0; }
.account-panel label { display: grid; gap: var(--space-2); }
.account-panel input:not([type="checkbox"]):not([type="hidden"]) { box-sizing: border-box; width: 100%; min-height: 40px; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface-2); color: var(--text); font: inherit; }
.account-panel input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.account-panel button { justify-self: start; }
.account-panel fieldset { border: 1px solid var(--border); border-radius: 10px; display: flex; flex-wrap: wrap; gap: var(--space-4); }
.account-panel .account-role { display: flex; align-items: center; }
.account-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: var(--space-4); }
.account-table-wrap { overflow-x: auto; }
.account-table { width: 100%; border-collapse: collapse; text-align: left; }
.account-table th, .account-table td { padding: var(--space-3); border-bottom: 1px solid var(--border); }
.user-management-frame { width: 100%; height: 850px; border: 0; border-radius: 10px; }

/* A quiet maritime backdrop frames the sign-in form. */
.login-page {
  min-height: 100vh;
  min-height: 100svh;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  padding: clamp(20px, 5vw, 56px);
  background-color: #0d1c2e;
  background-image:
    radial-gradient(ellipse at 12% 12%, rgba(27, 139, 149, .28), transparent 52%),
    radial-gradient(ellipse at 90% 90%, rgba(54, 98, 162, .25), transparent 50%),
    repeating-radial-gradient(ellipse at 100% 110%, transparent 0 66px, rgba(167, 211, 218, .05) 67px 68px, transparent 69px 118px);
}
.login-card {
  box-sizing: border-box;
  width: 100%;
  max-width: 440px;
  padding: clamp(24px, 5vw, 40px);
  border: 1px solid var(--border);
  border-top: 4px solid #22858e;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .28);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }
.login-brand img { flex: 0 0 48px; border-radius: 12px; }
.login-brand strong { display: block; font-size: 17px; letter-spacing: -.3px; }
.login-brand span { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }
.login-card h1 { margin: 0 0 10px; font-size: 28px; letter-spacing: -.7px; line-height: 1.2; }
.login-intro { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.login-card form { margin: 28px 0 0; gap: 20px; }
.login-card label { font-size: 13px; font-weight: 600; }
.login-card input:not([type="hidden"]) { min-height: 46px; font-size: 15px; font-weight: 400; }
.login-card .primary-button { width: 100%; min-height: 46px; margin-top: 4px; font-size: 14px; }
.login-help { margin: 24px 0 0; padding-top: 20px; border-top: 1px solid var(--border); text-align: center; font-size: 12px; line-height: 1.7; color: var(--muted); }
.login-card .account-message { padding: 12px 14px; border: 1px solid var(--border-strong); border-left: 3px solid var(--danger); border-radius: 8px; background: var(--surface-2); font-size: 13px; line-height: 1.6; }
