/* history.css — layout + cards for the /history page. */

/* Header layout: brand left, refresh + conn pill right.
   Duplicated from flow.css / control.css / details.css — the rule lives per-
   page because common.css stops short of opinionated page-chrome. */
header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 28px; gap: 24px; }

/* Vertical rhythm between top-level cards on /history. */
.wrap > .card { margin-bottom: 16px; }
.wrap > .card:last-of-type { margin-bottom: 0; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pill-muted {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  padding: 3px 10px;
  letter-spacing: 0.02em;
}

.card-desc {
  margin: 2px 0 14px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Protected headline ---------- */
.status-headline {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 14px 0 18px;
}
.status-badge {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.status-badge.protected {
  color: #34d399;
}
.status-badge.not-protected {
  color: #f87171;
}
.status-badge.at-risk {
  color: #fbbf24;
}
.status-sub {
  color: var(--text-dim);
  font-size: 13px;
}

/* ---------- kv rows (reusable for both cards) ---------- */
.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 7px 0;
  border-top: 1px solid rgba(255,255,255,0.04);
  gap: 12px;
}
.kv-row:first-of-type { border-top: none; }
.kv-row .k {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}
.kv-row .v {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  text-align: right;
}
.kv-row .v.mono {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  letter-spacing: -0.01em;
}

/* ---------- Per-meter protected blocks ---------- */
.prot-per-meter {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 14px 0 18px;
}
@media (max-width: 720px) {
  .prot-per-meter { grid-template-columns: 1fr; }
}
.prot-meter-block {
  background: rgba(255,255,255,0.025);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  padding: 12px 14px;
}
.prot-meter-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.prot-meter-id {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}
.prot-meter-state {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--card-edge);
}
.prot-meter-state.active {
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.3);
  background: rgba(52, 211, 153, 0.08);
}
.prot-meter-state.idle {
  color: var(--text-dim);
}
.prot-meter-block .status-badge {
  font-size: 14px;     /* smaller than the combined-view badge */
  margin-left: auto;   /* push to right edge of the head row */
}
.prot-meter-block .kv-row {
  padding: 5px 0;
}

/* ---------- Small disclaimer under a card ---------- */
.card-disclaimer {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--card-edge);
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.5;
  letter-spacing: 0.01em;
}
.card-disclaimer code {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--text);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--card-edge);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ---------- Meters card ---------- */
.meter-card {
  margin-bottom: 16px;
}
.meter-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--card-edge);
  background: rgba(255,255,255,0.02);
  border-radius: 10px;
  margin-bottom: 10px;
  transition: border-color .2s, background .2s;
}
.meter-row.active {
  border-color: rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.05);
}
.meter-row.over-threshold {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.06);
}
.meter-row:last-child { margin-bottom: 0; }
.meter-main { flex: 1; min-width: 0; }
.meter-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.meter-active-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}
.meter-units {
  font-size: 24px;
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  margin: 2px 0 6px;
}
.meter-units-unit {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
  margin-left: 4px;
  font-family: "Inter", sans-serif;
}
.meter-sub {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
  word-break: break-all;
}
.meter-sub .unset {
  color: #6b7280;
  font-style: italic;
}
.meter-warn {
  color: #fbbf24;
  font-weight: 600;
  font-size: 12.5px;
  margin-top: 6px;
}
.meter-next {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12.5px;
  margin-top: 6px;
}
.meter-actions {
  flex-shrink: 0;
}
.btn-switch {
  background: var(--batt-soft);
  color: #0b1220;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background .15s, transform .1s;
}
.btn-switch:hover { background: #7dd3fc; }
.btn-switch:active { transform: scale(0.96); }
.btn-switch:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
.btn-switch.active-label {
  background: rgba(52, 211, 153, 0.15);
  color: #34d399;
  cursor: default;
}
.btn-switch.active-label:hover { background: rgba(52, 211, 153, 0.15); }

/* ---------- Alert banner ---------- */
.alert-banner {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #fca5a5;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-top: 10px;
}
.alert-banner.hidden { display: none; }

/* ---------- ECharts canvases ---------- */
.echart-canvas {
  width: 100%;
  height: 200px;
  margin-top: 14px;
}
.echart-canvas.tall {
  height: 280px;
}
.echart-empty {
  color: var(--text-dim);
  font-size: 13px;
  padding: 60px 0;
  text-align: center;
}

/* ---------- Chart tabs + navigation ---------- */
.chart-tabs {
  display: inline-flex;
  gap: 4px;
  margin-top: 14px;
  padding: 4px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--card-edge);
  border-radius: 10px;
}
.chart-tab {
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: transparent;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.01em;
  transition: background .15s, color .15s;
}
.chart-tab:hover:not(.active) {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}
.chart-tab.active {
  background: var(--batt-soft);
  color: #0b1220;
  font-weight: 600;
}

