:root {
  --bg: #0f1218;
  --panel: #171b23;
  --panel-2: #1e232d;
  --border: #2a303c;
  --text: #e4e7ec;
  --muted: #8b93a3;
  --accent: #e0457b;
  --accent-2: #b8325f;
  --ok: #2fbf71;
  --warn: #f2a93b;
  --crit: #ef4b4b;
  --off: #6b7280;
  --unk: #4b5563;
  --link: #7aa7ff;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --radius: 10px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f7; --panel: #ffffff; --panel-2: #f6f7fa; --border: #dfe2e8;
    --text: #1d2330; --muted: #677085; --link: #2b5fd9; --shadow: 0 6px 24px rgba(20, 30, 50, .12);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* layout */
#app { display: flex; min-height: 100vh; }
#sidebar { width: 210px; flex: none; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: radial-gradient(circle at 35% 50%, #fff 0 3px, transparent 4px), radial-gradient(circle at 68% 50%, #fff 0 3px, transparent 4px), linear-gradient(135deg, var(--accent), var(--accent-2)); }
nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; }
nav a { color: var(--text); padding: 8px 12px; border-radius: 8px; opacity: .85; }
nav a:hover { background: var(--panel-2); text-decoration: none; opacity: 1; }
nav a.active { background: var(--panel-2); opacity: 1; box-shadow: inset 3px 0 0 var(--accent); }
nav a.nav-add { margin-top: 10px; color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; }
#main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.card.tight { padding: 0; overflow: hidden; }
.card > .card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

/* buttons & forms */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--panel-2); color: var(--text); padding: 7px 14px; border-radius: 8px; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--crit); }
button.danger.solid { background: var(--crit); border-color: var(--crit); color: #fff; }
button.link { background: none; border: none; color: var(--link); padding: 0; }
button.sm { padding: 4px 10px; font-size: 12.5px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: -1px; }
input[type=checkbox] { width: auto; }
textarea { min-height: 80px; font-family: var(--mono); font-size: 12.5px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; background: var(--panel-2); position: sticky; top: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--panel-2) 70%, transparent); }
tbody tr.clickable { cursor: pointer; }
.table-wrap { overflow: auto; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv > div:nth-child(odd) { color: var(--muted); }
.kv > div:nth-child(even) { word-break: break-word; }

/* status */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--unk); flex: none; }
.s-ok { --c: var(--ok); } .s-warning { --c: var(--warn); } .s-critical { --c: var(--crit); }
.s-offline { --c: var(--off); } .s-unknown { --c: var(--unk); }
.dot[class*="s-"] { background: var(--c); }
.dot.s-ok { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: color-mix(in srgb, var(--c, var(--unk)) 16%, transparent); color: var(--c, var(--muted)); text-transform: capitalize; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); font-size: 12px; margin-right: 4px; }

/* bars */
.bar { position: relative; height: 7px; background: var(--panel-2); border-radius: 4px; overflow: hidden; min-width: 70px; border: 1px solid var(--border); }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--ok); border-radius: 4px; }
.bar.warn > i { background: var(--warn); } .bar.crit > i { background: var(--crit); }
.barcell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.barcell > span { font-variant-numeric: tabular-nums; width: 42px; text-align: right; font-size: 12.5px; }

/* KPIs */
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }

