/* ── Reset & Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; zoom: 1.33; }

:root {
  --bg:        #08090d;
  --surface:   #0f1117;
  --surface2:  #171c27;
  --surface3:  #1e2433;
  --border:    rgba(255,255,255,0.07);
  --border2:   rgba(255,255,255,0.12);

  --purple:    #7c3aed;
  --purple-l:  #a78bfa;
  --blue:      #3b82f6;
  --blue-l:    #60a5fa;
  --green:     #22c55e;
  --green-l:   #4ade80;
  --yellow:    #eab308;
  --yellow-l:  #facc15;
  --red:       #ef4444;
  --red-l:     #f87171;
  --orange:    #f97316;

  --text:      #e2e8f0;
  --text-m:    #94a3b8;
  --text-d:    #475569;

  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scrollbar ──────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 10px; }

/* ── Navbar ─────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.nav-logo {
  width: 32px; height: 32px;
  background: rgba(124,58,237,0.15);
  border: 1px solid rgba(167,139,250,0.25);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}

.nav-title {
  font-weight: 600;
  font-size: 15px;
  color: #e8eaf0;
}

.nav-sub {
  font-size: 11px;
  color: var(--text-d);
  padding: 2px 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
}

.nav-search {
  flex: 1;
  max-width: 380px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--text-m);
  transition: border-color .15s;
}
.nav-search:focus-within { border-color: rgba(124,58,237,0.5); }
.nav-search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  padding: 8px 0;
}
.nav-search input::placeholder { color: var(--text-d); }

.nav-actions { margin-left: auto; }

.btn-refresh {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  background: rgba(124,58,237,0.12);
  border: 1px solid rgba(124,58,237,0.3);
  color: var(--purple-l);
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500; font-family: inherit;
  cursor: pointer;
  transition: background .15s;
}
.btn-refresh:hover { background: rgba(124,58,237,0.22); }
.btn-refresh.spinning svg { animation: spin .7s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── App Body ───────────────────────────────────────────────────────── */
.app-body {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* ── Left Sidebar ───────────────────────────────────────────────────── */
.left-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.brand-icon {
  width: 110px; height: 110px;
  border-radius: 8px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.brand-icon img { width: 110px; height: 110px; object-fit: contain; }
.brand-name { font-size: 14px; font-weight: 600; color: var(--text); text-align: center; }
.brand-sub  { font-size: 10px; color: var(--text-d); margin-top: 1px; text-align: center; }

.sidebar-stat {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 16px;
}

.sidebar-stat-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: rgba(124,58,237,.15);
  color: var(--purple-l);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.sidebar-stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.sidebar-stat-label {
  font-size: 11px;
  color: var(--text-m);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-top: 2px;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 0 0 12px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 10px 12px;
}

.sidebar-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; font-family: inherit;
  color: var(--text-m);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
  width: 100%;
}
.sidebar-tab:hover { background: var(--surface2); color: var(--text); }
.sidebar-tab.active {
  background: rgba(124,58,237,.15);
  color: var(--purple-l);
}
.sidebar-tab svg { flex-shrink: 0; }

/* ── Content ────────────────────────────────────────────────────────── */
.content {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  min-width: 0;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Panel Toolbar ──────────────────────────────────────────────────── */
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.filter-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px; font-weight: 500; font-family: inherit;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text-m);
  cursor: pointer;
  transition: all .15s;
}
.filter-pill:hover { border-color: var(--purple-l); color: var(--text); }
.filter-pill.active {
  background: rgba(124,58,237,.2);
  border-color: rgba(124,58,237,.5);
  color: var(--purple-l);
}

.row-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-d);
}

/* ── Tables ─────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-m);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th.sorted { color: var(--purple-l); }

.sort-icon { opacity: .4; font-size: 10px; }
th.sorted .sort-icon { opacity: 1; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  cursor: pointer;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.03); }

tbody td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text);
  vertical-align: middle;
}

.loading-row {
  text-align: center;
  padding: 48px 16px !important;
  color: var(--text-m);
}

.loading-row .spinner,
.sp-loading .spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border2);
  border-top-color: var(--purple-l);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 10px;
}

/* ── Score Bar ──────────────────────────────────────────────────────── */
.score-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 120px;
}
.score-bar-bg {
  flex: 1;
  height: 5px;
  background: var(--surface3);
  border-radius: 10px;
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  border-radius: 10px;
  transition: width .4s ease;
}
.score-label {
  font-size: 12px;
  font-weight: 600;
  width: 38px;
  text-align: right;
  flex-shrink: 0;
}