.chart-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.chart-nav-btn {
  width: 28px;
  height: 28px;
  padding: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chart-nav-btn svg { width: 14px; height: 14px; }
.chart-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
#chart-range-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  letter-spacing: 0.02em;
  min-width: 180px;
  text-align: center;
}

/* ---------- Monthly audit ---------- */
.audit-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.audit-sync-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.10);
  color: #7dd3fc;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.audit-sync-btn svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}
.audit-sync-btn:hover {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.55);
}
.audit-sync-btn:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}
.audit-sync-btn.hidden,
.audit-sync-status.hidden {
  display: none;
}
.audit-sync-status {
  margin: -4px 0 12px;
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.08);
  color: #7dd3fc;
  padding: 9px 12px;
  font-size: 12.5px;
  line-height: 1.4;
}
.audit-sync-status.error {
  border-color: rgba(248, 113, 113, 0.35);
  background: rgba(248, 113, 113, 0.10);
  color: #fca5a5;
}
.audit-sync-status.done {
  border-color: rgba(52, 211, 153, 0.32);
  background: rgba(52, 211, 153, 0.10);
  color: #86efac;
}
.audit-table-wrap {
  overflow-x: auto;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.audit-table th, .audit-table td {
  padding: 9px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.audit-table th:first-child, .audit-table td:first-child {
  text-align: left;
}
.audit-table thead th {
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: rgba(255,255,255,0.02);
  border-bottom: 1px solid var(--border);
}
.audit-table tbody tr:last-child td { border-bottom: none; }
.audit-table tbody tr.audit-current {
  background: rgba(56, 189, 248, 0.05);
}
.audit-month {
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
}
.audit-tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-left: 4px;
}
.audit-warn  { color: #f59e0b; font-weight: 600; }
.audit-info  { color: #38bdf8; font-weight: 600; }
.audit-mute  { color: var(--text-dim); }
.audit-dash  { color: var(--text-muted); }
.audit-drift {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  cursor: help;
}
.audit-drift.good {
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.28);
}
.audit-drift.weak {
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.28);
}

/* ---------- Load-shedding card ---------- */
.outages-window-pills {
  display: flex;
  gap: 4px;
}
.outages-pill {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.outages-pill:hover { color: var(--text); }
.outages-pill.active {
  background: rgba(248, 113, 113, 0.10);
  border-color: rgba(248, 113, 113, 0.40);
  color: #fca5a5;
}

.outages-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
}
.outages-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
}

.outages-row {
  display: grid;
  grid-template-columns: 64px 1fr 180px;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
}
.outages-date {
  color: var(--text-dim);
  font-weight: 500;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}
