/* ============================================================================
   Design tokens. Change once here; everything cascades.
   The product name is just a CSS var so we can rebrand without code hunting.

   These tokens are copied verbatim from the admin portal so the two SPAs
   share a visual language. Only the shell/login/modal/view chrome lives
   here — internal-module styling (clients, activities, etc.) stays in the
   admin portal. Keep this file lean.
   ============================================================================ */

:root {
  /* Surfaces */
  --color-bg:            #f6f7f9;
  --color-surface:       #ffffff;
  --color-surface-alt:   #fafbfc;
  --color-border:        #e3e6ea;
  --color-border-strong: #c9ced6;

  /* Text */
  --color-text:          #1a1d20;
  --color-text-muted:    #6b7280;
  --color-text-subtle:   #9ca3af;

  /* Action */
  --color-primary:        #1f2937;
  --color-primary-hover:  #111827;
  --color-primary-active: #0b1018;
  --color-primary-on:     #ffffff;

  /* Accent — selection / active highlights. The brand blue (= the default map-feature colour). */
  --color-accent:      #2563eb;
  --color-accent-bg:   #eff6ff;
  --color-accent-line: #bfdbfe;

  /* Status */
  --color-error:    #b91c1c;
  --color-error-bg: #fef2f2;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Radius / shadows */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.06);

  /* Layout */
  --content-max: 1200px;
}

/* ============================================================================
   Reset + base
   ============================================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
input  { font: inherit; }
a      { color: inherit; }

/* Browsers ship `[hidden] { display: none }` as a user-agent rule, but
   any class we set `display: flex/grid` on (e.g. .field) overrides it.
   Bump the [hidden] rule to !important so the attribute always wins. */
[hidden] { display: none !important; }

/* Visually hidden but accessible */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================================
   Login page
   ============================================================================ */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-8) var(--space-4);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-10) var(--space-8) var(--space-8);
}

.login-brand {
  text-align: center;
  margin-bottom: var(--space-8);
}

.login-brand__wordmark {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.login-brand__subtitle {
  margin: var(--space-2) 0 0;
  color: var(--color-text-muted);
  font-size: 13px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field__input {
  width: 100%;
  padding: 10px 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.field__input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(31, 41, 55, 0.12);
}

.field__input:disabled {
  background: var(--color-surface-alt);
  color: var(--color-text-subtle);
  cursor: not-allowed;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
  user-select: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-primary);
  color: var(--color-primary-on);
  border-color: var(--color-primary);
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn--primary:active:not(:disabled) {
  background: var(--color-primary-active);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border-strong);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--color-surface-alt);
}

.btn--block {
  width: 100%;
}

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 13px;
  border: 1px solid transparent;
}

.alert--error {
  color: var(--color-error);
  background: var(--color-error-bg);
  border-color: #fecaca;
}

.alert[hidden] { display: none; }

.login-footer {
  margin-top: var(--space-6);
  text-align: center;
  color: var(--color-text-subtle);
  font-size: 12px;
}

/* ============================================================================
   Application shell — persistent SPA layout
   Grid: topbar full-width on top, sidebar on the left, content fills the rest.
   ============================================================================ */

.shell {
  display: grid;
  grid-template-areas:
    "topbar  topbar"
    "sidebar content";
  grid-template-rows: auto 1fr;
  grid-template-columns: 240px 1fr;
  /* Definite height (not min-height): the content row is `1fr`, and the Maps
     view fills it with an absolutely-positioned map. With only min-height the
     1fr track collapses to 0 when its content is out-of-flow. .content has
     overflow-y:auto, so views taller than the viewport still scroll. */
  height: 100vh;
}

/* Hide the shell until /me resolves so users bounced to /login don't see
   a flash of authenticated chrome. */
[data-auth-state="pending"] { visibility: hidden; }

/* ----- Topbar ----- */

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 1;
}

.topbar__brand {
  font-size: 15px;
  font-weight: 600;
}

/* Contextual slot — the active view drops a breadcrumb/title here, filling the
   topbar's otherwise-empty middle so we don't stack a second bar below it. */
.topbar__context {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  overflow: hidden;
}

.topbar__breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-size: 13px;
}

.topbar__crumb-link {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-text-muted);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

.topbar__crumb-link:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.topbar__crumb-sep { color: var(--color-text-subtle); flex: none; }

.topbar__crumb-current {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-muted);
  font-size: 13px;
}

.topbar__user-name {
  color: var(--color-text);
}

/* ----- Sidebar ----- */

