/*
 * SPEAR theme: dark (default) and light (the original look).
 * Every dark rule is scoped to html[data-theme="dark"], so light mode is
 * exactly the pre-2.0.1 styling. The theme is set in base.html before any
 * CSS loads, and the toggle next to the brand switches it.
 */

/* ---------- Theme toggle (both themes) ---------- */
.spear-theme-toggle {
  float: left;
  margin: 14px 8px 0 -4px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  line-height: 0;
}
.spear-theme-toggle:focus {
  outline: none;
}
.spear-theme-toggle:focus-visible .spear-theme-toggle-track {
  box-shadow: 0 0 0 2px #b8843d;
}
.spear-theme-toggle-track {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.35);
  transition: background 0.2s ease;
}
.spear-theme-toggle-track svg {
  position: absolute;
  top: 4px;
  width: 12px;
  height: 12px;
  fill: #f1f3f8;
  opacity: 0.75;
}
.spear-theme-toggle-track .spear-icon-moon { left: 5px; }
.spear-theme-toggle-track .spear-icon-sun { right: 5px; }
.spear-theme-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease;
}
html[data-theme="light"] .spear-theme-toggle-thumb { transform: translateX(18px); }
html[data-theme="dark"] .spear-theme-toggle-thumb { transform: translateX(0); }
html[data-theme="dark"] .spear-theme-toggle-track { background: rgba(156, 188, 205, 0.25); }
@media (prefers-reduced-motion: reduce) {
  .spear-theme-toggle-thumb,
  .spear-theme-toggle-track { transition: none; }
}

