/* ---------------------------------------------------------------- tokens */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #1b2433;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbe7ff;
  --ok: #16a34a;
  --warn: #d97706;
  --crit: #dc2626;
  --track: #e8edf4;
  --sidebar-bg: #111827;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1f2a40;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  --sidebar-w: 240px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #131b2e;
    --surface-2: #18223a;
    --border: #243049;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #60a5fa;
    --accent-soft: #1e3a5f;
    --ok: #22c55e;
    --warn: #f59e0b;
    --crit: #f87171;
    --track: #24304a;
    --sidebar-bg: #0a0f1c;
    --sidebar-active: #18233b;
    --shadow: none;
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.break { word-break: break-all; }

/* ---------------------------------------------------------------- shell */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  z-index: 40;
  transition: transform .2s ease;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px; color: #fff; font-weight: 700; font-size: 16px;
}
.brand-logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #22c55e);
  display: grid; place-items: center;
}
.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500;
}
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #3b82f6; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-foot { padding: 14px 20px; font-size: 12px; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-foot .host { color: #fff; font-weight: 600; word-break: break-all; }

.backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30;
}

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.menu-btn {
  display: none; background: none; border: 0; padding: 6px; margin-left: -6px;
  color: var(--text); cursor: pointer; border-radius: 6px;
}
.menu-btn svg { width: 22px; height: 22px; display: block; }
.live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.live.stale .live-dot { background: var(--warn); }
.user-chip {
  display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; text-transform: uppercase;
}

.content { padding: 24px; display: flex; flex-direction: column; gap: 20px; max-width: 1600px; width: 100%; }

/* ---------------------------------------------------------------- components */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-sm { padding: 5px 10px; font-size: 13px; }

.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }

