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

:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --card-border: #e2e8f0;
  --sidebar-bg: #f8fafc;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --accent: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --radius: 10px;
  --topbar-h: 56px;
  --sidebar-w: 500px;
  --chart-grid: #e2e8f0;
  --chart-text: #64748b;
  --hover-bg: #f1f5f9;
  --table-hover: rgba(0,0,0,0.02);
  --tab-hover: rgba(0,0,0,0.04);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --card-border: #334155;
  --sidebar-bg: #1a2332;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --chart-grid: #1e293b;
  --chart-text: #64748b;
  --hover-bg: #253347;
  --table-hover: rgba(255,255,255,0.03);
  --tab-hover: rgba(255,255,255,0.05);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow: hidden;
}

/* ── Top Bar ───────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--card-border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

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

.topbar-logo { width: 32px; height: 32px; }

.topbar-title {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
}

.topbar-center {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 24px;
}

.search-input {
  width: 100%;
  max-width: 400px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }

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

.group-filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}

.group-badge {
  padding: 4px 12px;
  border: 1px solid var(--card-border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.group-badge:hover {
  border-color: var(--accent);
  color: var(--text);
}

.group-badge.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.live-dot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--green);
  font-weight: 600;
}

.live-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Layout ────────────────────────────────────────── */

.layout {
  display: flex;
  margin-top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}

/* ── Sidebar ───────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--card-border);
}

.sidebar-title { font-weight: 600; font-size: 0.9rem; }

.sidebar-count {
  font-size: 0.78rem;
  background: var(--card-border);
  padding: 2px 8px;
  border-radius: 10px;
  color: var(--text-muted);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-loading {
  text-align: center;
  padding: 40px 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ── Site Card (sidebar) ───────────────────────────── */

.site-card {
  background: var(--card);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.site-card:hover {
  border-color: var(--card-border);
  background: var(--hover-bg);
}

.site-card.selected { border-color: var(--accent); }

.site-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.site-card-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  min-width: 0;
}

.site-card-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-up { background: var(--green); }
.dot-down { background: var(--red); }
.dot-unknown { background: var(--text-dim); }

.site-card-status {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-up { color: var(--green); }
.status-down { color: var(--red); }
.status-unknown { color: var(--text-dim); }

.site-card-url {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mini uptime bar */
.mini-uptime-bar {
  display: flex;
  gap: 1px;
  height: 14px;
  margin-bottom: 8px;
  border-radius: 2px;
  overflow: hidden;
}

.mini-bar { flex: 1; min-width: 0; }
.mini-bar-ok { background: var(--green); }
.mini-bar-warn { background: var(--yellow); }
.mini-bar-down { background: var(--red); }
.mini-bar-none { background: var(--card-border); }

/* Badge row */
.site-card-badges {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.badge {
  flex: 1;
  text-align: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid var(--card-border);
}

.badge-avail { color: var(--green); }
.badge-avail:hover { background: rgba(34, 197, 94, 0.12); }
.badge-avail.degraded { color: var(--yellow); }
.badge-avail.down { color: var(--red); }

.badge-visitors { color: var(--accent); }
.badge-visitors:hover { background: rgba(59, 130, 246, 0.12); }

.site-card-time {
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* ── Main Content ──────────────────────────────────── */

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.view { display: block; }
.view.hidden { display: none; }

.view-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 20px;
}

/* ── Cards ─────────────────────────────────────────── */

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--card-border);
}

.card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-muted);
}

/* ── Overview Stats ────────────────────────────────── */

.overview-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.o-stat-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}

.o-stat-value {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.o-stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

/* ── Detail Header ─────────────────────────────────── */

.detail-header { margin-bottom: 16px; }

.btn-back {
  padding: 4px 12px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  margin-bottom: 8px;
}

.btn-back:hover { background: var(--card); color: var(--text); }

.detail-site-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.detail-dot { width: 10px; height: 10px; border-radius: 50%; }

.detail-name { font-size: 1.1rem; font-weight: 700; }

.detail-status {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
}

.detail-url { font-size: 0.78rem; color: var(--text-dim); margin-bottom: 8px; }

/* ── Visitor Top (2-column) ────────────────────────── */

.visitor-top {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 16px;
}

.visitor-top-left .btn-back { margin-bottom: 6px; }
.visitor-top-left .detail-url { margin-bottom: 10px; }

.visitor-top-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}

.visitor-stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
}

