:root {
  --bg: #f3f6f8;
  --panel: #ffffff;
  --ink: #12212b;
  --muted: #64727c;
  --line: #dce4e8;
  --brand: #173d5d;
  --danger: #c62828;
  --danger-dark: #9f1f1f;
  --restored: #2e7d32;
  --shadow: 0 10px 30px rgba(16, 37, 52, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

body { min-height: 100vh; }

button, input { font: inherit; }

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 22px;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
  z-index: 3;
}

.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 34px; line-height: 1; }

h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.25rem, 2vw, 1.75rem); letter-spacing: -0.02em; }
.subtitle { margin-top: 3px; font-size: .9rem; opacity: .78; }

.refresh-block {
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: right;
  white-space: nowrap;
}

.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #77d27a;
  box-shadow: 0 0 0 4px rgba(119,210,122,.14);
}
.live-dot.error { background: #ff8a80; box-shadow: 0 0 0 4px rgba(255,138,128,.14); }
.connection-label { font-size: .82rem; font-weight: 700; }
.last-updated { font-size: .76rem; opacity: .72; margin-top: 2px; }

.summary-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}

.summary-card {
  background: var(--panel);
  padding: 12px 20px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.summary-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.summary-value { font-size: 1.35rem; }

.main-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
}

.map-panel { position: relative; min-height: 600px; }
#map { position: absolute; inset: 0; }

.map-legend {
  position: absolute;
  left: 14px;
  bottom: 30px;
  z-index: 2;
  padding: 9px 11px;
  border-radius: 9px;
  background: rgba(255,255,255,.94);
  box-shadow: var(--shadow);
  font-size: .76rem;
  display: grid;
  gap: 7px;
}
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; }
.legend-dot.outage { background: var(--danger); }
.legend-dot.restored { background: var(--restored); }

.outage-panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-heading {
  padding: 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.panel-heading h2 { font-size: 1.1rem; }
.panel-heading p { margin-top: 5px; color: var(--muted); font-size: .78rem; line-height: 1.35; }

.refresh-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 7px 10px;
  cursor: pointer;
  color: var(--ink);
}
.refresh-button:hover { background: #f7f9fa; }
.refresh-button:disabled { opacity: .55; cursor: wait; }

.outage-list {
  overflow-y: auto;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.outage-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--danger);
  border-radius: 10px;
  padding: 13px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.outage-card:hover { transform: translateY(-1px); box-shadow: 0 7px 18px rgba(20,40,55,.09); }
.outage-card.restored { border-left-color: var(--restored); }

.outage-card-top { display: flex; justify-content: space-between; align-items: start; gap: 10px; }
.outage-title { font-weight: 750; }
.outage-count { font-weight: 800; color: var(--danger-dark); white-space: nowrap; }
.outage-card.restored .outage-count { color: var(--restored); }

.status-pill {
  margin-top: 8px;
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 7px;
  font-size: .7rem;
  font-weight: 700;
  background: #fdeaea;
  color: var(--danger-dark);
}
.status-pill.restored { background: #e8f5e9; color: var(--restored); }

.outage-meta {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  font-size: .77rem;
  color: var(--muted);
}

.panel-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.4;
}

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

.outage-popup { min-width: 220px; }
.outage-popup h3 { margin: 0 0 8px; font-size: 1rem; }
.outage-popup .big-count { font-size: 1.45rem; font-weight: 800; color: var(--danger-dark); }
.outage-popup .popup-row { margin-top: 7px; font-size: .8rem; color: #4e5d66; }

.maplibregl-popup-content { border-radius: 10px; box-shadow: var(--shadow); padding: 14px 16px; }
.maplibregl-ctrl-attrib { font-size: 10px; }

@media (max-width: 900px) {
  .main-grid { grid-template-columns: 1fr; grid-template-rows: minmax(55vh, 520px) auto; }
  .outage-panel { border-left: 0; border-top: 1px solid var(--line); }
  .map-panel { min-height: 520px; }
}

@media (max-width: 620px) {
  .topbar { padding: 12px 14px; }
  .brand-mark { display: none; }
  .subtitle { display: none; }
  .summary-bar { grid-template-columns: 1fr 1fr; }
  .summary-card:last-child { grid-column: 1 / -1; }
  .summary-card { padding: 9px 12px; }
  .summary-label { font-size: .67rem; }
  .summary-value { font-size: 1.05rem; }
  .refresh-block { font-size: .75rem; }
  .map-panel { min-height: 62vh; }
}


/* =========================================================
   MERIWETHER LEWIS PUBLIC BRANDING
   ========================================================= */

:root {
  --mlec-blue: #0c4164;
  --mlec-blue-dark: #082f49;
  --mlec-orange: #d84527;
  --mlec-orange-dark: #b9341d;
}


/* Override original dark header */

.topbar {
  min-height: 92px;
  padding: 15px 22px;
  background: #ffffff;
  color: var(--mlec-blue);
  border-bottom: 1px solid #d9e2e7;
  box-shadow: 0 3px 14px rgba(8, 47, 73, 0.12);
}


.brand-row {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}


.brand-logo {
  display: block;
  width: clamp(245px, 26vw, 390px);
  max-height: 58px;
  object-fit: contain;
  object-position: left center;
}


.brand-divider {
  width: 1px;
  height: 46px;
  flex: 0 0 1px;
  background: #dce4e8;
}


.brand-title-block {
  min-width: 130px;
}


.brand-title-block h1 {
  color: var(--mlec-blue);
  font-size: clamp(1.15rem, 1.7vw, 1.55rem);
  line-height: 1.05;
}


.brand-title-block .subtitle {
  color: #607480;
  opacity: 1;
  font-size: .8rem;
  margin-top: 5px;
}


.topbar-actions {
  display: flex;
  align-items: center;
  gap: 20px;
}


.ask-ai-button {
  border: 0;
  border-radius: 999px;
  background: var(--mlec-orange);
  color: #ffffff;
  padding: 10px 17px;
  font-weight: 760;
  font-size: .86rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  box-shadow: 0 5px 15px rgba(216, 69, 39, .22);
  transition:
    background .15s ease,
    transform .15s ease,
    box-shadow .15s ease;
}


.ask-ai-button:hover {
  background: var(--mlec-orange-dark);
  transform: translateY(-1px);
  box-shadow: 0 7px 18px rgba(216, 69, 39, .28);
}


.ask-ai-button:active {
  transform: translateY(0);
}


.refresh-block {
  color: var(--mlec-blue);
}


.live-dot {
  background: #45b96b;
  box-shadow: 0 0 0 4px rgba(69, 185, 107, .14);
}


.connection-label {
  color: var(--mlec-blue-dark);
}


.last-updated {
  color: #647984;
  opacity: 1;
}


/* =========================================================
   HEATMAP LEGEND
   ========================================================= */

.heat-legend {
  min-width: 165px;
}


.heat-legend-title {
  font-weight: 750;
  margin-bottom: 6px;
}


.heat-gradient {
  height: 9px;
  border-radius: 999px;
  background:
    linear-gradient(
      90deg,
      rgba(45, 212, 191, .5),
      rgb(34, 197, 94),
      rgb(250, 204, 21),
      rgb(251, 146, 60),
      rgb(239, 68, 68),
      rgb(153, 27, 27)
    );
}


.heat-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: .65rem;
  color: var(--muted);
}


.heat-privacy {
  margin-top: 7px;
  color: var(--muted);
  font-size: .67rem;
}


/* =========================================================
   ASK AI MODAL
   ========================================================= */

.ai-modal[hidden] {
  display: none;
}


.ai-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
}


