/* ===========================================================================
   Rooftop Unit Detection — minimal, thin-line theme (dark default + light)
   Accent #2493F2 · ReCover-branded · theming via CSS variables
   =========================================================================== */
:root {
  --accent:     #2493F2;          /* fills, borders, swatches (non-text) */
  --accent-ink: #5fb0f7;          /* accent used as TEXT (contrast-safe on dark) */
  --bg:         #333333;
  --bg-2:       #3d3d3d;
  --bg-pop:     #2e2e2e;
  --map-bg:     #2a2a2a;
  --ink:        #f0f0f0;
  --ink-soft:   #c4c4c4;          /* ~6.6:1 on --bg (AA) */
  --line:       rgba(255,255,255,0.14);
  --line-2:     rgba(255,255,255,0.26);
  --track:      rgba(255,255,255,0.18);
  --thumb-bg:   #2a2a2a;
  --focus:      rgba(36,147,242,0.45);

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sidebar-w: 320px;
}

body.light {
  --accent-ink: #1366aa;          /* darker for contrast on white */
  --bg:       #ffffff;
  --bg-2:     #f1f3f4;
  --bg-pop:   #ffffff;
  --map-bg:   #e8eaec;
  --ink:      #1b2226;
  --ink-soft: #586066;            /* ~5.9:1 on white (AA) */
  --line:     rgba(0,0,0,0.12);
  --line-2:   rgba(0,0,0,0.24);
  --track:    rgba(0,0,0,0.16);
  --thumb-bg: #ffffff;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); overflow: hidden; }

#app { position: absolute; inset: 0; display: flex; }

/* ===== Sidebar ===== */
#sidebar {
  position: relative; width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--bg); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; transition: margin-left 0.25s ease; z-index: 10;
}
#mapWrap { position: relative; flex: 1 1 auto; min-width: 0; background: var(--map-bg); }
#viewDiv { position: absolute; inset: 0; }

#app.collapsed #sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
#sidebarToggle {
  position: absolute; top: 12px; right: -25px; width: 25px; height: 42px;
  border: 1px solid var(--line); border-left: none; background: var(--bg);
  color: var(--accent-ink); font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#sidebarToggle:hover { background: var(--accent); color: #fff; }
#app.collapsed #sidebarToggle { transform: rotate(180deg); }

/* brand */
#brand { position: relative; padding: 16px 18px 15px; border-bottom: 1px solid var(--line); }
.brand-logo { display: block; height: 30px; width: auto; }
.brand-titles { margin-top: 12px; padding-right: 38px; }
.brand-title { margin: 0; font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
.brand-sub { margin: 3px 0 0; font-size: 12px; color: var(--ink-soft); }

/* theme toggle */
#themeToggle {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line-2); cursor: pointer;
}
#themeToggle:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
#themeToggle svg { width: 16px; height: 16px; }

/* sections */
.sidebar-scroll { flex: 1 1 auto; overflow-y: auto; }
.sec { padding: 15px 18px; border-bottom: 1px solid var(--line); }
.sec-t { margin: 0 0 12px; font-size: 11px; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase; color: var(--ink-soft); }
.sec-note { margin: 11px 0 0; font-size: 12px; line-height: 1.5; color: var(--ink-soft); }
.sec-note b { color: var(--ink); font-weight: 600; }

/* metrics */
.stat-row { display: flex; }
.stat { flex: 1; padding-right: 14px; }
.stat + .stat { padding-right: 0; padding-left: 14px; border-left: 1px solid var(--line); }
.stat-v { display: block; font-size: 27px; font-weight: 700; color: var(--ink); line-height: 1; }
.stat-v i { font-style: normal; font-size: 15px; font-weight: 600; color: var(--accent-ink); }
.stat-l { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 13px; }
.chip { font-size: 11.5px; color: var(--ink-soft); background: var(--bg-2); padding: 3px 8px; border: 1px solid var(--line); }
.chip b { color: var(--accent-ink); font-weight: 700; }

