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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f0f4f8;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  color: #1a202c;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 560px) minmax(0, 380px);
  gap: 1.5rem;
  align-items: stretch;
  width: 100%;
  max-width: 980px;
}

.card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,.10);
  padding: 2.5rem 2rem;
  width: 100%;
  text-align: center;
}

/* ── Latency chart card ── */
.audit-card {
  --time-w: 46px;      /* left gutter: clock labels   */
  --val-w:  52px;      /* right gutter: value labels  */
  --grid:   #edf2f7;
  --track:  #f7fafc;

  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,.10);
  padding: 1.5rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: 1rem;
}

.audit-heading {
  font-size: 1rem;
  font-weight: 700;
  color: #4a5568;
  text-align: left;
}

.chart-window {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #a0aec0;
  white-space: nowrap;
}

/* Summary tiles */
.chart-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin-bottom: 1rem;
}

.stat {
  background: #f7fafc;
  border-radius: 10px;
  padding: .5rem .625rem;
}

.stat-label {
  font-size: .62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #a0aec0;
}

.stat-value {
  font-size: .95rem;
  font-weight: 600;
  color: #2d3748;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Plot area — time runs top (now) to bottom (older) */
/* Tall enough that all 20 rows clear their minimum height without overflowing */
.chart-body {
  position: relative;
  flex: 1 1 0;
  min-height: 340px;
  overflow: hidden;
}

.chart-grid {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--time-w);
  right: var(--val-w);
  border-right: 1px solid var(--grid);
  background-image: repeating-linear-gradient(
    to right, var(--grid) 0 1px, transparent 1px 25%
  );
  pointer-events: none;
}

