/* App layout: top bar, map + dock, mobile bottom sheet, map overlays, palette, popovers. */
.app { display: grid; grid-template-rows: var(--topbar-h) 1fr; height: 100dvh; }

/* ── Top bar ── */
.topbar {
  display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-3) 0 var(--s-4); background: var(--c-brand); color: #fff;
  z-index: 1100; position: relative;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; font-size: var(--fs-14); flex: none; }
.brand-mark { width: 10px; height: 22px; background: var(--c-accent); border-radius: 2px; }
.search-slot { flex: 1; display: flex; justify-content: center; min-width: 0; }
.search-trigger {
  display: flex; align-items: center; gap: 10px; width: min(560px, 100%); height: 36px; padding: 0 10px 0 12px;
  border: 1px solid rgba(255, 255, 255, .22); border-radius: var(--r-2); background: rgba(255, 255, 255, .12); color: rgba(255, 255, 255, .92); text-align: left;
}
.search-trigger:hover { background: rgba(255, 255, 255, .18); }
.search-trigger:focus-visible { outline-color: #fff; }
.st-text { flex: 1; font-size: var(--fs-13); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-kbd { background: rgba(255, 255, 255, .15); border-color: rgba(255, 255, 255, .25); color: #fff; }
.user-slot { flex: none; }
.avatar-btn { border: 0; padding: 2px; border-radius: 50%; background: none; }
.avatar-btn:focus-visible { outline-color: #fff; }
.avatar-btn .avatar { background: rgba(255, 255, 255, .92); }

/* ── Stage ── */
.stage { display: flex; min-height: 0; position: relative; }
.map-wrap { flex: 1; min-width: 0; position: relative; }
.map { position: absolute; inset: 0; z-index: 0; background: #dfe5ea; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing .map-wrap { pointer-events: none; }

/* Floating toolbar over the map (blur only on floating overlays) */
.toolbar { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 900; pointer-events: none; display: flex; }
.filter-slot {
  pointer-events: auto; display: flex; align-items: center; gap: 8px; max-width: 100%; padding: 6px; border-radius: var(--r-3);
  background: rgba(255, 255, 255, .88); backdrop-filter: blur(10px) saturate(160%); -webkit-backdrop-filter: blur(10px) saturate(160%); box-shadow: var(--sh-2);
}
.btn-toolbar { flex: none; background: var(--c-surface); }
.btn-toolbar.has-active { border-color: var(--c-brand-600); color: var(--c-brand); }
.visible-count { flex: none; padding: 0 8px; font-size: var(--fs-12); color: var(--c-ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }

.hl-legend {
  position: absolute; left: 12px; bottom: 132px; z-index: 900; display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 12px;
  background: var(--c-surface); border-radius: 999px; box-shadow: var(--sh-2); font-size: var(--fs-12); font-weight: 600; max-width: calc(100% - 24px);
}
.hl-dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px var(--c-accent); background: var(--c-accent); flex: none; }
.hl-dot-tech { box-shadow: 0 0 0 2px var(--c-brand-600); background: var(--c-brand-600); }

.loading { position: absolute; inset: 0; display: grid; place-items: center; z-index: 950; background: var(--c-bg); color: var(--c-muted); gap: 8px; grid-auto-flow: column; align-content: center; justify-content: center; }

/* ── Dock ── */
.dock {
  position: relative; width: var(--dock-w); flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--c-surface); border-left: 1px solid var(--c-line); z-index: 1000; transition: width .2s var(--ease);
}
body.resizing .dock { transition: none; }
.dock-resize { position: absolute; left: -4px; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 3; }
.dock-resize:hover, .dock-resize:focus-visible { background: linear-gradient(90deg, transparent 3px, var(--c-brand-600) 3px, var(--c-brand-600) 5px, transparent 5px); outline: none; }
.dock-head { display: flex; align-items: center; gap: 4px; padding: 0 6px 0 var(--s-2); border-bottom: 1px solid var(--c-line); min-height: 48px; }
.dock-tabs { display: flex; gap: 2px; flex: 1; min-width: 0; }
.dock-tab {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 10px; border: 0; border-radius: var(--r-1);
  background: none; color: var(--c-muted); font-size: var(--fs-13); font-weight: 650; white-space: nowrap;
}
.dock-tab:hover { background: var(--c-surface-2); color: var(--c-ink); }
.dock-tab[aria-selected="true"] { background: var(--c-brand-50); color: var(--c-brand); }
.dock-collapse { color: var(--c-muted); }
.dock-pane { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; position: relative; }
.sheet-grip { display: none; }

.dock.collapsed { width: 52px; }
.dock.collapsed .dock-head { flex-direction: column; border: 0; padding: 8px 0; gap: 6px; }
.dock.collapsed .dock-tabs { flex-direction: column; }
.dock.collapsed .dock-tab { width: 40px; height: 40px; padding: 0; justify-content: center; }
.dock.collapsed .dock-tab-label, .dock.collapsed .dock-pane, .dock.collapsed .dock-resize { display: none; }
.dock.collapsed .dock-collapse { order: -1; transform: rotate(180deg); }

.back-pill {
  position: sticky; top: 8px; z-index: 20; display: flex; align-items: center; gap: 6px; margin: 8px auto -36px; height: 28px; padding: 0 12px 0 8px;
  border: 1px solid var(--c-brand-100); border-radius: 999px; background: var(--c-brand-50); color: var(--c-brand); font-size: var(--fs-12); font-weight: 650; box-shadow: var(--sh-1);
}

/* ── Mobile: bottom sheet ── */
@media (max-width: 768px) {
  .topbar { gap: var(--s-2); padding: 0 var(--s-2) 0 var(--s-3); }
  .brand-name { display: none; }
  .st-kbd { display: none; }
  .dock {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; border: 0; border-radius: var(--r-3) var(--r-3) 0 0; box-shadow: var(--sh-3);
    height: var(--sheet-drag, 132px); transition: height .25s var(--ease); padding-bottom: env(safe-area-inset-bottom);
  }
  .dock[data-sheet="half"] { height: var(--sheet-drag, 50dvh); }
  .dock[data-sheet="full"] { height: var(--sheet-drag, calc(100dvh - var(--topbar-h))); }
  .dock.dragging { transition: none; }
  .dock.collapsed { width: auto; }
  .dock.collapsed .dock-pane { display: block; }
  .dock-resize, .dock-collapse { display: none; }
  .dock-head { position: relative; padding-top: 14px; touch-action: none; }
  .sheet-grip { display: block; position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 64px; height: 18px; border: 0; background: none; padding: 0; touch-action: none; }
  .sheet-grip span { display: block; width: 36px; height: 4px; margin: 6px auto 0; border-radius: 2px; background: var(--c-line-2); }
  .dock-tab-label { display: inline; }
  .hl-legend { bottom: 148px; }
  .toolbar { top: 8px; left: 8px; right: 8px; }
  .visible-count, .visible-nosite { display: none; }
  .map-wrap .leaflet-bottom.leaflet-left { bottom: 140px; }
}

/* ── Map pieces ── */
.pin { transition: transform .15s var(--ease); transform-origin: 50% 100%; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, .3)); }
.pin:hover { transform: scale(1.12); }
.pin-selected { transform: scale(1.35); filter: drop-shadow(0 0 0 #fff) drop-shadow(0 2px 4px rgba(0, 0, 0, .45)); }
.cluster {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: var(--fs-12);
  background: var(--c-brand); box-shadow: 0 0 0 4px rgba(0, 70, 125, .22);
}
.cluster-md { background: #0E5A96; box-shadow: 0 0 0 6px rgba(0, 70, 125, .2); }
.cluster-lg { background: #083D69; box-shadow: 0 0 0 8px rgba(0, 70, 125, .18); }
.hl { width: 22px; height: 22px; border-radius: 50%; background: var(--c-accent); border: 3px solid #fff; box-shadow: 0 0 0 2px var(--c-accent), 0 2px 6px rgba(0, 0, 0, .35); }
.hl-tech { background: var(--c-brand-600); box-shadow: 0 0 0 2px var(--c-brand-600), 0 2px 6px rgba(0, 0, 0, .35); }
.visit-ring { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(31, 100, 168, .55); background: rgba(31, 100, 168, .08); }
.visit-ring.soon { border-color: var(--c-brand); background: rgba(0, 70, 125, .14); }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26, 115, 232, .2); }
.map-ctl { display: flex; flex-direction: column; gap: 1px; border-radius: var(--r-2); overflow: hidden; box-shadow: var(--sh-2); }
.map-btn { width: 36px; height: 36px; border: 0; background: var(--c-surface); color: var(--c-ink-2); display: grid; place-items: center; }
.map-btn:hover { background: var(--c-surface-2); }
.leaflet-bottom.leaflet-left { margin-bottom: 12px; }
.leaflet-container { font-family: var(--font); }
.leaflet-control-attribution { font-size: 10px; }
.hover-popup .leaflet-popup-content-wrapper { border-radius: var(--r-2); box-shadow: var(--sh-2); padding: 0; }
.hover-popup .leaflet-popup-content { margin: 10px 12px; min-width: 180px; }
.hover-popup .leaflet-popup-tip-container { display: none; }
.hover-card { font-size: var(--fs-12); color: var(--c-ink-2); display: grid; gap: 3px; }
.hc-name { font-size: var(--fs-13); font-weight: 700; color: var(--c-ink); }
.hc-loc { color: var(--c-muted); }
.hc-stats { display: flex; flex-wrap: wrap; gap: 8px; }
.hc-warn { color: var(--c-warn); font-weight: 600; }
.hc-visit { color: var(--c-brand-600); font-weight: 600; }
.hc-sales { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.hc-sm { display: inline-flex; align-items: center; gap: 6px; }

/* ── Search palette ── */
.dialog-palette { align-self: start; margin-top: 10vh; width: min(640px, 100%); }
.dialog-palette .dialog-head { display: none; }
.dialog-palette .dialog-body { padding: 0; }
.palette-bar { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--c-line); }
.palette-bar .i { color: var(--c-muted); }
.palette-input { flex: 1; height: 54px; border: 0; font-size: var(--fs-16); background: none; }
.palette-input:focus-visible { outline: none; }
.palette-results { max-height: min(56vh, 520px); overflow: auto; padding: 6px; }
.palette-group { padding: 10px 10px 4px; font-size: var(--fs-11); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--c-muted); }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: var(--r-1); cursor: pointer; }
.palette-item .i { color: var(--c-muted); }
.palette-item[aria-selected="true"] { background: var(--c-brand-50); }
.palette-item[aria-selected="true"] .i { color: var(--c-brand); }
.pi-text { display: flex; flex-direction: column; min-width: 0; }
.pi-title { font-weight: 600; font-size: var(--fs-13); }
.pi-sub { font-size: var(--fs-12); color: var(--c-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-hint { padding: 18px 14px; color: var(--c-muted); font-size: var(--fs-13); }
.palette-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--c-line); font-size: var(--fs-12); color: var(--c-muted); flex-wrap: wrap; }
.palette-foot kbd { margin: 0 2px; }
.palette-keys { margin-left: auto; }

/* ── Filter popover ── */
.popover-filters { width: min(560px, calc(100vw - 16px)); display: flex; }
.filter-pop { display: grid; grid-template-columns: 170px 1fr; grid-template-rows: 1fr auto; width: 100%; min-height: 0; max-height: inherit; }
.fp-tabs { display: flex; flex-direction: column; gap: 2px; padding: 8px; border-right: 1px solid var(--c-line); background: var(--c-surface-2); }
.fp-tab { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 36px; padding: 0 10px; border: 0; border-radius: var(--r-1); background: none; text-align: left; font-size: var(--fs-13); font-weight: 600; color: var(--c-ink-2); }
.fp-tab[aria-selected="true"] { background: var(--c-surface); color: var(--c-brand); box-shadow: var(--sh-1); }
.fp-main { display: flex; flex-direction: column; gap: 8px; padding: 10px; min-height: 0; overflow: hidden; }
.fp-list { overflow: auto; max-height: 360px; min-height: 120px; }
.fp-foot { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--c-line); }
.fp-mine { justify-content: flex-start; }
.fp-hint { margin: 0; line-height: 1.35; }
@media (max-width: 560px) {
  .filter-pop { grid-template-columns: 1fr; }
  .fp-tabs { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--c-line); }
  .fp-tab { flex: none; }
}

.popover-layers { width: 300px; }
.layers-pop { padding: 12px; display: grid; gap: 12px; }
.layers-group { border: 0; margin: 0; padding: 0; }
.layers-group legend, .legend-title { font-size: var(--fs-12); font-weight: 700; color: var(--c-ink-2); margin-bottom: 4px; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 260px; overflow: auto; }
.legend-note { margin: 6px 0 0; line-height: 1.35; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: var(--fs-12); min-height: 24px; }
.legend-name { flex: 1; }

/* ── Fatal screen ── */
.fatal { grid-row: 1 / -1; display: grid; place-items: center; padding: 24px; }
.fatal-box { max-width: 440px; text-align: center; display: grid; gap: 12px; justify-items: center; background: var(--c-surface); padding: 32px; border-radius: var(--r-3); box-shadow: var(--sh-2); }
.fatal-box .i { width: 32px; height: 32px; color: var(--c-danger); }
.fatal-box h1 { font-size: var(--fs-20); }
