.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.75rem;
  background: var(--border);
}
.badge.healthy { background: #1e3a2f; color: var(--ok); }
.badge.warning { background: #3d3520; color: #fbbf24; }
.badge.critical { background: #3d2020; color: var(--err); }
.badge.risk-low { background: #1e3a2f; color: var(--ok); }
.badge.risk-medium { background: #3d3520; color: #fbbf24; }
.badge.risk-high { background: #3d2820; color: #fb923c; }
.badge.risk-critical { background: #3d2020; color: var(--err); }
.scope-group { border: 1px solid var(--border); margin: 0.5rem 0; padding: 0.5rem 1rem; border-radius: 6px; }
.scope-item { display: block; margin: 0.35rem 0; }
.scope-item .block { display: block; font-size: 0.85rem; }
.preset-btns button { margin-right: 0.35rem; margin-bottom: 0.5rem; }
.settings-subnav { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.settings-subnav button.active { background: var(--accent); color: #fff; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-inner { max-width: 520px; width: 92%; max-height: 90vh; overflow: auto; }

.data-table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.9rem; }
.data-table th, .data-table td { border: 1px solid var(--border); padding: 0.5rem 0.65rem; text-align: left; }
.data-table th { background: var(--panel); }
.warn { color: #fbbf24; font-weight: 600; }
#settings-mfa-qr svg { max-width: 220px; background: #fff; padding: 8px; border-radius: 8px; }
button.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }

:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --border: #2d3a4d;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --ok: #3dd68c;
  --err: #f87171;
  --warn: #fbbf24;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.app-brand h1 { margin: 0; font-size: 1.35rem; font-weight: 600; }
.app-brand #platform-version { margin: 0.2rem 0 0; font-size: 0.85rem; }
.app-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.app-user #user-info { margin: 0; max-width: 28rem; text-align: right; }

.app-main {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 0 2rem;
}

#login-section { padding: 1.5rem clamp(1rem, 3vw, 2rem); }

.app-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem clamp(1rem, 3vw, 2rem);
  margin-bottom: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

.app-content { padding: 1.25rem clamp(1rem, 3vw, 2rem); }

.nav-icon {
  display: inline-block;
  min-width: 1.15em;
  margin-right: 0.4rem;
  text-align: center;
  opacity: 0.9;
  font-size: 1.05em;
}
.tab-dropdown-toggle .nav-icon { margin-right: 0.45rem; }
.tab-dropdown-menu .nav-icon { opacity: 0.55; font-size: 0.85em; }

h2 { font-size: 1.1rem; margin-top: 0; }

label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  max-width: 420px;
  margin-top: 0.25rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

button {
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1.2;
}
button:hover { filter: brightness(1.1); }
button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}
.toolbar h2 { margin: 0; flex: 1 1 auto; min-width: 120px; }
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted, #8b949e);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.devices-bulk-bar {
  margin-bottom: 0.5rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border, #30363d);
  border-radius: 6px;
  background: var(--panel, #161b22);
}
.dev-timeline {
  margin: 0.5rem 0 1rem;
  padding-left: 1.25rem;
  color: var(--muted, #8b949e);
  font-size: 0.9rem;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
  align-items: flex-end;
}
.filter-row label {
  margin: 0;
  flex: 0 1 auto;
  min-width: 120px;
  max-width: 200px;
  font-size: 0.8rem;
}
.filter-row input, .filter-row select {
  max-width: 100%;
  margin-top: 0.2rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}
.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.78rem;
  border-radius: 4px;
}
.btn-primary { background: var(--accent); color: #fff; border: none; }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: #7f1d1d; color: #fecaca; border: 1px solid #991b1b; }
.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
}
.pagination-meta { margin: 0.5rem 0; font-size: 0.85rem; }
.data-table.compact td, .data-table.compact th { padding: 0.35rem 0.5rem; font-size: 0.82rem; }
.ops-section { margin-bottom: 1.5rem; width: 100%; }
.ops-section h3 { margin: 0 0 0.75rem; font-size: 1rem; font-weight: 600; }
.ops-grid,
#tab-overview .widgets-grid {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem;
}
.ops-card {
  padding: 1rem 1.1rem;
  min-height: 5.75rem;
  margin-top: 0;
}
.ops-card.healthy { border-left: 3px solid #22c55e; }
.ops-card.warning { border-left: 3px solid #eab308; }
.ops-card.critical { border-left: 3px solid #ef4444; }
.ops-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted, #888); }
.ops-value { font-size: 1.65rem; font-weight: 600; line-height: 1.15; }
.ops-sub { font-size: 0.78rem; margin-top: 0.25rem; }
#tab-overview .warnings-panel { width: 100%; margin-bottom: 1rem; }
#overview-widgets { width: 100%; }
.btn-warning { background: #854d0e; color: #fef3c7; border: 1px solid #a16207; }
button:not(.btn-sm) { padding: 0.35rem 0.65rem; font-size: 0.82rem; }
.table-wrap {
  overflow-x: auto;
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.detail-panel, .result-panel {
  padding: 0.75rem 1rem;
  background: rgba(0,0,0,0.2);
  border-top: 1px solid var(--border);
}
tr.detail-row td { background: var(--panel); padding: 0 !important; }
.scroll-pre {
  max-height: 280px;
  overflow: auto;
  font-size: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0.35rem 0;
}
.inv-tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0; }
.inv-tab-body { min-height: 80px; }
td.action-row, th:last-child { white-space: nowrap; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}
.tabs-primary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-right: 0.25rem;
}
.tabs button,
.tab-dropdown-toggle {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.62rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.2;
}
.tabs button:hover,
.tab-dropdown-toggle:hover {
  color: inherit;
  border-color: var(--accent);
}
.tabs button.active,
.tab-dropdown-toggle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.tab-dropdown { position: relative; }
.tab-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  min-width: 11rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.tab-dropdown.open .tab-dropdown-menu { display: block; }
.tab-dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 0;
  margin: 0;
}
.tab-dropdown-menu button:hover {
  background: rgba(255, 255, 255, 0.06);
}
.tab-dropdown-menu button.active {
  background: var(--accent);
  color: #fff;
}

.warnings-panel { margin-bottom: 1rem; }
.warn-item {
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 0.9rem;
}
.warn-critical { border-color: #c0392b; background: rgba(192, 57, 43, 0.12); }
.warn-high { border-color: #e67e22; background: rgba(230, 126, 34, 0.1); }
.warn-medium { border-color: #f39c12; }
.warn-low { border-color: var(--border); opacity: 0.95; }

.widgets { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1rem; }
.widgets .card { min-width: 140px; }
.widgets-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.85rem; margin-bottom: 1rem; width: 100%; }
.progress-bar { display: inline-block; width: 80px; height: 8px; background: var(--border); border-radius: 4px; vertical-align: middle; overflow: hidden; }
.progress-bar.wide { width: 100%; max-width: 320px; display: block; margin: 0.5rem 0; }
.progress-fill { height: 100%; background: var(--ok); border-radius: 4px; transition: width 0.3s ease; }
.is-loading { opacity: 0.6; pointer-events: none; }
[aria-busy="true"] { cursor: wait; }

.card {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.card pre {
  overflow: auto;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
th, td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
}
tr:hover { background: rgba(255,255,255,0.03); }

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  max-width: 420px;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.error { border-color: var(--err); color: var(--err); }
.toast.ok { border-color: var(--ok); }

.install-cmd {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  background: var(--bg);
  padding: 0.75rem;
  border-radius: 6px;
  margin: 0.5rem 0;
}

.table-wrap { overflow-x: auto; }
.table-sticky thead th { position: sticky; top: 0; z-index: 2; background: var(--panel); box-shadow: 0 1px 0 var(--border); }
.data-table.compact th, .data-table.compact td { padding: 0.35rem 0.5rem; font-size: 0.82rem; }
.table-toolbar { display: flex; gap: 0.75rem; align-items: center; margin: 0.5rem 0; flex-wrap: wrap; }
.table-search { min-width: 180px; padding: 0.35rem 0.5rem; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: inherit; }
.table-meta { font-size: 0.8rem; }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { padding: 1.5rem; text-align: center; }
.inv-tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.75rem 0; }
.inv-tabs .inv-tab.active { background: var(--accent); color: #fff; }
.scope-group { border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.75rem; margin: 0.35rem 0; }
.scope-group legend { font-size: 0.8rem; font-weight: 600; padding: 0 0.25rem; }
.scope-item { display: block; margin: 0.35rem 0; font-size: 0.85rem; }
.scope-item .block { display: block; margin-left: 1.4rem; font-size: 0.78rem; }
.preset-btns button { margin-right: 0.35rem; margin-bottom: 0.5rem; }
.badge.risk-critical { background: rgba(248,81,73,0.2); color: var(--err); }
.badge.risk-high { background: rgba(210,153,34,0.2); color: var(--warn); }
.badge.risk-medium { background: rgba(88,166,255,0.15); color: var(--accent); }
.badge.risk-low { background: rgba(46,160,67,0.15); color: var(--ok); }
td.warn, .warn-item { color: var(--warn); }
.loading-inline { font-style: italic; }
body.density-compact .data-table th, body.density-compact .data-table td { padding: 0.25rem 0.4rem; font-size: 0.78rem; }

/* Devices table: readable status cells without horizontal scroll */
.devices-table-wrap { overflow-x: auto; max-width: 100%; }
.devices-table { table-layout: fixed; width: 100%; min-width: 920px; }
.devices-table .col-dev-name { width: 18%; }
.devices-table .col-dev-role { width: 11%; }
.devices-table .col-dev-health { width: 14%; }
.devices-table .col-dev-status { width: 8%; }
.devices-table .col-dev-agent { width: 11%; }
.devices-table .col-dev-updates { width: 10%; }
.devices-table .col-dev-compliance { width: 12%; }
.devices-table .col-dev-seen { width: 10%; }
.devices-table .col-dev-action { width: 6%; }
.devices-table { min-width: 980px; }
.sortable-th { user-select: none; }
.sortable-th:hover { color: var(--accent); }

/* Device detail — operational overview */
.dev-health-block { margin-bottom: 1rem; padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: 8px; background: rgba(0,0,0,0.15); }
.dev-health-score { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.dev-health-num { font-size: 1.1rem; font-weight: 700; }
.dev-health-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.25rem 1rem; }
.dev-health-item { font-size: 0.85rem; line-height: 1.35; }
.dev-health-item.ok { color: var(--ok); }
.dev-health-item.warn { color: var(--warn); }
.dev-health-item.critical { color: var(--err); }
.dev-kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.5rem 1rem; margin: 1rem 0; }
.dev-kv-item { padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); }
.dev-kv-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin-bottom: 0.2rem; }
.dev-kv-value { font-size: 0.88rem; word-break: break-word; }
.dev-metrics-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.75rem; margin: 1rem 0; }
.dev-metric { padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: 6px; }
.dev-metric-head { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 0.35rem; }
.dev-metric-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.dev-metric-fill { height: 100%; background: var(--ok); border-radius: 3px; }
.dev-metric-warning .dev-metric-fill { background: var(--warn); }
.dev-metric-critical .dev-metric-fill { background: var(--err); }
.dev-metric-detail { font-size: 0.75rem; margin-top: 0.25rem; }
.dev-metric-static { padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; }
.dev-counts-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.75rem 0; }
.dev-count-chip { padding: 0.25rem 0.55rem; border-radius: 4px; background: rgba(88,166,255,0.1); font-size: 0.8rem; }
.dev-tag { display: inline-block; padding: 0.1rem 0.4rem; margin: 0.1rem; border-radius: 4px; background: var(--border); font-size: 0.75rem; }
.dev-compliance-checklist { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.75rem; }
.dev-compliance-row { display: flex; gap: 0.5rem; padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: 6px; }
.dev-compliance-row.ok { border-left: 3px solid var(--ok); }
.dev-compliance-row.warn { border-left: 3px solid var(--warn); }
.dev-compliance-row.fail { border-left: 3px solid var(--err); }
.dev-compliance-icon { font-weight: 700; min-width: 1.2rem; }
.dev-compliance-reason { font-size: 0.8rem; margin-top: 0.15rem; }
.dev-updates-header { margin-bottom: 0.75rem; }
.dev-update-badges { margin-top: 0.35rem; }
.dev-service-groups h4 { margin: 1rem 0 0.35rem; font-size: 0.9rem; }

.devices-table td, .devices-table th { white-space: normal; word-break: break-word; vertical-align: top; }
.devices-table .cell-name .cell-sub { display: block; font-size: 0.78rem; line-height: 1.25; }
.devices-table .cell-status { line-height: 1.3; }
.status-cell { display: flex; flex-direction: column; gap: 0.15rem; align-items: flex-start; max-width: 100%; }
.status-cell .badge { flex-shrink: 0; }
.reason-short { font-size: 0.75rem; color: var(--muted, #888); line-height: 1.25; max-width: 100%; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; word-break: break-word; }
.btn-link.btn-xs.reason-more { font-size: 0.72rem; padding: 0; border: 0; background: none; color: var(--accent, #4a9); cursor: pointer; text-decoration: underline; }
.compliance-checks-table .wrap-cell { white-space: normal; word-break: break-word; max-width: 14rem; }
.badge { display: inline-block; padding: 0.15rem 0.45rem; border-radius: 4px; font-size: 0.75rem; background: var(--border); }
.badge.healthy { background: rgba(46,160,67,0.2); color: var(--ok); }
.badge.critical { background: rgba(248,81,73,0.2); color: var(--err); }
.badge.warning { background: rgba(210,153,34,0.2); color: var(--warn); }
.badge.pending { background: rgba(88,166,255,0.15); color: var(--accent); }
.btn-warning { background: var(--warn); color: #111; border: none; }
.btn-warning:hover { filter: brightness(1.05); }
.detail-row td { background: rgba(0,0,0,0.2); }
.detail-panel { padding: 0.75rem 0; }
.scroll-pre { max-height: 320px; overflow: auto; font-size: 0.8rem; }
.ops-card.clickable { cursor: pointer; }
.ops-card.clickable:hover { outline: 1px solid var(--accent, #3b82f6); }
.enroll-platform-tabs { display: flex; gap: 0.5rem; margin: 0.75rem 0; }
.enroll-plat.active { outline: 2px solid var(--accent, #3b82f6); }
.enroll-plat-panel.hidden { display: none; }
.token-block { user-select: all; }

.ops-card.clickable:hover { outline: 1px solid var(--accent, #3b82f6); }

@media (max-width: 768px) {
  main { padding: 0.75rem; }
  .tabs button, .tab-dropdown-toggle { font-size: 0.88rem; padding: 0.5rem 0.75rem; }
  .app-user #user-info { text-align: left; max-width: none; }
  .filter-row { flex-direction: column; align-items: stretch; }
}
