/* Cenco Roofing dashboard — map-first, glass floating widgets.
   Theme strictly from /vendor/apex/design/tokens.css (hellojade dark).
   Three layouts (A/B/C) share one set of DOM widgets; CSS positions them. */

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--color-bg, #0A1F1B);
  color: var(--color-fg, #F1EFE4);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }

/* ---- Full-screen map base layer ---- */
#map { position: absolute; inset: 0; z-index: 0; }
.maplibregl-ctrl-attrib { background: rgba(10,31,27,.7) !important; }
.maplibregl-ctrl-attrib a { color: var(--color-fg-muted, #B5BFB9) !important; }
.maplibregl-ctrl-group { background: var(--color-surface, #0F2A26) !important; border: 1px solid var(--color-border) !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--color-border) !important; }
.maplibregl-ctrl-zoom-in, .maplibregl-ctrl-zoom-out, .maplibregl-ctrl-compass { filter: invert(.9) hue-rotate(180deg); }

/* ---- Floating UI host ---- */
#ui { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
#ui > * { pointer-events: auto; }

/* ===== Glass card primitive ===== */
.glass {
  background: color-mix(in srgb, var(--color-surface) 78%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg, 16px);
  box-shadow: var(--shadow-md, 0 8px 28px -6px rgba(0,0,0,.6));
  color: var(--color-fg);
}

/* ===== Layout switcher ===== */
#switcher {
  position: absolute; top: 14px; right: 14px; z-index: 40;
  display: flex; gap: 4px; padding: 4px;
  background: color-mix(in srgb, var(--color-surface) 82%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--color-border); border-radius: var(--radius-pill, 9999px);
  box-shadow: var(--shadow-md);
}
#switcher button {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 0; border-radius: var(--radius-pill); background: transparent;
  color: var(--color-fg-muted); cursor: pointer;
  transition: background var(--motion-dur-fast, 120ms) var(--motion-ease-standard), color var(--motion-dur-fast) var(--motion-ease-standard);
}
#switcher button:hover { background: var(--color-surface-hover); color: var(--color-fg); }
#switcher button.active { background: var(--color-primary); color: var(--color-primary-fg); }

/* expand-card (full glass card form of a widget) is hidden by default; each
   layout opts specific ones in. Prevents the bubble cards leaking into A/C. */
.expand-card { display: none; }
/* When an expand-card is shown (any layout), it must be a vertical card that
   fills its positioned container and lets its children shrink — otherwise a bare
   `display:flex` lays head+body out as a horizontal row that overflows the
   fixed-width parent (#w-layers/#w-zip) and spills off-screen. */
.expand-card { flex-direction: column; width: 100%; min-width: 0; max-height: 100%; overflow: hidden; }
.expand-card .widget-body { min-width: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
.widget-head { min-width: 0; }
.widget-head .ttl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Generic widget chrome ===== */
.widget-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px 8px; font-size: 12px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--color-fg-muted);
}
.widget-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-primary); flex: 0 0 auto; }
.widget-body { padding: 0 14px 14px; }

/* scrollable region — content scrolls, never clips/overflows the card */
.scroll { overflow-y: auto; overscroll-behavior: contain; }
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: var(--color-border-strong); border-radius: 8px; }
.scroll::-webkit-scrollbar-track { background: transparent; }

/* ===== Stats widget ===== */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat {
  background: color-mix(in srgb, var(--color-surface-hover) 60%, transparent);
  border: 1px solid var(--color-border); border-radius: var(--radius-md, 10px);
  padding: 10px 12px;
}
.stat .num { font-size: 20px; font-weight: 700; color: var(--color-primary); line-height: 1.1; }
.stat .lbl { font-size: 11px; color: var(--color-fg-muted); margin-top: 3px; }
.stat.accent .num { color: var(--color-accent); }

/* compact chip variant (Layout A corner HUD) */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: flex; flex-direction: column; align-items: flex-start;
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  padding: 8px 12px; box-shadow: var(--shadow-sm);
}
.chip .num { font-size: 18px; font-weight: 700; color: var(--color-primary); line-height: 1; }
.chip .lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--color-fg-muted); margin-top: 4px; }
.chip.accent .num { color: var(--color-accent); }

/* ===== Layers widget ===== */
.layer-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: var(--radius-md); cursor: pointer; min-width: 0; max-width: 100%;
  transition: background var(--motion-dur-fast) var(--motion-ease-standard);
}
.layer-row:hover { background: var(--color-surface-hover); }
.layer-row .ico { width: 28px; height: 28px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 8px; background: color-mix(in srgb, var(--color-surface-hover) 70%, transparent);
  border: 1px solid var(--color-border); color: var(--color-fg-muted); }
