:root {
  /* Tell the browser this is a dark app so native UI — the date-picker calendar
     popup, scrollbars, form-control internals — renders dark, and the date input's
     calendar icon is drawn light (visible) instead of dark-on-dark. */
  color-scheme: dark;
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1d212c;
  --border: #2a2f3c;
  --text: #e2e4e9;
  --muted: #8b93a7;
  --accent: #38bdac;
  --accent-2: #5eead4;
  --danger: #f87171;
  --warn: #fbbf24;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  min-height: 100vh;
}

h1 {
  font-size: 18px;
  margin: 0;
}

h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  color: var(--accent);
  font-size: 26px;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

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

.pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.pill-on {
  color: var(--accent-2);
  border-color: var(--accent);
}

.pill-off {
  color: var(--muted);
}

.pill-demo {
  color: var(--warn);
  border-color: var(--warn);
}

/* Sample-data notice shown under the header in demo / web mode. */
.demo-banner {
  margin: 0;
  padding: 8px 14px;
  background: var(--panel);
  border: 1px solid var(--warn);
  border-radius: 10px;
  color: var(--warn);
  font-size: 13px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

label.inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

input,
select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

input.narrow {
  width: 80px;
}

/* Date inputs: keep the (now light, via color-scheme) calendar icon clearly
   visible and clickable. */
input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 0.9;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

/* Device / Patch filters: one filter per row, each row's title inline with its
   controls. The min-width on the titles lines the controls up into a single
   column; the shared width on inputs/selects keeps that column straight. */
.stacked-filters {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.stacked-filters > .control-group > .chips-label {
  min-width: 148px;
}

.stacked-filters > .control-group > input,
.stacked-filters > .control-group > select {
  width: 260px;
  max-width: 100%;
}

/* The install-window field is a small number input — keep it compact rather than
   stretching to the shared 260px column width above. */
.stacked-filters > .control-group > input.narrow {
  width: 80px;
}

select:disabled {
  opacity: 0.5;
}

.chips,
.row,
.controls,
.control-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.chips,
.row {
  margin-top: 12px;
}

/* The Filters header is the only `.row` with an h2; its default bottom margin
   leaves dead space below the title and offsets it from the Show/Hide toggle.
   The row supplies its own gap, so drop the heading margin here. */
.row h2 {
  margin: 0;
}

.controls {
  gap: 14px;
}

.controls .presets {
  margin-top: 0;
}

.chips-label {
  font-size: 12px;
  color: var(--muted);
  margin-right: 2px;
}

.chip {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  color: var(--text);
  cursor: pointer;
}

.chip input {
  margin: 0;
}

.chip-preset {
  gap: 2px;
  padding: 2px 4px 2px 10px;
}

.btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}

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

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06231f;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
}

/* Collapse toggle in the Filters header — pushed to the right, compact. */
.filters-toggle {
  margin-left: auto;
  padding: 4px 10px;
  font-size: 12px;
}

.link {
  background: none;
  border: none;
  color: var(--accent-2);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 13px;
}

.x {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px 6px;
}

/* Sortable Patches-table column headers — a button styled as the header text. */
.th-sort {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.th-sort:hover {
  color: var(--text);
}

/* Two-click confirm: the first click "arms" a destructive control, the second
   fires it (mouseleave/blur disarm). Reuses the danger palette as a warning. */
.x-armed {
  background: rgba(248, 113, 113, 0.18);
  border-radius: 6px;
  color: #fca5a5;
  font-size: 12px;
  font-weight: 600;
}

.btn-armed {
  border-color: var(--danger);
  color: #fca5a5;
}

.seg {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: 6px 14px;
  cursor: pointer;
}

.seg-on {
  background: var(--accent);
  color: #06231f;
  border-color: var(--accent);
  font-weight: 600;
}

.preset-name {
  width: 150px;
}

.tabs {
  display: flex;
  /* The row's min content width (two labelled tab groups + summary) exceeds a
     phone viewport; without wrapping it overflows the panel's right edge. */
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  padding-bottom: 8px;
}

.tab {
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 8px;
}

.tab-on {
  background: var(--panel-2);
  color: var(--text);
}

.result-summary {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

/* Tab bar grouped by scope tier (Filtered results | Fleet health). */
.tab-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-right: 2px;
}

.tab-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 0 6px;
}

.table-wrap {
  overflow: auto;
  max-height: 56vh;
  border: 1px solid var(--border);
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  text-align: left;
  padding: 9px 10px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:hover {
  background: var(--panel-2);
}

.patch-name {
  white-space: normal;
  max-width: 360px;
}

.empty,
.note {
  color: var(--muted);
  padding: 14px 4px;
}

.note {
  color: var(--warn);
}

.sev,
.stat {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
}

.sev-critical {
  background: rgba(248, 113, 113, 0.18);
  color: #fca5a5;
}

.sev-important {
  background: rgba(251, 146, 60, 0.18);
  color: #fdba74;
}

.sev-moderate {
  background: rgba(251, 191, 36, 0.16);
  color: #fcd34d;
}

.sev-low {
  background: rgba(96, 165, 250, 0.16);
  color: #93c5fd;
}

.sev-none {
  background: var(--panel-2);
  color: var(--muted);
}

.stat-installed {
  background: rgba(56, 189, 172, 0.18);
  color: var(--accent-2);
}

.stat-approved {
  background: rgba(96, 165, 250, 0.16);
  color: #93c5fd;
}

.stat-pending {
  background: rgba(251, 191, 36, 0.16);
  color: #fcd34d;
}

.stat-rejected {
  background: var(--panel-2);
  color: var(--muted);
}

.stat-failed {
  background: rgba(248, 113, 113, 0.18);
  color: #fca5a5;
}

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: 480px;
}

