/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --bg: #020617;
  --surface: #0f172a;
  --surface-2: #1e293b;
  --surface-3: #263449;
  --border: #1e293b;
  --border-soft: rgba(148, 163, 184, 0.12);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --accent: #22c55e;
  --accent-dim: rgba(34, 197, 94, 0.15);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.15);
  --crit: #ef4444;
  --crit-dim: rgba(239, 68, 68, 0.15);
  --info: #38bdf8;

  --font-sans: "Fira Sans", system-ui, -apple-system, sans-serif;
  --font-mono: "Fira Code", ui-monospace, "SF Mono", monospace;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur-base: 250ms;
  --dur-slow: 450ms;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}

::selection { background: var(--accent-dim); color: var(--text); }

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

/* ============================================================
   Background ambience
   ============================================================ */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60vw 40vw at 85% -5%, rgba(34, 197, 94, 0.10), transparent 60%),
    radial-gradient(50vw 35vw at 5% 10%, rgba(56, 189, 248, 0.08), transparent 60%);
  pointer-events: none;
}

/* ============================================================
   Login screen
   ============================================================ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, var(--surface), var(--surface) 70%, var(--surface-2));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 36px 28px 28px;
  text-align: center;
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.6);
  animation: card-in var(--dur-slow) var(--ease) both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
  width: 52px; height: 52px;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border-radius: 14px;
  border: 1px solid var(--border-soft);
}

.login-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.login-sub { margin: 0 0 24px; color: var(--text-muted); font-size: 14px; }

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.pin-dots .dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border-soft);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast);
}
.pin-dots .dot.filled {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.15);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.55);
}

.pin-input-hidden {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0.01;
  pointer-events: none;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.key {
  height: 56px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 500;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--dur-fast) var(--ease), transform 100ms var(--ease), border-color var(--dur-fast);
}
.key:hover { background: var(--surface-3); border-color: rgba(148,163,184,0.25); }
.key:active { transform: scale(0.93); background: var(--accent-dim); }
.key-ghost { color: var(--text-muted); font-family: var(--font-sans); font-size: 13px; }

.btn-primary {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #04170c;
  font-weight: 600;
  font-size: 15px;
  transition: filter var(--dur-fast) var(--ease), transform 100ms var(--ease);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: scale(0.98); }

.login-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--crit);
  font-size: 13px;
}

.login-card.shake { animation: shake 420ms var(--ease); }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

/* ============================================================
   App shell
   ============================================================ */
.app { min-height: 100vh; animation: fade-in var(--dur-slow) var(--ease) both; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(2, 6, 23, 0.75);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}

.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 15px; letter-spacing: -0.01em;
}

.topbar-right { display: flex; align-items: center; gap: 14px; }

.live-indicator {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: pulse-dot 2s var(--ease) infinite;
}
@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}
.live-dot.stale { background: var(--warn); animation: none; }

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  color: var(--text-muted);
  transition: color var(--dur-fast), border-color var(--dur-fast), background var(--dur-fast);
}
.icon-btn:hover { color: var(--text); border-color: rgba(148,163,184,0.3); background: var(--surface-2); }

.content {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 32px 0 14px;
}

/* ============================================================
   Overview stat tiles
   ============================================================ */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  opacity: 0;
  transform: translateY(10px);
  animation: rise-in var(--dur-slow) var(--ease) forwards;
}
@keyframes rise-in {
  to { opacity: 1; transform: translateY(0); }
}

.gauge { flex-shrink: 0; }
.gauge svg { display: block; }
.gauge-track { fill: none; stroke: var(--surface-3); stroke-width: 6; }
.gauge-value { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round;
  transform-origin: 50% 50%; transform: rotate(-90deg);
  transition: stroke-dashoffset 700ms var(--ease), stroke 400ms; }
.gauge-value.warn { stroke: var(--warn); }
.gauge-value.crit { stroke: var(--crit); }
.gauge-label {
  font-family: var(--font-mono); font-size: 13px; font-weight: 600;
  fill: var(--text); text-anchor: middle; dominant-baseline: middle;
}

.stat-meta { min-width: 0; }
.stat-title { font-size: 12px; color: var(--text-muted); margin: 0 0 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-family: var(--font-mono); font-size: 20px; font-weight: 600; margin: 0; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--text-faint); margin: 2px 0 0; }

/* ============================================================
   Alerts
   ============================================================ */
.alerts-section {
  margin-top: 20px;
  background: var(--warn-dim);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  animation: rise-in var(--dur-base) var(--ease) both;
}
.alerts-header {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--warn);
  margin-bottom: 8px;
}
.alerts-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.alerts-list li {
  font-size: 13px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
}
.alerts-list .dot-crit, .alerts-list .dot-warn {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.dot-crit { background: var(--crit); }
.dot-warn { background: var(--warn); }

/* ============================================================
   Site cards
   ============================================================ */
.sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
}

