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

:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-focus: #93c5fd;
  --text: #0f172a;
  --text-dim: #334155;
  --text-muted: #94a3b8;
  --green: #16a34a;
  --green-bg: #f0fdf4;
  --green-border: #bbf7d0;
  --green-light: #86efac;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #fecaca;
  --red-light: #fca5a5;
  --yellow: #d97706;
  --yellow-bg: #fffbeb;
  --yellow-light: #fcd34d;
  --blue: #2563eb;
  --blue-bg: #eff6ff;
  --shadow-sm: 0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
  --shadow-md: 0 4px 16px rgba(15,23,42,0.08), 0 2px 6px rgba(15,23,42,0.05);
  --shadow-lg: 0 16px 40px rgba(15,23,42,0.12), 0 4px 12px rgba(15,23,42,0.07);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  min-height: 100vh;
  line-height: 1.5;
}

/* ── HEADER ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-left { display: flex; align-items: center; gap: 14px; }
.header-right { display: flex; align-items: center; gap: 12px; }

.logo { display: flex; align-items: center; gap: 10px; }

.logo-dot {
  width: 10px; height: 10px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--green-bg), 0 0 0 1px var(--green-border);
  animation: logo-pulse 3s ease-in-out infinite;
}

@keyframes logo-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--green-bg), 0 0 0 1px var(--green-border); }
  50% { box-shadow: 0 0 0 5px var(--green-bg), 0 0 0 1px var(--green-border); }
}

h1 { font-size: 17px; font-weight: 800; color: var(--text); letter-spacing: -0.4px; }

.badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
}

.refresh-info { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.refresh-info strong { color: var(--text-dim); }

/* ── BUTTONS ── */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--blue);
  color: white;
  box-shadow: 0 1px 3px rgba(37,99,235,0.25);
}
.btn-primary:hover { background: #1d4ed8; box-shadow: 0 2px 8px rgba(37,99,235,0.35); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--surface-2); border-color: #cbd5e1; }

/* ── MAIN ── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 28px 56px;
}

/* ── ERROR BANNER ── */
.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  color: var(--red);
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 20px;
  font-size: 13px;
  font-weight: 500;
}
.error-banner button {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  opacity: 0.6;
}
.error-banner button:hover { opacity: 1; }

/* ── STATS BAR ── */
.stats-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 32px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  gap: 0;
}

.stat-global {
  flex: 1;
  text-align: center;
  min-width: 80px;
}

.stat-global-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -1.5px;
  color: var(--text);
  line-height: 1;
  margin-bottom: 5px;
}
.stat-global-value.v-green { color: var(--green); }
.stat-global-value.v-red { color: var(--red); }
.stat-global-value.v-yellow { color: var(--yellow); }

.stat-global-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
}

.stats-divider {
  width: 1px;
  height: 44px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 8px;
}

/* ── LOADING ── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
  padding: 80px;
  font-size: 14px;
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMPTY ── */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 80px;
  color: var(--text-muted);
  text-align: center;
}
.empty-icon { font-size: 44px; }
.empty p { font-size: 15px; }

.hidden { display: none !important; }

/* ── GRID ── */
.sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

/* ── CARD ── */
.site-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, transform 0.2s;
}

.site-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.site-card.up    { border-top-color: var(--green); }
.site-card.down  { border-top-color: var(--red); }
.site-card.checking { border-top-color: #cbd5e1; }

/* CARD HEADER */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.status-dot.up {
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-bg);
  animation: pulse-dot 2.5s infinite;
}
.status-dot.down {
  background: var(--red);
  box-shadow: 0 0 0 3px var(--red-bg);
}
.status-dot.checking {
  background: #cbd5e1;
}

@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0   rgba(22, 163, 74, 0.35); }
  70%  { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); }
  100% { box-shadow: 0 0 0 0   rgba(22, 163, 74, 0); }
}

.card-title-text { min-width: 0; flex: 1; }

.card-title-text h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-url {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  transition: color 0.15s;
}
.site-url:hover { color: var(--blue); text-decoration: underline; }

.btn-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px 7px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
  transition: all 0.15s;
}
.btn-delete:hover { color: var(--red); background: var(--red-bg); }

/* STATUS BADGE */
.status-badge {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 9px 14px;
  border-radius: 8px;
  text-align: center;
  word-break: break-word;
  border: 1px solid transparent;
}
.status-badge.up {
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green-border);
}
.status-badge.down {
  background: var(--red-bg);
  color: var(--red);
  border-color: var(--red-border);
}
.status-badge.checking {
  background: var(--surface-2);
  color: var(--text-muted);
  border-color: var(--border);
}

/* STATS GRID */
.card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.stat { display: flex; flex-direction: column; gap: 3px; }

.stat-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.stat-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-value.v-muted  { color: var(--text-muted); font-weight: 400; font-size: 13px; }
.stat-value.v-green  { color: var(--green); }
.stat-value.v-red    { color: var(--red); }
.stat-value.v-yellow { color: var(--yellow); }
.stat-value.v-blue   { color: var(--blue); }

.trend-icon { font-size: 12px; }

/* SPARKLINE */
.sparkline-wrap {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.sparkline-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.sparkline {
  display: flex;
  gap: 2px;
  height: 36px;
  align-items: flex-end;
}

.sparkline-bar {
  flex: 1;
  border-radius: 3px 3px 0 0;
  min-width: 4px;
  transition: opacity 0.15s;
  cursor: default;
}
.sparkline-bar:hover { opacity: 0.65; }
.sparkline-bar.s-up   { background: var(--green-light); }
.sparkline-bar.s-slow { background: var(--yellow-light); }
.sparkline-bar.s-down { background: var(--red-light); }
.sparkline-bar.s-empty { background: var(--border); height: 30% !important; }

/* CARD FOOTER */
.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 12px;
  gap: 8px;
}

.footer-incident {
  display: flex;
  align-items: center;
  gap: 5px;
}

.incident-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green-border);
  flex-shrink: 0;
}
.incident-dot.has { background: var(--yellow); }
.incident-dot.recent { background: var(--red); }

/* ── MODAL ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow-lg);
}

.modal-content h2 {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 28px;
  letter-spacing: -0.3px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }

label { font-size: 13px; font-weight: 600; color: var(--text-dim); }

.required { color: var(--red); }
.optional { color: var(--text-muted); font-weight: 400; font-size: 11px; }
.form-hint { font-size: 11px; color: var(--text-muted); }

input[type="text"] {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
input[type="text"]:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(147,197,253,0.3);
}
input[type="text"]::placeholder { color: var(--text-muted); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 28px;
}

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .stats-bar { padding: 18px 20px; }
  .stat-global-value { font-size: 22px; }
}

@media (max-width: 640px) {
  header { padding: 0 16px; height: auto; min-height: 56px; }
  .header-content { flex-wrap: wrap; padding: 10px 0; gap: 8px; }
  .refresh-info { display: none; }
  main { padding: 16px 16px 40px; }
  .stats-bar { flex-wrap: wrap; gap: 12px; padding: 16px; }
  .stats-divider { display: none; }
  .stat-global { min-width: 40%; }
  .sites-grid { grid-template-columns: 1fr; }
  .card-stats { grid-template-columns: 1fr 1fr; }
}
