/* Awesome Electrical Grid Mapping — browser
   Minimalist dark data-map. Colours from the dataviz reference palette. */

:root {
  --plane:      #0d0d0d;   /* page / ocean */
  --surface-1:  #1a1a19;   /* panels */
  --surface-2:  #201f1d;   /* land, no data */
  --ink:        #ffffff;
  --ink-2:      #c3c2b7;
  --muted:      #898781;
  --hair:       rgba(255,255,255,0.10);
  --hair-soft:  rgba(255,255,255,0.06);

  --accent:     #3987e5;
  --violet:     #9085e9;   /* capacity data */

  --t-capacitydata: #9085e9;
  --t-map:          #3987e5;
  --t-dataset:      #199e70;
  --t-report:       #d95926;
  --t-other:        #d55181;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 12px 40px rgba(0,0,0,0.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--plane);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }

/* ---- Map ---- */
#map {
  position: absolute; inset: 0;
  background: radial-gradient(120% 120% at 50% 30%, #121214 0%, var(--plane) 70%);
  z-index: 0;
  outline: none;
}
.leaflet-container { background: transparent; font-family: var(--font); }
.leaflet-interactive:focus { outline: none; }

/* dark-theme leaflet chrome */
.leaflet-bar a {
  background: rgba(26,26,25,0.85); color: var(--ink-2);
  border-bottom: 1px solid var(--hair);
  backdrop-filter: blur(8px);
}
.leaflet-bar a:hover { background: rgba(40,40,38,0.9); color: var(--ink); }
.leaflet-bar a.home-btn { display: flex; align-items: center; justify-content: center; }
.leaflet-bar { border: 1px solid var(--hair); box-shadow: none; }
.leaflet-tooltip.lf-tip {
  background: var(--surface-1); color: var(--ink);
  border: 1px solid var(--hair); box-shadow: var(--shadow);
  font-size: 12px; font-weight: 550; padding: 4px 9px; border-radius: 8px;
}
.leaflet-tooltip.lf-tip::before { display: none; }

/* ---- Top bar ---- */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 500;
  display: flex; align-items: center; gap: 18px;
  padding: 14px 20px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text { display: flex; flex-direction: column; }
.brand .t { font-size: 15px; font-weight: 650; letter-spacing: .2px; }

.brand-logos { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.brand .logo {
  display: flex; align-items: center;
  opacity: 0.88; transition: opacity .15s;
}
.brand .logo:hover { opacity: 1; }
.brand .logo img { height: 33px; width: auto; display: block; }
.brand .logo.oet img { height: 24px; }
.brand .logo + .logo { padding-left: 6px; border-left: 1px solid var(--hair); }

.stats { display: flex; gap: 22px; margin-left: 6px; }
.stat { display: flex; flex-direction: column; }
.stat .n { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

.spacer { flex: 1; }

.search {
  position: relative; width: min(320px, 40vw);
}
.search input {
  width: 100%;
  background: rgba(26,26,25,0.82);
  backdrop-filter: blur(10px);
  border: 1px solid var(--hair);
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 12px 9px 34px;
  font-size: 13px; font-family: var(--font);
  outline: none;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--accent); }
.search .ico {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 13px; pointer-events: none;
}
.results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface-1);
  border: 1px solid var(--hair);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 46vh; overflow-y: auto;
  display: none;
}
.results.open { display: block; }
.results .r {
  padding: 8px 12px; font-size: 13px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--hair-soft);
}
.results .r:last-child { border-bottom: none; }
.results .r:hover, .results .r.active { background: rgba(57,135,229,0.14); }
.results .r .sub { color: var(--muted); font-size: 11px; }
.results .r .cnt { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-block; vertical-align: middle;
  background: rgba(26,26,25,0.82);
  backdrop-filter: blur(10px);
  border: 1px solid var(--hair);
  color: var(--ink-2);
  border-radius: 10px;
  padding: 9px 12px; font-size: 12.5px; font-family: var(--font);
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--accent); color: var(--ink); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 650;
  padding: 9px 16px;
}
.btn-primary:hover { background: #2a78d6; border-color: #2a78d6; color: #ffffff; }

.downloadwrap { position: relative; display: flex; }
.cc-badge {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  margin-top: 4px;
  display: flex; color: var(--ink); opacity: 0.85; transition: opacity .15s;
}
.cc-badge:hover { opacity: 1; }

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: none;
  background: rgba(26,26,25,0.82);
  backdrop-filter: blur(10px);
  border: 1px solid var(--hair);
  border-radius: 10px;
  color: var(--ink-2);
}
.icon-btn:hover { border-color: var(--accent); color: var(--ink); }