.sidebar {
  grid-area: sidebar;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav__item {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 100ms ease, color 100ms ease;
}

.nav__item:hover {
  background: var(--color-surface-alt);
}

.nav__item--active,
.nav__item--active:hover {
  background: var(--color-primary);
  color: var(--color-primary-on);
}

.nav__item--nested {
  padding-left: var(--space-6);
}

.nav__group {
  margin-top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav__group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.nav__group-toggle:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.nav__group-chevron {
  transition: transform 120ms ease;
  font-size: 12px;
}

.nav__group--collapsed .nav__group-chevron {
  transform: rotate(-90deg);
}

.nav__group-items {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav__group--collapsed .nav__group-items {
  display: none;
}

/* ----- Content — router target ----- */

.content {
  grid-area: content;
  padding: var(--space-8);
  overflow-y: auto;
}

/* ============================================================================
   View — shared chrome for view modules rendered into .content
   ============================================================================ */

.view {
  max-width: var(--content-max);
  margin: 0 auto;
}

.view__header {
  margin-bottom: var(--space-6);
}

.view__title {
  margin: 0 0 var(--space-2);
  font-size: 24px;
  font-weight: 600;
}

.view__subtitle {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 14px;
}

.view__placeholder {
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  color: var(--color-text-muted);
}

.view__placeholder p {
  margin: 0 0 var(--space-2);
}

.view__placeholder p:last-child {
  margin-bottom: 0;
}

.view__placeholder code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--color-surface-alt);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.view__placeholder a {
  color: var(--color-primary);
  text-decoration: underline;
}

/* ============================================================================
   Home quick-links — compact cards linking into the main sections.
   ============================================================================ */

.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.quick-link {
  display: block;
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--color-text);
  box-shadow: var(--shadow-card);
  transition: border-color 120ms ease, transform 120ms ease;
}

.quick-link:hover {
  border-color: var(--color-border-strong);
  transform: translateY(-1px);
}

.quick-link__title {
  margin: 0 0 var(--space-1);
  font-size: 15px;
  font-weight: 600;
}

.quick-link__desc {
  margin: 0;
  font-size: 13px;
  color: var(--color-text-muted);
}

/* ============================================================================
   Modal overlay — used by the 401 re-auth flow (see shell.js / api.js)
   ============================================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}

.modal--open {
  display: block;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
}

.modal__card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: calc(100% - 32px);
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(15, 23, 42, 0.2);
  padding: var(--space-8);
}

.modal__title {
  margin: 0 0 var(--space-2);
  font-size: 18px;
  font-weight: 600;
}

.modal__subtitle {
  margin: 0 0 var(--space-6);
  color: var(--color-text-muted);
  font-size: 13px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

/* ============================================================================
   Button size variant (topbar sign-out, modal actions)
   ============================================================================ */

.btn--sm {
  padding: 6px 12px;
  font-size: 13px;
}

/* ============================================================================
   Utilities (used by view modules)
   ============================================================================ */

.muted { color: var(--color-text-muted); }
.small { font-size: 12px; }

/* ============================================================================
   Map detail view — full-bleed MapLibre canvas with overlay panels +
   a compact header bar (back link + map name).

   .content normally has padding + scroll; the map detail needs the whole box
   and its own positioning context for the absolutely-positioned overlays. We
   strip both when .content hosts the DETAIL view. The selector is scoped to
   `.maps-view` (the detail's root element) — the Maps LIST view uses a plain
   `.view` and so renders as a normal padded `.content` page, untouched by
   this rule. (Modern :has() support is fine for the app's evergreen target.)
   ============================================================================ */

/* Full-bleed detail surfaces (map workspace + work-order dispatch) need the
   whole .content box and their own positioning context for absolute overlays. */
.content:has(.maps-view),
.content:has(.view--wo-detail),
.content:has(.view--wor) {
  padding: 0;
  overflow: hidden;
  position: relative;
}

/* The Work Orders module doesn't inherit `.view`'s readable max-width + auto-
   centering margin — its views use the FULL width to the right of the sidebar
   (the sidebar itself stays; grids/maps want the space). The workspaces
   (.view--wor / .view--wo-detail) fill their unpadded content box; the catalog
   list (.view--work-orders) is a normal padded page, just uncapped. (The maps
   view escapes the cap only because it omits `.view`.) */
.view--wor,
.view--wo-detail,
.view--work-orders {
  max-width: none;
  margin: 0;
}

.maps-view {
  position: absolute;
  inset: 0;
  /* The workspace is a docked LEFT RAIL + a MAP STAGE. The stage holds the
     map canvas plus the bottom data-grid, right feature panel, and basemap
     overlays. The breadcrumb lives in the topbar slot, so no in-canvas bar. */
  display: flex;
  --map-detail-bar-h: 0px;
}

.map {
  /* MapLibre's own stylesheet (loaded from the CDN AFTER main.css) sets
     `.maplibregl-map { position: relative }`, which beats `position:absolute`
     here by source order and ignores `inset`, collapsing the height. Fill via
     100%/100% of the absolutely-positioned .maps-view instead — robust
     regardless of the positioning MapLibre puts on the container. */
  width: 100%;
  height: 100%;
}

/* The MapLibre canvas/controls inherit no app font; keep attribution legible. */
.maplibregl-ctrl-attrib { font-size: 11px; }

/* ----- Left rail (docked) + map stage ----- */

.maps-rail {
  flex: none;
  width: 264px;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  z-index: 3;
}

/* The settings drill-in needs more room for tabs + the field list/style form. */
.maps-rail--wide { width: 344px; }

.maps-rail__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 38px;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.maps-rail__body {
  flex: 1 1 auto;
  padding: var(--space-2);
  overflow-y: auto;
}

.maps-stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

/* ----- One layer row in the toggle panel ----- */

.maps-layer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}

.maps-layer:hover {
  background: var(--color-surface-alt);
}

.maps-layer__toggle {
  margin: 0;
  flex: none;
}

.maps-layer__swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(15, 23, 42, 0.15);
}

.maps-layer__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ----- Basemap switcher (segmented control, top-right) ----- */

