/* Uganda Power Tracker — status-page style dashboard, mobile first, no build step. */

:root {
  --green: #0b3d2e;
  --green-2: #14654a;
  --green-soft: #e8f3ee;
  --ink: #14201c;
  --muted: #5f6f68;
  --line: #e3e9e6;
  --bg: #f4f7f5;
  --card: #ffffff;
  --ok: #1f9d55;
  --ok-soft: #e6f6ec;
  --warn: #e8a33d;
  --warn-soft: #fdf3e0;
  --bad: #d64545;
  --bad-soft: #fdecec;
  --info: #2b6cb0;
  --info-soft: #e8f1fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 40, 32, .06), 0 4px 12px rgba(16, 40, 32, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--green-2); }

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

.is-hidden { display: none !important; }

/* ---------- top bar ---------- */

.topbar {
  background: var(--green);
  color: #fff;
  padding: 14px 0;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

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

.brand-mark {
  font-size: 1.6rem;
  line-height: 1;
  background: rgba(255, 255, 255, .12);
  border-radius: 10px;
  padding: 8px 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: #b9d6c9;
}

.topbar-meta {
  text-align: right;
  font-size: 0.8rem;
  color: #b9d6c9;
}

.freshness { margin: 0; display: flex; align-items: center; gap: 6px; justify-content: flex-end; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(31, 157, 85, .25);
}
.dot.is-stale { background: var(--warn); box-shadow: 0 0 0 3px rgba(232, 163, 61, .25); }
.dot.is-error { background: var(--bad); box-shadow: 0 0 0 3px rgba(214, 69, 69, .25); }

.dataset-link {
  display: inline-block;
  margin-top: 4px;
  color: #d9ece3;
  font-size: 0.78rem;
  border-bottom: 1px dotted rgba(217, 236, 227, .6);
  text-decoration: none;
}
.dataset-link:hover { color: #fff; }

/* ---------- overall banner ---------- */

.banner {
  background: var(--ok);
  color: #fff;
  padding: 16px 0;
}
.banner.is-warn { background: var(--warn); }
.banner.is-bad { background: var(--bad); }
.banner.is-info { background: var(--info); }

.banner-inner { display: flex; align-items: center; gap: 14px; }

.banner-icon {
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, .2);
  display: grid; place-items: center;
  font-size: 1.3rem; font-weight: 700;
}

.banner-text { display: flex; flex-direction: column; }
.banner-text strong { font-size: 1.05rem; }
.banner-text span { font-size: 0.85rem; opacity: .9; }

.banner-stats {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-size: 0.82rem;
}
.banner-stats div { display: flex; flex-direction: column; }
.banner-stats b { font-size: 1.15rem; line-height: 1.2; }
.banner-stats span { opacity: .85; }

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  margin-top: 18px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  border: 0;
  background: none;
  font: inherit;
  font-size: .95rem;
  color: var(--muted);
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--green); border-bottom-color: var(--green); font-weight: 600; }

.tab-count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--line);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  text-align: center;
}
.tab.is-active .tab-count { background: var(--green-soft); color: var(--green); }

/* ---------- controls ---------- */

main { padding: 18px 0 44px; }

.controls {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 18px;
}

.control-row { display: flex; gap: 12px; flex-wrap: wrap; }

.control { display: flex; flex-direction: column; gap: 5px; }
.control.grow { flex: 1 1 240px; }
.control > span { font-size: .78rem; font-weight: 600; color: var(--muted); }

.control input, .control select {
  padding: 10px 12px;
  font: inherit;
  font-size: .95rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--ink);
}
.control input:focus, .control select:focus {
  outline: 2px solid var(--green-2);
  outline-offset: 1px;
}