.ai-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 23, 35, .52);
  backdrop-filter: blur(3px);
}


.ai-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(92vw, 620px);
  max-height: min(88vh, 720px);
  transform: translate(-50%, -50%);
  overflow: auto;

  border-radius: 18px;
  background: #ffffff;

  box-shadow:
    0 30px 80px rgba(0, 0, 0, .28);
}


.ai-dialog-header {
  padding: 20px 22px 17px;
  border-bottom: 1px solid var(--line);

  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}


.ai-eyebrow {
  color: var(--mlec-orange);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .7rem;
  font-weight: 800;
  margin-bottom: 5px;
}


.ai-dialog-header h2 {
  color: var(--mlec-blue-dark);
  font-size: 1.35rem;
}


.ai-close-button {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;

  border: 1px solid var(--line);
  border-radius: 50%;

  background: #ffffff;
  color: var(--ink);

  font-size: 1.4rem;
  line-height: 1;

  cursor: pointer;
}


.ai-close-button:hover {
  background: #f4f7f8;
}


.ai-dialog-body {
  padding: 20px 22px 22px;
}


.ai-intro {
  color: var(--muted);
  line-height: 1.5;
  font-size: .88rem;
}


.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 15px;
  margin-bottom: 19px;
}


.ai-suggestion {
  border: 1px solid #d7e1e6;
  background: #f7fafb;
  color: var(--mlec-blue);

  border-radius: 999px;
  padding: 7px 11px;

  font-size: .76rem;
  font-weight: 650;

  cursor: pointer;
}


.ai-suggestion:hover {
  border-color: #adc3cf;
  background: #eef5f8;
}


.ai-question-label {
  display: block;
  margin-bottom: 7px;

  color: var(--mlec-blue-dark);
  font-size: .78rem;
  font-weight: 750;
}