.site-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 18px;
  cursor: pointer;
  transition: border-color var(--dur-base) var(--ease), transform var(--dur-base) var(--ease), background var(--dur-base);
  opacity: 0;
  transform: translateY(10px);
  animation: rise-in var(--dur-slow) var(--ease) forwards;
}
.site-card:hover { border-color: rgba(148,163,184,0.3); background: var(--surface-2); transform: translateY(-2px); }
.site-card:active { transform: translateY(-1px) scale(0.99); }
.site-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.site-card-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  margin-bottom: 12px;
}
.site-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
  animation: pulse-dot 2.4s var(--ease) infinite;
}
.status-dot.down { background: var(--crit); animation: none; box-shadow: none; }
.status-dot.warn { background: var(--warn); }

.site-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site-desc { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }

.site-link {
  color: var(--text-faint);
  display: flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  transition: color var(--dur-fast), background var(--dur-fast);
  flex-shrink: 0;
}
.site-link:hover { color: var(--info); background: var(--surface-3); }

.metric-row { display: flex; gap: 18px; margin-bottom: 12px; }
.metric { flex: 1; min-width: 0; }
.metric-label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 4px; }
.metric-value { font-family: var(--font-mono); font-size: 15px; font-weight: 600; margin: 0 0 6px; font-variant-numeric: tabular-nums; }
.bar-track { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 3px; background: var(--accent); transition: width 700ms var(--ease), background 400ms; }
.bar-fill.warn { background: var(--warn); }
.bar-fill.crit { background: var(--crit); }

.sparkline { display: block; width: 100%; height: 32px; margin-bottom: 10px; }
.sparkline path.line { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.sparkline path.fill { fill: var(--accent); opacity: 0.12; stroke: none; }
.sparkline path.line.warn { stroke: var(--warn); }
.sparkline path.fill.warn { fill: var(--warn); }
.sparkline path.line.crit { stroke: var(--crit); }
.sparkline path.fill.crit { fill: var(--crit); }

.site-foot { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--text-faint); }
.http-badge {
  font-family: var(--font-mono);
  padding: 2px 7px; border-radius: 6px;
  background: var(--surface-3); color: var(--text-muted);
}
.http-badge.ok { background: var(--accent-dim); color: var(--accent); }
.http-badge.bad { background: var(--crit-dim); color: var(--crit); }

.site-card.is-down { border-color: rgba(239, 68, 68, 0.35); }
.site-card.is-warn { border-color: rgba(245, 158, 11, 0.35); }

/* value flash when it changes */
.flash { animation: flash-bg 700ms var(--ease); }
@keyframes flash-bg {
  0% { background-color: rgba(34, 197, 94, 0.18); }
  100% { background-color: transparent; }
}

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(2, 6, 23, 0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade-in var(--dur-base) var(--ease) both;
}
.modal {
  width: 100%; max-width: 640px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 28px;
  position: relative;
  animation: modal-in var(--dur-slow) var(--ease) both;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(18px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-close {
  position: absolute; top: 18px; right: 18px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; border: 1px solid var(--border-soft);
  background: var(--surface-2); color: var(--text-muted);
  transition: color var(--dur-fast), background var(--dur-fast);
}
.modal-close:hover { color: var(--text); background: var(--surface-3); }

.modal-title-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; padding-right: 40px; }
.modal-title-row h2 { margin: 0; font-size: 20px; font-weight: 600; }
.modal-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }

.modal-chart { width: 100%; height: 120px; margin-bottom: 18px; }
.modal-chart path.line { fill: none; stroke-width: 2; }
.modal-chart path.line.cpu { stroke: var(--info); }
.modal-chart path.line.mem { stroke: var(--accent); }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); margin-bottom: 18px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.detail-item {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.detail-item .metric-label { margin-bottom: 6px; }
.detail-item .metric-value { font-size: 14px; }

.sub-containers { display: flex; flex-direction: column; gap: 8px; }
.sub-container-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
}
.sub-container-name { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); }
.sub-container-metrics { display: flex; gap: 14px; color: var(--text-muted); font-family: var(--font-mono); font-size: 12px; }

/* ============================================================
   Footer
   ============================================================ */
.footer-note {
  margin-top: 40px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
  color: var(--text-faint);
  font-size: 12px;
  display: flex; gap: 8px; flex-wrap: wrap;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
  .content { padding: 20px 16px 48px; }
  .overview-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-tile { padding: 14px; gap: 10px; }
  .sites-grid { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
}