/* ---------- summary ---------- */

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

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .value { font-size: 1.6rem; font-weight: 700; color: var(--green); line-height: 1.1; }
.stat .label { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stat.is-bad .value { color: var(--bad); }
.stat.is-warn .value { color: var(--warn); }

/* ---------- section heads ---------- */

.section-head { margin: 6px 0 14px; }
.section-head h2 { margin: 0 0 4px; font-size: 1.1rem; color: var(--green); }
.section-note { margin: 0; font-size: .85rem; color: var(--muted); }
.mini-head { margin: 0 0 8px; font-size: .95rem; color: var(--green); }

/* ---------- unit cards ---------- */

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

.unit {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.unit-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.unit-name { font-weight: 700; font-size: 1.02rem; }
.unit-sub { font-size: .78rem; color: var(--muted); }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: #126a37; }
.pill.warn { background: var(--warn-soft); color: #8a5c07; }
.pill.bad { background: var(--bad-soft); color: #9b2c2c; }
.pill.info { background: var(--info-soft); color: #1c4e80; }
.pill.muted { background: #eef1ef; color: var(--muted); }

.unit-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.metric .num { font-weight: 700; font-size: 1.05rem; }
.metric .lbl { font-size: .74rem; color: var(--muted); }

.bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 34px;
  padding-top: 4px;
}
.bar {
  flex: 1 1 0;
  min-width: 0;
  height: 22px;
  border-radius: 2px;
  background: var(--ok);
  opacity: .85;
}
.bar.lv1 { background: var(--warn); }
.bar.lv2 { background: var(--bad); }
.bar.lv0 { background: var(--ok); }
.bar.nodata { background: #dfe5e2; opacity: 1; }
.bar.lv3 { background: var(--info); }

.bar-legend {
  display: flex;
  gap: 12px;
  font-size: .72rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.bar-legend i {
  display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px;
}

.unit-foot {
  font-size: .78rem;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 8px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- feeds ---------- */

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { color: var(--ink); }
.chip.is-active { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }

.feed { display: flex; flex-direction: column; gap: 10px; }

.entry {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--green-2);
  border-radius: var(--radius);
  padding: 13px 16px;
  box-shadow: var(--shadow);
}
.entry.ongoing { border-left-color: var(--bad); }
.entry.partial { border-left-color: var(--warn); }
.entry.completed { border-left-color: var(--ok); opacity: .82; }
.entry.scheduled { border-left-color: var(--info); }

.entry-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.entry-title { font-weight: 700; }
.entry-time { font-size: .8rem; color: var(--muted); }
.entry-where { font-size: .9rem; margin-top: 3px; }
.entry-meta { font-size: .82rem; color: var(--muted); margin-top: 3px; }

.areas { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.area {
  font-size: .76rem;
  background: var(--green-soft);
  color: var(--green);
  border: 1px solid #d5e8de;
  padding: 2px 8px;
  border-radius: 999px;
}

.day-group { margin-bottom: 22px; }
.day-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  border-bottom: 2px solid var(--green);
  padding-bottom: 5px;
  margin-bottom: 10px;
}
.day-head h3 { margin: 0; font-size: 1rem; color: var(--green); }
.day-head .wd { font-size: .82rem; color: var(--muted); }
.day-head .tag {
  margin-left: auto; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; background: var(--warn); color: #3a2a00; padding: 2px 8px; border-radius: 999px;
}

/* ---------- history ---------- */

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

.chart-row { display: flex; align-items: flex-end; gap: 8px; height: 170px; padding-top: 10px; }
.chart-col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.chart-bar {
  width: 100%;
  background: linear-gradient(180deg, var(--green-2), var(--green));
  border-radius: 4px 4px 0 0;
  min-height: 3px;
}
.chart-bar.is-empty { background: #e6ebe8; }
.chart-val { font-size: .72rem; font-weight: 700; color: var(--green); }
.chart-lbl { font-size: .7rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.history-split { display: grid; grid-template-columns: 1fr; gap: 18px; }

.month-table-wrap { overflow-x: auto; }
.month-table { width: 100%; border-collapse: collapse; font-size: .87rem; background: var(--card); }
.month-table th, .month-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.month-table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.month-table td { font-variant-numeric: tabular-nums; }
.month-table tbody tr:hover { background: #fafcfb; }

.placeholder, .notice {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--muted);
  font-size: .92rem;
}
.notice.stale { border-left: 4px solid var(--warn); color: #6b4c00; background: #fff8e8; }
.notice.error { border-left: 4px solid var(--bad); color: #8a2a2a; background: #fdf0f0; }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px 0 34px;
  color: var(--muted);
  font-size: .87rem;
}
.site-footer p { margin: 0 0 8px; }
.small { font-size: .8rem; }

@media (min-width: 760px) {
  .history-split { grid-template-columns: 1fr 1fr; }
  .banner { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
  .banner-stats { margin-top: 0; }
}

@media (max-width: 520px) {
  .topbar-meta { text-align: left; }
  .freshness { justify-content: flex-start; }
  .unit-grid { grid-template-columns: 1fr; }
}