/* site cards */
.site-card { display: flex; flex-direction: column; gap: 12px; border-top: 3px solid var(--c, var(--unk)); }
.site-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.site-card .name { font-weight: 600; font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 7px; background: var(--panel-2); border: 1px solid var(--border); font-size: 12px; color: var(--text); }
.chip:hover { border-color: var(--c, var(--muted)); text-decoration: none; }
.chip .dot { width: 7px; height: 7px; }
.stat-line { display: flex; gap: 18px; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.stat-line b { color: var(--text); font-weight: 600; }

/* gauges */
.gauges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.gauge { text-align: center; }
.gauge svg { width: 100%; max-width: 120px; }
.gauge .gl { font-size: 12px; color: var(--muted); margin-top: -4px; }
@media (max-width: 900px) { .gauges { grid-template-columns: repeat(2, 1fr); } }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* terminal */
.term-wrap { background: #0b0d11; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; height: calc(100vh - 290px); min-height: 360px; }
.term-wrap .xterm { height: 100%; }

/* file browser */
.crumbs { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; font-family: var(--mono); font-size: 13px; }
.crumbs a { padding: 2px 4px; border-radius: 4px; }
.dropzone.drag { outline: 2px dashed var(--accent); outline-offset: -6px; }
.ficon { display: inline-block; width: 18px; text-align: center; margin-right: 6px; opacity: .8; }

/* charts */
.chart { width: 100%; height: 150px; display: block; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke-width: 1.6; }
.chart .area { opacity: .12; }

/* modal & toasts */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; z-index: 50; overflow: auto; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: var(--shadow); }
.modal.wide { max-width: 860px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); max-width: 420px; animation: slidein .2s ease-out; }
.toast.error { border-left-color: var(--crit); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; width: 100%; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { padding: 0 0 18px; justify-content: center; font-size: 22px; }
.err { color: var(--crit); margin: 8px 0; min-height: 1em; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h2 { color: var(--text); }
.reason { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.copybox { display: flex; gap: 8px; align-items: stretch; }
.copybox pre { flex: 1; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: static; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { display: none; }
  #main { padding: 16px; }
  .g2, .g3 { grid-template-columns: 1fr; }
}

/* site map */
#site-map { height: 380px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-2); z-index: 0; }
.site-picker { height: 260px; border-radius: 8px; border: 1px solid var(--border); margin-top: 4px; background: var(--panel-2); }
#site-map.placing, #site-map.placing .leaflet-interactive { cursor: crosshair; }
.map-unplaced { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 0; }
.map-unplaced:empty { display: none; }
.map-hint { color: var(--accent); }
.map-legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); text-transform: capitalize; flex-wrap: wrap; }
.map-legend span { display: inline-flex; align-items: center; gap: 5px; }
.map-pin { width: 30px; height: 30px; border-radius: 50%; background: var(--c, var(--unk)); border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 12px; position: relative; }
.map-pin.editing { cursor: move; outline: 2px dashed #fff; outline-offset: 3px; }
.map-pin.s-critical::after, .map-pin.s-offline::after { content: ""; position: absolute; inset: -3px; border-radius: 50%;
  border: 3px solid var(--c); animation: pinpulse 1.6s ease-out infinite; }
@keyframes pinpulse { from { transform: scale(1); opacity: .8; } to { transform: scale(2.1); opacity: 0; } }
.map-popup { min-width: 180px; line-height: 1.6; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-tooltip { background: var(--panel); color: var(--text); border-color: var(--border); }
.leaflet-container { font: inherit; }
/* dark theme: darken the map tiles */
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
@media (prefers-color-scheme: light) { .leaflet-tile-pane { filter: none; } }

/* address search */
.addr-search { position: relative; }
.addr-results { position: absolute; z-index: 1000; left: 0; right: 0; top: calc(100% + 4px); background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; }
.addr-item { display: block; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--border);
  border-radius: 0; padding: 8px 12px; white-space: normal; line-height: 1.35; }
.addr-item:last-child { border-bottom: none; }
button.addr-item:hover { background: var(--panel-2); }
.addr-item .small { display: block; margin-top: 2px; }

/* site name next to the map pin */
.map-label { position: absolute; left: calc(100% + 7px); top: 50%; transform: translateY(-50%); white-space: nowrap;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px;
  font-size: 12px; font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); pointer-events: none; }
.mfa-qr { display: flex; justify-content: center; margin: 12px 0; }
.mfa-qr svg { background: #fff; padding: 8px; border-radius: 6px; max-width: 100%; height: auto; }
.mfa-secret { letter-spacing: 1px; white-space: pre-wrap; word-break: break-all; }