.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.bar { height: 8px; background: var(--track); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 99px; background: var(--ok); transition: width .5s ease; }
.bar > span.warn { background: var(--warn); }
.bar > span.crit { background: var(--crit); }
.bar.thin { height: 6px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.crit { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.dl { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: 8px 16px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 500; word-break: break-word; }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.name { max-width: 280px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: " \2195"; opacity: .35; }
th[data-dir="asc"]::after { content: " \2191"; opacity: 1; }
th[data-dir="desc"]::after { content: " \2193"; opacity: 1; }
.scroll-y { max-height: 560px; overflow-y: auto; }
.cell-bar { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.cell-bar .bar { flex: 1; }
.cell-bar span.v { width: 50px; text-align: right; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.input, select.input {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; min-width: 0;
}
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.toolbar .input[type=search] { flex: 1 1 220px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; cursor: pointer; white-space: nowrap; }

/* charts */
.chart { width: 100%; height: 160px; display: block; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .line-cpu { stroke: var(--accent); }
.chart .line-mem { stroke: #a855f7; }
.chart .line-heap { stroke: var(--ok); }
.chart path.line { fill: none; stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.cores { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.core { font-size: 12px; color: var(--muted); }
.core b { color: var(--text); font-variant-numeric: tabular-nums; float: right; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13.5px; border: 1px solid; }
.alert-error { color: var(--crit); background: color-mix(in srgb, var(--crit) 8%, transparent); border-color: color-mix(in srgb, var(--crit) 30%, transparent); }
.alert-info { color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, transparent); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.alert-warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 8%, transparent); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }

pre.cmd {
  margin: 0; padding: 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border);
  white-space: pre-wrap; word-break: break-all; font-family: var(--mono); font-size: 12.5px; max-height: 220px; overflow: auto;
}

/* ---------------------------------------------------------------- login */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(circle at 15% 20%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 45%),
    radial-gradient(circle at 85% 80%, color-mix(in srgb, var(--ok) 14%, transparent), transparent 45%),
    var(--bg);
}
.login-card { width: 100%; max-width: 400px; padding: 32px 28px; }
.login-card .brand { color: var(--text); padding: 0; margin-bottom: 6px; font-size: 20px; }
.login-card p.lead { margin: 0 0 22px; color: var(--muted); }
.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 13px; }
.field .input { padding: 11px 12px; font-size: 15px; }
.pw { position: relative; }
.pw .input { width: 100%; padding-right: 64px; }
.pw button {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 6px 8px;
}
.form .btn-primary { padding: 12px; font-size: 15px; }
.login-foot { margin-top: 18px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- secure content */
.secure-block { display: contents; }
.content > .secure-block.pending {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 240px; color: var(--muted);
}
.content > .secure-block.pending::before {
  content: ""; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.content > .secure-block.pending::after { content: "Establishing secure connection\2026"; }
@keyframes spin { to { transform: rotate(360deg); } }
a.user-chip { color: var(--text); border-radius: 99px; padding: 2px 10px 2px 2px; }
a.user-chip:hover { text-decoration: none; background: var(--surface-2); }
.topbar .badge.warn:hover { text-decoration: none; }

/* ---------------------------------------------------------------- settings */
.profile-head { display: flex; align-items: center; gap: 16px; padding: 18px; }
.profile-head h2 { font-size: 18px; }
.avatar-lg { width: 56px; height: 56px; font-size: 24px; flex-shrink: 0; }
.settings { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; align-items: start; }
.settings-nav { display: flex; flex-direction: column; padding: 8px; gap: 2px; position: sticky; top: 76px; }
.settings-nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: var(--text); font-weight: 500; white-space: nowrap;
}
.settings-nav a:hover { background: var(--surface-2); text-decoration: none; }
.settings-nav a.active { background: var(--accent-soft); color: var(--accent); }
.settings-nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.settings-nav .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-left: auto; }
.settings-panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.settings-panel .form { max-width: 520px; }
.border-top { border-top: 1px solid var(--border); }
.card-body > .alert + .form, .card-body > .alert + .alert { margin-top: 14px; }
.strength { margin-top: 4px; }
.rules { margin: 4px 0 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 2px 12px; font-size: 12.5px; color: var(--muted); }
.rules li::before { content: "\2022"; display: inline-block; width: 16px; color: var(--muted); }
.rules li.ok { color: var(--ok); }
.rules li.ok::before { content: "\2713"; color: var(--ok); }
.login-foot svg { vertical-align: -1px; margin-right: 4px; }

@media (max-width: 960px) {
  .settings { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { flex-direction: row; overflow-x: auto; position: static; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .settings-nav::-webkit-scrollbar { display: none; }
  .settings-nav a { padding: 8px 12px; }
}

/* ---------------------------------------------------------------- AI insights */
.nav-tag { margin-left: auto; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 99px;
  background: linear-gradient(135deg, #3b82f6, #a855f7); color: #fff; letter-spacing: .04em; }
.insight-hero { display: flex; align-items: center; gap: 24px; padding: 22px; }
.hero-body { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.hero-body h2 { font-size: 17px; font-weight: 600; line-height: 1.4; }
.hero-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12.5px; }
.score-ring { position: relative; width: 112px; height: 112px; flex-shrink: 0; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring circle { fill: none; stroke-width: 10; }
.score-ring .track { stroke: var(--track); }
.score-ring .value { stroke: var(--ok); stroke-linecap: round; transition: stroke-dasharray .6s ease; }
.score-ring.warn .value { stroke: var(--warn); }
.score-ring.crit .value { stroke: var(--crit); }
.score-text { position: absolute; inset: 0; display: flex; align-items: baseline; justify-content: center; padding-top: 36px; }
.score-text b { font-size: 32px; font-variant-numeric: tabular-nums; }
.score-text span { color: var(--muted); font-size: 12px; margin-left: 2px; }
.kpi-value.small { font-size: 20px; }
.findings, .priorities { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.priorities { counter-reset: prio; }
.findings li, .priorities li { border-left: 3px solid var(--border); padding: 6px 0 6px 12px; }
.findings li.critical, .priorities li.critical { border-left-color: var(--crit); }
.findings li.warning, .priorities li.warning { border-left-color: var(--warn); }
.findings li.info { border-left-color: var(--accent); }
.findings li.good { border-left-color: var(--ok); }
.f-title, .p-title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.f-evidence { color: var(--muted); font-size: 13px; margin-top: 2px; }
.findings, .priorities, .hero-body h2, .ai-output { overflow-wrap: anywhere; }
.f-action, .p-action { font-size: 13px; margin-top: 3px; }
.f-action::before, .p-action::before { content: "\2192  "; color: var(--accent); font-weight: 700; }
.sev { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
li.critical .sev { color: var(--crit); border-color: color-mix(in srgb, var(--crit) 40%, transparent); }
li.warning .sev { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
li.info .sev { color: var(--accent); }
li.good .sev { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.ai-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.ai-form textarea { width: 100%; resize: vertical; font: inherit; }
.ai-loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 10px 0; }
.ai-loading::before { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border);
  border-top-color: var(--accent); animation: spin .8s linear infinite; }
.ai-output { font-size: 14px; line-height: 1.6; }
.ai-output h3 { font-size: 14.5px; margin: 14px 0 4px; }
.ai-output h3:first-child { margin-top: 0; }
.ai-output p { margin: 4px 0; }
.ai-output ol, .ai-output ul { margin: 4px 0; padding-left: 22px; }
.ai-output li { margin: 3px 0; }
.ai-card .card-body + .card-body { padding-top: 0; }
@media (max-width: 640px) {
  .insight-hero { flex-direction: column; align-items: flex-start; gap: 14px; }
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1200px) {
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .content { padding: 16px; gap: 16px; }
  .topbar { padding: 10px 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 21px; }
  .hide-sm { display: none; }
  .cell-bar { min-width: 0; }
  .cell-bar .bar { display: none; }
  .cell-bar span.v { width: auto; }
  .live span.txt, .user-chip .uname { display: none; }
  th, td { padding: 8px 10px; }
  .card-head, .card-body { padding-left: 14px; padding-right: 14px; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }
}
@media (max-width: 360px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
}