.chart-rows {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.lat-row {
  flex: 1 1 0;
  min-height: 16px;
  display: grid;
  grid-template-columns: var(--time-w) 1fr var(--val-w);
  align-items: center;
  gap: 0;
}

.lat-time {
  font-size: .66rem;
  color: #a0aec0;
  font-variant-numeric: tabular-nums;
  padding-right: .5rem;
  text-align: right;
  white-space: nowrap;
}

.lat-track {
  position: relative;
  height: 100%;
  display: flex;
  align-items: center;
}

/* The mark: thin, anchored to the zero baseline, rounded outer end */
.lat-bar {
  height: 9px;
  min-width: 3px;
  border-radius: 0 4px 4px 0;
  background: #22c55e;
  transition: width .35s ease, background-color .35s ease;
}

.lat-fair .lat-bar { background: #f59e0b; }
.lat-poor .lat-bar { background: #ef4444; }

/* An outage fills the row with a hatched red band */
.lat-down .lat-bar {
  background: repeating-linear-gradient(
    135deg, #ef4444 0 4px, rgba(239,68,68,.35) 4px 8px
  );
}

.lat-val {
  font-size: .68rem;
  font-weight: 600;
  color: #718096;
  font-variant-numeric: tabular-nums;
  padding-left: .5rem;
  text-align: right;
  white-space: nowrap;
}

.lat-down .lat-val { color: #ef4444; }

/* Newest bucket, still filling */
.lat-live .lat-time { color: #4a5568; font-weight: 700; }
.lat-live .lat-bar  { box-shadow: 0 0 0 2px rgba(34,197,94,.18); }
.lat-live.lat-fair .lat-bar { box-shadow: 0 0 0 2px rgba(245,158,11,.18); }
.lat-live.lat-poor .lat-bar,
.lat-live.lat-down .lat-bar { box-shadow: 0 0 0 2px rgba(239,68,68,.18); }

/* Event marker — a dot in the gutter for buckets that logged something */
.lat-flag {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  margin-right: .3rem;
  vertical-align: middle;
  background: #a0aec0;
}
.lat-flag-online  { background: #22c55e; }
.lat-flag-warning { background: #f59e0b; }
.lat-flag-offline { background: #ef4444; }

/* Empty slots keep the frame steady while the window fills */
.lat-empty .lat-time,
.lat-empty .lat-val { color: #cbd5e1; }
.lat-empty .lat-bar { display: none; }

/* Tick labels sit directly under their gridline, not spread edge-to-edge */
.chart-axis {
  position: relative;
  height: 1rem;
  margin: .4rem var(--val-w) 0 var(--time-w);
  font-size: .62rem;
  color: #a0aec0;
  font-variant-numeric: tabular-nums;
}

.chart-axis span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}

.chart-axis span:nth-child(1) { left: 0;    transform: none; }
.chart-axis span:nth-child(2) { left: 50%;  }
.chart-axis span:nth-child(3) { left: 100%; transform: translateX(-100%); }

.chart-event {
  margin-top: .9rem;
  padding-top: .75rem;
  border-top: 1px solid #e2e8f0;
  font-size: .72rem;
  color: #718096;
  min-height: 1.9rem;
}

.chart-event .evt-time { color: #a0aec0; margin-right: .4rem; font-variant-numeric: tabular-nums; }
.chart-event.evt-online  .evt-msg { color: #22c55e; font-weight: 600; }
.chart-event.evt-warning .evt-msg { color: #f59e0b; font-weight: 600; }
.chart-event.evt-offline .evt-msg { color: #ef4444; font-weight: 600; }

/* ── Status section ── */
.status-section { margin-bottom: 2rem; }

.checkmark-wrap {
  width: 96px;
  height: 96px;
  margin: 0 auto 1rem;
}

.checkmark-circle {
  fill: none;
  stroke: #22c55e;
  stroke-width: 3;
  stroke-dasharray: 283;
  stroke-dashoffset: 283;
  animation: draw-circle .5s ease forwards;
}

.checkmark-check {
  fill: none;
  stroke: #22c55e;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: draw-check .4s ease .45s forwards;
}

@keyframes draw-circle {
  to { stroke-dashoffset: 0; }
}
@keyframes draw-check {
  to { stroke-dashoffset: 0; }
}

/* Offline state */
.card.offline .checkmark-circle { stroke: #ef4444; animation: none; stroke-dashoffset: 0; }
.card.offline .checkmark-check  { display: none; }
.cross-path {
  display: none;
  fill: none;
  stroke: #ef4444;
  stroke-width: 4;
  stroke-linecap: round;
}
.card.offline .cross-path { display: block; }

.status-label {
  font-size: 1.6rem;
  font-weight: 700;
  color: #22c55e;
}
.card.offline .status-label { color: #ef4444; }

.status-sub {
  font-size: .95rem;
  color: #718096;
  margin-top: .25rem;
}

/* ── Info grid ── */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem 1rem;
  text-align: left;
  margin-bottom: 2rem;
}

.info-item {
  background: #f7fafc;
  border-radius: 10px;
  padding: .75rem 1rem;
}

.info-label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #a0aec0;
  margin-bottom: .25rem;
}

.info-value {
  font-size: .95rem;
  font-weight: 500;
  color: #2d3748;
  word-break: break-all;
}

/* ── Timestamps ── */
.timestamps {
  border-top: 1px solid #e2e8f0;
  padding-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.ts-row {
  display: flex;
  justify-content: space-between;
  font-size: .82rem;
  color: #718096;
}

.ts-label { font-weight: 600; }

/* ── Version credit ── */
.version-credit {
  text-align: right;
  font-size: .7rem;
  color: #a0aec0;
  margin-top: 1rem;
}

/* ── Offline cleared field placeholder ── */
.info-value.dim { color: #cbd5e1; font-style: italic; }

/* ── Latency quality labels ── */
.quality-good { color: #22c55e; }
.quality-fair { color: #f59e0b; }
.quality-poor { color: #ef4444; }

/* ── Heartbeat countdown ring ── */
/* Sits in the "Latency to Server" label row and drains over the interval, so the
   reading below it reads as live rather than stale. Colored by the last sample.  */
.info-item-latency .info-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.hb-countdown {
  display: inline-block;
  flex: none;
  width: 14px;
  height: 14px;
  color: #22c55e;
  transition: color .3s ease;
}

.hb-countdown svg {
  display: block;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);          /* start the sweep at 12 o'clock */
}

.hb-track,
.hb-progress {
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
}

.hb-track    { opacity: .22; }
.hb-progress {
  stroke-linecap: round;
  stroke-dasharray: 50.27;            /* 2πr, r = 8 */
  stroke-dashoffset: 50.27;
}

.hb-countdown.hb-fair { color: #f59e0b; }
.hb-countdown.hb-poor { color: #ef4444; }
.hb-countdown.hb-off  { color: #94a3b8; }

.hb-countdown.is-beat { animation: hb-pulse .55s ease-out; }

@keyframes hb-pulse {
  0%   { transform: scale(1);    opacity: 1;  }
  35%  { transform: scale(1.45); opacity: .6; }
  100% { transform: scale(1);    opacity: 1;  }
}

@media (prefers-reduced-motion: reduce) {
  .hb-countdown.is-beat { animation: none; }
}

/* ── Theme toggle ── */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: none;
  border: 2px solid #cbd5e1;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4a5568;
  transition: background .2s, color .2s, border-color .2s;
  z-index: 100;
  padding: 0;
}
.theme-toggle:hover {
  background: rgba(0,0,0,.06);
}

/* ── Notification toggle (sits left of the theme toggle) ── */
.notify-toggle { right: 3.75rem; }

.notify-toggle .icon-bell           { display: none;  }
.notify-toggle .icon-bell-off       { display: block; }
.notify-toggle.is-on .icon-bell     { display: block; }
.notify-toggle.is-on .icon-bell-off { display: none;  }

.notify-toggle.is-on { border-color: #22c55e; color: #22c55e; }

.notify-toggle:disabled       { opacity: .45; cursor: not-allowed; }
.notify-toggle:disabled:hover { background: none; }

/* Light mode: show moon, hide sun */
.icon-sun  { display: none; }
.icon-moon { display: block; }

/* Dark mode: show sun, hide moon */
body.dark .icon-sun  { display: block; }
body.dark .icon-moon { display: none; }

/* ── Dark mode ── */
body.dark {
  background: #0f172a;
  color: #e2e8f0;
}

body.dark .card {
  background: #1e293b;
  box-shadow: 0 4px 24px rgba(0,0,0,.4);
}

body.dark .status-sub { color: #94a3b8; }

body.dark .info-item { background: #0f172a; }

body.dark .info-label { color: #64748b; }

body.dark .info-value { color: #cbd5e1; }

body.dark .timestamps { border-top-color: #334155; }

body.dark .ts-row { color: #94a3b8; }

body.dark .audit-card {
  --grid:  #263449;
  --track: #0f172a;
  background: #1e293b;
  box-shadow: 0 4px 24px rgba(0,0,0,.4);
}
body.dark .audit-heading { color: #94a3b8; }
body.dark .chart-window  { color: #64748b; }
body.dark .stat          { background: #0f172a; }
body.dark .stat-label    { color: #64748b; }
body.dark .stat-value    { color: #cbd5e1; }
body.dark .lat-time      { color: #64748b; }
body.dark .lat-val       { color: #94a3b8; }
body.dark .lat-live .lat-time { color: #e2e8f0; }
body.dark .lat-empty .lat-time,
body.dark .lat-empty .lat-val { color: #334155; }
body.dark .chart-axis    { color: #64748b; }
body.dark .chart-event   { color: #94a3b8; border-top-color: #334155; }
body.dark .chart-event .evt-time { color: #64748b; }

/* Dark-surface steps: lifted so the marks keep contrast against #1e293b */
body.dark .lat-bar            { background: #4ade80; }
body.dark .lat-fair .lat-bar  { background: #fbbf24; }
body.dark .lat-poor .lat-bar  { background: #f87171; }
body.dark .lat-down .lat-bar  {
  background: repeating-linear-gradient(135deg, #f87171 0 4px, rgba(248,113,113,.35) 4px 8px);
}
body.dark .lat-down .lat-val  { color: #f87171; }
body.dark .chart-event.evt-online  .evt-msg { color: #4ade80; }
body.dark .chart-event.evt-warning .evt-msg { color: #fbbf24; }
body.dark .chart-event.evt-offline .evt-msg { color: #f87171; }
body.dark .lat-flag-online  { background: #4ade80; }
body.dark .lat-flag-warning { background: #fbbf24; }
body.dark .lat-flag-offline { background: #f87171; }

body.dark .theme-toggle {
  border-color: #475569;
  color: #e2e8f0;
}
body.dark .theme-toggle:hover {
  background: rgba(255,255,255,.08);
}

body.dark .notify-toggle.is-on {
  border-color: #22c55e;
  color: #4ade80;
}

/* ── Responsive ── */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .audit-card { min-height: 480px; }
}

@media (max-width: 480px) {
  .info-grid { grid-template-columns: 1fr; }
  .ts-row { flex-direction: column; gap: .1rem; }
}