.maps-basemaps {
  position: absolute;
  top: calc(var(--map-detail-bar-h) + var(--space-3));
  right: var(--space-3);
  z-index: 2;
  display: inline-flex;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.maps-basemap-btn {
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
}

.maps-basemap-btn:last-child {
  border-right: none;
}

.maps-basemap-btn:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.maps-basemap-btn--active,
.maps-basemap-btn--active:hover {
  background: var(--color-primary);
  color: var(--color-primary-on);
}

/* ----- Centered notice in the map area (empty / no key / error) ----- */

.maps-msg {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  text-align: center;
  color: var(--color-text-muted);
  background: var(--color-bg);
}

/* ----- Feature attribute panel (right side, slides in) ----- */

.maps-feature {
  position: absolute;
  top: calc(var(--map-detail-bar-h) + var(--space-3));
  right: var(--space-3);
  bottom: var(--space-3);
  z-index: 3;
  width: 300px;
  max-width: calc(100% - var(--space-6));
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.maps-feature__close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 20px;
  line-height: 1;
  color: var(--color-text-muted);
}

.maps-feature__close:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.maps-feature__body {
  padding: var(--space-4);
  padding-right: var(--space-8);
  overflow-y: auto;
}

.maps-feature__layer {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.maps-feature__title {
  margin: var(--space-1) 0 var(--space-4);
  font-size: 16px;
  font-weight: 600;
}

.maps-feature__fields {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.maps-feature__row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.maps-feature__label {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.maps-feature__value {
  margin: 0;
  font-size: 13px;
  color: var(--color-text);
  word-break: break-word;
}

.maps-feature__empty {
  color: var(--color-text-subtle);
}

/* "Unplaced" notice in the feature panel (imported without a location). */
.maps-feature__warn {
  margin: 0 0 var(--space-3);
  padding: var(--space-2);
  font-size: 12px;
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  border-left: 3px solid #f59e0b;
  border-radius: var(--radius-sm);
}

/* ----- Rail controls: header bar (title / back / action) ----- */

.maps-rail__header { justify-content: space-between; }

.maps-rail__title {
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

.maps-rail__title--trunc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.maps-rail__action,
.maps-rail__back {
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  flex: none;
}

.maps-rail__action { color: var(--color-primary); }
.maps-rail__back   { color: var(--color-text-muted); }

.maps-rail__action:hover,
.maps-rail__back:hover { background: var(--color-surface-alt); }

.maps-rail__divider {
  height: 1px;
  background: var(--color-border);
  margin: var(--space-3) 0;
}

/* ----- Layer rows (the row is a container; name + gear are the targets) ----- */

.maps-layers-list { display: flex; flex-direction: column; }

.maps-layer { cursor: default; }

.maps-layer--active { background: var(--color-surface-alt); }

.maps-layer__name {
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.maps-layer__name:hover { text-decoration: underline; }

.maps-layer__gear,
.maps-layer__kebab {
  flex: none;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  opacity: 0.7;
}

.maps-layer__gear:hover,
.maps-layer__kebab:hover { background: var(--color-surface-alt); opacity: 1; }

.maps-note {
  margin: 0;
  padding: var(--space-2);
  font-size: 13px;
  color: var(--color-text-muted);
}

.maps-note--pad { padding: var(--space-6); text-align: center; }

/* ----- Settings tabs ----- */

.maps-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-2);
}

.maps-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
}

.maps-tab--active {
  color: var(--color-text);
  border-bottom-color: var(--color-primary);
}

/* ----- Read-only field list (Settings → Fields, until the editor lands) ----- */

.maps-fieldlist { list-style: none; margin: 0; padding: 0; }

.maps-fieldrow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 6px 4px;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}

.maps-fieldrow__label { font-weight: 500; }
.maps-fieldrow__meta  { font-size: 11px; color: var(--color-text-muted); white-space: nowrap; }

/* ----- Inline forms inside the rail (panel-not-popup model) ----- */

.maps-subform {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-1) var(--space-3);
}

.maps-subform .field { margin: 0; }

.field--row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.maps-subform__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

.maps-subform__error {
  font-size: 12px;
  color: var(--color-error);
  background: var(--color-error-bg);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
}

.maps-subform__error--ok {
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
}

.maps-color { height: 34px; padding: 2px; cursor: pointer; }

/* ---- Titled section card (shared) — the Labels-tab card idiom: bordered box,
   tinted header band, padded body. Style tab groups its channels with these. ---- */
.maps-sect { border: 1px solid var(--color-border); border-radius: var(--radius-sm); overflow: hidden; }
.maps-sect__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); background: var(--color-surface-alt);
}
.maps-sect__title { font-size: 13px; font-weight: 600; color: var(--color-text); }
.maps-sect__body { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-3); }

/* ---- Style tab: multi-channel rows ---- */
.maps-style-rows { display: flex; flex-direction: column; gap: var(--space-3); }

.maps-ch { display: flex; flex-direction: column; gap: 4px; }
.maps-ch__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.maps-ch__label { font-size: 12px; font-weight: 500; color: var(--color-text-muted); }
.maps-ch__mode { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--radius-sm); overflow: hidden; }
.maps-ch__modebtn { font-size: 11px; line-height: 1; padding: 3px 8px; background: var(--color-surface); color: var(--color-text-subtle); border: 0; cursor: pointer; }
.maps-ch__modebtn.is-active { background: var(--color-accent-bg); color: var(--color-accent); }
.maps-ch__modebtn:disabled { cursor: not-allowed; opacity: 0.5; }

