:root {
  --bg: #FFFFFF;
  --bg-soft: #F7F8FA;
  --text: #111827;
  --text-soft: #4B5563;
  --muted: #9CA3AF;
  --border: #E5E7EB;
  --border-soft: #EEF0F3;
  --ok: #16A34A;
  --warn: #D97706;
  --crit: #DC2626;
  --down: #7F1D1D;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { cursor: pointer; background: none; border: none; padding: 0; margin: 0; font: inherit; color: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
table { border-collapse: collapse; }
a { color: inherit; }

@keyframes beat { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@keyframes halo { 0% { transform: scale(.86); opacity: .6; } 70% { transform: scale(1.12); opacity: 0; } 100% { opacity: 0; } }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}
.login-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; margin-bottom: 22px; }
.login-brand i { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); display: block; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select {
  border: 1px solid var(--border); border-radius: 6px; padding: 9px 11px;
  width: 100%; outline: none; font-size: 13.5px; background: #fff;
}
.field input:focus, .field select:focus { border-color: #111827; }
.form-error {
  background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA;
  border-radius: 6px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 14px;
}
.form-hint { font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 6px; padding: 9px 16px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border); color: var(--text-soft); background: #fff; white-space: nowrap;
}
.btn:hover { border-color: #D1D5DB; }
.btn-primary { background: #111827; color: #fff; border-color: #111827; width: 100%; }
.btn-primary:hover { background: #1F2937; }
.btn-danger { color: var(--crit); }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- Topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: #fff; border-bottom: 1px solid var(--border); }
.topbar-inner {
  display: flex; align-items: center; gap: 16px; padding: 0 24px; height: 60px;
  max-width: 1400px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; letter-spacing: -.01em; flex: 1; min-width: 0; }
.brand i { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); display: block; flex: none; }
.nav { display: flex; gap: 4px; flex: none; }
.nav-btn { padding: 9px 15px; border-radius: 7px; font-size: 14.5px; display: flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--text-soft); }
.nav-btn.active { background: var(--bg-soft); color: var(--text); font-weight: 600; }
.nav-badge { background: var(--crit); color: #fff; border-radius: 20px; font-size: 10.5px; padding: 1px 6px; font-weight: 600; }
.topbar-right { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.search-box { display: flex; align-items: center; gap: 7px; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; width: 190px; }
.search-box input { border: none; outline: none; background: none; width: 100%; font-size: 13px; }
.live-btn { border: 1px solid var(--border); border-radius: 6px; padding: 6px 11px; font-size: 12.5px; color: var(--text-soft); display: flex; align-items: center; gap: 7px; }
.live-btn.live { border-color: #BBF7D0; color: var(--ok); }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); display: block; }
.live-btn.live .live-dot { background: var(--ok); animation: beat 2s infinite; }
.avatar-menu { position: relative; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--bg-soft); border: 1px solid var(--border); display: grid; place-items: center; font-size: 11px; font-weight: 600; }
.avatar-dropdown {
  position: absolute; right: 0; top: 36px; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.10); min-width: 200px; padding: 8px; display: none; z-index: 40;
}
.avatar-dropdown.open { display: block; }
.avatar-dropdown .who { padding: 8px 10px; font-size: 12.5px; }
.avatar-dropdown .who b { display: block; font-size: 13.5px; }
.avatar-dropdown .who span { color: var(--muted); text-transform: capitalize; }
.avatar-dropdown button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.avatar-dropdown button:hover { background: var(--bg-soft); }

.subbar { border-top: 1px solid var(--border-soft); background: var(--bg-soft); }
.subbar-inner { max-width: 1400px; margin: 0 auto; padding: 8px 24px; font-size: 12px; color: var(--muted); display: flex; gap: 14px; }

/* ---------- Page ---------- */
.page { max-width: 1400px; margin: 0 auto; padding: 24px; }
.page h2 { margin: 0 0 2px; font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.page > p.hint { margin: 0 0 20px; font-size: 13px; color: var(--muted); }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); font-size: 12.5px; }
.empty b { display: block; color: var(--text-soft); margin-bottom: 5px; font-size: 14px; }

/* ---------- Dashboard clusters ---------- */
.cluster-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 58px; }
@media (max-width: 1100px) { .cluster-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 36px; } }
@media (max-width: 620px) { .cluster-grid { grid-template-columns: 1fr; } }
.cluster h3 { margin: 0 0 12px; font-size: 12.5px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.cluster h3 .count { margin-left: auto; background: var(--bg-soft); border-radius: 20px; padding: 1px 7px; font-size: 10.5px; color: var(--text-soft); }
.node-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px 2px; }
.node-chip { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 7px 2px; border-radius: 6px; border: 1px solid transparent; background: transparent; }
.node-chip:hover { background: var(--bg-soft); }
.node-ring-wrap { position: relative; width: 44px; height: 44px; flex: none; }
.node-ring-wrap .halo { position: absolute; inset: 0; border-radius: 50%; border: 1px solid var(--down); opacity: 0; animation: halo 2.4s infinite; }
.node-ring-wrap svg { display: block; }
.node-ring-val { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; font-size: 11px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.node-chip-name { font-size: 10px; text-align: center; line-height: 1.25; color: var(--text-soft); word-break: break-word; width: 100%; }

.stat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--border-soft); }
.stat-chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 7px; padding: 7px 12px; background: #fff; }
.stat-chip.active { border-color: #111827; box-shadow: 0 0 0 1px #111827; }
.stat-chip i { width: 9px; height: 9px; border-radius: 50%; display: block; }
.stat-chip .n { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-chip .l { font-size: 12px; color: var(--text-soft); }

.legend { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-top: 22px; width: max-content; max-width: 100%; }
.legend h4 { margin: 0 0 9px; font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.legend-row { display: flex; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 7px; }
.legend-row:last-child { margin-bottom: 0; }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; display: block; }

/* ---------- Panels / KPIs ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 800px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi-card { border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.kpi-card .n { font-size: 23px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-card .k { font-size: 12.5px; color: var(--text-soft); margin-top: 3px; }
.kpi-card .d { font-size: 11px; color: var(--muted); margin-top: 7px; }

.panel { border: 1px solid var(--border); border-radius: 8px; padding: 18px; }
.panel h3 { margin: 0 0 2px; font-size: 14px; font-weight: 600; }
.panel > p.hint { margin: 0 0 16px; font-size: 12px; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

.metric-row { margin-bottom: 12px; }
.metric-row-top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px; }
.metric-row-top b { font-weight: 600; font-variant-numeric: tabular-nums; }
.metric-bar { height: 5px; border-radius: 4px; background: var(--border-soft); overflow: hidden; }
.metric-bar i { display: block; height: 100%; border-radius: 4px; }

/* ---------- Node detail ---------- */
.back-btn { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.node-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 22px; }
.node-head-ring { position: relative; width: 52px; height: 52px; flex: none; }
.node-head-ring .node-ring-val { font-size: 14px; }
.node-head h2 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -.01em; }
.node-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.sev-pill { font-size: 10.5px; padding: 2px 8px; border-radius: 20px; border: 1px solid; white-space: nowrap; font-weight: 500; margin-top: 6px; }
.node-head-actions { margin-left: auto; display: flex; gap: 8px; }

.detail-row { display: flex; justify-content: space-between; gap: 14px; padding: 10px 0; font-size: 12.5px; }
.detail-row + .detail-row { border-top: 1px solid var(--border-soft); }
.detail-row span:first-child { color: var(--muted); }
.detail-row b { font-weight: 500; }

.dep-row { display: flex; justify-content: space-between; gap: 14px; padding: 10px 0; border-top: 1px solid var(--border-soft); font-size: 12.5px; }
.dep-row .name-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 7px; }