/* layer toggles */
.toggle { display: flex; align-items: center; gap: 9px; padding: 8px 0; cursor: pointer; user-select: none; font-size: 13px; }
.layer-item + .layer-item { border-top: 1px solid var(--line); }
.toggle-sub { padding: 4px 0 9px 26px; }
.toggle-sub[hidden] { display: none; }
.elg { display: flex; align-items: center; gap: 9px; font-size: 12px; color: var(--ink-soft); padding: 3px 0; }
.elg-sw { width: 22px; height: 11px; flex: 0 0 22px; border: 2px solid; background: transparent; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .box { width: 15px; height: 15px; flex: 0 0 15px; border: 1px solid var(--line-2); display: inline-flex; align-items: center; justify-content: center; }
.toggle input:checked + .box { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .box::after { content: ""; width: 7px; height: 7px; background: #fff; }
.toggle input:focus-visible + .box { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle .sw { width: 22px; height: 12px; flex: 0 0 22px; }
.toggle .tg-label { color: var(--ink); }
.toggle.is-off .tg-label { color: var(--ink-soft); }
.tg-count { color: var(--ink-soft); font-weight: 400; }

/* About link (opens info dialog) */
.info-link { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--line); padding: 14px 18px; font: inherit; font-size: 13px; font-weight: 600; color: var(--ink); cursor: pointer; }
.info-link:hover { background: var(--bg-2); color: var(--accent-ink); }
.info-arrow { color: var(--accent-ink); font-size: 15px; }

.ctrl { margin-top: 13px; }
.ctrl-l { display: block; font-size: 12.5px; color: var(--ink); margin-bottom: 8px; }
.ctrl-v { float: right; font-weight: 700; color: var(--accent-ink); }

/* find a building */
.search-wrap { position: relative; }
#searchInput { width: 100%; height: 34px; padding: 0 9px; background: var(--bg-2); color: var(--ink); border: 1px solid var(--line-2); font-family: var(--font); font-size: 13px; }
#searchInput::placeholder { color: var(--ink-soft); }
#searchInput:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus); }
.search-results { position: absolute; left: 0; right: 0; top: 36px; z-index: 25; margin: 0; padding: 0; list-style: none; background: var(--bg-pop); border: 1px solid var(--line-2); max-height: 220px; overflow-y: auto; }
.search-results li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 9px; font-size: 12.5px; color: var(--ink); cursor: pointer; border-bottom: 1px solid var(--line); }
.search-results li:last-child { border-bottom: none; }
.search-results li:hover { background: var(--accent); color: #fff; }
.search-results li.empty, .search-results li.empty:hover { color: var(--ink-soft); cursor: default; background: var(--bg-pop); }
.search-results .r-cnt { color: var(--accent-ink); font-weight: 700; }
.search-results li:hover .r-cnt { color: #fff; }
.hl-select { width: 100%; height: 34px; margin-top: 9px; background: var(--bg-2); color: var(--ink); border: 1px solid var(--line-2); font-family: var(--font); font-size: 13px; padding: 0 8px; }
.hl-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus); }

/* legend — wide outline samples (NOT checkboxes) */
.legend { list-style: none; margin: 0; padding: 0; }
.legend li { display: flex; align-items: center; gap: 11px; padding: 6px 0; font-size: 13px; color: var(--ink); }
.lg-sw { width: 26px; height: 13px; flex: 0 0 26px; background: transparent; }
.lg-rtu { border: 2px solid var(--accent); }
.lg-bld { border: 1px solid var(--ink-soft); }
.lg-img { background: linear-gradient(135deg, #6a5f54, #8c7e6c); }

/* credit footer */
#credit { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start; gap: 9px; padding: 15px 18px; border-top: 1px solid var(--line); }
.credit-l { font-size: 11.5px; letter-spacing: 0.02em; color: var(--ink-soft); }
.credit-logo { height: 56px; width: auto; max-width: 100%; }
#brand a, #credit a { display: inline-flex; line-height: 0; text-decoration: none; }
#brand a:hover, #credit a:hover { opacity: 0.82; }
a:focus-visible, #themeToggle:focus-visible, #sidebarToggle:focus-visible, #infoClose:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===== status ===== */
.status {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #1f1f1f; color: #f0f0f0; font-size: 12.5px; font-weight: 600;
  padding: 7px 14px; z-index: 30; border-left: 3px solid var(--accent); transition: opacity 0.4s ease;
}
.status.hidden { opacity: 0; pointer-events: none; }
.status.error { border-left-color: #e25555; }

/* ===========================================================================
   Custom popup (ESRI popup disabled)
   =========================================================================== */
#infoPopup {
  position: absolute; z-index: 20; min-width: 178px; max-width: 244px;
  background: var(--bg-pop); border: 1px solid var(--line-2); border-top: 2px solid var(--accent);
}
#infoPopup::after {
  content: ""; position: absolute; left: 50%; bottom: -7px; transform: translateX(-50%);
  width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 7px solid var(--bg-pop);
}
#infoClose { position: absolute; top: 3px; right: 7px; background: none; border: none; color: var(--ink-soft); font-size: 18px; line-height: 1; cursor: pointer; }
#infoClose:hover { color: var(--ink); }
.ip-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); padding: 11px 22px 0 12px; }
.ip-title { font-size: 14px; font-weight: 600; color: var(--ink); padding: 1px 22px 0 12px; }
.ip-body { padding: 9px 12px 12px; }
.ip-big { font-size: 30px; font-weight: 700; color: var(--accent-ink); line-height: 1; }
.ip-big small { font-size: 15px; color: var(--ink-soft); font-weight: 600; }
.ip-sub { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); margin-top: 3px; }
.conf-bar { margin-top: 9px; height: 5px; background: var(--track); }
.conf-bar > i { display: block; height: 100%; background: var(--accent); }
.count-badge { display: inline-flex; align-items: baseline; gap: 5px; padding: 5px 11px; font-weight: 700; font-size: 21px; }
.count-badge small { font-size: 10px; font-weight: 600; opacity: 0.85; }
.ip-meta { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; line-height: 1.5; color: var(--ink-soft); }
.ip-meta b { color: var(--ink); font-weight: 600; }

