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

:root {
  --bg:        #080c14;
  --surface:   #0f1520;
  --surface-2: #141c2b;
  --border:    rgba(255, 255, 255, .07);
  --text:      #e2e8f0;
  --muted:     #64748b;
  --accent:    #3b82f6;
  --green:     #10b981;
  --orange:    #f59e0b;
  --red:       #ef4444;
  --purple:    #8b5cf6;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── header ─────────────────────────────────────────── */
header {
  background: rgba(15, 21, 32, .86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0 24px;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 6px 0;
}

.logo { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-icon { font-size: 22px; flex-shrink: 0; }
.logo h1 { font-size: 17px; font-weight: 700; letter-spacing: -.3px; white-space: nowrap; }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
.dot.warn {
  background: var(--orange);
  box-shadow: 0 0 8px var(--orange);
}
.dot.error {
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
  animation: pulse 1.2s infinite;
}
.dot.paused {
  background: var(--muted);
  box-shadow: none;
  animation: none;
}

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

.monitor-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(16, 185, 129, .15);
  color: #34d399;
  white-space: nowrap;
}
.monitor-pill.warn { background: rgba(245, 158, 11, .18); color: #fbbf24; }
.monitor-pill.error { background: rgba(239, 68, 68, .18); color: #f87171; }
.monitor-pill.muted { background: rgba(100, 116, 139, .18); color: #94a3b8; }

#last-updated, #refresh-countdown { font-variant-numeric: tabular-nums; }

.header-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .03);
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
  line-height: 1.4;
  white-space: nowrap;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── main ────────────────────────────────────────────── */
main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 32px; }

/* ── banners ─────────────────────────────────────────── */
.banner {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 16px;
}
.banner.visible { display: flex; }
.banner-error {
  background: rgba(239, 68, 68, .14);
  border: 1px solid rgba(239, 68, 68, .4);
  color: #fca5a5;
}
.banner-warn {
  background: rgba(245, 158, 11, .14);
  border: 1px solid rgba(245, 158, 11, .42);
  color: #fcd34d;
}

/* ── stat cards ──────────────────────────────────────── */
.summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.summary-bar h2 { font-size: 15px; font-weight: 600; }
.summary-date { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(0, 0, 0, .4); }
.card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}
.card-value { font-size: 30px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.card-value-text { font-size: 20px; font-weight: 700; line-height: 1.3; padding: 4px 0; overflow-wrap: anywhere; }
.card-sub { font-size: 12px; color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }

.accent { color: var(--accent); }
.green  { color: var(--green); }
.orange { color: var(--orange); }
.red    { color: var(--red); }
.muted  { color: var(--muted); }

/* ── sections & controls ─────────────────────────────── */
.section { margin-bottom: 28px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.section-title { display: flex; align-items: center; gap: 10px; }
.section-title h2 { font-size: 15px; font-weight: 600; }

.count-pill {
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, .06);
  color: var(--muted);
  padding: 2px 8px;
  border-radius: 20px;
}
.count-pill-ok   { background: rgba(16, 185, 129, .15); color: #34d399; }
.count-pill-warn { background: rgba(245, 158, 11, .16); color: #fbbf24; }
.count-pill-bad  { background: rgba(239, 68, 68, .18); color: #f87171; }

.section-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.seg-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, .02);
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 5px 12px;
  cursor: pointer;
  transition: all .15s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: rgba(59, 130, 246, .22);
  color: #93c5fd;
  font-weight: 600;
}

/* ── quality cards & 24h status bars ─────────────────── */
.quality-empty {
  padding: 16px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
}
.quality-cards {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 14px;
}
.quality-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}
.qbar-legend-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, .05);
  font-size: 11px;
  color: var(--muted);
}
.qbar-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.qbar-legend-item { display: inline-flex; align-items: center; gap: 5px; }
.qbar-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

.qbar-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 10px;
}
.qbar-axis-row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 10px;
  margin-top: 2px;
}
.qbar-axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.qbar-label { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; }
.qbar-track {
  display: grid;
  grid-template-columns: repeat(48, 1fr);
  gap: 2px;
  height: 18px;
}
.qbar-slot {
  border-radius: 3px;
  background: rgba(100, 116, 139, .25);
  transition: opacity .15s;
}
.qbar-slot:hover { opacity: .8; }
.qbar-slot.status-ok,   .qbar-swatch.status-ok   { background: var(--green); }
.qbar-slot.status-warn, .qbar-swatch.status-warn { background: var(--orange); }
.qbar-slot.status-down, .qbar-swatch.status-down { background: var(--red); }
.qbar-slot.status-none, .qbar-swatch.status-none { background: rgba(100, 116, 139, .28); }