.layer-row.on .ico { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-primary-fg); }
.layer-row .meta { flex: 1 1 0; min-width: 0; width: 0; overflow: hidden; }
.layer-row .name { display: block; font-size: 13px; font-weight: 600; color: var(--color-fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.layer-row .sub { display: block; font-size: 11px; color: var(--color-fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
/* toggle pill */
.toggle { width: 34px; height: 18px; flex: 0 0 auto; border-radius: 9999px; background: var(--color-border-strong);
  position: relative; transition: background var(--motion-dur-base) var(--motion-ease-standard); }
.toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--color-fg); transition: transform var(--motion-dur-base) var(--motion-ease-spring); }
.layer-row.on .toggle { background: var(--color-primary); }
.layer-row.on .toggle::after { transform: translateX(16px); background: var(--color-primary-fg); }

/* service select */
.svc-select { width: 100%; margin-top: 8px; padding: 8px 10px; font-size: 13px;
  background: color-mix(in srgb, var(--color-surface-hover) 60%, transparent); color: var(--color-fg);
  border: 1px solid var(--color-border); border-radius: var(--radius-md); cursor: pointer; }
.svc-select:disabled { opacity: .4; cursor: not-allowed; }

/* legend */
.legend { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--color-border); }
.legend-title { font-size: 11px; color: var(--color-fg-muted); margin-bottom: 6px; }
.legend-bar { height: 10px; border-radius: 9999px; }
.legend-scale { display: flex; justify-content: space-between; font-size: 10px; color: var(--color-fg-subtle); margin-top: 4px; }

/* ===== ZIP detail widget ===== */
.zip-detail .zh { display: flex; align-items: baseline; gap: 8px; }
.zip-detail .zh .code { font-size: 22px; font-weight: 700; color: var(--color-fg); letter-spacing: -.5px; }
.zip-detail .zh .name { font-size: 13px; color: var(--color-fg-muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zip-detail .kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.zip-detail .kpi { background: color-mix(in srgb, var(--color-surface-hover) 55%, transparent);
  border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 8px 10px; }
.zip-detail .kpi .v { font-size: 17px; font-weight: 700; color: var(--color-primary); }
.zip-detail .kpi.gold .v { color: var(--color-accent); }
.zip-detail .kpi .k { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--color-fg-muted); margin-top: 2px; }
.sec { margin-top: 12px; }
.sec h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--color-fg-muted); margin: 0 0 6px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 9999px; background: color-mix(in srgb, var(--color-surface-hover) 70%, transparent);
  border: 1px solid var(--color-border); color: var(--color-fg); }
.pill.svc { border-color: var(--color-primary); color: var(--color-primary); }
.nbhd-list { list-style: none; margin: 0; padding: 0; max-height: 160px; }
.nbhd-list li { display: flex; align-items: center; gap: 8px; padding: 5px 2px; font-size: 13px; color: var(--color-fg);
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 60%, transparent); }
.nbhd-list li:last-child { border-bottom: 0; }
.nbhd-list li .src { font-size: 10px; color: var(--color-fg-subtle); margin-left: auto; flex: 0 0 auto; text-transform: uppercase; }
.muted { color: var(--color-fg-muted); font-size: 13px; }
.empty { color: var(--color-fg-subtle); font-size: 13px; padding: 6px 0; }

/* spinner */
.spin { width: 18px; height: 18px; border: 2px solid var(--color-border-strong); border-top-color: var(--color-primary);
  border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: 8px; color: var(--color-fg-muted); font-size: 13px; padding: 6px 0; }

/* close button */
.x-btn { margin-left: auto; width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--color-border);
  background: transparent; color: var(--color-fg-muted); cursor: pointer; display: grid; place-items: center; }
.x-btn:hover { background: var(--color-surface-hover); color: var(--color-fg); }

/* ============================================================
   LAYOUT A — Corner HUD + bottom drawer
   ============================================================ */
.layout-a #w-stats { position: absolute; top: 14px; left: 14px; width: auto; }
.layout-a #w-stats .chips { display: flex; }               /* chips, not the full card */
.layout-a #w-layers { position: absolute; top: 62px; right: 14px; width: 290px; max-width: calc(100vw - 28px); }
.layout-a #w-layers .layers-card { display: flex; }
.layout-a #w-zip .zip-card { display: flex; }
.layout-a #w-stats .pill-btn { display: none; }
.layout-a #w-zip {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 720px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  transform: translateY(110%); transition: transform var(--motion-dur-slow, 360ms) var(--motion-ease-emphasized);
  max-height: 56vh; display: flex; flex-direction: column;
}
.layout-a #w-zip.open { transform: translateY(0); }
.layout-a #w-zip .zip-scroll { overflow-y: auto; }
.layout-a #w-search { display: none; }
.layout-a #rail { display: none; }

