:root {
  --bg: #0f1420;
  --surface: #161d2e;
  --surface-2: #1c2438;
  --border: #262f45;
  --text: #e7ecf5;
  --text-muted: #8b93a8;
  --up: #35d399;
  --down: #ff5d6c;
  --degraded: #f5a742;
  --accent: #6c8cff;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.25);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-left: max(28px, env(safe-area-inset-left));
  padding-right: max(28px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.logo-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--up);
  box-shadow: 0 0 10px var(--up);
}

.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; }

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

.muted { color: var(--text-muted); font-size: 13px; }

.btn-icon {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 32px; height: 32px;
  cursor: pointer;
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.btn-icon:hover { background: #24304c; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 28px 60px;
  padding-left: max(28px, env(safe-area-inset-left));
  padding-right: max(28px, env(safe-area-inset-right));
  padding-bottom: max(60px, env(safe-area-inset-bottom));
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat-label { color: var(--text-muted); font-size: 13px; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 700; }

.stat-up .stat-value { color: var(--up); }
.stat-down .stat-value { color: var(--down); }

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-header h2 { font-size: 16px; font-weight: 600; margin: 0; }

.projects-list { display: flex; flex-direction: column; gap: 14px; }

/* --- Project card (groups multiple URLs) --- */
.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.project-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.project-title { display: flex; align-items: center; gap: 10px; }
.project-name { font-weight: 700; font-size: 15px; }

.project-body { display: flex; flex-direction: column; }

.url-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.url-row:first-child { border-top: none; }
.url-row:hover { background: var(--surface-2); }

.url-main { display: flex; align-items: center; gap: 12px; min-width: 0; }

.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.status-dot.up { background: var(--up); box-shadow: 0 0 8px var(--up); }
.status-dot.down { background: var(--down); box-shadow: 0 0 8px var(--down); }
.status-dot.degraded { background: var(--degraded); box-shadow: 0 0 8px var(--degraded); }
.status-dot.unknown { background: #566078; }

.url-info { min-width: 0; }
.url-label { font-weight: 600; font-size: 13.5px; }
.url-address {
  color: var(--text-muted); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 380px;
}

.url-meta { display: flex; align-items: center; gap: 20px; flex-shrink: 0; }
.meta-item { text-align: right; }
.meta-label { color: var(--text-muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; }
.meta-value { font-size: 13px; font-weight: 600; margin-top: 2px; }

.badge {
  font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.badge.up { background: rgba(53,211,153,0.15); color: var(--up); }
.badge.down { background: rgba(255,93,108,0.15); color: var(--down); }
.badge.degraded { background: rgba(245,167,66,0.15); color: var(--degraded); }
.badge.unknown { background: rgba(139,147,168,0.15); color: var(--text-muted); }

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}
.modal.hidden { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%; max-width: 640px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 15.5px; }

.modal-body { padding: 12px 20px; overflow-y: auto; }

.history-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.history-row:last-child { border-bottom: none; }
.history-time { color: var(--text-muted); }
.history-error { color: var(--down); font-size: 12px; margin-top: 2px; }

.install-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: install-banner-in 0.25s ease-out;
}
.install-banner.hidden { display: none; }

@keyframes install-banner-in {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.install-icon {
  flex-shrink: 0;
  width: 36px; height: 36px;
  border-radius: 9px;
  overflow: hidden;
}
.install-icon img { display: block; width: 100%; height: 100%; }

.install-text { flex: 1; min-width: 0; }
.install-title { font-size: 13.5px; font-weight: 700; }
.install-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.btn-install {
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-install:hover { opacity: 0.9; }

@media (max-width: 480px) {
  .install-banner { left: 12px; right: 12px; padding: 12px; gap: 10px; }
  .install-sub { display: none; }
}

@media (max-width: 720px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .url-row { flex-direction: column; align-items: flex-start; }
  .url-meta { width: 100%; justify-content: space-between; }
  .url-address { max-width: 260px; }
}

@media (max-width: 480px) {
  .topbar { padding: 12px 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .topbar h1 { font-size: 15px; }
  .muted { font-size: 12px; }

  .container { padding: 16px 16px 40px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 20px; }
  .stat-card { padding: 12px 14px; }
  .stat-value { font-size: 22px; }

  .project-header { padding: 12px 14px; }
  .project-name { font-size: 14px; }

  .url-row { padding: 12px 14px; }
  .url-address { max-width: 100%; }
  .url-meta { gap: 12px; flex-wrap: wrap; }
  .meta-item { text-align: left; }

  .modal-content { width: 94%; max-height: 88vh; }
  .modal-header { padding: 14px 16px; }
  .modal-body { padding: 10px 16px; }
}

@supports (padding: max(0px)) {
  .history-modal-content { padding-bottom: env(safe-area-inset-bottom); }
}