.maps-ch__control { display: flex; align-items: center; gap: var(--space-2); min-height: 32px; }
.maps-ch__control input[type="color"] {
  height: 30px; width: 46px; padding: 2px; cursor: pointer;
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface);
}
.maps-ch__num { display: flex; align-items: center; gap: var(--space-2); flex: 1; }
.maps-ch__range { flex: 1; min-width: 0; cursor: pointer; }
.maps-ch__readout { font-size: 12px; color: var(--color-text-muted); min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; }
.maps-ch__select { flex: 1; }
.maps-ch__bool { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.maps-ch__boollabel { font-size: 12px; color: var(--color-text-muted); }

/* "By data" category classifier */
.maps-ch__body { margin-top: 4px; }
.maps-ch__data {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-2); margin-top: 2px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
}
.maps-ch__fieldrow { display: flex; flex-direction: column; gap: 3px; }
.maps-ch__stops { display: flex; flex-direction: column; gap: 4px; }
.maps-ch__stop { display: flex; align-items: center; gap: var(--space-2); }
.maps-ch__stopval {
  flex: 1; min-width: 0; font-size: 12px; color: var(--color-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.maps-ch__stop--other .maps-ch__stopval { color: var(--color-text-muted); font-style: italic; }
.maps-ch__stopout { flex: none; display: inline-flex; align-items: center; }
.maps-ch__stopout input[type="color"] {
  height: 26px; width: 40px; padding: 1px; cursor: pointer;
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
}
.maps-ch__stopout .maps-ch__num { width: 124px; }
.maps-ch__stopdel {
  flex: none; width: 22px; height: 22px; line-height: 1; font-size: 12px;
  border: 0; background: transparent; color: var(--color-text-subtle);
  cursor: pointer; border-radius: var(--radius-sm);
}
.maps-ch__stopdel:hover { color: var(--color-error); background: var(--color-error-bg); }
.maps-ch__add { display: flex; flex-direction: column; gap: 4px; }
.maps-ch__addrow { display: flex; align-items: center; gap: var(--space-2); }
.maps-ch__addrow .field__input { flex: 1; min-width: 0; }
.maps-ch__addnote, .maps-ch__empty { font-size: 12px; color: var(--color-text-subtle); margin: 0; line-height: 1.35; }
.maps-ch__reset {
  align-self: flex-start; font-size: 11px; padding: 2px 6px; cursor: pointer;
  border: 0; background: transparent; color: var(--color-text-muted); text-decoration: underline;
}
.maps-ch__reset:hover { color: var(--color-text); }

/* Cross-cutting block (min-zoom + clickable) */
.maps-style-cross { display: flex; flex-direction: column; gap: var(--space-3); }
.maps-style-check { cursor: pointer; }
.maps-style-zhint {
  margin: 5px 0 0; font-size: 12px; color: var(--color-text-muted);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.maps-style-zhint strong { color: var(--color-text); font-weight: 600; }
.maps-style-usecur {
  font-size: 11px; line-height: 1; padding: 3px 8px; cursor: pointer;
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-text);
}
.maps-style-usecur:hover { background: var(--color-surface-alt); }

/* ---- Labels tab: text slots + parts builder ---- */
.maps-labels { display: flex; flex-direction: column; gap: var(--space-3); }
.maps-lbl { border: 1px solid var(--color-border); border-radius: var(--radius-sm); overflow: hidden; }
.maps-lbl__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); background: var(--color-surface-alt);
}
.maps-lbl__title { font-size: 13px; font-weight: 600; color: var(--color-text); }
.maps-lbl__sub { font-size: 11px; font-weight: 400; color: var(--color-text-subtle); }
.maps-lbl__switch { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; flex: none; }
.maps-lbl__switch input { opacity: 0; width: 0; height: 0; }
.maps-lbl__track { position: absolute; inset: 0; background: var(--color-border-strong); border-radius: 999px; transition: background .15s; }
.maps-lbl__track::before { content: ""; position: absolute; height: 16px; width: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.maps-lbl__switch input:checked + .maps-lbl__track { background: var(--color-accent); }
.maps-lbl__switch input:checked + .maps-lbl__track::before { transform: translateX(16px); }
.maps-lbl__body { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-3); }
.maps-lbl__fieldlabel { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--color-text-subtle); margin-bottom: -6px; }

/* parts builder — one part per line (never reflows) */
.maps-lbl__build { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px dashed var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface); }
.maps-lbl__build--drag { border-color: var(--color-accent); }
.maps-lbl__part { display: flex; align-items: center; gap: 7px; width: 100%; background: var(--color-surface); border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); padding: 3px 6px; }
.maps-lbl__part--field { background: var(--color-accent-bg); border-color: var(--color-accent-line); }
.maps-lbl__part--over { box-shadow: 0 0 0 2px var(--color-accent); }
.maps-lbl__grip { cursor: grab; color: var(--color-text-subtle); font-size: 13px; user-select: none; }
.maps-lbl__partkind { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-subtle); min-width: 30px; }
.maps-lbl__partsel, .maps-lbl__parttxt { flex: 1; min-width: 0; border: 0; background: transparent; padding: 2px; font-size: 13px; }
.maps-lbl__partsel { color: var(--color-accent); font-weight: 600; }
.maps-lbl__parttxt { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--color-text); }
.maps-lbl__partsel:focus, .maps-lbl__parttxt:focus { outline: none; }
.maps-lbl__partx { border: 0; background: transparent; color: var(--color-text-subtle); font-size: 13px; line-height: 1; padding: 0 4px; border-radius: 3px; cursor: pointer; }
.maps-lbl__partx:hover { color: var(--color-error); background: var(--color-error-bg); }
.maps-lbl__buildempty { font-size: 12.5px; color: var(--color-text-subtle); font-style: italic; margin: 0; padding: 2px 4px; }
.maps-lbl__add { display: flex; gap: 6px; margin-top: 2px; }
.maps-lbl__addbtn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  border: 1px solid var(--color-border-strong); background: var(--color-surface-alt); color: var(--color-text);
  border-radius: var(--radius-sm); padding: 6px 9px; font-size: 12px; font-weight: 500; cursor: pointer;
  box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
}
.maps-lbl__addbtn:hover { border-color: var(--color-accent); color: var(--color-accent); background: var(--color-accent-bg); }
.maps-lbl__addbtn:active { box-shadow: none; transform: translateY(1px); }