.c-green  { color: var(--green-l); }
.c-blue   { color: var(--blue-l); }
.c-yellow { color: var(--yellow-l); }
.c-red    { color: var(--red-l); }
.bg-green  { background: var(--green); }
.bg-blue   { background: var(--blue); }
.bg-yellow { background: var(--yellow); }
.bg-red    { background: var(--red); }

/* ── Status Badge ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.badge-active    { background: rgba(34,197,94,.12); color: var(--green-l); }
.badge-active::before  { background: var(--green); }
.badge-disconnected { background: rgba(239,68,68,.12); color: var(--red-l); }
.badge-disconnected::before { background: var(--red); }
.badge-pending   { background: rgba(234,179,8,.12); color: var(--yellow-l); }
.badge-pending::before { background: var(--yellow); }
.badge-unknown   { background: rgba(148,163,184,.1); color: var(--text-m); }
.badge-unknown::before { background: var(--text-d); }
.badge-failed    { background: rgba(239,68,68,.15); color: var(--red-l); }
.badge-failed::before  { background: var(--red); }
.badge-passed    { background: rgba(34,197,94,.15); color: var(--green-l); }
.badge-passed::before  { background: var(--green); }
.badge-na        { background: rgba(148,163,184,.1); color: var(--text-m); }
.badge-na::before      { background: var(--text-d); }

/* ── OS Icon ─────────────────────────────────────────────────────────── */
.os-cell { display: flex; align-items: center; gap: 7px; }
.os-icon {
  width: 22px; height: 22px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  background: var(--surface3);
  flex-shrink: 0;
}

/* ── Side Panel ──────────────────────────────────────────────────────── */
.panel-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.panel-overlay.visible { opacity: 1; pointer-events: all; }

.side-panel {
  position: fixed;
  top: 0; right: 0;
  width: min(720px, 95vw);
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border2);
  z-index: 210;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  box-shadow: -8px 0 40px rgba(0,0,0,.5);
}
.side-panel.open { transform: translateX(0); }

.sp-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sp-title-group { display: flex; flex-direction: column; gap: 3px; }
.sp-title { font-size: 17px; font-weight: 700; color: var(--text); }
.sp-subtitle { font-size: 12px; color: var(--text-m); }

.sp-close {
  background: none; border: none;
  color: var(--text-m); font-size: 18px;
  cursor: pointer; padding: 4px 8px;
  border-radius: 5px;
  line-height: 1;
  transition: background .15s, color .15s;
}
.sp-close:hover { background: var(--surface2); color: var(--text); }

/* ── Agent trends chart (main page) ────────────────────────────────── */
.trends-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}

.trends-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.trends-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.trends-sub {
  font-size: 11px;
  color: var(--text-d);
  flex: 1;
}

.trends-filters {
  display: flex;
  gap: 4px;
}

.trends-pill {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid var(--border2);
  background: var(--surface2);
  color: var(--text-m);
  cursor: pointer;
  transition: all .15s;
}
.trends-pill:hover { border-color: var(--purple-l); color: var(--text); }
.trends-pill.active {
  background: rgba(124,58,237,.2);
  border-color: rgba(124,58,237,.5);
  color: var(--purple-l);
}

.trends-chart-area {
  padding: 16px 20px 12px;
  height: 280px;
  position: relative;
}

.trends-chart-area canvas {
  width: 100% !important;
  height: 100% !important;
}

.trends-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-d);
}

/* ── Score trend chart (side panel) ────────────────────────────────── */
.sp-trend {
  padding: 14px 24px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 130px;
  position: relative;
}
.sp-trend canvas {
  width: 100% !important;
  height: 106px !important;
}
.sp-trend-empty {
  font-size: 12px;
  color: var(--text-d);
  text-align: center;
  line-height: 106px;
}

/* ── Asset meta strip ───────────────────────────────────────────────── */
.sp-meta {
  display: flex;
  gap: 20px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-label { font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-d); }
.meta-value { font-size: 13px; font-weight: 500; color: var(--text); }

/* ── Score Row ──────────────────────────────────────────────────────── */
.sp-score-row {
  display: flex;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.score-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
}
.score-pill .pill-num { font-size: 20px; font-weight: 700; }
.sp-pass  { background: rgba(34,197,94,.1);  color: var(--green-l); border: 1px solid rgba(34,197,94,.2); }
.sp-fail  { background: rgba(239,68,68,.1);  color: var(--red-l);   border: 1px solid rgba(239,68,68,.2); }
.sp-na    { background: rgba(148,163,184,.08); color: var(--text-m); border: 1px solid var(--border); }
.sp-score { background: rgba(124,58,237,.1); color: var(--purple-l); border: 1px solid rgba(124,58,237,.2); }

