* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; color: #e7eef5; }

#app {
  display: grid; height: 100vh; height: 100dvh;
  grid-template-columns: 320px 1fr 340px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top top" "left map right";
  background: #0b1622;
}

/* ── top bar: brand · biome key · map mode ─────────────────────────────── */
#topbar {
  grid-area: top; display: flex; align-items: center; gap: 18px;
  padding: 8px 16px; background: #10161f; border-bottom: 1px solid #223141;
  box-shadow: 0 2px 12px rgba(0,0,0,.35); z-index: 500;
}
.brand { font-size: 16px; font-weight: 700; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; flex: 1; }
.legend .row { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #b9c7d6; cursor: pointer; white-space: nowrap; border-radius: 4px; padding: 1px 4px; margin: 0 -4px; }
.legend .row:hover { color: #fff; }
.legend .row.active { color: #fff; background: #1c2c3b; }
.legend .chip { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.mode { display: flex; align-items: center; gap: 10px; font-size: 12px; white-space: nowrap; color: #cdd9e5; }
.mode-label { color: #8ea2b6; text-transform: uppercase; font-size: 10px; letter-spacing: .8px; }
/* segmented control (radios underneath, so it stays a real form control) */
.seg { display: inline-flex; border: 1px solid #2c3e4f; border-radius: 7px; overflow: hidden; }
.seg label { position: relative; padding: 4px 10px; cursor: pointer; color: #9fb2c4; font-size: 12px; }
.seg label + label { border-left: 1px solid #2c3e4f; }
.seg label:hover { color: #fff; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: #1f3245; color: #fff; }
.seg label:has(input:focus-visible) { outline: 2px solid #5aa9ff; outline-offset: -2px; }

/* ── panels ─────────────────────────────────────────────────────────────── */
aside { position: relative; overflow-y: auto; padding: 16px 18px; background: rgba(16,24,34,.94); transition: padding .18s ease; }
#left { grid-area: left; border-right: 1px solid #223141; }
#right { grid-area: right; border-left: 1px solid #223141; }
#app { transition: grid-template-columns .18s ease; }
#app.left-collapsed { grid-template-columns: 40px 1fr 340px; }
#app.right-collapsed { grid-template-columns: 320px 1fr 40px; }
#app.left-collapsed.right-collapsed { grid-template-columns: 40px 1fr 40px; }
aside::-webkit-scrollbar { width: 8px; }
aside::-webkit-scrollbar-thumb { background: #24333f; border-radius: 4px; }
aside { scrollbar-width: thin; scrollbar-color: #24333f transparent; }
:focus-visible { outline: 2px solid #5aa9ff; outline-offset: 1px; }

/* collapse control + collapsed rail */
.collapse-btn {
  position: absolute; top: 10px; z-index: 5; width: 22px; height: 22px;
  border: 1px solid #2c3e4f; background: #16212e; color: #b9c7d6;
  border-radius: 5px; cursor: pointer; font-size: 13px; line-height: 1; padding: 0;
}
.collapse-btn:hover { color: #fff; border-color: #3d5568; }
#left .collapse-btn { right: 10px; }
#right .collapse-btn { left: 10px; }
.rail-label { display: none; }
@media (min-width: 861px) {           /* collapsing is a wide-screen feature */
  aside.collapsed { padding: 40px 4px; overflow: hidden; }
  aside.collapsed > *:not(.collapse-btn):not(.rail-label) { display: none; }
  aside.collapsed .rail-label {
    display: block; writing-mode: vertical-rl; transform: rotate(180deg);
    margin: 0 auto; font-size: 12px; letter-spacing: 1px; color: #8ea2b6; text-transform: uppercase;
  }
  #left.collapsed .collapse-btn { right: 6px; }
  #right.collapsed .collapse-btn { left: 6px; }
}
aside h2 { margin: 0 0 3px; font-size: 15px; letter-spacing: .3px; }
#left > h2 { padding-right: 28px; }
#right > .tabs { margin-left: 28px; }              /* clear the collapse button */

/* right-panel tabs */
.tabs { display: flex; gap: 2px; margin-bottom: 10px; border-bottom: 1px solid #24333f; }
.tabs [role=tab] { font: inherit; font-size: 13px; font-weight: 650; padding: 4px 8px 7px; margin-bottom: -1px; cursor: pointer;
  background: none; border: 0; border-bottom: 2px solid transparent; color: #7f93a8; white-space: nowrap; }
.tabs [role=tab]:hover { color: #cdd9e5; }
.tabs [role=tab][aria-selected=true] { color: #e7eef5; border-bottom-color: #9fd0ff; }
.tab-count { font-size: 10px; font-weight: 600; color: #9fb2c4; background: #1c2c3b; border-radius: 8px; padding: 1px 6px; margin-left: 2px; }
.tab-count:empty { display: none; }
.sub { margin: 0 0 14px; font-size: 11.5px; line-height: 1.5; color: #9fb2c4; }
.tag { font-size: 11px; font-weight: 500; color: #7f93a8; margin-left: 4px; }
.tag.stale { color: #ffb454; cursor: help; }
.section-label { font-size: 9.5px; text-transform: uppercase; letter-spacing: .8px; color: #8ea2b6; margin: 22px 0 6px; }

#map { grid-area: map; background: #0b1622; }
.loading { grid-area: map; z-index: 600; place-self: center; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-radius: 8px; background: rgba(16,24,34,.94); border: 1px solid #24333f; font-size: 13px; color: #cdd9e5; }
.loading.error { color: #ff8a5c; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #2c3e4f; border-top-color: #9fd0ff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── left: today dashboard ─────────────────────────────────────────────── */
.global { display: flex; gap: 10px; margin-bottom: 14px; }
.global .card { flex: 1; background: #16212e; border: 1px solid #24333f; border-radius: 8px; padding: 8px 10px; }
.global .card .k { font-size: 9.5px; text-transform: uppercase; letter-spacing: .7px; color: #8ea2b6; }
.global .card .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.global .card .n { font-size: 10.5px; color: #9fb2c4; margin-top: 1px; }

.toggles-wrap { margin-bottom: 14px; }
.toggles-label { font-size: 9.5px; text-transform: uppercase; letter-spacing: .8px; color: #8ea2b6; margin-bottom: 6px; }
.toggles { display: flex; flex-wrap: wrap; gap: 5px; }
.toggles .chipbtn {
  font-family: inherit;
  display: inline-flex; align-items: center; gap: 3px; cursor: pointer; user-select: none;
  font-size: 11px; padding: 3px 8px; border-radius: 12px;
  border: 1px solid #2c3e4f; background: #131d28; color: #7f93a8;
}
.toggles .chipbtn.on { background: #1c2c3b; border-color: #3d5568; color: #e7eef5; }
.toggles .chipbtn:hover { border-color: #4a677e; }

.axis { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 10px; color: #93a6ba; font-variant-numeric: tabular-nums; margin-bottom: 8px; padding-top: 8px; border-top: 1px solid #24333f; }
.axis-mid { font-size: 8.5px; text-transform: uppercase; letter-spacing: .6px; color: #6f8296; }

.today-list { display: flex; flex-direction: column; gap: 9px; }
.trow { padding: 6px 8px; border-radius: 7px; cursor: pointer; border: 1px solid transparent; }
.trow:hover { background: #17222f; border-color: #2c3e4f; }
.trow.active { background: #1a2836; border-color: #3d5568; }
.trow-top { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.trow-top .chip { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.trow-top .tname { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trow-top .tavg { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { position: relative; height: 6px; margin: 6px 0 3px; background: #1f2c3a; border-radius: 3px; }
.bar-range { position: absolute; top: 0; height: 6px; border-radius: 3px; opacity: .85; }
.bar-avg { position: absolute; top: -2px; width: 2px; height: 10px; background: #fff; border-radius: 1px; }
.ends { display: flex; justify-content: space-between; font-size: 10px; color: #8ea2b6; font-variant-numeric: tabular-nums; }
.metrics { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 5px; font-size: 10.5px; color: #aebfce; font-variant-numeric: tabular-nums; }
.metrics span { white-space: nowrap; }
.metrics .mi { opacity: .85; margin-right: 2px; }
.metrics .uv-high { color: #ff9d5c; }

/* ── right: trend detail ────────────────────────────────────────────────── */
.detail { font-size: 13px; line-height: 1.55; border-top: 1px solid #24333f; padding-top: 12px; }
.detail.empty { display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px 24px;
  color: #7488a0; font-style: italic; font-size: 12px; border: 1px dashed #24333f; border-radius: 8px; }
/* Reserve the filled card's height (2-line names included) so hovering the list
   below never shifts it out from under the cursor. */
@media (min-width: 861px) { .detail { min-height: 288px; } }
.detail .name { font-size: 15px; font-weight: 650; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.detail .dname { flex: 1; }
.detail .unpin { flex: none; width: 22px; height: 22px; padding: 0; border-radius: 5px; border: 1px solid #2c3e4f;
  background: #16212e; color: #b9c7d6; font-size: 15px; line-height: 1; cursor: pointer; }
.detail .unpin:hover { color: #fff; border-color: #3d5568; }
.detail .swatch { width: 13px; height: 13px; border-radius: 3px; flex: none; border: 1px solid rgba(255,255,255,.3); }
.detail table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.detail td { padding: 3px 0; }
.detail td.k { color: #93a6ba; }
.detail td.v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.detail .anom.pos { color: #ff8a5c; }
.detail .anom.neg { color: #6bc6ff; }
.detail .note { margin-top: 10px; font-size: 11px; color: #7f93a8; }

/* all-biome anomaly overview (diverging bars around 0) */
.anom-list { display: flex; flex-direction: column; gap: 2px; }
.arow { display: grid; grid-template-columns: 11px minmax(0, 1fr) 90px 44px; align-items: center; gap: 7px;
  padding: 4px 6px; border-radius: 6px; cursor: pointer; font-size: 11.5px; border: 1px solid transparent; }
.arow:hover { background: #17222f; }
.arow.active { background: #1a2836; border-color: #3d5568; }
.arow .chip { width: 11px; height: 11px; border-radius: 3px; }
.arow .aname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #cdd9e5; }
.abar { position: relative; height: 8px; background: #1a2532; border-radius: 2px; }
.abar::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: #4a5d70; }
.abar-fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.aval { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.aval.pos { color: #ff8a5c; }
.aval.neg { color: #6bc6ff; }

.leaflet-interactive:hover { cursor: pointer; }

/* ── earth-activity overlay control + markers ───────────────────────────────── */
.haz-control { background: rgba(16,24,34,.94); border: 1px solid #24333f; border-radius: 8px; padding: 8px 10px; color: #e7eef5; box-shadow: 0 2px 12px rgba(0,0,0,.4); min-width: 150px; }
.haz-title { display: flex; align-items: center; gap: 4px; width: 100%; padding: 0; margin-bottom: 6px; border: 0; background: none;
  color: inherit; font: inherit; font-size: 11px; font-weight: 700; letter-spacing: .3px; cursor: pointer; text-align: left; }
.haz-caret { margin-left: auto; color: #8ea2b6; transition: transform .15s ease; }
.haz-control.folded .haz-body { display: none; }
.haz-control.folded .haz-title { margin-bottom: 0; }
.haz-control.folded .haz-caret { transform: rotate(-90deg); }
.haz-live { font-size: 8px; text-transform: uppercase; letter-spacing: 1px; color: #64d178; border: 1px solid #2f5f38; border-radius: 6px; padding: 1px 4px; margin-left: 3px; vertical-align: middle; }
.haz-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; font-size: 11.5px; }
.haz-row input { margin: 0; cursor: pointer; }
.haz-count { margin-left: auto; color: #9fb2c4; font-variant-numeric: tabular-nums; min-width: 18px; text-align: right; }
.haz-foot { margin-top: 6px; padding-top: 5px; border-top: 1px solid #24333f; font-size: 8.5px; color: #6f8296; letter-spacing: .3px; }
.leaflet-div-icon.hz-icon { display: flex; align-items: center; justify-content: center; background: transparent; border: 0; filter: drop-shadow(0 1px 1px rgba(0,0,0,.7)); }
.hz-icon span { line-height: 1; }

/* anomaly key (map, anomaly mode only) */
.anom-key { display: none; background: rgba(16,24,34,.94); border: 1px solid #24333f; border-radius: 8px; padding: 7px 10px; color: #cdd9e5; box-shadow: 0 2px 12px rgba(0,0,0,.4); }
#app.mode-anomaly .anom-key { display: block; }
.anom-key-title { font-size: 10px; text-transform: uppercase; letter-spacing: .7px; color: #8ea2b6; margin-bottom: 5px; }
.anom-key-bar { width: 170px; height: 8px; border-radius: 3px; }
.anom-key-ticks { display: flex; justify-content: space-between; margin-top: 3px; font-size: 10px; font-variant-numeric: tabular-nums; color: #9fb2c4; }

/* ── Leaflet chrome, dark-themed to match ───────────────────────────────── */
.leaflet-container { font-family: inherit; }
.leaflet-bar { border: 1px solid #24333f !important; box-shadow: 0 2px 12px rgba(0,0,0,.4) !important; }
.leaflet-bar a, .leaflet-bar a:hover { background: #16212e; color: #cdd9e5; border-bottom-color: #24333f; }
.leaflet-bar a:hover { background: #1f3245; color: #fff; }
.leaflet-bar a.leaflet-disabled { background: #111a24; color: #4a5d70; }
.leaflet-control-attribution { background: rgba(11,22,34,.75) !important; color: #7f93a8; font-size: 10px; }
.leaflet-control-attribution a { color: #9fb2c4; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: #16212e; color: #e7eef5; box-shadow: 0 3px 14px rgba(0,0,0,.5); }
.leaflet-popup-content { font-size: 12px; line-height: 1.45; }
.leaflet-popup-content small { color: #9fb2c4; }
.leaflet-container a.leaflet-popup-close-button { color: #8ea2b6; }
.leaflet-tooltip { background: #16212e; color: #e7eef5; border: 1px solid #2c3e4f; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.leaflet-tooltip-top::before { border-top-color: #2c3e4f; }
.leaflet-tooltip-bottom::before { border-bottom-color: #2c3e4f; }
.leaflet-tooltip-left::before { border-left-color: #2c3e4f; }
.leaflet-tooltip-right::before { border-right-color: #2c3e4f; }

/* ── phones / narrow windows: stack top bar → map → trend → today ───────── */
@media (max-width: 860px) {
  #app, #app.left-collapsed, #app.right-collapsed, #app.left-collapsed.right-collapsed {
    height: auto; min-height: 100vh;
    grid-template-columns: minmax(0, 1fr);       /* don't let the key's scroll row widen the page */
    grid-template-rows: auto 58vh auto auto;
    grid-template-areas: "top" "map" "right" "left";
  }
  #topbar { flex-wrap: wrap; gap: 8px 12px; padding: 8px 12px; position: sticky; top: 0; }
  .brand { order: 1; }
  .mode { order: 2; margin-left: auto; }
  .mode-label { display: none; }
  .legend { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; gap: 14px; padding-bottom: 2px; scrollbar-width: none; }
  .legend::-webkit-scrollbar { display: none; }
  aside { overflow: visible; border: 0 !important; border-top: 1px solid #223141 !important; }
  .collapse-btn { display: none; }
  #left > h2 { padding: 0; }
  #right > .tabs { margin-left: 0; }
  .haz-control { min-width: 0; }
}

/* ── earth-activity table (right panel, "Earth activity" tab) ───────────── */
.ev-filters { margin-bottom: 10px; }
.toggles .chipbtn .cnt { margin-left: 4px; font-size: 10px; color: #8ea2b6; font-variant-numeric: tabular-nums; }
.toggles .chipbtn.on .cnt { color: #cdd9e5; }
.toggles .chipbtn.empty:not(.on) { opacity: .55; }
.ev-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 11.5px; }
.ev-table th { position: sticky; top: -16px; z-index: 1; background: #111a25; text-align: left; font-weight: 600; font-size: 9.5px;
  text-transform: uppercase; letter-spacing: .6px; color: #8ea2b6; padding: 6px 4px; border-bottom: 1px solid #24333f; white-space: nowrap; }
.ev-table th[data-col] { cursor: pointer; user-select: none; }
.ev-table th[data-col]:hover { color: #e7eef5; }
.ev-table th.sorted { color: #e7eef5; }
.ev-table th.sorted::after { content: " " attr(data-dir); font-size: 8px; }
.ev-table td { padding: 5px 4px; border-bottom: 1px solid #18232f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-table .ev-ico { width: 22px; text-align: center; padding-left: 2px; padding-right: 0; }
.ev-table .ev-size { width: 58px; text-align: right; font-variant-numeric: tabular-nums; }
.ev-table .ev-size small { font-size: 9.5px; color: #8ea2b6; }
.ev-table .ev-time { width: 46px; text-align: right; font-variant-numeric: tabular-nums; color: #9fb2c4; }
.ev-table td.ev-title { white-space: normal; line-height: 1.3; }
.ev-title > div:first-child { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.ev-title .ev-biome { margin-top: 2px; font-size: 10.5px; color: #93a6ba; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-biome .chip { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 0; }
.ev-biome.none { color: #5d7084; font-style: italic; }
.ev-table tbody tr { cursor: pointer; }
.ev-table tbody tr:hover, .ev-table tbody tr.hover { background: #1a2836; }
.ev-table tbody tr.hover td:first-child { box-shadow: inset 2px 0 #9fd0ff; }
.ev-table tbody tr.off td:not(.ev-ico), .ev-table tbody tr.off .ev-biome { color: #6f8296; }
.ev-table tbody tr.off .ev-ico { opacity: .45; }
.alert { display: inline-block; padding: 0 5px; border-radius: 6px; font-size: 10px; font-weight: 600; text-transform: capitalize; }
.alert-green { color: #64d178; background: rgba(100,209,120,.12); }
.alert-orange { color: #ffa94d; background: rgba(255,169,77,.14); }
.alert-red { color: #ff6b6b; background: rgba(255,107,107,.15); }
.ev-status { padding: 18px 8px; text-align: center; font-size: 12px; font-style: italic; color: #7488a0; }

/* hover-a-row locator ring on the map */
.leaflet-div-icon.hz-ring { background: transparent; border: 0; pointer-events: none; }
.hz-ring::before, .hz-ring::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid #9fd0ff;
  box-shadow: 0 0 10px rgba(159,208,255,.7); }
.hz-ring::after { animation: ring-pulse 1.1s ease-out infinite; }
@keyframes ring-pulse { from { transform: scale(1); opacity: .9; } to { transform: scale(2.2); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .hz-ring::after { animation: none; } }
@media (max-width: 860px) { .ev-table th { top: 0; } }
