:root {
  --bg: #05070d;
  --panel: rgba(13, 17, 28, 0.86);
  --border: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #6366f1;
  --ok: #10b981;
  --warn: #f59e0b;
  --down: #ef4444;
  --off: #64748b;
  font-family: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid rgba(99, 102, 241, 0.45); outline-offset: 2px; }
.mono { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; }
.muted { color: var(--muted); }

/* ── login ─────────────────────────────────────────────────────────── */
.login-body {
  display: grid; place-items: center; min-height: 100vh; padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, #141a33 0%, var(--bg) 70%);
}
.login-card {
  width: 100%; max-width: 380px; padding: 28px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.login-card h1 { margin: 18px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 18px; font-size: 14px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  height: 44px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border);
  background: rgba(2, 6, 23, 0.7); color: var(--text); font-size: 15px;
}
.login-card button[type="submit"] {
  height: 44px; margin-top: 4px; border: 0; border-radius: 6px; background: var(--primary); color: white; font-weight: 600;
}
.login-card button[type="submit"]:hover { background: #4f46e5; }
.login-error {
  padding: 10px 12px; border-radius: 6px; background: rgba(239, 68, 68, 0.12); color: #fca5a5 !important;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-sub { font-weight: 500; color: var(--muted); }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 12px var(--primary); }

/* ── twin ──────────────────────────────────────────────────────────── */
.twin-body { overflow: hidden; }
#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }

.topbar {
  position: fixed; top: 12px; left: 12px; right: 12px; z-index: 10;
  display: flex; align-items: center; gap: 16px; padding: 10px 14px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(8px);
}
.kpis { display: flex; gap: 6px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.kpi { padding: 4px 10px; border-radius: 8px; background: rgba(148, 163, 184, 0.07); white-space: nowrap; }
.kpi b { display: block; font-size: 16px; font-family: "JetBrains Mono", ui-monospace, monospace; }
.kpi span { font-size: 11px; color: var(--muted); }
.kpi.warn b { color: var(--warn); }
.kpi.down b { color: var(--down); }
.topbar-right { display: flex; align-items: center; gap: 10px; font-size: 13px; white-space: nowrap; }
.topbar-right form { margin: 0; }
.updated { color: var(--muted); font-size: 12px; }
.who { color: var(--muted); }
.btn-ghost {
  min-height: 36px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--border); background: transparent; color: var(--text);
}
.btn-ghost:hover { background: rgba(148, 163, 184, 0.1); }

.stale {
  position: fixed; top: 84px; left: 50%; transform: translateX(-50%); z-index: 10; padding: 8px 14px; border-radius: 8px;
  background: rgba(245, 158, 11, 0.15); border: 1px solid rgba(245, 158, 11, 0.4); color: #fcd34d; font-size: 13px;
}

.panel {
  position: fixed; top: 84px; right: 12px; bottom: 56px; z-index: 10; width: 360px; overflow-y: auto; padding: 16px;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(8px); font-size: 13px;
}
.panel h2 { margin: 0 0 2px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.panel h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.panel .sub { color: var(--muted); margin: 0 0 6px; }
.panel a { color: #a5b4fc; }
.rows { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; }
.rows dt { color: var(--muted); }
.rows dd { margin: 0; text-align: right; font-family: "JetBrains Mono", ui-monospace, monospace; overflow-wrap: anywhere; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }
.badge.warn { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }
.badge.down { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
.badge.off { background: rgba(100, 116, 139, 0.2); color: #cbd5e1; }
.alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.alerts li { padding: 8px 10px; border-radius: 8px; background: rgba(148, 163, 184, 0.07); border-left: 3px solid var(--warn); }
.alerts li.down { border-left-color: var(--down); }
.alerts li b { display: block; font-size: 12px; }
.containers { display: grid; gap: 6px; }
.container-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: rgba(148, 163, 184, 0.07); }
.container-row .name { flex: 1; }
.container-row .meta { color: var(--muted); font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12px; }
.client-list { display: grid; gap: 6px; }
.client-list button {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid transparent; background: rgba(148, 163, 184, 0.07); color: var(--text); text-align: left;
}
.client-list button:hover { border-color: var(--border); }
.client-list .grow { flex: 1; }
.back { margin-bottom: 10px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.down { background: var(--down); } .dot.off { background: var(--off); }

.legend {
  position: fixed; left: 12px; bottom: 12px; z-index: 10; display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  padding: 8px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--border); font-size: 12px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .hint { color: var(--muted); }

/* 3D labels (CSS2DRenderer) */
.label3d {
  padding: 3px 8px; border-radius: 6px; background: rgba(13, 17, 28, 0.82); border: 1px solid var(--border);
  font-size: 12px; white-space: nowrap; pointer-events: none; text-align: center; line-height: 1.3;
}
.label3d small { display: block; color: var(--muted); font-size: 10px; font-family: "JetBrains Mono", ui-monospace, monospace; }
.label3d.client { font-weight: 700; }
.label3d.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.35); }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .kpis { order: 3; flex-basis: 100%; }
  .panel { top: auto; left: 12px; right: 12px; bottom: 56px; width: auto; max-height: 42vh; }
  .stale { top: 128px; }
  .legend .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* foldable panel */
.panel-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; margin: -6px 0 8px; padding: 6px 8px;
  border: 0; border-radius: 8px; background: rgba(148, 163, 184, 0.07); color: var(--text); text-align: left; font-weight: 600;
}
.panel-toggle .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel.collapsed { bottom: auto; padding-bottom: 6px; }
.panel.collapsed .panel-toggle { margin-bottom: 0; }
@media (max-width: 900px) {
  .panel.collapsed { top: auto; bottom: 56px; max-height: none; }
}
