:root {
  --bg-0: #161820;
  --bg-1: #1f222d;
  --bg-2: #282c3a;
  --bg-3: #333849;
  --bg-hover: #313647;
  --border: #34394b;
  --border-strong: #632737;

  --red: #e11d48;
  --red-bright: #ff2e4c;
  --red-dark: #be123c;
  --red-soft: rgba(239, 45, 76, 0.16);
  --red-glow: rgba(255, 46, 76, 0.30);

  --text-0: #ffffff;
  --text-1: #e2e5ef;
  --text-2: #a3a9bd;

  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.16);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.16);
  --blue: #38bdf8;
  --blue-soft: rgba(56, 189, 248, 0.16);

  --radius: 12px;
  --radius-sm: 8px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--red-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-0); }
::-webkit-scrollbar-thumb { background: #262634; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--red-dark); }

/* Boot */
.boot-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: radial-gradient(circle at 50% 30%, rgba(225, 29, 72, 0.12), var(--bg-0) 60%);
}
.boot-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--red-bright);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.boot-text {
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--text-2);
  font-weight: 700;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Login Gate */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(600px 380px at 50% 0%, rgba(225, 29, 72, 0.18), transparent 70%),
    radial-gradient(500px 400px at 85% 95%, rgba(159, 18, 57, 0.12), transparent 70%),
    var(--bg-0);
}
.login-card {
  width: 100%;
  max-width: 410px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-top: 2px solid var(--red-bright);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.75), 0 0 40px rgba(225, 29, 72, 0.08);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--red-bright), var(--red-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 20px var(--red-glow);
  flex-shrink: 0;
}
.brand-title {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: var(--text-0);
  line-height: 1.15;
}
.brand-sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--red-bright);
  font-weight: 700;
}
.login-desc {
  color: var(--text-2);
  font-size: 13px;
  margin-bottom: 22px;
}

/* Form controls */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 6px;
}
.input, .select, .textarea {
  width: 100%;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--red-bright);
  box-shadow: 0 0 0 3px var(--red-soft);
}
.select { cursor: pointer; }
.form-error {
  background: var(--red-soft);
  border: 1px solid rgba(255, 36, 66, 0.35);
  color: #fda4af;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  margin-bottom: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(180deg, var(--red-bright), var(--red));
  color: #fff;
  box-shadow: 0 4px 16px rgba(225, 29, 72, 0.32);
}
.btn-primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 22px rgba(255, 36, 66, 0.45);
}
.btn-secondary {
  background: var(--bg-2);
  color: var(--text-0);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--bg-3);
  border-color: #363649;
}
.btn-danger {
  background: rgba(225, 29, 72, 0.12);
  color: #fb7185;
  border-color: rgba(225, 29, 72, 0.32);
}
.btn-danger:hover {
  background: var(--red);
  color: #fff;
}
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* App Layout */
.layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 248px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  transition: transform 0.2s ease;
}
.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 11px;
}
.nav {
  padding: 14px 10px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.nav-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-2);
  font-weight: 700;
  padding: 12px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: all 0.14s;
}
.nav-item:hover {
  background: var(--bg-2);
  color: var(--text-0);
}
.nav-item.active {
  background: linear-gradient(90deg, var(--red-soft), rgba(225, 29, 72, 0.03));
  color: #fff;
  border-color: rgba(225, 29, 72, 0.35);
  box-shadow: inset 3px 0 0 var(--red-bright);
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-item.active svg { color: var(--red-bright); opacity: 1; }

.sidebar-footer {
  padding: 14px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--red-soft);
  border: 1px solid rgba(255, 36, 66, 0.4);
  color: var(--red-bright);
  font-weight: 800;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role { font-size: 11px; color: var(--text-2); }

/* Main area */
.main {
  flex: 1;
  margin-left: 248px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(22, 24, 32, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.menu-toggle { display: none; }

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  background: var(--red-soft);
  border: 1px solid rgba(255, 36, 66, 0.35);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
}
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red-bright);
  box-shadow: 0 0 8px var(--red-bright);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.6; }
}

