:root {
  --bg: #0b0f17;
  --panel: #121826;
  --panel-2: #172033;
  --border: #232d42;
  --text: #e6eaf2;
  --muted: #8b95a9;
  --accent: #4f8cff;
  --green: #2fbf71;
  --amber: #f0b429;
  --red: #ef5350;
  --purple: #a78bfa;
  --cyan: #22c3d6;
  --radius: 10px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

input, select, textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; }

.btn { border: 1px solid var(--border); background: var(--panel-2); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn:hover { filter: brightness(1.1); }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; font: inherit; font-size: 12px; }
.link:hover { color: var(--text); }
.icon { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; background: radial-gradient(circle at 30% 20%, #16223d, var(--bg) 60%); }
.login-card { width: min(380px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 32px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.login-card .brand { font-size: 20px; }
.login-card .btn { padding: 10px; }
.error { color: var(--red); min-height: 1em; font-size: 13px; }

/* Layout */
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 20px 14px; display: flex; flex-direction: column; gap: 8px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.logo { color: var(--accent); }
.host { color: var(--muted); font-size: 12px; margin-bottom: 18px; font-family: ui-monospace, Consolas, monospace; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { color: var(--muted); text-decoration: none; padding: 9px 12px; border-radius: 8px; }
nav a:hover { background: var(--panel-2); color: var(--text); }
nav a.active { background: rgba(79,140,255,.14); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.me { margin-top: auto; border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.me-actions { display: flex; gap: 14px; }

main { padding: 24px 28px; min-width: 0; }
.view { display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.banner { background: rgba(240,180,41,.12); border: 1px solid rgba(240,180,41,.4); color: var(--amber); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 18px; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card.flush { padding: 0; overflow-x: auto; }
.card.inset { background: var(--panel-2); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.chart { height: 220px; position: relative; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 600; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.warn > i { background: var(--amber); } .bar.crit > i { background: var(--red); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel); color: var(--muted); border: 0; padding: 7px 12px; cursor: pointer; font: inherit; }
.seg button.on { background: var(--accent); color: #fff; }

.filters { display: flex; gap: 8px; }
.filters input { width: 260px; } .filters select { width: auto; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.click { cursor: pointer; }
.table tbody tr.click:hover { background: var(--panel-2); }
.table tr.down td { opacity: .6; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.sub-line { color: var(--muted); font-size: 12px; }

.status { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; text-transform: capitalize; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.up::before { background: var(--green); box-shadow: 0 0 0 3px rgba(47,191,113,.18); }
.status.degraded::before { background: var(--amber); box-shadow: 0 0 0 3px rgba(240,180,41,.18); }
.status.down::before { background: var(--red); box-shadow: 0 0 0 3px rgba(239,83,80,.18); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); text-transform: capitalize; }
.env-production { background: rgba(239,83,80,.14); color: #ff8a87; border-color: rgba(239,83,80,.35); }
.env-staging { background: rgba(167,139,250,.14); color: var(--purple); border-color: rgba(167,139,250,.35); }
.env-testing { background: rgba(34,195,214,.12); color: var(--cyan); border-color: rgba(34,195,214,.35); }
.env-development { background: rgba(79,140,255,.14); color: #8db4ff; border-color: rgba(79,140,255,.35); }
.exp-public { color: var(--amber); } .exp-local { color: var(--green); }
.badge { background: var(--panel-2); border-radius: 999px; padding: 1px 7px; font-size: 11px; color: var(--muted); }

.attention-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.attention-item:last-child { border-bottom: 0; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--panel); border-left: 1px solid var(--border); z-index: 11; display: flex; flex-direction: column; box-shadow: -20px 0 60px rgba(0,0,0,.4); }
.drawer header { display: flex; justify-content: space-between; align-items: flex-start; padding: 20px; border-bottom: 1px solid var(--border); }
.drawer-body { overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 18px; }
.d-meta { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 18px; }
.d-meta div { display: flex; flex-direction: column; gap: 2px; }
.d-meta span:first-child { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }
.comment { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; }
.comment .head { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.comment .body { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form > * { flex: 1 1 160px; }
.inline-form .btn { flex: 0 0 auto; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel-2); border: 1px solid var(--border); padding: 12px 16px; border-radius: 8px; z-index: 20; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.toast.err { border-color: var(--red); color: #ff8a87; }

body:not(.is-admin) .admin-only { display: none !important; }
body.is-viewer .editor-only { display: none !important; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .grid2 { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .filters { flex-wrap: wrap; } .filters input { width: 100%; }
}