.toast-ok {
  border-color: var(--accent);
}

.toast-err {
  border-color: var(--danger);
  color: #fca5a5;
}

/* Persistent record of the last failed query in the results area — same danger
   palette as .toast-err, but it stays until the next success or a dismiss. */
.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.1);
  color: #fca5a5;
  font-size: 13px;
}

.error-banner .x {
  margin-left: auto;
}

/* --- Running-query progress --- */
.query-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.progress {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.progress-indeterminate {
  width: 35%;
  animation: progress-slide 1.1s ease-in-out infinite;
}

@keyframes progress-slide {
  0% {
    margin-left: -35%;
  }
  100% {
    margin-left: 100%;
  }
}

.progress-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.query-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- Filter sub-section headings (Device / Patch) --- */
.subhead {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.subhead:first-of-type {
  border-top: 0;
  padding-top: 0;
}

/* --- Patches table pagination --- */
.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.pager-info {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* --- Update splash modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  width: min(560px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.modal h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.modal-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.changelog {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 12px 14px;
  margin-bottom: 16px;
}

.changelog h3 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.changelog-body {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  max-height: 40vh;
  overflow-y: auto;
}

.changelog-body h4 {
  margin: 12px 0 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.changelog-body ul {
  margin: 0;
  padding-left: 18px;
}

.changelog-body li {
  margin: 0 0 4px;
}

.changelog-body p {
  margin: 0 0 8px;
}

.changelog-body strong {
  font-weight: 600;
  color: var(--text);
}

.changelog-body > :first-child {
  margin-top: 0;
}

.changelog-body > :last-child {
  margin-bottom: 0;
}

.modal-actions {
  margin-top: 0;
}

.app-version {
  margin-top: 16px;
  font-size: 11px;
  color: var(--muted);
}

/* --- Scope clarity: per-tab scope banner + filter-section note --- */
.scope-banner {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 8px;
  background: var(--panel-2);
}

.scope-banner-filtered {
  border-left-color: var(--accent);
}

.scope-banner-fleet {
  border-left-color: var(--warn);
}

.scope-banner-tier {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.scope-banner-text {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text);
}

.scope-banner-filters {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* Applied-filter chips: read-only snapshot of the filters behind the current result. */
.applied-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}

.applied-chip {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
}

/* Patch-tier chip on a Fleet-health tab — the filter is set but ignored here. */
.applied-chip-dim {
  opacity: 0.4;
  text-decoration: line-through;
  cursor: help;
}

.applied-chip-none {
  color: var(--muted);
  font-style: italic;
}

.subhead-note {
  margin-left: 8px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  font-size: 11px;
  color: var(--muted);
}

/* Shown in place of the patch-filter controls while a Fleet-health tab is active. */
.filters-hidden-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* Failures: the full affected-device list can be long — keep the cell readable. */
.device-list {
  max-width: 380px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* --- Dashboard charts (inline SVG) --- */
.charts {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  padding: 14px 16px;
}

.chart-title {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* "Compliance by OS" section — divided from the per-org compliance above it. */
.compliance-os {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.compliance-os .chart-card {
  margin-bottom: 12px;
}

.chart {
  max-width: 100%;
  height: auto;
}

.chart-lbl {
  fill: var(--muted);
  font-size: 12px;
}

.chart-val {
  fill: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chart-track {
  fill: var(--border);
}

/* Compliance bar fills, by health band. */
.chart .bar-good {
  fill: var(--accent);
}

.chart .bar-warn {
  fill: var(--warn);
}

.chart .bar-bad {
  fill: var(--danger);
}

/* Severity segment fills (stacked bar) — solid variants of the .sev-* badges. */
.chart .seg-critical {
  fill: #f87171;
}

.chart .seg-important {
  fill: #fb923c;
}

.chart .seg-moderate {
  fill: #fbbf24;
}

.chart .seg-low {
  fill: #60a5fa;
}

.chart .seg-optional {
  fill: var(--muted);
}

.chart .seg-unknown {
  fill: #6b7280;
}

.chart-legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 0 0;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.chart-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}

.chart-swatch.seg-critical {
  background: #f87171;
}

.chart-swatch.seg-important {
  background: #fb923c;
}

.chart-swatch.seg-moderate {
  background: #fbbf24;
}

.chart-swatch.seg-low {
  background: #60a5fa;
}

.chart-swatch.seg-optional {
  background: var(--muted);
}

.chart-swatch.seg-unknown {
  background: #6b7280;
}

/* --- Mobile / narrow viewports --- */
@media (max-width: 640px) {
  main {
    padding: 12px;
    gap: 12px;
  }

  .panel {
    padding: 12px 13px;
  }

  /* Each stacked filter row puts its label on its own line and lets the
     controls span the full width, instead of fighting the fixed 148px label
     column + 260px control width that crowd a phone screen. */
  .stacked-filters > .control-group > .chips-label {
    flex-basis: 100%;
    min-width: 0;
    margin-right: 0;
  }

  .stacked-filters > .control-group > input,
  .stacked-filters > .control-group > select {
    width: 100%;
  }

  /* The results summary takes its own full line under the wrapped tab groups
     instead of squeezing beside them (margin-left:auto only suits one row). */
  .result-summary {
    flex-basis: 100%;
    margin-left: 0;
  }
}