.ai-question {
  width: 100%;
  resize: vertical;
  min-height: 92px;
  max-height: 180px;

  border: 1px solid #ccd9df;
  border-radius: 11px;

  padding: 12px 13px;

  background: #ffffff;
  color: var(--ink);

  outline: none;
}


.ai-question:focus {
  border-color: var(--mlec-blue);
  box-shadow: 0 0 0 3px rgba(12, 65, 100, .1);
}


.ai-form-footer {
  margin-top: 9px;

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


.ai-character-count {
  color: var(--muted);
  font-size: .7rem;
}


.ai-submit-button {
  border: 0;
  border-radius: 9px;

  background: var(--mlec-blue);
  color: #ffffff;

  padding: 9px 14px;

  font-weight: 750;
  cursor: pointer;
}


.ai-submit-button:hover {
  background: var(--mlec-blue-dark);
}


.ai-submit-button:disabled {
  opacity: .55;
  cursor: wait;
}


.ai-status {
  min-height: 20px;
  margin-top: 12px;

  color: var(--muted);
  font-size: .78rem;
}


.ai-status.error {
  color: #a42626;
}


.ai-response {
  margin-top: 12px;
  padding: 15px 16px;

  border: 1px solid #d9e4e8;
  border-left: 4px solid var(--mlec-orange);

  border-radius: 10px;
  background: #f8fafb;
}


.ai-response-label {
  color: var(--mlec-blue);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 800;
  margin-bottom: 8px;
}


.ai-response-text {
  color: #243842;
  line-height: 1.55;
  font-size: .88rem;
  white-space: pre-wrap;
}


.ai-disclaimer {
  margin-top: 17px;
  padding-top: 13px;
  border-top: 1px solid var(--line);

  color: var(--muted);
  font-size: .7rem;
  line-height: 1.45;
}


/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 760px) {

  .topbar {
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
  }

  .brand-row {
    gap: 10px;
  }

  .brand-logo {
    width: min(55vw, 250px);
  }

  .brand-divider {
    display: none;
  }

  .brand-title-block {
    display: none;
  }

  .topbar-actions {
    gap: 9px;
    margin-left: auto;
  }

  .ask-ai-button {
    padding: 8px 12px;
    font-size: .76rem;
  }

  .refresh-block {
    font-size: .7rem;
  }

  .last-updated {
    display: none;
  }

}


@media (max-width: 480px) {

  .brand-logo {
    width: min(48vw, 205px);
  }

  .connection-label {
    font-size: .7rem;
  }

  .live-dot {
    width: 8px;
    height: 8px;
  }

  .ai-dialog {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    border-radius: 14px;
  }

  .ai-dialog-header,
  .ai-dialog-body {
    padding-left: 16px;
    padding-right: 16px;
  }

}


/* =========================================================
   ASK AI — BUTTON-ONLY PUBLIC INTERFACE
   ========================================================= */

#ai-form {
  display: none !important;
}


.ai-suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 17px;
  margin-bottom: 8px;
}


.ai-suggestion {
  width: 100%;
  min-height: 54px;

  display: flex;
  align-items: center;

  text-align: left;

  border: 1px solid #d7e1e6;
  border-radius: 12px;

  background: #f7fafb;
  color: var(--mlec-blue);

  padding: 11px 13px;

  font-size: .8rem;
  font-weight: 700;

  cursor: pointer;

  transition:
    background .15s ease,
    border-color .15s ease,
    transform .15s ease;
}


.ai-suggestion:hover {
  border-color: #9eb8c7;
  background: #eef5f8;
  transform: translateY(-1px);
}


.ai-suggestion:disabled {
  opacity: .5;
  cursor: wait;
  transform: none;
}


.ai-suggestion.report-outage {
  grid-column: 1 / -1;

  background: #fff6f2;
  border-color: rgba(216, 69, 39, .35);
  color: var(--mlec-orange-dark);
}


.ai-suggestion.report-outage:hover {
  background: #ffede6;
  border-color: var(--mlec-orange);
}


@media (max-width: 540px) {

  .ai-suggestions {
    grid-template-columns: 1fr;
  }


  .ai-suggestion.report-outage {
    grid-column: auto;
  }

}


/* Public outage summary: Active Outages only */
.summary-bar {
  grid-template-columns: 1fr !important;
}

.summary-card-primary {
  padding-left: 22px;
  padding-right: 22px;
}

@media (max-width: 620px) {
  .summary-bar {
    grid-template-columns: 1fr !important;
  }

  .summary-card-primary {
    grid-column: 1 / -1 !important;
  }
}


/* =========================================================
   PUBLIC OUTAGE MAP LAYOUT FIX
   ========================================================= */

/*
 * Desktop application fills the browser window.
 * Outage cards no longer make the entire map/page taller.
 */
