html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8eefc;
  --muted: #9da9c1;
  --line: #2d3952;
  --blue-soft: #142a50;
  --bg: #0b1220;
}

html[data-theme="dark"] body,
html[data-theme="dark"] main {
  background: #0b1220;
  color: var(--ink);
}

html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .card,
html[data-theme="dark"] .metric-card,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .drawer,
html[data-theme="dark"] .modal-panel,
html[data-theme="dark"] .select-like,
html[data-theme="dark"] .date-control,
html[data-theme="dark"] .filters input,
html[data-theme="dark"] .filters select,
html[data-theme="dark"] .analysis-inputs select,
html[data-theme="dark"] .analysis-inputs textarea,
html[data-theme="dark"] .followup input,
html[data-theme="dark"] #account-search {
  background: #111a2c;
  color: var(--ink);
}

html[data-theme="dark"] .topbar {
  background: rgba(11, 18, 32, 0.96);
}

html[data-theme="dark"] th {
  background: #121d31;
  color: #bdc9df;
}

html[data-theme="dark"] tbody tr:hover,
html[data-theme="dark"] tbody tr.selected,
html[data-theme="dark"] .account-row:hover {
  background: #152847;
}

html[data-theme="dark"] .secondary,
html[data-theme="dark"] .account-row {
  background: #111a2c;
  color: var(--ink);
}

html[data-theme="dark"] .security-note,
html[data-theme="dark"] .selection-bar,
html[data-theme="dark"] .job-progress {
  background: #142443;
}

html[data-theme="dark"] .warning-box {
  background: #38280f;
  border-color: #72521d;
  color: #ffd48a;
}

html[data-theme="dark"] .drawer pre {
  background: #0a1120;
}

html[data-theme="dark"] .analysis-summary-item,
html[data-theme="dark"] .analysis-history-item,
html[data-theme="dark"] .analysis-history-open,
html[data-theme="dark"] #recent-analyses .stack-item {
  appearance: none;
  background: #111a2c !important;
  color: var(--ink);
}

html[data-theme="dark"] .analysis-summary-item:hover,
html[data-theme="dark"] .analysis-history-item:hover,
html[data-theme="dark"] .analysis-history-item:hover .analysis-history-open,
html[data-theme="dark"] #recent-analyses .stack-item:hover {
  background: #16243b !important;
  border-color: #3b4b68;
}

.analysis-summary-item {
  color: var(--ink);
  font: inherit;
  text-align: left;
  width: 100%;
}

.scope-action {
  background: #f59e0b;
  border: 1px solid #d88705;
  border-radius: 6px;
  box-shadow: 0 3px 10px rgba(217, 119, 6, 0.22);
  color: #291804;
  cursor: pointer;
  flex: 0 0 auto;
  font: inherit;
  font-weight: 700;
  padding: 8px 13px;
}

.scope-action:hover {
  background: #fbbf24;
  border-color: #f59e0b;
}

.scope-action:focus-visible {
  outline: 3px solid rgba(245, 158, 11, 0.35);
  outline-offset: 2px;
}

.analysis-result-actions {
  display: flex;
  gap: 10px;
}

.analysis-result-actions [data-delete-investigation] {
  background: #7f1d2d;
  border-color: #a53648;
  color: #ffe4e8;
  font-weight: 700;
}

.analysis-result-actions [data-delete-investigation]:hover {
  background: #9f2940;
  border-color: #d05768;
}

.analysis-result-actions #generate-recommendations {
  background: #4338ca;
  border-color: #6366f1;
  color: #f2f1ff;
  font-weight: 700;
}

.analysis-result-actions #generate-recommendations:hover {
  background: #5145dc;
  border-color: #818cf8;
}

.analysis-result-actions [data-delete-investigation]:focus-visible,
.analysis-result-actions #generate-recommendations:focus-visible {
  outline: 3px solid rgba(129, 140, 248, 0.4);
  outline-offset: 2px;
}

.user-menu {
  align-items: center;
  display: flex;
  gap: 10px;
}

.user-menu small,
.admin-user-row small {
  color: var(--muted);
  display: block;
}

.user-management {
  margin-top: 16px;
}

.user-create-form {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1.2fr 1.6fr 130px auto;
  margin: 14px 0 20px;
}

.user-create-form input,
.user-create-form select,
.admin-user-row select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  padding: 9px 11px;
}

.admin-users {
  display: grid;
  gap: 9px;
}

.admin-user-row {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1.4fr) 130px 90px minmax(220px, 2fr) auto;
  padding: 12px;
}

.admin-user-row label {
  display: grid;
  font-size: 12px;
  gap: 5px;
}

.admin-user-row .active-user {
  align-items: center;
  display: flex;
  font-size: 14px;
}

.admin-user-row select[multiple] {
  min-height: 68px;
}

.login-page {
  background: #0b1220;
}