/* ============================================================
   LAYOUT B — Floating draggable bubbles
   ============================================================ */
.layout-b .bubble { position: absolute; }
.layout-b #w-stats { left: 16px; top: 70px; }
.layout-b #w-layers { right: 16px; top: 70px; }
.layout-b #w-zip { left: 50%; top: 40%; }
.layout-b #w-search { display: none; }
.layout-b #rail { display: none; }
.layout-b .chips { display: none; }

/* collapsed pill */
.bubble .pill-btn {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; cursor: grab;
  border-radius: var(--radius-pill); font-size: 13px; font-weight: 600; color: var(--color-fg);
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--color-border); box-shadow: var(--shadow-md);
  transition: background var(--motion-dur-fast) var(--motion-ease-standard);
}
.bubble .pill-btn:hover { background: var(--color-surface-hover); }
.bubble .pill-btn .glyph { width: 18px; height: 18px; color: var(--color-primary); flex: 0 0 auto; }
.bubble.dragging .pill-btn { cursor: grabbing; }
.layout-b .bubble.expanded .pill-btn { display: none; }
.layout-b .bubble .expand-card { display: none; }
.layout-b .bubble.expanded .expand-card {
  display: flex; flex-direction: column; width: 300px; max-height: 60vh;
  animation: popin var(--motion-dur-base) var(--motion-ease-spring);
}
.layout-b .bubble .expand-card .drag-handle { cursor: grab; }
@keyframes popin { from { opacity: 0; transform: scale(.92) translateY(6px); } to { opacity: 1; transform: none; } }

/* ============================================================
   LAYOUT C — Top search + left icon rail + right inspector
   ============================================================ */
.layout-c #w-search { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); width: min(520px, 70vw); display: block; }
.layout-c #w-layers .layers-card, .layout-c #w-zip .zip-card { display: flex; }
.layout-c #w-layers .pill-btn, .layout-c #w-stats .pill-btn, .layout-c #w-zip .pill-btn { display: none; }
.layout-a #w-layers .pill-btn, .layout-a #w-zip .pill-btn { display: none; }
.layout-c #rail {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%); z-index: 12;
  display: flex; flex-direction: column; gap: 6px; padding: 8px;
}
.layout-c #w-stats { display: none; }   /* stats fold into inspector default / search */
.layout-c #w-zip {
  position: absolute; top: 0; right: 0; bottom: 0; width: 360px; max-width: 88vw;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  transform: translateX(110%); transition: transform var(--motion-dur-slow) var(--motion-ease-emphasized);
  display: flex; flex-direction: column;
}
.layout-c #w-zip.open { transform: translateX(0); }
.layout-c #w-zip .zip-scroll { overflow-y: auto; }
/* layers panel lives top-right under switcher in C, but rail icons toggle them */
.layout-c #w-layers { position: absolute; top: 62px; right: 14px; width: 290px; max-width: calc(100vw - 28px); max-height: calc(100vh - 76px); }
.layout-c #w-zip.open ~ #w-layers { right: 374px; }   /* nudge layers out of inspector's way */

/* search box */
.search-box { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.search-box input { flex: 1 1 auto; background: transparent; border: 0; outline: 0; color: var(--color-fg); font-size: 15px; }
.search-box input::placeholder { color: var(--color-fg-subtle); }
.search-box .ico { color: var(--color-fg-muted); display: grid; place-items: center; }
.search-results { max-height: 320px; overflow-y: auto; border-top: 1px solid var(--color-border); }
.search-results .sr {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer;
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 60%, transparent);
}
.search-results .sr:hover, .search-results .sr.sel { background: var(--color-surface-hover); }
.search-results .sr .z { font-weight: 700; color: var(--color-primary); width: 56px; flex: 0 0 auto; }
.search-results .sr .c { font-size: 13px; color: var(--color-fg-muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-results .none { padding: 12px 14px; color: var(--color-fg-subtle); font-size: 13px; }

/* left icon rail */
#rail { display: none; }
#rail .rail-btn {
  width: 40px; height: 40px; border-radius: var(--radius-md); border: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 80%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  color: var(--color-fg-muted); cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--shadow-sm); transition: all var(--motion-dur-fast) var(--motion-ease-standard);
}
#rail .rail-btn:hover { background: var(--color-surface-hover); color: var(--color-fg); }
#rail .rail-btn.on { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-primary-fg); }

