:root {
  --bg: #070b12;
  --panel: #101826;
  --panel-soft: #132033;
  --border: #26364d;
  --text: #e9f2ff;
  --muted: #8ea3bb;
  --green: #31d27c;
  --yellow: #ffc857;
  --red: #ff4d5d;
  --cyan: #59d8ff;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(89, 216, 255, 0.12), transparent 35%),
    radial-gradient(circle at bottom right, rgba(49, 210, 124, 0.08), transparent 38%),
    var(--bg);
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 12px;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(24px, 3vw, 38px); letter-spacing: 0.02em; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: var(--muted); }
.topbar p { margin-top: 8px; color: var(--muted); }

.server-pill, .threshold-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid rgba(49, 210, 124, 0.45);
  color: var(--green);
  background: rgba(49, 210, 124, 0.08);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 700;
  white-space: nowrap;
}

.threshold-pill {
  border-color: rgba(255, 77, 93, 0.5);
  color: var(--red);
  background: rgba(255, 77, 93, 0.08);
  font-size: 13px;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 18px var(--green);
  animation: pulse 1.4s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.75; }
  50% { transform: scale(1.35); opacity: 1; }
}

.layout {
  display: grid;
  grid-template-columns: 1.55fr 1fr 0.9fr;
  gap: 18px;
  padding: 18px 28px 28px;
}

.panel {
  background: linear-gradient(180deg, rgba(19, 32, 51, 0.94), rgba(12, 18, 30, 0.96));
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.security-panel { min-height: 610px; }
.charts-panel { grid-column: 1 / -1; }
.panel-title-row, .chart-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.mono { font-family: Consolas, Menlo, Monaco, monospace; }
.small { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }

.terminal {
  background: #05080d;
  border: 1px solid #1d2a3d;
  border-radius: 18px;
  padding: 16px;
  min-height: 540px;
  box-shadow: inset 0 0 28px rgba(49, 210, 124, 0.04);
}

.terminal-row + .terminal-row { margin-top: 14px; }
.terminal-label {
  display: block;
  margin-bottom: 7px;
  color: var(--cyan);
  font-size: 12px;
  font-family: Consolas, Menlo, Monaco, monospace;
  letter-spacing: 0.12em;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #b7ffca;
  background: rgba(49, 210, 124, 0.035);
  border: 1px solid rgba(49, 210, 124, 0.13);
  border-radius: 12px;
  padding: 12px;
  max-height: 165px;
  overflow: auto;
  font-family: Consolas, Menlo, Monaco, monospace;
  font-size: 12px;
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  color: var(--muted);
}

.badge {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  letter-spacing: 0.04em;
}
.badge-ok { color: var(--green); background: rgba(49, 210, 124, 0.12); border: 1px solid rgba(49, 210, 124, 0.35); }
.badge-warn { color: var(--yellow); background: rgba(255, 200, 87, 0.12); border: 1px solid rgba(255, 200, 87, 0.35); }
.badge-bad { color: var(--red); background: rgba(255, 77, 93, 0.12); border: 1px solid rgba(255, 77, 93, 0.35); }
.badge-muted { color: var(--muted); background: rgba(142, 163, 187, 0.1); border: 1px solid rgba(142, 163, 187, 0.22); }

.event-log {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 150px;
  overflow: auto;
  font-family: Consolas, Menlo, Monaco, monospace;
  font-size: 12px;
}

.log-line {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.log-line.ok { border-color: rgba(49, 210, 124, 0.25); color: #b7ffca; }
.log-line.bad { border-color: rgba(255, 77, 93, 0.35); color: #ffb7bd; animation: dangerGlow 1s infinite alternate; }
.log-line.warn { border-color: rgba(255, 200, 87, 0.35); color: #ffe3a2; }

.mode-card, .metric-card {
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  margin-top: 14px;
}

.mode-card span, .metric-card span { color: var(--muted); display: block; margin-bottom: 8px; }
.mode-card strong { font-size: 28px; letter-spacing: 0.06em; }
.mode-card.monitor { border-color: rgba(49, 210, 124, 0.45); box-shadow: inset 0 0 18px rgba(49, 210, 124, 0.08); }
.mode-card.learn { border-color: rgba(255, 200, 87, 0.45); box-shadow: inset 0 0 18px rgba(255, 200, 87, 0.08); }
.metric-card strong { font-size: 30px; }
.metric-card.subdued strong { font-size: 24px; }

.alerts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.alert-card {
  min-height: 116px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(142, 163, 187, 0.07);
  border: 1px solid rgba(142, 163, 187, 0.14);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}
.alert-card span { filter: grayscale(1); opacity: 0.45; }
.alert-card strong { color: var(--text); font-size: 15px; }
.alert-card small { color: var(--muted); }
.alert-card.on {
  color: #fff;
  background: rgba(255, 77, 93, 0.2);
  border-color: rgba(255, 77, 93, 0.75);
  box-shadow: 0 0 24px rgba(255, 77, 93, 0.22), inset 0 0 24px rgba(255, 77, 93, 0.1);
  animation: dangerGlow 0.7s infinite alternate;
}
.alert-card.on span { filter: none; opacity: 1; }
.alert-card.on small { color: #ffd5d9; }

@keyframes dangerGlow {
  from { box-shadow: 0 0 10px rgba(255, 77, 93, 0.12); }
  to { box-shadow: 0 0 26px rgba(255, 77, 93, 0.38); }
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.chart-card {
  background: #08101c;
  border: 1px solid #1d2a3d;
  border-radius: 18px;
  padding: 16px;
  min-height: 280px;
}
canvas { width: 100%; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .security-panel { grid-column: 1 / -1; }
  .env-panel { grid-column: auto; }
}

@media (max-width: 820px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .layout, .charts-grid, .status-grid, .alerts-grid { grid-template-columns: 1fr; }
  .layout { padding: 14px; }
}

/* ===== UI performance and compact charts patch ===== */
.charts-panel {
  contain: layout paint;
}

.charts-grid {
  align-items: stretch;
}

.chart-card {
  min-height: 0;
  height: 236px;
  max-height: 236px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 166px;
  gap: 10px;
}

.chart-heading {
  min-height: 30px;
  margin-bottom: 0;
}

.chart-card canvas {
  display: block;
  width: 100% !important;
  height: 166px !important;
  max-height: 166px !important;
}

@media (max-width: 1180px) {
  .chart-card {
    height: 226px;
    max-height: 226px;
    grid-template-rows: auto 156px;
  }

  .chart-card canvas {
    height: 156px !important;
    max-height: 156px !important;
  }
}

@media (max-width: 820px) {
  .chart-card {
    height: 216px;
    max-height: 216px;
    grid-template-rows: auto 146px;
  }

  .chart-card canvas {
    height: 146px !important;
    max-height: 146px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