/* styled preview on a map-toned stage so the halo reads */
.maps-lbl__preview { display: flex; align-items: center; gap: 8px; }
.maps-lbl__arrow { color: var(--color-text-subtle); font-size: 13px; }
.maps-lbl__stage {
  flex: 1; min-width: 0; display: flex; align-items: center; min-height: 30px; padding: 5px 10px; border-radius: var(--radius-sm); overflow: hidden;
  background: #e6e9ee; background-image: radial-gradient(circle at 1px 1px, rgba(15, 23, 42, .07) 1px, transparent 0); background-size: 11px 11px;
}
.maps-lbl__stage b { font-weight: 600; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.maps-lbl__stagemuted { color: var(--color-text-subtle); font-style: italic; font-weight: 400; font-size: 12.5px; }

/* appearance (collapsed) — chevron + a peek of the current values */
.maps-lbl__appearance > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface-alt);
  font-size: 12.5px; color: var(--color-text); font-weight: 500;
}
.maps-lbl__appearance > summary:hover { border-color: var(--color-border-strong); }
.maps-lbl__appearance > summary::-webkit-details-marker { display: none; }
.maps-lbl__chev { color: var(--color-text-subtle); font-size: 12px; transition: transform .15s; display: inline-block; }
.maps-lbl__appearance[open] .maps-lbl__chev { transform: rotate(90deg); }
.maps-lbl__aphint { margin-left: auto; display: flex; align-items: center; gap: 6px; color: var(--color-text-subtle); font-size: 11.5px; font-weight: 400; }
.maps-lbl__aphint .maps-lbl__sw { width: 11px; height: 11px; border-radius: 2px; border: 1px solid rgba(0, 0, 0, .15); display: inline-block; }
.maps-lbl__appearance[open] .maps-lbl__aphint { display: none; }
.maps-lbl__apgrid { display: flex; flex-direction: column; gap: var(--space-2); margin-top: 10px; padding: 0 2px; }
.maps-lbl__row { display: flex; align-items: center; gap: var(--space-2); }
.maps-lbl__row .field__label { min-width: 48px; }
/* Builder controls use minimal inline styling — NOT the app's bordered/ALL-CAPS form chrome.
   Keep the appearance labels normal-case + light (the sandbox look). */
.maps-lbl__apgrid .field__label { text-transform: none; font-weight: 400; letter-spacing: normal; }
.maps-lbl__row input[type="color"] {
  height: 28px; width: 40px; padding: 2px; cursor: pointer;
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface);
}
.maps-lbl__rowgap { margin-left: var(--space-2); }

/* Bold / Italic / UPPERCASE format toolbar */
.maps-lbl__style { display: flex; gap: 7px; flex: 1; }
.maps-lbl__stylebtn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 4px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text); cursor: pointer; }
.maps-lbl__stylebtn:hover { background: var(--color-surface-alt); }
.maps-lbl__stylebtn.is-on { background: var(--color-accent-bg); border-color: var(--color-accent); color: var(--color-accent); }
.maps-lbl__styleg { font-size: 15px; line-height: 1.2; font-family: Georgia, "Times New Roman", serif; }
.maps-lbl__stylecap { font-size: 9.5px; letter-spacing: .02em; color: var(--color-text-subtle); white-space: nowrap; }
.maps-lbl__stylebtn.is-on .maps-lbl__stylecap { color: var(--color-accent); }

