/* CWEP Outage Map — styled to sit inside the cwep.com Outage Center iframe.
 * Brand: CWEP blue #004892 (settings.json logoBGColor), Open Sans (cwep.com),
 * light surface #f4f4f4 (cwep.com background).
 * Status colors from the vendor settings.json: verified #f40000, predicted
 * #f67e00, planned #70b77e, restored #354d74.
 */

@font-face {
  font-family: "Open Sans";
  src: url("vendor/fonts/opensans-var.woff2") format("woff2");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --brand: #004892;
  --brand-dark: #00366d;
  --ink: #1c2733;
  --ink-2: #5a6b7d;
  --surface: #f4f4f4;
  --card: #ffffff;
  --line: #e2e6ea;
  --verified: #f40000;
  --predicted: #f67e00;
  --planned: #70b77e;
  --restored: #354d74;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Open Sans", "Segoe UI", system-ui, Arial, sans-serif;
  background: var(--surface);
  color: var(--ink);
}

body {
  display: flex;
  flex-direction: column;
  /* dynamic viewport height: tracks the mobile URL bar showing/hiding */
  height: 100dvh;
}

/* ---- header ------------------------------------------------------------ */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  /* keep header content clear of notches / rounded corners */
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
}

#brand { display: flex; flex-direction: column; min-width: 0; }
#brand-title { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }
#brand-sub { font-size: 0.72rem; font-weight: 400; opacity: 0.8; white-space: nowrap; }

#status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  white-space: nowrap;
}

#refresh-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #7be495;
  display: inline-block;
  flex: none;
}
#refresh-dot.stale { background: #f2c94c; }
#refresh-dot.error { background: #ff6b6b; }

#fullmap-link {
  display: none;
  color: #fff;
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  white-space: nowrap;
}
#fullmap-link:hover { background: rgba(255, 255, 255, 0.12); }

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

#summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 10px 12px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 9px 4px 7px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tile-value {
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--brand);
}
.tile.alert .tile-value { color: var(--verified); }

.tile-label {
  font-size: 0.68rem;
  color: var(--ink-2);
}

/* ---- map ---------------------------------------------------------------- */

#map-wrap { flex: 1; position: relative; padding: 0 12px; min-height: 260px; }

#map {
  position: absolute;
  inset: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #dcd8d0;
}

/* scroll-hijack hint (embedded mode) */
#scroll-hint {
  position: absolute;
  inset: 0 12px;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(28, 39, 51, 0.45);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
#scroll-hint.visible { opacity: 1; }

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

#legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 9px 16px 11px;
  padding-bottom: calc(11px + env(safe-area-inset-bottom));
  font-size: 0.74rem;
  color: var(--ink-2);
}
.key { display: inline-flex; align-items: center; gap: 5px; }
.key i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* stale-data mode: hide live indicators, show the social-redirect card */
body.data-stale #refresh-dot, body.data-stale #data-age { display: none; }

/* the display:flex below would otherwise override the hidden attribute */
#stale-card[hidden] { display: none; }

#stale-card {
  position: absolute;
  inset: 0 12px;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(28, 39, 51, 0.5);
  border-radius: var(--radius);
}

.stale-inner {
  max-width: 380px;
  padding: 26px 28px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.stale-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--brand);
}

.stale-msg {
  margin: 0 0 16px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink-2);
}

.stale-btn {
  display: inline-block;
  padding: 10px 22px;
  background: var(--brand);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: 999px;
}
.stale-btn:hover { background: var(--brand-dark); }

/* ---- outage markers & popups --------------------------------------------- */

.outage-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%; height: 100%;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.95);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
}

/* status colors as classes: CSP style-src 'self' blocks inline style attrs */
.c-verified { background: var(--verified); }
.c-predicted { background: var(--predicted); }
.c-planned { background: var(--planned); }
.c-restored { background: var(--restored); }

.leaflet-popup-content-wrapper { border-radius: var(--radius); }
.leaflet-popup-content { font-family: inherit; font-size: 0.8rem; margin: 12px 14px; }
.leaflet-popup-content h3 { margin: 0 0 6px; font-size: 0.88rem; color: var(--brand); }
.leaflet-popup-content table { border-collapse: collapse; }
.leaflet-popup-content td { padding: 1px 6px 1px 0; vertical-align: top; }
.leaflet-popup-content td:first-child { color: var(--ink-2); white-space: nowrap; }

/* ---- embedded (iframe) mode ---------------------------------------------- */
/* The surrounding cwep.com page already says "Outage Center", so shrink our
 * chrome: slim header strip, tighter tiles, visible open-full-map link. */

body.embedded #topbar { padding: 6px 12px; }
body.embedded #brand-title { font-size: 0.85rem; }
body.embedded #brand-sub { display: none; }
body.embedded #fullmap-link { display: inline-block; }
body.embedded #summary { padding: 8px 10px; gap: 6px; }
body.embedded .tile { padding: 6px 4px 5px; border-radius: 8px; }
body.embedded .tile-value { font-size: 1.1rem; }
body.embedded .tile-label { font-size: 0.62rem; }
body.embedded #map-wrap { padding: 0 10px; }
body.embedded #map, body.embedded #scroll-hint, body.embedded #stale-card { inset: 0 10px; }
body.embedded #legend { padding: 7px 12px 9px; }

/* ---- narrow widths (phone / slim iframe) ---------------------------------- */

@media (max-width: 560px) {
  #topbar { gap: 8px; }
  #brand-sub { display: none; }
  #brand-title { font-size: 1rem; }
  #status { font-size: 0.7rem; }
  /* 3 readable tiles per row (wrapping to 2 rows) beats 5 unreadable ones */
  #summary { grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 8px 10px; }
  .tile { padding: 7px 4px 6px; }
  .tile-value { font-size: 1.1rem; }
  .tile-label { font-size: 0.64rem; }
  #map-wrap { padding: 0 10px; }
  #map, #scroll-hint, #stale-card { inset: 0 10px; }
  #legend { gap: 5px 10px; padding: 8px 12px 10px;
            padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

@media (max-width: 400px) {
  /* keep Total outages / Out now / Affected — the three customers care about;
     one row of tiles leaves maximum room for the map */
  .tile:nth-child(2), .tile:nth-child(4) { display: none; }
  #brand-title { font-size: 0.92rem; }
}