.login-shell {
  align-items: center;
  display: flex;
  justify-content: center;
  margin: 0;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-width: 420px;
  padding: 30px;
  width: 100%;
}

.login-brand {
  align-items: center;
  display: flex;
  font-size: 18px;
  gap: 10px;
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-card label {
  display: grid;
  font-weight: 600;
  gap: 6px;
}

.login-card input {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 11px 12px;
}

.login-error {
  color: #c52d3d;
}

html[data-theme="dark"] .user-create-form input,
html[data-theme="dark"] .user-create-form select,
html[data-theme="dark"] .admin-user-row select {
  background: #0b1220;
}

@media (max-width: 1000px) {
  .user-create-form,
  .admin-user-row {
    grid-template-columns: 1fr 1fr;
  }
}

.badge.red {
  background: #fde8e8;
  color: #b42323;
}

html[data-theme="dark"] .badge {
  background: #26334a;
  color: #d8e2f4;
  border: 1px solid #3a4a66;
}

html[data-theme="dark"] .badge.blue {
  background: #17345e;
  color: #78b5ff;
  border-color: #28558e;
}

html[data-theme="dark"] .badge.green {
  background: #163c31;
  color: #72e2b3;
  border-color: #245746;
}

html[data-theme="dark"] .badge.amber {
  background: #493519;
  color: #ffc86b;
  border-color: #684b20;
}

html[data-theme="dark"] .badge.red {
  background: #492326;
  color: #ff999f;
  border-color: #6d3439;
}

html[data-theme="dark"] input[type="date"] {
  color-scheme: dark;
}

.appearance-control {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.appearance-control select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
  width: 100%;
}

html[data-theme="dark"] .appearance-control select {
  background: #0b1220;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    color-scheme: dark;
    --ink: #e8eefc;
    --muted: #9da9c1;
    --line: #2d3952;
    --blue-soft: #142a50;
    --bg: #0b1220;
  }

  html[data-theme="system"] body,
  html[data-theme="system"] main {
    background: #0b1220;
    color: var(--ink);
  }

  html[data-theme="system"] .sidebar,
  html[data-theme="system"] .topbar,
  html[data-theme="system"] .card,
  html[data-theme="system"] .metric-card,
  html[data-theme="system"] .table-wrap,
  html[data-theme="system"] .drawer,
  html[data-theme="system"] .modal-panel,
  html[data-theme="system"] .select-like,
  html[data-theme="system"] .date-control,
  html[data-theme="system"] .filters input,
  html[data-theme="system"] .filters select,
  html[data-theme="system"] .analysis-inputs select,
  html[data-theme="system"] .analysis-inputs textarea,
  html[data-theme="system"] .followup input,
  html[data-theme="system"] #account-search,
  html[data-theme="system"] .secondary,
  html[data-theme="system"] .account-row {
    background: #111a2c;
    color: var(--ink);
  }

  html[data-theme="system"] .topbar {
    background: rgba(11, 18, 32, 0.96);
  }

  html[data-theme="system"] th {
    background: #121d31;
    color: #bdc9df;
  }

  html[data-theme="system"] tbody tr:hover,
  html[data-theme="system"] tbody tr.selected,
  html[data-theme="system"] .account-row:hover {
    background: #152847;
  }

  html[data-theme="system"] .security-note,
  html[data-theme="system"] .selection-bar,
  html[data-theme="system"] .job-progress {
    background: #142443;
  }

  html[data-theme="system"] .appearance-control select,
  html[data-theme="system"] .drawer pre {
    background: #0b1220;
  }

  html[data-theme="system"] .analysis-summary-item,
  html[data-theme="system"] .analysis-history-item,
  html[data-theme="system"] .analysis-history-open,
  html[data-theme="system"] #recent-analyses .stack-item {
    appearance: none;
    background: #111a2c !important;
    color: var(--ink);
  }

  html[data-theme="system"] .analysis-summary-item:hover,
  html[data-theme="system"] .analysis-history-item:hover,
  html[data-theme="system"] .analysis-history-item:hover .analysis-history-open,
  html[data-theme="system"] #recent-analyses .stack-item:hover {
    background: #16243b !important;
    border-color: #3b4b68;
  }

  html[data-theme="system"] .badge {
    background: #26334a;
    color: #d8e2f4;
    border: 1px solid #3a4a66;
  }

  html[data-theme="system"] .badge.blue {
    background: #17345e;
    color: #78b5ff;
    border-color: #28558e;
  }

  html[data-theme="system"] .badge.green {
    background: #163c31;
    color: #72e2b3;
    border-color: #245746;
  }

  html[data-theme="system"] .badge.amber {
    background: #493519;
    color: #ffc86b;
    border-color: #684b20;
  }

  html[data-theme="system"] .badge.red {
    background: #492326;
    color: #ff999f;
    border-color: #6d3439;
  }
}