/* per-slot zoom (Current view / Use this) */
.maps-lbl__zhint { margin: 5px 0 0; font-size: 12px; color: var(--color-text-muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.maps-lbl__znow { color: var(--color-text); font-weight: 600; }
.maps-lbl__zuse { font-size: 11px; line-height: 1; padding: 3px 8px; cursor: pointer; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text); }
.maps-lbl__zuse:hover { background: var(--color-surface-alt); }

.maps-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.maps-danger { color: var(--color-error); }
.maps-danger:hover:not(:disabled) { background: var(--color-error-bg); }

/* ============================================================================
   Bottom DATA GRID — floating overlay over the map stage, opens on layer click.
   Height is set inline (JS) and drag-resized via the top handle.
   ============================================================================ */

.maps-grid {
  position: absolute;
  left: var(--space-3);
  right: var(--space-3);
  bottom: var(--space-3);
  z-index: 4;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.maps-grid__resize {
  flex: none;
  height: 9px;
  cursor: ns-resize;
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
}

.maps-grid__resize:hover { background: var(--color-border); }

.maps-grid__header {
  flex: none;
  display: flex;
  flex-wrap: wrap;               /* narrow widths: search controls wrap under the title */
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.maps-grid__title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.maps-grid__search {
  margin-left: auto;
  flex: 0 1 200px;               /* shrinks before the header wraps */
  min-width: 90px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 13px;
}

.maps-grid__search:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Search-linked controls — only visible while a query is active. */
.maps-grid__count {
  flex: none;
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.maps-grid__mapbtn {
  flex: none;
  font: inherit;
  font-size: 12px;
  padding: 3px 10px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.maps-grid__mapbtn:hover {
  border-color: var(--color-primary);
  color: var(--color-text);
}

.maps-grid__mapbtn--on {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.maps-grid__fbadge {
  display: inline-block;
  min-width: 16px;
  padding: 0 4px;
  margin-left: 5px;
  border-radius: 8px;
  background: rgba(37, 99, 235, .14);
  color: var(--color-primary);
  font-weight: 700;
  text-align: center;
}

.maps-grid__mapbtn--on .maps-grid__fbadge { background: rgba(255, 255, 255, .28); color: #fff; }

/* Active filter-condition chips — "Clear filters" leads so it survives narrow widths. */
.maps-grid__chips {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--color-border);
  background: #fbfdff;
}

.maps-grid__chipclear {
  font: inherit;
  font-size: 12px;
  color: var(--color-text-muted);
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: underline;
  padding: 2px 4px;
}

.maps-grid__chipclear:hover { color: var(--color-text); }

.maps-grid__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: #eef4ff;
  border: 1px solid #cfe0ff;
  color: #1d4ed8;
  border-radius: 999px;
  padding: 3px 6px 3px 10px;
}

.maps-grid__chip b { font-weight: 600; }

.maps-grid__chiprm {
  border: 0;
  background: transparent;
  color: #1d4ed8;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 50%;
}

.maps-grid__chiprm:hover { background: #dbe7ff; }

/* Filter builder popover (body-mounted, opens above the Filters button). */
.maps-gfpop {
  position: fixed;
  z-index: 60;
  width: 620px;
  max-width: 94vw;
  background: var(--color-surface);
  border: 1px solid #d8dee6;
  border-radius: 10px;
  box-shadow: 0 14px 40px rgba(15, 23, 42, .22);
  padding: 12px;
}

.maps-gfpop__title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}

.maps-gf__row {
  display: grid;
  grid-template-columns: 14px 34px minmax(130px, 170px) 118px 1fr 26px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.maps-gf__dot { width: 9px; height: 9px; border-radius: 50%; background: #22c55e; }
.maps-gf__row--pending .maps-gf__dot { background: #cbd5e1; }
.maps-gf__where { font-size: 12px; color: var(--color-text-muted); text-align: right; }
.maps-gf__row select, .maps-gf__row input {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 5px 8px;
  width: 100%;
  background: #fff;
  min-width: 0;
}

.maps-gf__choices { display: flex; flex-wrap: wrap; gap: 5px; }
.maps-gf__choices label {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  font-size: 12.5px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 3px 9px;
  cursor: pointer;
}

.maps-gf__rm {
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 15px;
  cursor: pointer;
  border-radius: 6px;
}

.maps-gf__rm:hover { background: var(--color-surface-alt); color: #dc2626; }

.maps-gf__add {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--color-primary);
  background: none;
  border: 0;
  cursor: pointer;
  padding: 6px 0 0;
}

.maps-grid__close {
  flex: none;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 20px;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
}

.maps-grid__close:hover { background: var(--color-surface-alt); color: var(--color-text); }

.maps-grid__body { flex: 1 1 auto; overflow: auto; }

.maps-grid__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.maps-grid__table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 6px 12px;
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  white-space: nowrap;
  cursor: pointer;               /* click to sort */
  user-select: none;
}

.maps-grid__table th:hover { color: var(--color-text); }
.maps-grid__th--sorted { color: var(--color-text); }
.maps-grid__sort { margin-left: 4px; font-size: 9px; color: var(--color-primary); }

.maps-grid__table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.maps-grid__row { cursor: pointer; }
.maps-grid__row:hover td { background: var(--color-surface-alt); }
.maps-grid__row--sel td { background: var(--color-surface-alt); }
.maps-grid__row--sel td:first-child { box-shadow: inset 2px 0 0 var(--color-primary); }
/* Unplaced (no-location) feature row — amber accent. */
.maps-grid__row--unplaced td:first-child { box-shadow: inset 3px 0 0 #f59e0b; }
.maps-grid__row--unplaced.maps-grid__row--sel td:first-child { box-shadow: inset 3px 0 0 #f59e0b, inset 5px 0 0 var(--color-primary); }

/* ============================================================================
   Placeholder regions (floor plan only — behaviour furnished later):
   the map-tools toolbar (stage top-left) and the map "⋯" menu (topbar).
   ============================================================================ */

/* Top-left control cluster: the tools toolbar + the address search box, side by side.
   The wrapper owns the absolute position; children flow in a flex row (and wrap onto
   a second line on a very narrow stage rather than overflowing). */
.maps-topleft {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 3;
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--space-2);
  max-width: calc(100% - var(--space-6));
}

.maps-tools {
  display: inline-flex;
  flex: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* Address search box (MapTiler geocoding). */
.maps-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 248px;
  max-width: 44vw;
  height: 33px;
  margin: 0;
  padding: 0 3px 0 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

/* The 🔍 submit button — a real tap target (works on touch without a hardware Enter). */
.maps-search__go {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 27px;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.maps-search__go:hover { background: var(--color-surface-alt); color: var(--color-text); }

.maps-search__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--color-text);
  outline: none;
  padding: 0;
}
.maps-search__input::-webkit-search-cancel-button { display: none; }
.maps-search__input::placeholder { color: var(--color-text-subtle); }

.maps-search__clear {
  flex: none;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.maps-search__clear:hover { color: var(--color-text); }

.maps-search__results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 288px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  z-index: 5;
}

.maps-search__empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.maps-tool {
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.maps-tool:last-child { border-right: none; }
.maps-tool:hover { background: var(--color-surface-alt); color: var(--color-text); }

.maps-tool--active,
.maps-tool--active:hover {
  background: var(--color-primary);
  color: var(--color-primary-on);
}

/* Map menu lives in the topbar context slot: breadcrumb left, "⋯" pushed right. */
.maps-topctx {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-width: 0;
}

.maps-mapmenu { position: relative; margin-left: auto; flex: none; }

.maps-mapmenu__btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--color-text-muted);
  padding: 2px 8px;
}

.maps-mapmenu__btn:hover { background: var(--color-surface-alt); color: var(--color-text); }

/* position:fixed so the topbar's overflow:hidden can't clip it (JS anchors it). */
.maps-mapmenu__dropdown {
  position: fixed;
  z-index: 50;
  min-width: 200px;
  padding: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
}

.maps-mapmenu__item {
  background: transparent;
  border: none;
  text-align: left;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--color-text);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.maps-mapmenu__item:hover { background: var(--color-surface-alt); }

.maps-mapmenu__sep { height: 1px; background: var(--color-border); margin: var(--space-1) 0; }

/* ----- Import wizard (modal body) ----- */

.import-drop {
  display: block;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-8) var(--space-4);
  text-align: center;
  cursor: pointer;
  background: var(--color-surface-alt);
}

.import-drop--over { border-color: var(--color-primary); background: var(--color-surface); }
.import-drop__title { font-weight: 600; font-size: 14px; }
.import-drop__hint { margin-top: var(--space-2); font-size: 12px; color: var(--color-text-muted); }

.import-summary__head { font-size: 13px; }
.import-summary__crs { color: var(--color-text-muted); }

.import-rows-label {
  display: block;
  margin: var(--space-3) 0 var(--space-1);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* Scrolls when a migration zip yields many layers. */
.import-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 340px;
  overflow-y: auto;
}

.import-row { display: flex; align-items: center; gap: var(--space-2); }
.import-row__name { flex: 1; min-width: 0; }
.import-row__meta { flex: none; font-size: 11px; color: var(--color-text-muted); white-space: nowrap; }

.import-busy { padding: var(--space-6); text-align: center; color: var(--color-text-muted); }

/* Exclude toggle (shared by ready rows + tabular tables). */
.import-x {
  flex: none;
  width: 24px;
  height: 24px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-muted);
  line-height: 1;
}
.import-x:hover { background: var(--color-surface-alt); color: var(--color-text); }
.import-row--off { opacity: 0.5; }

/* Tabular (CSV/XLS) mapping panel. */
.import-hint { margin: 0 0 var(--space-2); font-size: 12px; color: var(--color-text-muted); }
.import-hint code {
  font-family: ui-monospace, monospace;
  background: var(--color-surface-alt);
  padding: 0 3px;
  border-radius: 3px;
}

.import-tables { display: flex; flex-direction: column; gap: var(--space-3); max-height: 380px; overflow-y: auto; }

.import-table {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.import-table--off { opacity: 0.55; }
.import-table__head { display: flex; align-items: center; gap: var(--space-2); }
.import-table__name { flex: 1; min-width: 0; }

.import-maprow { display: flex; align-items: center; gap: var(--space-2); }
.import-maprow__label { flex: none; width: 88px; font-size: 12px; color: var(--color-text-muted); }
.import-maprow .field__input { flex: 1; min-width: 0; }

.import-validity { font-size: 12px; color: var(--color-text-muted); }
.import-validity--bad { color: var(--color-error); }

.import-keep { display: flex; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-3); font-size: 13px; cursor: pointer; }
.import-keep input { margin-top: 2px; flex: none; }
.import-keep__hint { color: var(--color-text-muted); }

/* ---- Layer data-import (append / update / replace) — layer-import.js ---- */
.limport-target { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3);
  border: 1px solid var(--color-accent-line); background: var(--color-accent-bg);
  border-radius: var(--radius-md); font-size: 13px; }
.limport-target__geo { width: 10px; height: 10px; border-radius: 2px; background: var(--color-accent); flex: none; }
.limport-meta { color: var(--color-text-muted); font-size: 12px; }
.limport-file { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3);
  padding: var(--space-3); border: 1px dashed var(--color-border-strong); border-radius: var(--radius-md); font-size: 13px; }
.limport-file__name { font-weight: 600; }

.limport-label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--color-text-muted); margin: var(--space-4) 0 var(--space-2); }

.limport-modes { display: inline-flex; border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md); overflow: hidden; }
.limport-modes button { font: inherit; font-size: 13px; font-weight: 500; border: 0; background: var(--color-surface);
  color: var(--color-text-muted); padding: 7px 18px; cursor: pointer; border-right: 1px solid var(--color-border); }
