:root {
  --bg: #0b1220;
  --bg-soft: #101a2c;
  --panel: #131f33;
  --panel-2: #182742;
  --line: #24344f;
  --line-soft: #1c2a42;
  --text: #e7eefb;
  --muted: #8ea1bd;
  --accent: #22c55e;
  --accent-2: #16a34a;
  --blue: #3b82f6;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #a855f7;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,.28);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }

/* ---------- boot / login ---------- */
.boot { height: 100vh; display: grid; place-items: center; align-content: center; gap: 18px; }
.boot-logo { font-size: 24px; font-weight: 800; letter-spacing: .08em; color: var(--accent); }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(800px 400px at 20% 10%, rgba(34,197,94,.10), transparent 60%),
  radial-gradient(700px 400px at 90% 90%, rgba(59,130,246,.12), transparent 60%), var(--bg); }
.login-card {
  width: 100%; max-width: 390px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 30px; box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .mark { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--accent-2)); color: #04160a; font-weight: 900; }
.login-brand b { display: block; font-size: 18px; }
.login-brand span { color: var(--muted); font-size: 12px; }
.login-note { margin-top: 16px; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 224px; flex: 0 0 224px; background: var(--bg-soft);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; border-bottom: 1px solid var(--line-soft); }
.brand .mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--accent-2)); color: #04160a; font-weight: 900; font-size: 15px; }
.brand b { font-size: 15px; letter-spacing: .02em; }
.brand span { display: block; color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-group { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .14em; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px;
  color: #b8c7dd; font-size: 13.5px; text-decoration: none; border: 1px solid transparent;
}
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.28); color: #4ade80; }
.nav .ico { width: 18px; text-align: center; opacity: .9; font-size: 15px; }
.nav .badge-dot { margin-left: auto; background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
  border-radius: 999px; padding: 1px 6px; min-width: 18px; text-align: center; }