.vs-stat {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.vs-stat-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.vs-stat-icon svg { width: 18px; height: 18px; }

.vs-stat-icon-pv { background: rgba(59,130,246,0.12); color: #3b82f6; }
.vs-stat-icon-v { background: rgba(245,158,11,0.12); color: #f59e0b; }
.vs-stat-icon-ppv { background: rgba(168,85,247,0.12); color: #a855f7; }
.vs-stat-icon-online { background: rgba(34,197,94,0.12); color: #22c55e; }

.vs-stat-body { min-width: 0; }
.vs-stat-val { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.vs-stat-lbl {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 1px;
}

.vs-stat-online .vs-stat-icon-online { background: rgba(34,197,94,0.18); }
.vs-stat-online .vs-stat-val { color: var(--green); }

/* ── Range Tabs ────────────────────────────────────── */

.range-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.range-tab {
  padding: 5px 14px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}

.range-tab:hover { border-color: var(--accent); color: var(--text); }

.range-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Uptime Stat Cards ─────────────────────────────── */

.uptime-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card-sm { text-align: center; padding: 14px; }
.stat-value-sm { font-size: 1.5rem; font-weight: 700; }

.stat-label-sm {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Bar Chart (uptime) ───────────────────────────── */

.bar-chart {
  display: flex;
  gap: 1px;
  align-items: end;
  height: 40px;
  width: 100%;
  margin-bottom: 4px;
}

.bar-chart .bar {
  flex: 1;
  border-radius: 1px;
  min-height: 2px;
  transition: opacity 0.15s;
}

.bar-chart .bar:hover { opacity: 0.7; }

.bar-ok { background: #2ecc71; }
.bar-warn { background: #f39c12; }
.bar-down { background: #e74c3c; }
.bar-none { background: var(--card-border); }

.bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* ── Incidents ─────────────────────────────────────── */

.incidents-list { max-height: 400px; overflow-y: auto; }

.incident {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 6px;
  border-left: 3px solid var(--red);
  background: rgba(239, 68, 68, 0.06);
}

.incident.resolved {
  border-left-color: var(--green);
  background: rgba(34, 197, 94, 0.06);
}

.incident-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.incident-name { font-weight: 600; font-size: 0.85rem; }

.incident-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.badge-ongoing { background: rgba(239, 68, 68, 0.15); color: var(--red); }
.badge-resolved { background: rgba(34, 197, 94, 0.15); color: var(--green); }

.incident-details { font-size: 0.78rem; color: var(--text-muted); }

/* ── Today Panel ───────────────────────────────────── */

.today-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.today-header .range-tabs { margin-bottom: 0; }

.today-date { font-size: 0.82rem; color: var(--text-muted); }

.today-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.today-stats {
  display: flex;
  align-items: center;
  gap: 14px;
}

.today-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 4px;
  border-radius: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  border: 1px solid var(--card-border);
  background: var(--card);
}

.today-chip svg {
  width: 16px;
  height: 16px;
  padding: 2px;
  border-radius: 4px;
  flex-shrink: 0;
}

.today-chip b {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-right: 1px;
}

.tc-pv svg { background: rgba(59,130,246,0.12); color: #3b82f6; }
.tc-v svg { background: rgba(245,158,11,0.12); color: #f59e0b; }
.tc-nv svg { background: rgba(168,85,247,0.12); color: #a855f7; }
.tc-ppv svg { background: rgba(59,130,246,0.12); color: #6366f1; }
.tc-online svg { background: rgba(34,197,94,0.12); color: #22c55e; }

/* ── Compare Toggle Row ────────────────────────────── */

.compare-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.compare-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 2px;
}

.compare-btn {
  padding: 3px 10px;
  border: 1px solid var(--card-border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.compare-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.compare-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Charts ────────────────────────────────────────── */

.chart-wrap { position: relative; width: 100%; overflow-x: auto; }
.chart-wrap canvas { width: 100%; }

.chart-legend {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-item { display: flex; align-items: center; gap: 6px; }

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* ── Tabs ──────────────────────────────────────────── */

.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab {
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.tab:hover { background: var(--tab-hover); }
.tab.active { background: var(--accent); color: #fff; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Data Tables ───────────────────────────────────── */

.data-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }

.data-table th {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 2px solid var(--card-border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.data-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--card-border);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--table-hover); }

.data-table td:nth-child(n+2), .data-table th:nth-child(n+2) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-msg {
  text-align: center;
  padding: 24px;
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ── Embed ─────────────────────────────────────────── */

.embed-styles { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

.embed-styles button {
  padding: 5px 12px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
}

.embed-styles button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(59,130,246,0.1);
}

.embed-preview { margin-bottom: 12px; }

.embed-code {
  background: var(--bg);
  padding: 10px 14px;
  border-radius: 6px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 8px;
}

.btn-copy {
  padding: 5px 14px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
}

.btn-copy:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Responsive ────────────────────────────────────── */

@media (max-width: 900px) {
  .sidebar { width: 240px; }
  :root { --sidebar-w: 240px; }
}

@media (max-width: 700px) {
  .topbar-center { display: none; }
  .group-filters { display: none; }

  .layout { flex-direction: column; }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: 260px;
    border-right: none;
    border-bottom: 1px solid var(--card-border);
  }

  .sidebar-list {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px;
    gap: 8px;
  }

  .site-card {
    min-width: 220px;
    flex-shrink: 0;
    margin-bottom: 0;
  }

  .main-content { padding: 16px; }
  .overview-stats { grid-template-columns: 1fr 1fr; }
  .today-stats { flex-wrap: wrap; gap: 10px; }
  .visitor-top { grid-template-columns: 1fr; gap: 12px; }
  .visitor-stat-row { grid-template-columns: repeat(2, 1fr); }
  .today-toolbar { flex-direction: column; align-items: flex-start; }
}