.site-select {
  width: auto;
  min-width: 190px;
  padding: 7px 12px;
  background: var(--bg-2);
  font-weight: 600;
}
.range-group {
  display: inline-flex;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.range-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.range-btn:hover { color: var(--text-0); }
.range-btn.active {
  background: var(--red);
  color: #fff;
}

.content {
  padding: 22px 24px 40px;
  max-width: 1460px;
  width: 100%;
  margin: 0 auto;
}

/* Security warning banner */
.alert-banner {
  background: linear-gradient(90deg, rgba(225, 29, 72, 0.2), rgba(225, 29, 72, 0.06));
  border: 1px solid rgba(255, 36, 66, 0.42);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.alert-banner strong { color: #fda4af; }

/* Page heading */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.page-sub {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s;
}
.kpi-card:hover { border-color: var(--border-strong); }
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--red-bright), transparent);
  opacity: 0.65;
}
.kpi-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
}
.kpi-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 6px 0 4px;
  font-variant-numeric: tabular-nums;
}
.kpi-meta {
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
}
.delta-up { color: var(--green); font-weight: 700; }
.delta-down { color: var(--red-bright); font-weight: 700; }
.delta-flat { color: var(--text-2); font-weight: 600; }

/* Panels & Grids */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.grid-2 .panel, .grid-3 .panel { margin-bottom: 0; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-0);
}
.panel-sub {
  font-size: 12px;
  color: var(--text-2);
}

/* Chart */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 250px;
}
.chart-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(24, 27, 36, 0.97);
  border: 1px solid rgba(255, 46, 76, 0.5);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 12px;
  color: var(--text-0);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 10;
  white-space: nowrap;
}
.live-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: #fecdd3;
  background: var(--red-soft);
  border: 1px solid rgba(255, 46, 76, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
}
.live-tag.paused {
  color: var(--text-2);
  background: var(--bg-2);
  border-color: var(--border);
}
.live-tag.paused .pulse-dot {
  background: var(--text-2);
  box-shadow: none;
  animation: none;
}

/* Metric Bars */
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { position: relative; }
.bar-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 4px;
}
.bar-label {
  font-weight: 500;
  color: var(--text-0);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-val {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-1);
  flex-shrink: 0;
}
.bar-track {
  height: 6px;
  background: var(--bg-3);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red-dark), var(--red-bright));
  border-radius: 99px;
}

/* Tables */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  font-weight: 700;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 10px 10px;
  border-bottom: 1px solid rgba(35, 35, 48, 0.65);
  color: var(--text-1);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.015); }
.num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}
.path-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-0);
  font-weight: 500;
}

/* Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-red { background: var(--red-soft); color: #fda4af; border: 1px solid rgba(255, 36, 66, 0.3); }
.badge-green { background: var(--green-soft); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-amber { background: var(--amber-soft); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-blue { background: var(--blue-soft); color: #7dd3fc; border: 1px solid rgba(56, 189, 248, 0.3); }
.badge-muted { background: var(--bg-3); color: var(--text-1); border: 1px solid var(--border); }

.issues-wrap { display: flex; flex-wrap: wrap; gap: 4px; }

/* Code box */
.code-box {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #fda4af;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Site cards */
.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}
.site-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.site-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.site-card-stats {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-2);
}
.site-card-stats strong { color: var(--text-0); }

/* Empty state */
.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--text-2);
  font-size: 13px;
}

/* Toast */
.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-2);
  border: 1px solid var(--red-bright);
  color: var(--text-0);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.7);
}

/* Region Map */
.region-map {
  width: 100%;
  height: 360px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #141720;
  overflow: hidden;
  z-index: 1;
}
.leaflet-container {
  background: #141720 !important;
  font-family: var(--font-sans) !important;
}
.leaflet-tile-pane {
  filter: invert(100%) hue-rotate(180deg) brightness(93%) contrast(88%) saturate(30%);
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-1) !important;
  color: var(--text-0) !important;
  border: 1px solid var(--border-strong);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55) !important;
}
.leaflet-popup-content {
  margin: 10px 12px !important;
  font-size: 12.5px !important;
  line-height: 1.45 !important;
}
.leaflet-control-attribution {
  background: rgba(22, 24, 32, 0.78) !important;
  color: var(--text-2) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--text-2) !important; }
.leaflet-bar a {
  background: var(--bg-1) !important;
  color: var(--text-0) !important;
  border-color: var(--border) !important;
}
.leaflet-bar a:hover { background: var(--bg-2) !important; color: var(--red-bright) !important; }

.map-pin-live {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--red-bright);
  border: 2px solid #fff;
  box-shadow: 0 0 14px var(--red-bright);
  position: relative;
}
.map-pin-live::after {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid var(--red-bright);
  animation: mapPulse 1.8s ease-out infinite;
}
@keyframes mapPulse {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(1.9); opacity: 0; }
}
.map-pin-hist {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(225, 29, 72, 0.72);
  border: 1.5px solid #fda4af;
}

/* Responsive */
@media (max-width: 1024px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 60px rgba(0,0,0,0.85); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px 14px 36px; }
  .topbar { padding: 10px 14px; }
}