.sidebar-foot { border-top: 1px solid var(--line-soft); padding: 12px; }
.userchip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.userchip:hover { background: var(--panel); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; color: #9fd3ff; flex: 0 0 32px; }
.userchip .u-meta { min-width: 0; flex: 1; }
.userchip b { display: block; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userchip small { color: var(--muted); font-size: 11px; text-transform: capitalize; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 24px;
  border-bottom: 1px solid var(--line-soft); background: rgba(11,18,32,.85);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 15;
}
.topbar .crumb { color: var(--muted); font-size: 12px; }
.topbar .spacer { flex: 1; }
.content { padding: 22px 24px 48px; max-width: 1500px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- grid / cards ---------- */
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.cols-5 { grid-template-columns: repeat(5, minmax(0,1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.card-head h2, .card-head h3 { flex: 1; }
.card-head .sub { color: var(--muted); font-size: 12px; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }
.card-body.scroll { max-height: 420px; overflow: auto; }

.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--line); }
.stat.up::after { background: var(--accent); }
.stat.down::after { background: var(--red); }
.stat.unknown::after { background: var(--amber); }
.stat.alerts::after { background: var(--purple); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.stat .value { font-size: 30px; font-weight: 750; line-height: 1.15; margin-top: 6px; letter-spacing: -.02em; }
.stat .value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .foot { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .07em; font-weight: 600; background: rgba(255,255,255,.015); }
tbody tr:hover { background: rgba(255,255,255,.025); }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
td.wrap { white-space: normal; }
td.right, th.right { text-align: right; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.empty .big { font-size: 28px; margin-bottom: 8px; opacity: .7; }

/* ---------- badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 650; border: 1px solid transparent; line-height: 1.6; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.up { color: #4ade80; background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.25); }
.badge.down { color: #f87171; background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.25); }
.badge.unknown { color: #fbbf24; background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.25); }
.badge.info { color: #93c5fd; background: rgba(59,130,246,.12); border-color: rgba(59,130,246,.25); }
.badge.warning, .badge.warn { color: #fbbf24; background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.25); }
.badge.critical { color: #f87171; background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.25); }
.badge.muted { color: var(--muted); background: rgba(148,163,184,.10); border-color: rgba(148,163,184,.2); }
.badge.ack { color: #c4b5fd; background: rgba(168,85,247,.12); border-color: rgba(168,85,247,.25); }
.badge.open { color: #f87171; background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.25); }
.badge.resolved { color: var(--muted); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--panel-2);
  border: 1px solid var(--line); color: #b8c7dd; font-size: 11px; margin-right: 4px; }
.sev { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px;
  font-size: 10px; font-weight: 800; }
.sev.s0,.sev.s1,.sev.s2 { background: rgba(239,68,68,.18); color: #f87171; }
.sev.s3 { background: rgba(245,158,11,.18); color: #fbbf24; }
.sev.s4 { background: rgba(59,130,246,.18); color: #93c5fd; }
.sev.s5,.sev.s6,.sev.s7 { background: rgba(148,163,184,.14); color: var(--muted); }

/* ---------- buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 7px 13px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; font-size: 13px; font-weight: 550;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #1f3150; border-color: #2d4266; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent-2)); border-color: #15803d; color: #04160a; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: #fca5a5; border-color: rgba(239,68,68,.4); background: rgba(239,68,68,.1); }
.btn.danger:hover { background: rgba(239,68,68,.18); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn.icon { padding: 6px 9px; }
.btn-group { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.btn-group button { border: 0; border-radius: 0; background: transparent; color: var(--muted); padding: 6px 11px; font: inherit; font-size: 12px; cursor: pointer; }
.btn-group button + button { border-left: 1px solid var(--line); }
.btn-group button.active { background: rgba(34,197,94,.14); color: #4ade80; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 550; }
label.field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: #0c1626; color: var(--text); font: inherit; font-size: 13px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: rgba(34,197,94,.55); box-shadow: 0 0 0 3px rgba(34,197,94,.12); }
input::placeholder, textarea::placeholder { color: #5f7390; }
textarea { resize: vertical; min-height: 74px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 14px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
fieldset { border: 1px solid var(--line-soft); border-radius: 10px; padding: 14px 14px 6px; margin: 0 0 14px; }
legend { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; padding: 0 6px; }
.check { display: flex; align-items: center; gap: 9px; font-size: 13px; margin-bottom: 12px; cursor: pointer; }
.check input { width: auto; accent-color: var(--accent); }
.inline { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.search { position: relative; min-width: 220px; }
.search input { padding-left: 32px; }
.search .mag { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(3,7,14,.72); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 100; padding: 18px; }
.modal { width: 100%; max-width: 620px; max-height: 90vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.modal.wide { max-width: 940px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line-soft); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line-soft); display: flex; justify-content: flex-end; gap: 8px; }
.x-btn { background: transparent; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; padding: 4px; }
.x-btn:hover { color: var(--text); }

/* ---------- toast ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--blue);
  border-radius: 10px; padding: 10px 14px; min-width: 260px; max-width: 380px; box-shadow: var(--shadow);
  font-size: 13px; animation: slideIn .18s ease-out; }
.toast.ok { border-left-color: var(--accent); }
.toast.err { border-left-color: var(--red); }
@keyframes slideIn { from { transform: translateY(8px); opacity: 0; } }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.flex { display: flex; align-items: center; gap: 10px; }
.flex.between { justify-content: space-between; }
.flex.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--line-soft); margin: 14px 0; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.up { background: var(--accent); box-shadow: 0 0 0 3px rgba(34,197,94,.15); }
.dot.down { background: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,.15); }
.dot.unknown { background: var(--amber); box-shadow: 0 0 0 3px rgba(245,158,11,.15); }
.progress { height: 6px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress.warn > i { background: var(--amber); }
.progress.bad > i { background: var(--red); }
pre.code { margin: 0; padding: 14px; background: #0a1322; border: 1px solid var(--line-soft);
  border-radius: 10px; overflow: auto; max-height: 60vh; font-size: 12px; line-height: 1.5; }
.diff-line { display: block; white-space: pre-wrap; padding: 0 8px; }
.diff-add { background: rgba(34,197,94,.13); color: #86efac; }
.diff-del { background: rgba(239,68,68,.12); color: #fca5a5; }
.diff-hunk { background: rgba(59,130,246,.12); color: #93c5fd; margin-top: 6px; }
.diff-head { color: var(--muted); }

.chart { width: 100%; height: 210px; }
.chart-tall { height: 280px; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 8px 2px 0; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); font-size: 12px; white-space: nowrap; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line-soft); }
.list li:last-child { border-bottom: 0; }
.list .li-main { flex: 1; min-width: 0; }
.list .li-main b { display: block; font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .li-main small { color: var(--muted); font-size: 11.5px; }

/* ---------- topology ---------- */
#topo { width: 100%; height: 620px; background: radial-gradient(600px 300px at 50% 0%, rgba(59,130,246,.07), transparent 70%), #0a1322; border-radius: 10px; }

/* ---------- wallboard ---------- */
body.wallboard-mode .sidebar, body.wallboard-mode .topbar { display: none; }
body.wallboard-mode .content { max-width: none; padding: 20px; }
.wall-head { display: flex; align-items: center; gap: 18px; margin-bottom: 18px; }
.wall-head .clock { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.wall-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.wall-tile { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--amber);
  border-radius: 10px; padding: 14px; min-height: 108px; }
.wall-tile.up { border-left-color: var(--accent); }
.wall-tile.down { border-left-color: var(--red); background: rgba(239,68,68,.06); }
.wall-tile b { display: block; font-size: 14px; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wall-tile .host { color: var(--muted); font-size: 11px; }
.wall-tile .stat-row { display: flex; gap: 14px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.wall-tile .stat-row b { font-size: 15px; color: var(--text); display: inline; margin: 0; }
.wall-summary { display: flex; gap: 20px; margin-left: auto; color: var(--muted); font-size: 13px; }
.wall-summary b { color: var(--text); }

@media (max-width: 1100px) {
  .grid.cols-5 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .nav-toggle { display: inline-flex !important; }
  .content { padding: 16px 14px 40px; }
  .topbar { padding: 12px 14px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .grid.cols-5 { grid-template-columns: 1fr; }
  .form-row, .form-row.three { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 100px 1fr; }
  .wall-grid { grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); }
}
.nav-toggle { display: none; }