.event-item { display: grid; grid-template-columns: 74px 1fr auto; gap: 14px; align-items: center; padding: 13px 2px; border-top: 1px solid var(--border-soft); }
.event-item time { font-size: 11.5px; color: var(--muted); }
.event-item .msg { font-size: 13px; }
.event-item .msg b { font-weight: 600; }
.event-item .msg em { font-style: normal; font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }
.event-item .ack-label { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ---------- Alerts ---------- */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { border: 1px solid var(--border); border-radius: 20px; padding: 6px 13px; font-size: 12.5px; color: var(--text-soft); display: flex; align-items: center; gap: 7px; background: transparent; }
.chip.active { background: #111827; color: #fff; border-color: #111827; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; display: block; }

/* ---------- Reports ---------- */
.avail-row { display: grid; grid-template-columns: 120px 1fr 52px; gap: 11px; align-items: center; padding: 7px 0; font-size: 12.5px; }
.avail-bar { height: 6px; background: var(--border-soft); border-radius: 4px; overflow: hidden; }
.avail-bar i { display: block; height: 100%; border-radius: 4px; }
.avail-pct { font-size: 11.5px; text-align: right; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.inc-chart { display: flex; align-items: flex-end; gap: 5px; height: 148px; margin-top: 8px; }
.inc-bar { flex: 1; border-radius: 3px 3px 0 0; min-height: 3px; }
.inc-x { display: flex; gap: 5px; margin-top: 7px; }
.inc-x span { flex: 1; text-align: center; font-size: 9.5px; color: var(--muted); }
.report-summary { font-size: 13px; line-height: 1.75; color: var(--text-soft); }
.report-list-item { padding: 12px 0; border-top: 1px solid var(--border-soft); }
.report-list-item .date { font-weight: 600; font-size: 13px; color: var(--text); }
.report-list-item .body { font-size: 12.5px; color: var(--text-soft); margin-top: 4px; }

/* ---------- Settings / forms ---------- */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border-soft); }
.toggle-row b { display: block; font-size: 13px; }
.toggle-row span.sub { font-size: 11.5px; color: var(--muted); }
.switch { width: 38px; height: 21px; border-radius: 20px; background: var(--border); position: relative; flex: none; }
.switch.on { background: var(--ok); }
.switch i { position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: left .15s; }
.switch.on i { left: 20px; }

.threshold-row { display: flex; gap: 10px; align-items: center; }
.threshold-dot { width: 18px; height: 18px; border-radius: 50%; flex: none; border: 3px solid; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data-table th { text-align: left; font-size: 10.5px; color: var(--muted); letter-spacing: .06em; padding: 0 8px 10px 0; font-weight: 600; text-transform: uppercase; }
table.data-table td { padding: 11px 8px 11px 0; border-top: 1px solid var(--border-soft); }
.table-scroll { overflow-x: auto; }

.state-pill { font-size: 10.5px; padding: 2px 8px; border-radius: 20px; border: 1px solid; font-weight: 500; white-space: nowrap; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(17,24,39,.35); z-index: 70; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 460px; padding: 22px; }
.modal h3 { margin: 0 0 16px; font-size: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Tooltip / toast ---------- */
.tooltip {
  position: fixed; z-index: 80; pointer-events: none; background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; box-shadow: 0 4px 14px rgba(0,0,0,.10); min-width: 168px;
}
.tooltip-head { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.tooltip-head i { width: 8px; height: 8px; border-radius: 50%; display: block; }
.tooltip-row { display: flex; justify-content: space-between; gap: 16px; font-size: 11.5px; padding: 2px 0; }
.tooltip-row span { color: var(--muted); }
.tooltip-row b { font-weight: 500; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; bottom: 24px; left: 50%; z-index: 60; background: #111827; color: #fff;
  border-radius: 7px; padding: 10px 18px; font-size: 13px; transition: opacity .25s, transform .25s;
  opacity: 0; transform: translate(-50%, 16px); pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.hidden { display: none !important; }