/* ===== Map-loading overlay ===== */
/* Above the map (z 0), below the floating UI (z 10) and landing (z 100). Fades
   out (opacity + pointer-events) once the map paints its first frame. */
#map-loading {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; background: radial-gradient(120% 120% at 50% 42%, #0F2A26 0%, #0A1F1B 72%);
  transition: opacity .55s var(--motion-ease-standard, ease);
}
#map-loading.hidden { opacity: 0; pointer-events: none; }
#map-loading canvas#map-mark { width: 132px; height: 132px; }
#map-loading .ml-text {
  margin: 0; font-size: 13px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--color-fg-muted, #B5BFB9);
}
/* animated trailing dots — pure CSS so it works even before the canvas paints */
#map-loading .ml-dots::after { content: ""; animation: ml-dots 1.4s steps(4, end) infinite; }
@keyframes ml-dots { 0% { content: ""; } 25% { content: "·"; } 50% { content: "··"; } 75% { content: "···"; } }
/* honor the OS "reduce motion" setting: no dot animation, instant fade */
@media (prefers-reduced-motion: reduce) {
  #map-loading { transition: none; }
  #map-loading .ml-dots::after { animation: none; content: "…"; }
}

/* ===== Landing overlay ===== */
#landing {
  position: absolute; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(120% 120% at 50% 30%, #0F2A26 0%, #0A1F1B 70%);
  transition: opacity .6s var(--motion-ease-standard, ease);
}
#landing.hidden { opacity: 0; pointer-events: none; }
#landing canvas#mark { width: 160px; height: 160px; }
#landing h1 { font-size: 34px; margin: 18px 0 4px; font-weight: 700; letter-spacing: -0.5px; }
#landing p { color: var(--color-fg-muted, #B5BFB9); margin: 0 0 24px; max-width: 440px; text-align: center; line-height: 1.5; }
#landing .cta {
  background: var(--color-primary, #3FB89F); color: var(--color-primary-fg, #0A1F1B);
  border: 0; border-radius: var(--radius-pill, 9999px); padding: 12px 28px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background var(--motion-dur-fast) var(--motion-ease-standard);
}
#landing .cta:hover { background: var(--color-primary-hover, #5FCAB4); }
.accent { color: var(--color-accent, #E5C075); }

/* ===== Responsive (4 breakpoints: desktop / laptop / tablet / mobile) ===== */

/* Laptop (≤1280px): keep panels, just cap height so the layers card never runs
   past the bottom edge; tighten the bubble expand width. */
@media (max-width: 1280px) {
  .layout-a #w-layers, .layout-c #w-layers { max-height: calc(100vh - 90px); }
  .layout-b .bubble.expanded .expand-card { width: min(300px, calc(100vw - 32px)); }
}

/* Tablet (≤900px): narrower fixed panels so two top-corner widgets never collide
   with the centered switcher; the bottom ZIP drawer stays centered. */
@media (max-width: 900px) {
  .layout-a #w-layers, .layout-c #w-layers { width: 264px; }
  .layout-c #w-zip { width: 340px; }
  .layout-c #w-zip.open ~ #w-layers { right: 14px; top: auto; bottom: 14px; }  /* stack, don't shove off-screen */
  .layout-c #w-search { width: min(420px, 60vw); }
}

/* Mobile (≤640px): panels go full-width and dock to an edge; nothing floats
   half-off-screen. Layers/zip become bottom sheets, search spans the top. */
@media (max-width: 640px) {
  #switcher { top: 10px; right: 10px; }
  .layout-a #w-stats, .layout-b #w-stats { left: 10px; top: 56px; }
  .layout-a #w-layers, .layout-c #w-layers,
  .layout-b #w-layers, .layout-b #w-stats {
    width: calc(100vw - 20px); max-width: calc(100vw - 20px);
    left: 10px; right: 10px; top: auto; bottom: 10px;
    max-height: 50vh;
  }
  .layout-b .bubble.expanded .expand-card { width: calc(100vw - 20px); max-height: 50vh; }
  .layout-a #w-zip, .layout-c #w-zip { width: 100vw; max-width: 100vw; left: 0; right: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .layout-c #w-zip { top: auto; bottom: 0; transform: translateY(110%); max-height: 70vh; }
  .layout-c #w-zip.open { transform: translateY(0); }
  .layout-c #w-zip.open ~ #w-layers { right: 10px; }
  .layout-c #w-search { width: calc(100vw - 20px); left: 10px; transform: none; }
  .layout-c #rail { left: 10px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