/* ---------- Footer version badge (both themes) ---------- */
.spear-version-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  color: #fff;
  background: #5e6367;
  vertical-align: 1px;
}
.spear-version-badge.env-prod { background: #3d8b37; }
.spear-version-badge.env-uat { background: #c77700; }

/* ---------- Search results (both themes) ---------- */
.spear-search {
  max-width: 900px;
  padding: 8px 16px 32px;
}
.spear-search h2 { margin-bottom: 4px; }
.spear-search-summary { margin-bottom: 16px; }
.spear-search .list-group-item { padding: 12px 16px; }
.spear-search .pager { text-align: center; }
.spear-search .pager > li.text-muted { padding: 6px 12px; }

/* ---------- Chart overlay while a theme toggle reloads the page (both themes) ---------- */
.spear-charts-reloading .spear-chart-card,
.spear-charts-reloading .js-plotly-plot {
  position: relative;
}
.spear-charts-reloading .spear-chart-card > *,
.spear-charts-reloading .js-plotly-plot > * {
  visibility: hidden;
}
.spear-charts-reloading .spear-chart-card::before,
.spear-charts-reloading .js-plotly-plot::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  margin: -30px 0 0 -14px;
  border: 3px solid var(--spear-edge, #ddd);
  border-top-color: var(--ssm-tide-light, #337ab7);
  border-radius: 50%;
  animation: spear-spin 0.8s linear infinite;
}
.spear-charts-reloading .spear-chart-card::after,
.spear-charts-reloading .js-plotly-plot::after {
  content: "Updating chart colors\2026";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  margin-top: 10px;
  text-align: center;
  color: var(--ssm-slate-100, #555);
}
@keyframes spear-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spear-charts-reloading .spear-chart-card::before,
  .spear-charts-reloading .js-plotly-plot::before { animation: none; }
}

/* ---------- Homepage desktop (wallpaper in dark only; light stays plain white) ---------- */
html[data-theme="dark"] body.spear-home {
  background: #0b1050 url("../img/spear-desktop.1e8fbb3478b9.jpg") center center / cover no-repeat fixed;
}
html[data-theme="dark"] body.spear-home .footer {
  background-color: rgba(8, 11, 48, 0.85);
}
html[data-theme="dark"] body.spear-home .footer .text-muted { color: #aab1cf; }
html[data-theme="dark"] body.spear-home .footer a { color: #cfd8ff; }
.spear-desktop-icon {
  position: fixed;
  top: 74px;
  right: 28px;
  z-index: 10;
  display: block;
  width: 96px;
  padding: 8px 4px;
  border-radius: 6px;
  text-align: center;
  color: #fff;
  text-decoration: none;
}
.spear-desktop-icon:hover,
.spear-desktop-icon:focus {
  color: #fff;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.12);
}
.spear-desktop-icon svg {
  display: block;
  width: 44px;
  height: 54px;
  margin: 0 auto 6px;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
}
.spear-desktop-icon span {
  display: block;
  font-size: 12px;
  line-height: 15px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
html[data-theme="light"] .spear-desktop-icon,
html[data-theme="light"] .spear-desktop-icon:hover,
html[data-theme="light"] .spear-desktop-icon:focus { color: #333; }
html[data-theme="light"] .spear-desktop-icon:hover,
html[data-theme="light"] .spear-desktop-icon:focus { background: rgba(0, 0, 0, 0.06); }
html[data-theme="light"] .spear-desktop-icon span { text-shadow: none; }
html[data-theme="light"] .spear-desktop-icon svg {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}

/* ---------- Dark theme ---------- */
/*
 * Brand values come from the SSM brand guide tokens (navy, SSM blue, slate,
 * tide, amber, rust). Page surfaces are charcoal rather than navy so the
 * content reads as dark, with navy kept for the navbar and footer chrome.
 * Text/background pairs meet WCAG AA (4.5:1 text, 3:1 controls and focus).
 */
html[data-theme="dark"] {
  color-scheme: dark;
  --ssm-navy: #0a0f41;
  --ssm-blue: #03388a;
  --ssm-blue-hover: #042b6e;
  --ssm-amber: #b8843d;
  --ssm-tide: #038a85;
  --ssm-tide-light: #a8d6d2;
  --ssm-rust: #a14530;
  --ssm-signal-blue: #2d6bb5;
  --ssm-slate-50: #f2f4fa;
  --ssm-slate-100: #dde0eb;
  --ssm-slate-300: #9097ac;
  --ssm-slate-700: #2a3050;
  --spear-bg: #181b24;
  --spear-surface: #20242f;
  --spear-surface-2: #272c39;
  --spear-hover: #313748;
  --spear-input: #1c1f29;
  --spear-line: #343a52;
  --spear-edge: #444b68;
  --spear-control-border: #6b7290;
}
html[data-theme="dark"] body {
  background-color: var(--spear-bg);
  color: var(--ssm-slate-100);
}
html[data-theme="dark"] a { color: var(--ssm-tide-light); }
html[data-theme="dark"] a:hover,
html[data-theme="dark"] a:focus { color: #fff; }
html[data-theme="dark"] .text-muted { color: var(--ssm-slate-300); }
html[data-theme="dark"] h1, html[data-theme="dark"] h2, html[data-theme="dark"] h3,
html[data-theme="dark"] h4, html[data-theme="dark"] h5, html[data-theme="dark"] h6 { color: var(--ssm-slate-50); }
html[data-theme="dark"] hr,
html[data-theme="dark"] .sub-header,
html[data-theme="dark"] .page-header { border-color: var(--spear-line); }

/* Keyboard focus: brand amber ring, visible on every dark surface. */
html[data-theme="dark"] a:focus-visible,
html[data-theme="dark"] button:focus-visible,
html[data-theme="dark"] .btn:focus-visible,
html[data-theme="dark"] input:focus-visible,
html[data-theme="dark"] select:focus-visible,
html[data-theme="dark"] textarea:focus-visible,
html[data-theme="dark"] [tabindex]:focus-visible {
  outline: 2px solid var(--ssm-amber);
  outline-offset: 2px;
}

/* Navbar: SSM navy chrome with slate text. */
html[data-theme="dark"] .navbar-inverse {
  background-color: var(--ssm-navy);
  border-color: var(--spear-line);
}
html[data-theme="dark"] .navbar-inverse .navbar-brand,
html[data-theme="dark"] .navbar-inverse .navbar-nav > li > a { color: var(--ssm-slate-100); }
html[data-theme="dark"] .navbar-inverse .navbar-brand:hover,
html[data-theme="dark"] .navbar-inverse .navbar-nav > li > a:hover,
html[data-theme="dark"] .navbar-inverse .navbar-nav > li > a:focus { color: #fff; }
html[data-theme="dark"] .navbar-inverse .navbar-nav > .open > a,
html[data-theme="dark"] .navbar-inverse .navbar-nav > .open > a:hover,
html[data-theme="dark"] .navbar-inverse .navbar-nav > .open > a:focus,
html[data-theme="dark"] .navbar-inverse .navbar-nav > .active > a {
  background-color: var(--ssm-blue);
  color: #fff;
}
html[data-theme="dark"] .navbar-inverse .navbar-collapse,
html[data-theme="dark"] .navbar-inverse .navbar-form { border-color: var(--spear-line); }

/* Dropdowns */
html[data-theme="dark"] .dropdown-menu {
  background-color: var(--spear-surface-2);
  border-color: var(--spear-edge);
}
html[data-theme="dark"] .dropdown-menu > li > a { color: var(--ssm-slate-100); }
html[data-theme="dark"] .dropdown-menu > li > a:hover,
html[data-theme="dark"] .dropdown-menu > li > a:focus {
  background-color: var(--spear-hover);
  color: #fff;
}
html[data-theme="dark"] .dropdown-menu > .active > a,
html[data-theme="dark"] .dropdown-menu > .active > a:hover,
html[data-theme="dark"] .dropdown-menu > .active > a:focus {
  background-color: var(--ssm-blue);
  color: #fff;
}
html[data-theme="dark"] .dropdown-menu .divider { background-color: var(--spear-line); }

/* Forms */
html[data-theme="dark"] .form-control,
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background-color: var(--spear-input);
  border-color: var(--spear-control-border);
  color: var(--ssm-slate-100);
}
html[data-theme="dark"] .form-control:focus {
  border-color: var(--ssm-amber);
  box-shadow: 0 0 0 2px rgba(184, 132, 61, 0.35);
}
html[data-theme="dark"] .form-control::placeholder { color: var(--ssm-slate-300); }
html[data-theme="dark"] .form-control[disabled],
html[data-theme="dark"] .form-control[readonly] { background-color: var(--spear-surface-2); }
html[data-theme="dark"] .input-group-addon {
  background-color: var(--spear-surface-2);
  border-color: var(--spear-control-border);
  color: var(--ssm-slate-100);
}
html[data-theme="dark"] .help-block { color: var(--ssm-slate-300); }

/* Buttons. Selected toggle buttons (e.g. chart ranges) use SSM blue so the
   current choice is obvious, not just a slightly different gray. */
html[data-theme="dark"] .btn-default {
  background-color: var(--spear-surface-2);
  border-color: var(--spear-control-border);
  color: var(--ssm-slate-100);
}
html[data-theme="dark"] .btn-default:hover,
html[data-theme="dark"] .btn-default:focus,
html[data-theme="dark"] .open > .dropdown-toggle.btn-default {
  background-color: var(--spear-hover);
  border-color: var(--ssm-slate-300);
  color: #fff;
}
html[data-theme="dark"] .btn-default.active,
html[data-theme="dark"] .btn-default:active,
html[data-theme="dark"] .btn-primary {
  background-color: var(--ssm-blue);
  border-color: var(--ssm-signal-blue);
  color: #fff;
}
html[data-theme="dark"] .btn-primary:hover,
html[data-theme="dark"] .btn-primary:focus,
html[data-theme="dark"] .btn-default.active:hover {
  background-color: var(--ssm-blue-hover);
  border-color: var(--ssm-signal-blue);
  color: #fff;
}
html[data-theme="dark"] .btn-link { color: var(--ssm-tide-light); }

/* Tables: each table sits in its own defined container. */
html[data-theme="dark"] .table {
  color: var(--ssm-slate-100);
  background-color: var(--spear-surface);
  box-shadow: 0 0 0 1px var(--spear-edge), 0 2px 8px rgba(0, 0, 0, 0.35);
}
html[data-theme="dark"] .panel > .table,
html[data-theme="dark"] .panel > .table-responsive > .table,
html[data-theme="dark"] .modal .table,
html[data-theme="dark"] .table .table { box-shadow: none; }
html[data-theme="dark"] .table > thead > tr > th {
  background-color: var(--spear-surface-2);
  color: var(--ssm-slate-50);
}
html[data-theme="dark"] .table > thead > tr > th,
html[data-theme="dark"] .table > tbody > tr > th,
html[data-theme="dark"] .table > tbody > tr > td,
html[data-theme="dark"] .table > tfoot > tr > td { border-color: var(--spear-line); }
html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) { background-color: var(--spear-surface-2); }
html[data-theme="dark"] .table-hover > tbody > tr:hover { background-color: var(--spear-hover); }
html[data-theme="dark"] .table-bordered,
html[data-theme="dark"] .table-bordered > thead > tr > th,
html[data-theme="dark"] .table-bordered > tbody > tr > td { border-color: var(--spear-line); }
html[data-theme="dark"] .table > tbody > tr.active > td,
html[data-theme="dark"] .table > tbody > tr > td.active { background-color: var(--spear-hover); }
html[data-theme="dark"] .table > tbody > tr.success > td,
html[data-theme="dark"] .table > tbody > tr > td.success { background-color: #0f3532; }
html[data-theme="dark"] .table > tbody > tr.warning > td,
html[data-theme="dark"] .table > tbody > tr > td.warning { background-color: #3d2e14; }
html[data-theme="dark"] .table > tbody > tr.danger > td,
html[data-theme="dark"] .table > tbody > tr > td.danger { background-color: #3f1d17; }
html[data-theme="dark"] .table > tbody > tr.info > td,
html[data-theme="dark"] .table > tbody > tr > td.info { background-color: #10234a; }
html[data-theme="dark"] table .header-fixed {
  /* fixedHeader() sets an inline light background */
  background-color: var(--spear-surface-2) !important;
  border-bottom-color: var(--spear-edge);
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
}

/* Charts get the same container treatment as tables. */
html[data-theme="dark"] .spear-chart-card {
  background-color: var(--spear-surface);
  border-radius: 6px;
  box-shadow: 0 0 0 1px var(--spear-edge), 0 2px 8px rgba(0, 0, 0, 0.35);
  margin-bottom: 16px;
}

/* Panels, wells, list groups, modals, tabs, pagination */
html[data-theme="dark"] .panel {
  background-color: var(--spear-surface);
  border-color: var(--spear-edge);
}
html[data-theme="dark"] .panel-default > .panel-heading,
html[data-theme="dark"] .panel-footer {
  background-color: var(--spear-surface-2);
  border-color: var(--spear-edge);
  color: var(--ssm-slate-100);
}
html[data-theme="dark"] .well {
  background-color: var(--spear-surface);
  border-color: var(--spear-edge);
}
html[data-theme="dark"] .list-group-item {
  background-color: var(--spear-surface);
  border-color: var(--spear-line);
  color: var(--ssm-slate-100);
}
html[data-theme="dark"] a.list-group-item:hover,
html[data-theme="dark"] a.list-group-item:focus { background-color: var(--spear-hover); color: #fff; }
html[data-theme="dark"] .spear-search a.list-group-item { color: var(--ssm-tide-light); }
html[data-theme="dark"] .spear-search a.list-group-item:hover,
html[data-theme="dark"] .spear-search a.list-group-item:focus { color: #fff; }
html[data-theme="dark"] .pager li > a,
html[data-theme="dark"] .pager li > span {
  background-color: var(--spear-surface);
  border-color: var(--spear-edge);
  color: var(--ssm-tide-light);
}
html[data-theme="dark"] .pager li > a:hover,
html[data-theme="dark"] .pager li > a:focus { background-color: var(--spear-hover); color: #fff; }
html[data-theme="dark"] .pager .disabled > span { background-color: var(--spear-surface); color: var(--ssm-slate-300); }
html[data-theme="dark"] .modal-content {
  background-color: var(--spear-surface);
  border-color: var(--spear-edge);
}
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer { border-color: var(--spear-line); }
html[data-theme="dark"] .close { color: #fff; text-shadow: none; opacity: 0.7; }
html[data-theme="dark"] .nav-tabs { border-bottom-color: var(--spear-edge); }
html[data-theme="dark"] .nav-tabs > li > a:hover { background-color: var(--spear-hover); border-color: var(--spear-edge); }
html[data-theme="dark"] .nav-tabs > li.active > a,
html[data-theme="dark"] .nav-tabs > li.active > a:hover,
html[data-theme="dark"] .nav-tabs > li.active > a:focus {
  background-color: var(--spear-bg);
  border-color: var(--spear-edge) var(--spear-edge) transparent;
  color: #fff;
}
html[data-theme="dark"] .nav-pills > li > a:hover { background-color: var(--spear-hover); }
html[data-theme="dark"] .nav-pills > li.active > a,
html[data-theme="dark"] .nav-pills > li.active > a:hover,
html[data-theme="dark"] .nav-pills > li.active > a:focus { background-color: var(--ssm-blue); color: #fff; }
html[data-theme="dark"] .pagination > li > a,
html[data-theme="dark"] .pagination > li > span {
  background-color: var(--spear-surface);
  border-color: var(--spear-edge);
  color: var(--ssm-tide-light);
}
html[data-theme="dark"] .pagination > .active > a,
html[data-theme="dark"] .pagination > .active > span {
  background-color: var(--ssm-blue);
  border-color: var(--ssm-signal-blue);
  color: #fff;
}
html[data-theme="dark"] .pagination > .disabled > span,
html[data-theme="dark"] .pagination > .disabled > a { background-color: var(--spear-input); color: var(--ssm-slate-300); }
html[data-theme="dark"] .breadcrumb { background-color: var(--spear-surface); }
html[data-theme="dark"] .label-default { background-color: #5a6178; }
html[data-theme="dark"] code { background-color: #2a1f2b; color: #f2b8c6; }
html[data-theme="dark"] pre {
  background-color: var(--spear-surface);
  border-color: var(--spear-edge);
  color: var(--ssm-slate-100);
}

/* Alerts: SSM tide / amber / rust / blue, darkened for backgrounds. */
html[data-theme="dark"] .alert-info { background-color: #10234a; border-color: var(--ssm-signal-blue); color: #d3e2f6; }
html[data-theme="dark"] .alert-success { background-color: #0f3532; border-color: var(--ssm-tide); color: #c9ece8; }
html[data-theme="dark"] .alert-warning { background-color: #3d2e14; border-color: var(--ssm-amber); color: #f1dfc0; }
html[data-theme="dark"] .alert-danger { background-color: #3f1d17; border-color: var(--ssm-rust); color: #f6d3cb; }

/* Sidebar (project_base) and footer */
@media (min-width: 768px) {
  html[data-theme="dark"] .sidebar {
    background-color: var(--spear-surface);
    border-right-color: var(--spear-edge);
  }
}
html[data-theme="dark"] .nav-sidebar > li > a { color: var(--ssm-slate-100); }
html[data-theme="dark"] .nav-sidebar > li > a:hover { background-color: var(--spear-hover); color: #fff; }
html[data-theme="dark"] .nav-sidebar > .active > a,
html[data-theme="dark"] .nav-sidebar > .active > a:hover,
html[data-theme="dark"] .nav-sidebar > .active > a:focus { background-color: var(--ssm-blue); color: #fff; }
html[data-theme="dark"] .footer {
  background-color: var(--ssm-navy);
}

/* Charts drawn as plain SVG (metricsgraphics, rickshaw): axes, grid and
   labels readable on dark; series colors unchanged. amCharts and Plotly
   charts are themed in simengmonitor.js. */
html[data-theme="dark"] .mg-axis text,
html[data-theme="dark"] .tick text,
html[data-theme="dark"] .mg-x-axis text,
html[data-theme="dark"] .mg-y-axis text,
html[data-theme="dark"] .mg-chart-title,
html[data-theme="dark"] .mg-active-datapoint,
html[data-theme="dark"] .mg-year-marker text,
html[data-theme="dark"] .mg-markers text { fill: var(--ssm-slate-100); }
html[data-theme="dark"] .mg-x-axis line,
html[data-theme="dark"] .mg-y-axis line,
html[data-theme="dark"] .domain,
html[data-theme="dark"] .tick line { stroke: var(--ssm-slate-300); }
html[data-theme="dark"] .mg-category-guides line,
html[data-theme="dark"] .mg-extended-yax-ticks { stroke: var(--spear-line); }
html[data-theme="dark"] .rickshaw_graph .detail .x_label,
html[data-theme="dark"] .rickshaw_legend {
  background-color: var(--spear-surface-2);
  color: var(--ssm-slate-100);
}
html[data-theme="dark"] .rickshaw_graph .y_ticks text,
html[data-theme="dark"] .rickshaw_graph .x_ticks_d3 text { fill: var(--ssm-slate-100); opacity: 1; }
html[data-theme="dark"] .rickshaw_graph .y_grid .tick,
html[data-theme="dark"] .rickshaw_graph .x_grid_d3 .tick { stroke: rgba(221, 224, 235, 0.18); }
html[data-theme="dark"] .chart-wrapper {
  background-color: var(--spear-surface);
  border-color: var(--spear-edge);
  border-radius: 6px;
  color: var(--ssm-slate-100);
}
html[data-theme="dark"] .chart-stage,
html[data-theme="dark"] .chart-notes,
html[data-theme="dark"] .chart-title {
  background-color: var(--spear-surface);
  border-color: var(--spear-line);
  color: var(--ssm-slate-100);
}

/* Django admin is a separate stylesheet; leave it alone. */