/* ---- Legends ---- */
.legend {
  position: absolute; left: 20px; bottom: 20px; z-index: 500;
  background: rgba(26,26,25,0.80);
  backdrop-filter: blur(10px);
  border: 1px solid var(--hair);
  border-radius: 12px;
  padding: 12px 14px;
  width: 230px;
}
.legend h4 {
  margin: 0 0 8px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .7px; color: var(--muted); font-weight: 600;
}
.legend .cov { display: flex; align-items: center; gap: 0; }
.legend .cov .sw { height: 10px; flex: 1; }
.legend .cov .sw:first-child { border-radius: 3px 0 0 3px; }
.legend .cov .sw:last-child { border-radius: 0 3px 3px 0; }
.legend .covlabels { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-top: 4px; }
.legend .hint { font-size: 10.5px; color: var(--muted); margin-top: 10px; line-height: 1.4; }

/* ---- Detail panel ---- */
.panel {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 600;
  width: min(420px, 92vw);
  background: var(--surface-1);
  border-left: 1px solid var(--hair);
  box-shadow: var(--shadow);
  transform: translateX(102%);
  transition: transform .32s cubic-bezier(.22,.61,.36,1);
  display: flex; flex-direction: column;
}
.panel.open { transform: translateX(0); }
.panel .head {
  padding: 20px 20px 14px; border-bottom: 1px solid var(--hair);
  position: relative;
}
.panel .close {
  position: absolute; top: 16px; right: 16px;
  width: 30px; height: 30px; border-radius: 8px;
  background: transparent; border: 1px solid var(--hair);
  color: var(--ink-2); cursor: pointer; font-size: 15px; line-height: 1;
}
.panel .close:hover { border-color: var(--accent); color: var(--ink); }
.panel .title { font-size: 21px; font-weight: 650; margin: 0 34px 4px 0; }
.panel .sub { font-size: 12px; color: var(--muted); }
.panel .typebar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--ink-2);
  border: 1px solid var(--hair); border-radius: 999px;
  padding: 3px 9px 3px 7px;
}
.chip .dot { width: 8px; height: 8px; border-radius: 2px; }

.panel .body { overflow-y: auto; padding: 8px 14px 28px; flex: 1; }

.group-h {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .7px;
  color: var(--muted); font-weight: 600;
  padding: 16px 6px 6px;
}

.card {
  display: block; text-decoration: none;
  background: var(--surface-2);
  border: 1px solid var(--hair-soft);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 11px 13px; margin: 6px 0;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--hair); border-left-color: var(--accent); transform: translateX(2px); }
.card .ct { font-size: 13.5px; font-weight: 550; line-height: 1.35; margin-bottom: 6px; color: var(--ink); }
.card .cmeta { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; font-size: 11px; color: var(--muted); }
.card .tags { display: flex; gap: 4px; }
.card .tag {
  font-size: 10px; padding: 1px 6px; border-radius: 999px;
  color: #0b0b0b; font-weight: 600;
}
.card .src { display: inline-flex; align-items: center; gap: 5px; }
.card .src .sdot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.card .host { color: var(--ink-2); }
.card .yr { font-variant-numeric: tabular-nums; }
.card .lic { color: var(--muted); }

.empty { color: var(--muted); font-size: 13px; padding: 40px 12px; text-align: center; }

/* scrollbars */
.body::-webkit-scrollbar, .results::-webkit-scrollbar { width: 8px; }
.body::-webkit-scrollbar-thumb, .results::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12); border-radius: 8px;
}

.loading {
  position: absolute; inset: 0; z-index: 800;
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px;
  background: var(--plane); color: var(--muted); font-size: 13px;
}
.loading .ring {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--hair); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading.hidden { display: none; }

/* ---- Responsive ---- */
.hide-sm { display: inline; }

@media (max-width: 900px) {
  .stats { display: none; }
  .hide-sm { display: none; }
  .brand .t { white-space: nowrap; }
  .search { width: min(280px, 34vw); }
}

@media (max-width: 640px) {
  .legend { display: none; }

  .topbar {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 10px 12px;
  }
  .brand .logo img { height: 26px; }
  .brand .logo.oet img { height: 19px; }

  /* search drops to a second row, sharing it with the GitHub button */
  .search { order: 10; width: calc(100% - 44px); }
  .icon-btn { order: 11; }
  /* 16px prevents iOS zoom-on-focus */
  .search input { font-size: 16px; padding-top: 10px; padding-bottom: 10px; }
  .results { max-height: 38vh; }

  /* detail panel becomes a bottom sheet */
  .panel {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: min(72vh, 560px);
    border-left: none;
    border-top: 1px solid var(--hair);
    border-radius: 16px 16px 0 0;
    transform: translateY(102%);
  }
  .panel .head { padding: 14px 16px 12px; }
  .panel .head::before {
    content: "";
    display: block;
    width: 36px; height: 4px;
    border-radius: 2px;
    background: var(--hair);
    margin: 0 auto 10px;
  }
  .panel .title { font-size: 18px; }
  .panel .close { top: 12px; right: 12px; width: 34px; height: 34px; }
  .panel .body { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