.limport-modes button:last-child { border-right: 0; }
.limport-modes button[aria-pressed="true"] { background: var(--color-primary); color: var(--color-primary-on); }
.limport-hint { font-size: 12px; color: var(--color-text-muted); margin-top: var(--space-2); }
.limport-hint2 { color: var(--color-text-muted); font-size: 12px; }
.limport-note { margin-top: var(--space-2); padding: var(--space-2) var(--space-3); font-size: 12.5px;
  color: var(--color-text); background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius-md); }

.limport-keyrow { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3);
  padding: var(--space-3); background: var(--color-accent-bg); border: 1px solid var(--color-accent-line);
  border-radius: var(--radius-md); font-size: 13px; }
.limport-keyrow .field__input { width: auto; min-width: 150px; }
.limport-lock { font-size: 11px; color: var(--color-accent); }
.limport-opt { display: flex; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-2);
  padding: var(--space-3); font-size: 13px; cursor: pointer; }
.limport-opt input { margin-top: 2px; flex: none; }

.limport-warn { margin-top: var(--space-3); padding: var(--space-3); border-radius: var(--radius-md);
  background: var(--color-error-bg); border: 1px solid var(--color-error); font-size: 12.5px; line-height: 1.45; }
.limport-warn strong { color: var(--color-error); }

.limport-table { width: 100%; margin-top: var(--space-2); border-collapse: collapse; font-size: 13px; }
.limport-table th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.03em;
  text-transform: uppercase; color: var(--color-text-subtle); padding: 0 0 var(--space-2); }
.limport-table td { padding: 5px 0; vertical-align: middle; }
.limport-src { width: 44%; padding-right: var(--space-3); }
.limport-arrow { width: 22px; text-align: center; color: var(--color-text-subtle); }
.limport-src code { font-family: var(--font-mono); font-size: 12px; background: var(--color-surface-alt);
  padding: 2px 6px; border-radius: var(--radius-sm); }
.limport-row--off .limport-src code { opacity: 0.55; }
.limport-row--off .field__input { color: var(--color-text-subtle); }
.limport-tag { font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 999px; margin-left: 6px; }
.limport-tag--auto { background: var(--color-ok-bg, #f0fdf4); color: var(--color-ok, #15803d); }
.limport-tag--key { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }

.limport-geo { display: flex; align-items: center; gap: var(--space-2); font-size: 12.5px;
  color: var(--color-text-muted); padding: var(--space-2) var(--space-3); margin-top: var(--space-2);
  background: var(--color-surface-alt); border: 1px dashed var(--color-border-strong); border-radius: var(--radius-md); }
.limport-summary { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-4);
  padding: var(--space-3); border-radius: var(--radius-md); background: var(--color-surface-alt);
  border: 1px solid var(--color-border); font-size: 13px; }
.limport-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--color-accent); flex: none; }