/* ── SVG charts ──────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.chart-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}
.chart-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 10px;
}
.chart-title { font-size: 13px; font-weight: 600; color: var(--text); }
.chart-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; font-size: 11px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { display: inline-block; width: 10px; height: 3px; border-radius: 2px; }
.swatch-router     { background: #34d399; }
.swatch-v4         { background: #60a5fa; }
.swatch-v6         { background: #a78bfa; }
.swatch-dns-router { background: #fbbf24; }
.swatch-dns-ext    { background: #60a5fa; }
.swatch-http       { background: #34d399; }
.swatch-reboot     { background: none; border-top: 2px dashed #f87171; height: 0; }

.chart-svg-host { width: 100%; min-height: 170px; margin-top: auto; }
.chart-svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart-grid-line { stroke: rgba(255, 255, 255, .07); stroke-width: 1; }
.chart-vgrid-line { stroke: rgba(255, 255, 255, .04); stroke-width: 1; }
.chart-axis-text { fill: #94a3b8; font-size: 10px; font-family: inherit; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-router     { stroke: #34d399; }
.series-v4         { stroke: #60a5fa; }
.series-v6         { stroke: #a78bfa; }
.series-dns-router { stroke: #fbbf24; }
.series-dns-ext    { stroke: #60a5fa; }
.series-http       { stroke: #34d399; }
.chart-hover-line { stroke: rgba(148, 163, 184, .55); stroke-width: 1; stroke-dasharray: 3 2; pointer-events: none; }
.chart-hover-dot { stroke: var(--surface); stroke-width: 1.5; pointer-events: none; }
.dot-router     { fill: #34d399; }
.dot-v4         { fill: #60a5fa; }
.dot-v6         { fill: #a78bfa; }
.dot-dns-router { fill: #fbbf24; }
.dot-dns-ext    { fill: #60a5fa; }
.dot-http       { fill: #34d399; }
.chart-hit-area { fill: transparent; cursor: crosshair; }
.chart-readout {
  margin-top: 6px;
  min-height: 18px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.chart-readout.active { color: var(--text); }
.chart-reboot-line { stroke: #f87171; stroke-width: 1.4; stroke-dasharray: 4 3; opacity: .85; }
.chart-empty {
  padding: 48px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

/* ── tables ──────────────────────────────────────────── */
.tbl-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow-y: auto;
  overflow-x: auto;
}
.tbl-wrap-incidents { max-height: 360px; }
.tbl-wrap-reboots   { max-height: 320px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-2);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, .04);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }

.ts-cell {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-gray   { background: rgba(100, 116, 139, .15); color: #94a3b8; }
.badge-green  { background: rgba(16, 185, 129, .15); color: #34d399; }
.badge-orange { background: rgba(245, 158, 11, .15); color: #fbbf24; }
.badge-red    { background: rgba(239, 68, 68, .15);  color: #f87171; }
.badge-blue   { background: rgba(59, 130, 246, .15); color: #60a5fa; }

.empty { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }

/* ── footer ──────────────────────────────────────────── */
.site-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 24px 36px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ── responsive ──────────────────────────────────────── */
@media (max-width: 960px) {
  .quality-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts-grid   { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  header { padding: 8px 12px; }
  .header-inner { min-height: 48px; flex-wrap: wrap; gap: 6px; }
  .logo h1 { font-size: 16px; }
  .header-right { width: 100%; justify-content: space-between; font-size: 11px; }

  main { padding: 14px 12px 24px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 20px; }
  .quality-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 13px; border-radius: 12px; }
  .card-value { font-size: 24px; }
  .card-value-text { font-size: 16px; }
  .card-sub { font-size: 11px; }

  .qbar-row { grid-template-columns: 1fr; gap: 4px; }
  .qbar-axis-row { grid-template-columns: 1fr; gap: 0; }
  .qbar-axis-spacer { display: none; }

  #incidents-table thead,
  #reboots-table thead { display: none; }

  #incidents-table, #incidents-table tbody, #incidents-table tr,
  #reboots-table, #reboots-table tbody, #reboots-table tr {
    display: block;
    width: 100%;
  }

  #incidents-table tr,
  #reboots-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 10px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
  }
  #incidents-table tr:last-child,
  #reboots-table tr:last-child { border-bottom: none; }

  #incidents-table td,
  #reboots-table td {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 0;
    border-bottom: none;
    font-size: 12px;
    min-width: 0;
  }
  #incidents-table td.empty,
  #reboots-table td.empty {
    grid-column: 1 / -1;
    justify-content: center;
    padding: 18px 0;
  }
  #incidents-table td[data-label]::before,
  #reboots-table td[data-label]::before {
    content: attr(data-label);
    font-size: 10px;
    color: var(--muted);
    font-weight: 600;
    flex-shrink: 0;
  }
  #incidents-table td:nth-child(1),
  #incidents-table td:nth-child(2),
  #incidents-table td:nth-child(4) { grid-column: 1 / -1; }
  #incidents-table td:nth-child(3) { grid-column: 1 / 2; }
  #incidents-table td:nth-child(5) { grid-column: 2 / 3; justify-content: flex-end; }
  #incidents-table td:nth-child(6) { grid-column: 1 / -1; }

  #reboots-table td:nth-child(1) { grid-column: 1 / -1; font-size: 11px; }
  #reboots-table td:nth-child(2) { grid-column: 1 / -1; }

  .site-footer { padding: 14px 12px 28px; }
}
