:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #182133;
  --border: #243047;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --ok: #10b981;
  --ok-bg: rgba(16, 185, 129, 0.14);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.14);
  --info: #38bdf8;
  --radius: 12px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #17233a 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; }
.login-brand h1 { margin: 0; font-size: 20px; }
.login-brand p { margin: 2px 0 0; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: rgba(59, 130, 246, 0.16); color: var(--primary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-icon svg { width: 24px; height: 24px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12.5px; color: var(--muted); font-weight: 500; }
input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus { border-color: var(--primary); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 14px; font-size: 13.5px; font-weight: 500;
  cursor: pointer; font-family: inherit; transition: all .15s;
  color: var(--text); background: var(--surface-2);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.btn-danger-outline { background: transparent; border-color: rgba(239,68,68,.4); color: #fca5a5; }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger-bg); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-xs { padding: 4px 8px; font-size: 12px; }

/* Topbar & Tabs */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(11, 15, 23, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand-mini { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px rgba(16,185,129,.7); }
.dot.warn { background: var(--warn); box-shadow: 0 0 8px rgba(245,158,11,.7); }
.dot.danger { background: var(--danger); box-shadow: 0 0 8px rgba(239,68,68,.8); }

.pill {
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.pill.ok { background: var(--ok-bg); color: #6ee7b7; border-color: rgba(16,185,129,.3); }
.pill.warn { background: var(--warn-bg); color: #fcd34d; border-color: rgba(245,158,11,.3); }
.pill.danger { background: var(--danger-bg); color: #fca5a5; border-color: rgba(239,68,68,.35); }
.pill.info { background: rgba(56,189,248,.14); color: #7dd3fc; border-color: rgba(56,189,248,.3); }

.meta-chip { font-size: 12px; color: var(--muted); }

.tabs {
  display: flex; gap: 4px; padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 12px 14px; font-size: 13.5px; font-weight: 500;
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.badge {
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px;
}

.container { max-width: 1240px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: 18px; }
.tab-panel { display: none; flex-direction: column; gap: 18px; }
.tab-panel.active { display: flex; }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.wrap-head { flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi-card { display: flex; flex-direction: column; gap: 8px; }
.kpi-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.progress { height: 7px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid rgba(255,255,255,0.04); }
.progress-bar { height: 100%; width: 0%; background: var(--primary); border-radius: 999px; transition: width .35s ease; }
.progress-bar.ok { background: var(--ok); }
.progress-bar.warn { background: var(--warn); }
.progress-bar.danger { background: var(--danger); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

/* RAM breakdown */
.ram-stacked {
  display: flex; height: 14px; border-radius: 8px; overflow: hidden;
  background: var(--bg); margin-bottom: 14px; border: 1px solid var(--border);
}
.ram-seg-used { background: var(--primary); }
.ram-seg-cache { background: #6366f1; }
.ram-seg-free { background: rgba(16,185,129,0.28); }
.stats-mini-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat-mini {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px;
}
.stat-mini .lbl { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat-mini .val { font-size: 15px; font-weight: 600; margin-top: 2px; }
.swatch { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Spec list */
.spec-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; margin: 0; }
.spec-item { display: flex; flex-direction: column; padding: 6px 0; border-bottom: 1px solid rgba(36,48,71,0.55); }
.spec-item dt { font-size: 11.5px; color: var(--muted); }
.spec-item dd { margin: 2px 0 0; font-size: 13px; font-weight: 500; word-break: break-word; }

/* Charts */
.seg-group { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg {
  background: transparent; border: none; color: var(--muted);
  padding: 5px 10px; font-size: 12px; border-radius: 6px; cursor: pointer; font-weight: 500;
}
.seg.active { background: var(--surface-2); color: var(--text); }

.charts-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-box { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.chart-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 13px; font-weight: 500; }
.svg-chart { width: 100%; height: 155px; }

/* Monitors */
.monitors-list { display: flex; flex-direction: column; gap: 10px; }
.monitor-row {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.monitor-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.monitor-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.monitor-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.bars-strip { display: flex; gap: 3px; height: 22px; align-items: stretch; }
.bar-tick {
  flex: 1; border-radius: 3px; background: var(--surface-2); min-width: 4px;
  transition: transform .1s;
}
.bar-tick:hover { transform: scaleY(1.15); }
.bar-tick.up { background: var(--ok); opacity: 0.85; }
.bar-tick.down { background: var(--danger); }

/* Sites */
.sites-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.site-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
}
.site-card a { color: var(--info); text-decoration: none; font-weight: 600; font-size: 15px; }
.site-card a:hover { text-decoration: underline; }
.site-meta { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  text-align: left; padding: 9px 10px; border-bottom: 1px solid rgba(36,48,71,0.65);
  vertical-align: middle;
}
.data-table th { color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.actions-cell { display: flex; gap: 6px; white-space: nowrap; }

/* Incidents & Events */
.incident-item {
  background: var(--bg); border: 1px solid var(--border); border-left: 3px solid var(--info);
  border-radius: 8px; padding: 11px 14px; margin-bottom: 8px;
}
.incident-item.critical { border-left-color: var(--danger); }
.incident-item.warning { border-left-color: var(--warn); }
.incident-item.open { background: rgba(239,68,68,0.08); border-color: rgba(239,68,68,0.35); }
.incident-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.incident-detail { margin-top: 5px; font-size: 12.5px; color: var(--muted); word-break: break-word; }

/* Forms & Logs */
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; padding: 12px; background: var(--bg); border-radius: 10px; border: 1px solid var(--border); }
.inline-form input, .inline-form select { flex: 1; min-width: 170px; }
.stack-form { display: flex; flex-direction: column; gap: 12px; }

.logs-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.log-viewer {
  margin: 0; background: #070a10; border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; font-family: var(--mono); font-size: 12px; line-height: 1.55;
  max-height: 540px; overflow: auto; white-space: pre-wrap; word-break: break-word;
  color: #cbd5e1;
}
.log-err { color: #fca5a5; }
.log-warn { color: #fcd34d; }

/* Alerts & Banners */
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.alert-danger { background: var(--danger-bg); color: #fca5a5; border: 1px solid rgba(239,68,68,.35); }
.alert-ok { background: var(--ok-bg); color: #6ee7b7; border: 1px solid rgba(16,185,129,.35); }

.banner-danger {
  background: var(--danger-bg); border: 1px solid rgba(239,68,68,.45);
  color: #fecaca; border-radius: var(--radius); padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 50;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45); font-size: 13px;
}

.disk-row { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.disk-row-head { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }

@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .charts-grid { grid-template-columns: 1fr; }
  .hide-md { display: none; }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .stats-mini-grid, .spec-list { grid-template-columns: 1fr 1fr; }
  .container { padding: 12px; }
  .topbar { padding: 10px 12px; }
  .tabs { padding: 0 8px; }
  .hide-sm { display: none; }
}