.limport-result { text-align: center; padding: var(--space-4) var(--space-2); }
.limport-result__big { font-size: 15px; font-weight: 600; margin-bottom: var(--space-2); }
.limport-result__line { font-size: 14px; }
.limport-result__skips { margin-top: var(--space-2); font-size: 12px; color: var(--color-text-muted); }

/* ---- Layer/map data-export panel — layer-export.js ---- */
.lexport-pills { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.lexport-pill { font: inherit; font-size: 12.5px; font-weight: 500; padding: 6px 12px;
  border: 1px solid var(--color-border-strong); border-radius: 999px; background: var(--color-surface);
  color: var(--color-text-muted); cursor: pointer; }
.lexport-pill:hover { background: var(--color-surface-alt); }
.lexport-pill--on { background: var(--color-primary); color: var(--color-primary-on); border-color: var(--color-primary); }
.lexport-geom { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3); font-size: 13px; }
.lexport-geom .field__input { width: auto; }
.lexport-list { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto;
  border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-2); }
.lexport-row { display: flex; align-items: center; gap: var(--space-2); padding: 4px 6px;
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; }
.lexport-row:hover { background: var(--color-surface-alt); }
.lexport-row__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lexport-lnk { font-size: 11px; font-weight: 500; text-transform: none; letter-spacing: 0; margin-left: 4px; }

/* ============================================================================
   Form modal — sizing + layout for the on-demand dialogs (modal.js).
   The base .modal/.modal__backdrop/.modal__card chrome lives in the modal
   section above (shared with the 401 re-auth modal); these add the form
   variant the app's add/edit dialogs need.
   ============================================================================ */

/* Slightly larger than the login modal so multi-field forms breathe; scrolls
   internally if a form ever exceeds the viewport. */
.modal__card--form {
  max-width: 520px;
  max-height: calc(100vh - 64px);
  overflow-y: auto;
}

/* Wider variant for richer editors (e.g. the choice-list items editor). */
.modal__card--wide {
  max-width: 680px;
}

.modal__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* A field flagged by the modal's required-field validation. */
.field--invalid .field__input {
  border-color: var(--color-error);
}

.field--invalid .field__input:focus {
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.14);
}

/* textareas reuse .field__input but need a sensible default height + resize. */
textarea.field__input {
  resize: vertical;
  min-height: 72px;
  font-family: inherit;
}

/* ============================================================================
   List view chrome — header-with-action row, search bar, results region.
   Shared shape with the admin Clients landing; tokens are identical between
   the two portals so the look matches.
   ============================================================================ */

.view__header--withbar { margin-bottom: var(--space-4); }

/* Row variant: title left, action(s) right. */
.view__header--row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.search-bar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  max-width: 720px;
}

.search-bar__input {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.search-bar__input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(31, 41, 55, 0.12);
}

.results-region {
  margin-top: var(--space-4);
}

.results-empty {
  padding: var(--space-8);
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  color: var(--color-text-muted);
  text-align: center;
}

/* First-run empty state stacks its message above the CTA button. */
.results-empty p {
  margin: 0 0 var(--space-4);
}

/* ============================================================================
   Maps list — one card-like row per map (name + description + actions).
   ============================================================================ */

.map-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.map-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  transition: background-color 100ms ease;
}

.map-row:last-child { border-bottom: none; }

.map-row:hover { background: var(--color-surface-alt); }

/* Keyboard focus (rows are role=button tabindex=0). */
.map-row:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.map-row__main {
  flex: 1;
  min-width: 0;
}

.map-row__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.map-row__desc {
  margin-top: 2px;
  font-size: 13px;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Actions stay out of the way until the row is hovered/focused, but remain
   reachable by keyboard (focus-within) and on touch (always rendered). */
.map-row__actions {
  flex: none;
  display: flex;
  gap: var(--space-2);
}

/* ============================================================================
   Work-order Fill view — /app/work-orders/:id/fill/:targetId

   A focused form-fill surface: a scrolling field area over a sticky commit bar
   (Save draft / Submit). Like the dispatch view it's full-bleed, so .content
   sheds its padding and the bar can pin to the bottom. Plain-scroll shell
   (density:'all'); the focus run-sheet plugs in behind the same renderer later.
   ============================================================================ */

.content:has(.view--wo-fill) {
  padding: 0;
  overflow: hidden;
  position: relative;
}

.wofill {
  position: absolute;
  inset: 0;
  max-width: none;
  margin: 0;
  display: flex;
  flex-direction: column;
}

.wofill__scroll {
  flex: 1 1 auto;
  overflow-y: auto;
}

.wofill__inner {
  max-width: 680px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-8);
}

.wofill__target {
  margin-bottom: var(--space-5);
  font-size: 13px;
  color: var(--color-text-muted);
}
.wofill__target strong { color: var(--color-text); font-weight: 600; }

.wofill__note {
  max-width: 640px;
  margin: var(--space-6) auto 0;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: #8a6d3b;
  background: #fff8e6;
  border: 1px solid #f3e2b3;
  border-radius: var(--radius-md);
}

.wofill__bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 10px var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.wofill__msg {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 13px;
  color: var(--color-text-muted);
}
.wofill__msg--err { color: var(--color-error); }

.wofill__cancel { flex: none; color: var(--color-text-muted); }

.wofill__actions {
  flex: none;
  display: flex;
  gap: var(--space-3);
}
.wofill__actions .btn { min-width: 112px; }
.wofill__actions .btn[disabled] { opacity: 0.6; cursor: default; }

/* Reuse the dispatch view's neutral state-screen styling for fill's loading /
   not-found / not-published / no-form messages. */
.wofill-state {
  max-width: 460px;
  margin: var(--space-12) auto;
  padding: 0 var(--space-5);
  text-align: center;
  color: var(--color-text-muted);
}
.wofill-state p { margin: 0 0 var(--space-4); }
