:root {
  color-scheme: dark;
  --bg: #08111f;
  --panel: #101c2d;
  --panel-strong: #14243a;
  --border: #24364d;
  --text: #edf4ff;
  --muted: #93a4bb;
  --accent: #5da8ff;
  --normal: #42d392;
  --warning: #f6bd60;
  --critical: #ff6b7a;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(50, 112, 180, 0.18), transparent 35%),
    var(--bg);
  color: var(--text);
}

button, input { font: inherit; }

.dashboard {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.topbar,
.section-heading,
.card-heading,
.metric-header,
.service-row,
.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(1.8rem, 4vw, 2.7rem); }
h2 { margin-bottom: 0; font-size: 1.15rem; }

.eyebrow {
  margin-bottom: 7px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.muted, .refresh-note, .metric-detail { color: var(--muted); }
.refresh-note { font-size: 0.82rem; }

.server-state { display: flex; align-items: center; gap: 9px; color: var(--muted); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 5px rgba(246, 189, 96, 0.12); }
.server-state.online .status-dot { background: var(--normal); box-shadow: 0 0 0 5px rgba(66, 211, 146, 0.12); }
.server-state.offline .status-dot { background: var(--critical); box-shadow: 0 0 0 5px rgba(255, 107, 122, 0.12); }

.topbar { margin-bottom: 34px; }
.topbar-actions { align-items: flex-end; }
.last-update { display: grid; gap: 4px; text-align: right; color: var(--muted); font-size: 0.78rem; }
.last-update strong { color: var(--text); font-size: 0.95rem; }

button {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  background: var(--accent);
  color: #05111f;
  font-weight: 800;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
.button-secondary { border: 1px solid var(--border); background: var(--panel); color: var(--text); }

.connection-alert, .alert {
  margin-bottom: 22px;
  border: 1px solid rgba(255, 107, 122, 0.45);
  border-radius: 12px;
  padding: 13px 15px;
  background: rgba(255, 107, 122, 0.10);
  color: #ffc7ce;
}

.section-heading { margin-bottom: 15px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
.card { border: 1px solid var(--border); border-radius: 16px; background: linear-gradient(145deg, var(--panel-strong), var(--panel)); box-shadow: var(--shadow); }
.metric-card { padding: 19px; min-width: 0; }
.metric-header { color: var(--muted); font-size: 0.84rem; font-weight: 700; }
.metric-value { display: block; margin: 16px 0 10px; font-size: clamp(1.6rem, 3vw, 2.25rem); }
.load-value { font-size: clamp(1.15rem, 2vw, 1.55rem); }
.metric-detail { margin: 10px 0 0; min-height: 1.2em; font-size: 0.78rem; }

.progress { height: 7px; overflow: hidden; border-radius: 99px; background: #26364b; }
.progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--normal); transition: width 0.35s ease, background-color 0.35s ease; }
.progress span.warning { background: var(--warning); }
.progress span.critical { background: var(--critical); }

.state-badge { border-radius: 99px; padding: 4px 8px; background: rgba(66, 211, 146, 0.12); color: var(--normal); font-size: 0.7rem; font-weight: 800; text-transform: uppercase; white-space: nowrap; }
.state-badge.warning { background: rgba(246, 189, 96, 0.12); color: var(--warning); }
.state-badge.critical, .state-badge.offline { background: rgba(255, 107, 122, 0.12); color: var(--critical); }
.state-badge.neutral, .state-badge.not_configured { background: rgba(147, 164, 187, 0.12); color: var(--muted); }

.content-grid { display: grid; grid-template-columns: minmax(280px, 0.8fr) minmax(380px, 1.2fr); gap: 15px; margin-top: 24px; }
.information-card, .services-card { padding: 21px; }
.card-heading { margin-bottom: 13px; }
.information-list { margin: 0; }
.information-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.information-list > div:last-child { border-bottom: 0; }
.information-list dt { color: var(--muted); }
.information-list dd { margin: 0; text-align: right; font-weight: 750; }
.information-list small { display: block; margin-top: 4px; color: var(--accent); }

.service-row { padding: 13px 0; border-bottom: 1px solid var(--border); }
.service-row:last-child { border-bottom: 0; }
.service-name { min-width: 0; font-weight: 760; overflow-wrap: anywhere; }
.service-meta { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.latency { min-width: 58px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.82rem; }
.empty-state { padding: 28px 0; color: var(--muted); text-align: center; }

.history-section { margin-top: 34px; }
.history-heading { align-items: flex-end; }
.history-ranges { display: flex; flex-wrap: wrap; gap: 7px; }
.history-range {
  min-width: 48px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  background: var(--panel);
  color: var(--muted);
}
.history-range:hover { border-color: var(--accent); color: var(--text); }
.history-range.active { border-color: var(--accent); background: rgba(93, 168, 255, 0.16); color: var(--accent); }
.history-message {
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 28px 18px;
  color: var(--muted);
  text-align: center;
}
.history-message.error { border-color: rgba(255, 107, 122, 0.45); color: #ffc7ce; }
.history-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.history-card { min-width: 0; padding: 18px; }
.history-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.history-card h3 { margin: 0; font-size: 0.95rem; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; color: var(--muted); font-size: 0.68rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { width: 9px; height: 3px; border-radius: 99px; background: var(--accent); }
.legend-swatch.cpu { background: #5da8ff; }
.legend-swatch.ram { background: #42d392; }
.legend-swatch.load-one { background: #f6bd60; }
.legend-swatch.load-five { background: #c994ff; }
.legend-swatch.latency-line { background: #62d6e8; }
.history-chart { display: block; width: 100%; min-height: 210px; overflow: visible; }
.chart-grid-line { stroke: rgba(147, 164, 187, 0.18); stroke-width: 1; }
.chart-axis-label { fill: var(--muted); font-size: 11px; }
.chart-line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-note { margin: 5px 0 0; color: var(--muted); font-size: 0.72rem; }

.login-body { display: grid; place-items: center; padding: 22px; }
.login-shell { width: min(430px, 100%); }
.login-card { border: 1px solid var(--border); border-radius: 20px; padding: 30px; background: var(--panel); box-shadow: var(--shadow); }
.brand-mark { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 22px; border-radius: 13px; background: linear-gradient(145deg, #75b8ff, #347dcc); color: #05111f; font-weight: 900; }
.login-card h1 { font-size: 1.75rem; }
.login-form { display: grid; gap: 9px; margin-top: 24px; }
.login-form label { margin-top: 8px; color: var(--muted); font-size: 0.82rem; font-weight: 700; }
.login-form input { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 12px 13px; background: #0a1626; color: var(--text); outline: none; }
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(93, 168, 255, 0.13); }
.login-form button { margin-top: 14px; }
.alert-error { margin-top: 20px; }

@media (max-width: 980px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid { grid-template-columns: 1fr; }
  .history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-card:last-child { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .dashboard { padding: 20px 15px 28px; }
  .topbar, .section-heading { align-items: flex-start; }
  .topbar { flex-direction: column; }
  .topbar-actions { width: 100%; align-items: center; }
  .last-update { text-align: left; margin-right: auto; }
  .metric-grid { grid-template-columns: 1fr; }
  .refresh-note { display: none; }
  .history-heading { align-items: flex-start; }
  .history-ranges { width: 100%; }
  .history-range { flex: 1; }
  .history-grid { grid-template-columns: 1fr; }
  .history-card:last-child { grid-column: auto; }
  .history-card-heading { flex-direction: column; }
  .chart-legend { justify-content: flex-start; }
  .service-row { align-items: flex-start; }
  .service-meta { flex-wrap: wrap; }
  .login-card { padding: 24px; }
}