/* ===========================================================================
   ESRI widget restyle — flat; map-corner buttons stay dark (work on both basemaps)
   =========================================================================== */
.esri-widget, .esri-component { font-family: var(--font); }
.esri-widget--button { border-radius: 0 !important; box-shadow: none !important; }
.esri-widget--button:hover { background: var(--accent); color: #fff; }
.esri-ui .esri-widget { box-shadow: none !important; border-radius: 0 !important; }
.esri-slider__track { background: var(--track); }
.esri-slider__segment-1 { background: var(--accent); }
.esri-slider__thumb { border-radius: 50% !important; box-shadow: none !important; border: 2px solid var(--accent); background: var(--thumb-bg); width: 16px; height: 16px; }
.esri-slider__anchor:focus .esri-slider__thumb { box-shadow: 0 0 0 3px var(--focus) !important; }
.esri-slider__label, .esri-slider__max, .esri-slider__min { font-size: 11px; color: var(--ink-soft); }
.esri-attribution { font-family: var(--font); }

/* ===== Info dialog ===== */
.dialog { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.dialog[hidden] { display: none; }
.dialog-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.dialog-card { position: relative; width: min(520px, calc(100vw - 40px)); max-height: 82vh; overflow-y: auto; background: var(--bg); color: var(--ink); border: 1px solid var(--line-2); border-top: 3px solid var(--accent); padding: 20px 24px 24px; }
.dialog-close { position: absolute; top: 9px; right: 12px; background: none; border: none; color: var(--ink-soft); font-size: 24px; line-height: 1; cursor: pointer; }
.dialog-close:hover { color: var(--ink); }
.dialog-badge { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: #fff; background: var(--accent); padding: 2px 9px; }
.dialog-title { margin: 9px 0 2px; font-size: 19px; font-weight: 700; color: var(--ink); }
.dialog-lede { margin: 6px 0 8px; font-size: 13px; line-height: 1.5; color: var(--ink-soft); }
.acc { border-top: 1px solid var(--line); }
.acc-h { width: 100%; text-align: left; background: none; border: none; padding: 11px 26px 11px 0; font: inherit; font-size: 13.5px; font-weight: 600; color: var(--ink); cursor: pointer; position: relative; }
.acc-h::after { content: "+"; position: absolute; right: 2px; top: 50%; transform: translateY(-50%); font-size: 17px; font-weight: 400; color: var(--ink-soft); }
.acc-h.open::after { content: "\2212"; }
.acc-h:hover { color: var(--accent-ink); }
.acc-c { padding: 0 0 12px; }
.acc-c[hidden] { display: none; }
.acc-c p { margin: 0 0 8px; font-size: 13px; line-height: 1.55; color: var(--ink-soft); }
.acc-c p:last-child { margin-bottom: 0; }
.acc-c p b { color: var(--ink); font-weight: 600; }
.src { display: flex; flex-direction: column; gap: 1px; }
.src b { font-size: 12px; }
.link-btn, .link-inline { background: none; border: none; padding: 0; margin: 0; font: inherit; color: var(--accent-ink); cursor: pointer; text-decoration: underline; }
.link-btn:hover, .link-inline:hover { color: var(--accent); }

/* ===== Embed mode ===== */
body.embed #brand, body.embed #credit { display: none; }
body.embed #metrics .sec-note { display: none; }

/* ===== Responsive ===== */
@media (max-width: 760px) {
  :root { --sidebar-w: 100vw; }
  #app { flex-direction: column; }
  #sidebar { width: 100%; flex-basis: auto; max-height: 52%; border-right: none; border-bottom: 1px solid var(--line); }
  #app.collapsed #sidebar { margin-left: 0; margin-top: -52vh; }
  #sidebarToggle { top: auto; bottom: -1px; right: 14px; height: 24px; width: 44px; border: 1px solid var(--line); }
  #app.collapsed #sidebarToggle { transform: rotate(-90deg); }
  /* compact chrome so controls aren't crowded out on small screens */
  #brand { padding: 11px 14px 10px; }
  .brand-logo { height: 26px; }
  #credit { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 9px 14px; }
  .credit-l { font-size: 10px; }
  .credit-logo { height: 30px; }
}