@media (min-width: 901px) {

  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: 0;
  }

  .app-shell {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }

  .main-grid {
    flex: 1 1 auto;
    min-height: 0;
    height: 0;
    overflow: hidden;
  }

  .map-panel {
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }

  #map {
    position: absolute;
    inset: 0;
  }

  .outage-panel {
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .panel-heading {
    flex: 0 0 auto;
  }

  .outage-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  .panel-footer {
    flex: 0 0 auto;
  }

}


/* =========================================================
   ACTIVE OUTAGES SUMMARY
   ========================================================= */

.summary-card-primary {
  justify-content: flex-start !important;
  align-items: baseline;
  gap: 10px;
}

.summary-card-primary .summary-label {
  flex: 0 0 auto;
}

.summary-card-primary .summary-value {
  flex: 0 0 auto;
}


/* Make outage-list scrolling feel independent */
.outage-list {
  -webkit-overflow-scrolling: touch;
}


/* Keep the mobile layout usable */
@media (max-width: 900px) {

  html,
  body {
    overflow-x: hidden;
  }

  .outage-list {
    max-height: 55vh;
    overflow-y: auto;
  }

}


/* =========================================================
   POWER / MLCONNECT MODE SWITCH
   ========================================================= */

[hidden] {
  display: none !important;
}


.outage-mode-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;

  padding: 8px 18px;

  background: #f7f9fa;
  border-bottom: 1px solid var(--line);
}


.outage-mode-switch {
  display: inline-flex;

  padding: 3px;

  border: 1px solid #cfdae0;
  border-radius: 11px;

  background: #eaf0f3;
}


.outage-mode-button {
  border: 0;
  border-radius: 8px;

  padding: 8px 15px;

  display: inline-flex;
  align-items: center;
  gap: 7px;

  background: transparent;
  color: #50656f;

  font-size: .78rem;
  font-weight: 760;

  cursor: pointer;

  transition:
    background .15s ease,
    color .15s ease,
    box-shadow .15s ease;
}


.outage-mode-button.power.active {
  background: #ffffff;
  color: var(--mlec-orange-dark);

  box-shadow:
    0 2px 7px rgba(0, 0, 0, .11);
}


.outage-mode-button.mlconnect.active {
  background: #ffffff;
  color: #3159b7;

  box-shadow:
    0 2px 7px rgba(0, 0, 0, .11);
}


.outage-mode-button:hover:not(.active) {
  color: var(--mlec-blue);
}


.mode-icon {
  font-size: .85rem;
}


/* MLConnect heat / UI */

.mlconnect-card {
  border-left:
    3px solid
    rgba(79, 70, 229, .75);
}


.mlconnect-count {
  color: #4f46e5 !important;
}


.status-pill.mlconnect-pill {
  background: #eef2ff;
  color: #4338ca;
}


.mlconnect-status-block
.live-dot {
  background: #4f7ee8;

  box-shadow:
    0 0 0 4px
    rgba(79, 126, 232, .14);
}


.mlconnect-status-block
.live-dot.error {
  background: #c62828;
}


/*
 * Keep either sidebar independently scrollable.
 */
.mlconnect-outage-panel {
  min-height: 0;
  overflow: hidden;
}


.mlconnect-outage-panel
.outage-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}


@media (max-width: 620px) {

  .outage-mode-bar {
    padding:
      7px 10px;
  }


  .outage-mode-switch {
    width: 100%;
  }


  .outage-mode-button {
    flex: 1 1 50%;

    justify-content: center;

    padding:
      8px 8px;

    font-size:
      .72rem;
  }

}


/* =========================================================
   OUTAGE MODE SWITCH — HEADER PLACEMENT
   ========================================================= */

.topbar > .outage-mode-bar {
  flex: 0 0 auto;

  margin-left: auto;

  padding: 0;

  background: transparent;

  border: 0;
}


.topbar > .outage-mode-bar
.outage-mode-switch {
  background:
    rgba(255, 255, 255, .92);

  border:
    1px solid
    rgba(12, 65, 100, .16);

  box-shadow:
    0 2px 8px
    rgba(0, 0, 0, .08);
}


.topbar > .outage-mode-bar
.outage-mode-button {
  white-space: nowrap;
}


.topbar > .outage-mode-bar
.outage-mode-button.active {
  box-shadow:
    0 2px 6px
    rgba(0, 0, 0, .13);
}


@media (max-width: 980px) {

  .topbar {
    flex-wrap: wrap;
  }


  .topbar > .outage-mode-bar {
    order: 3;

    width: 100%;

    margin-left: 0;
  }


  .topbar > .outage-mode-bar
  .outage-mode-switch {
    width: 100%;
  }


  .topbar > .outage-mode-bar
  .outage-mode-button {
    flex: 1 1 50%;

    justify-content: center;
  }

}