.outages-strip {
  position: relative;
  height: 18px;
  background: rgba(34, 197, 94, 0.06);
  border: 1px solid rgba(34, 197, 94, 0.14);
  border-radius: 4px;
  overflow: hidden;
}
.outages-row.no-data .outages-strip {
  background: rgba(255,255,255,0.02);
  border-color: rgba(255,255,255,0.05);
}
/* Vertical hour-grid: every 3h. CSS gradient avoids 7 extra DOM nodes per row. */
.outages-strip::before {
  content: "";
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(
    to right,
    transparent 0,
    transparent calc(100% / 8 - 1px),
    rgba(255,255,255,0.05) calc(100% / 8 - 1px),
    rgba(255,255,255,0.05) calc(100% / 8)
  );
  pointer-events: none;
}
.outages-bar {
  position: absolute;
  top: 1px; bottom: 1px;
  background: rgba(248, 113, 113, 0.85);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.12s;
}
.outages-bar:hover { background: #f87171; }
.outages-bar.open {
  background: repeating-linear-gradient(
    45deg,
    rgba(248, 113, 113, 0.85) 0,
    rgba(248, 113, 113, 0.85) 5px,
    rgba(248, 113, 113, 0.50) 5px,
    rgba(248, 113, 113, 0.50) 10px
  );
}
.outages-bar.continued-left { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.outages-bar.continued-right { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* Data-gap bars: time windows where we have NO sample (Mac off, BLE
   down, poll-loop gap). Distinct from outage bars so the user can tell
   "we don't know" apart from "grid was up". Hatched grey, sits below
   outage bars in z-order. */
.outages-gap {
  position: absolute;
  top: 1px; bottom: 1px;
  background: repeating-linear-gradient(
    45deg,
    rgba(255,255,255,0.05) 0,
    rgba(255,255,255,0.05) 5px,
    rgba(255,255,255,0.10) 5px,
    rgba(255,255,255,0.10) 10px
  );
  border-radius: 2px;
  cursor: help;
  z-index: 0;
}
.outages-gap:hover {
  background: repeating-linear-gradient(
    45deg,
    rgba(255,255,255,0.10) 0,
    rgba(255,255,255,0.10) 5px,
    rgba(255,255,255,0.18) 5px,
    rgba(255,255,255,0.18) 10px
  );
}
.outages-bar { z-index: 1; }
.outages-stats.no-data {
  color: var(--text-muted);
  font-style: italic;
}
.outages-stats.partial {
  color: #f59e0b;
}
.outages-stats.partial .stat-count { color: #f59e0b; }

.outages-stats {
  color: var(--text-dim);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  letter-spacing: 0.01em;
}
.outages-stats.none { color: rgba(34, 197, 94, 0.65); }
.outages-stats .stat-count { color: #fca5a5; font-weight: 600; }

.outages-axis {
  display: flex;
  justify-content: space-between;
  margin: 8px 0 0;
  padding-left: 76px;
  padding-right: 192px;
  font-size: 10.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.outages-tooltip {
  position: fixed;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.96);
  color: var(--text);
  border: 1px solid rgba(248, 113, 113, 0.30);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 11.5px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.40);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.outages-tooltip strong { color: #fca5a5; font-weight: 600; }

/* ---------- Tablet ---------- */
@media (max-width: 900px) {
  .outages-row { grid-template-columns: 56px 1fr 150px; gap: 10px; }
  .outages-stats { font-size: 11px; }
  .outages-axis { padding-left: 66px; padding-right: 162px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  header { gap: 12px; margin-bottom: 14px; align-items: center; }
  .meter-row { flex-direction: column; }
  .meter-actions { align-self: flex-end; }
  .echart-canvas { height: 180px; }
  .echart-canvas.tall { height: 220px; }
  .chart-tabs { flex-wrap: wrap; width: 100%; }
  .chart-tab { flex: 1 0 auto; padding: 6px 10px; font-size: 11.5px; }
  #chart-range-label { min-width: 0; font-size: 12px; flex: 1; }

  .outages-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .outages-date {
    font-size: 11.5px;
    color: var(--text);
  }
  .outages-stats { text-align: left; font-size: 11px; }
  .outages-axis { padding-left: 0; padding-right: 0; }
}