/* ── SP toolbar ─────────────────────────────────────────────────────── */
.sp-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.sp-search {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px; font-family: inherit;
  padding: 5px 10px;
  width: 200px; outline: none;
  transition: border-color .15s;
}
.sp-search:focus { border-color: rgba(124,58,237,.5); }
.sp-search::placeholder { color: var(--text-d); }

.sp-table-wrap {
  overflow-y: auto;
  flex: 1;
}

.sp-table { width: 100%; border-collapse: collapse; }
.sp-table thead th {
  position: sticky; top: 0; z-index: 2;
  padding: 10px 14px;
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-d); background: var(--surface2);
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.sp-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: default;
  transition: background .1s;
}
.sp-table tbody tr:hover { background: rgba(255,255,255,.03); }
.sp-check-row:hover td:nth-child(2) .check-title-cell { color: var(--purple-l); }
.sp-table tbody td {
  padding: 11px 14px;
  font-size: 12.5px;
  color: var(--text);
  vertical-align: top;
}
.check-title-cell { font-weight: 500; }
.check-desc       { font-size: 11px; color: var(--text-m); margin-top: 3px; line-height: 1.4; }

/* ── Checks tab side panel ──────────────────────────────────────────── */
.check-meta {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.check-meta p { font-size: 13px; color: var(--text-m); line-height: 1.6; margin-bottom: 10px; }
.check-meta h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-d); margin-bottom: 6px; }
.remediation-box {
  background: rgba(124,58,237,.06);
  border: 1px solid rgba(124,58,237,.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-m);
  font-family: 'Inter', monospace;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

.cp-assets {
  overflow-y: auto;
  flex: 1;
  padding: 16px 24px;
}
.cp-assets h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-d); margin-bottom: 12px;
}

.cp-section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: var(--text-m);
  margin: 16px 0 8px;
}
.cp-section-title:first-child { margin-top: 0; }

.asset-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
}
.asset-chip .chip-name { font-weight: 600; }
.asset-chip .chip-ip   { color: var(--text-m); font-size: 12px; }
.asset-chip .chip-os   { color: var(--text-d); font-size: 11px; margin-left: auto; }

/* ── Failure rate bar ────────────────────────────────────────────────── */
.fail-rate-cell { min-width: 150px; }
.fail-rate-wrap { display: flex; align-items: center; gap: 8px; }
.check-csv-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 5px; font-size: 11px; font-weight: 600;
  background: rgba(59,130,246,.08); color: var(--blue);
  border: 1px solid rgba(59,130,246,.2); cursor: pointer;
  white-space: nowrap; opacity: 0; transition: opacity .15s, background .15s;
  flex-shrink: 0;
}
tr:hover .check-csv-btn { opacity: 1; }
.check-csv-btn:hover { background: rgba(59,130,246,.18); }
.fail-rate-bar  { flex: 1; height: 5px; background: var(--surface3); border-radius: 10px; overflow: hidden; }
.fail-rate-fill { height: 100%; border-radius: 10px; background: var(--red); }
.fail-rate-label { font-size: 11px; font-weight: 600; width: 32px; text-align: right; flex-shrink: 0; }

/* ── Agent count pills in checks table ──────────────────────────────── */
.count-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 12px; font-weight: 600;
}
.count-fail { background: rgba(239,68,68,.15); color: var(--red-l); }
.count-pass { background: rgba(34,197,94,.15);  color: var(--green-l); }
.count-zero { background: var(--surface3); color: var(--text-d); }

/* ── Relative time ───────────────────────────────────────────────────── */
.rel-time { color: var(--text-m); font-size: 12px; }

/* ── Empty / Error states ────────────────────────────────────────────── */
.empty-row td {
  text-align: center;
  padding: 40px !important;
  color: var(--text-m);
}

/* ── Check title in checks table ─────────────────────────────────────── */
.check-row-title {
  font-weight: 500;
  white-space: normal;
  word-break: break-word;
}
.check-row-policy {
  font-size: 11px;
  color: var(--text-m);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Toast notification ─────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13px;
  z-index: 9999;
  box-shadow: var(--shadow);
  animation: slideUp .2s ease;
}
.toast.error { border-color: rgba(239,68,68,.4); color: var(--red-l); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar { padding: 0 14px; }
  .nav-search { max-width: 180px; }
  .left-sidebar { width: 180px; }
  .content { padding: 14px; }
  .panel-toolbar { flex-wrap: wrap; }
  .side-panel { width: 100vw; }
}
