/* ------------------------------------------------------------------
 * Ferney GIS Viewer - application chrome
 * Map widgets are styled by the Esri theme loaded in index.html;
 * everything here is the shell around them.
 * ------------------------------------------------------------------ */

:root {
  --bg:            #f7f6f1;
  --surface:       #ffffff;
  --surface-2:     #eeede4;
  --border:        #dcdace;
  --text:          #212529;
  --text-muted:    #707070;
  --accent:        #2a5431;
  --accent-hover:  #1c3a22;
  --accent-weak:   #e6ebe3;
  --danger:        #e65952;
  --shadow:        0 1px 2px rgba(0, 40, 24, .08), 0 4px 16px rgba(0, 40, 24, .08);
  --radius:        8px;
  --appbar-h:      56px;
  --sidebar-w:     300px;
  --table-h:       clamp(200px, 32vh, 360px);
  /* Roboto, the face every mapping UI is set in - and what the basemap
     labels underneath are already using. The stack after it matters:
     Roboto is fetched from Google Fonts, and on a phone in a field that
     request can be slow or fail, so the fallbacks are the system faces
     rather than another download. */
  --font: "Roboto", "Segoe UI", -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  --font-head: "Old Standard TT", Georgia, serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg:            #0e1712;
  --surface:       #16211a;
  --surface-2:     #1e2c22;
  --border:        #2e4033;
  --text:          #e4e3d9;
  --text-muted:    #93a396;
  --accent:        #5c9a63;
  --accent-hover:  #79b380;
  --accent-weak:   #1c3322;
  --danger:        #f0847c;
  --shadow:        0 1px 2px rgba(0, 0, 0, .4), 0 4px 18px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

/* The hidden attribute is only a UA rule, so any class that sets display
   beats it - .btn sets inline-flex, which silently defeated hidden on
   every button in the app bar. Make it authoritative once, here, rather
   than patching each control that hits it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}

/* ---------------------------------------------------------- app bar */

.appbar {
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}

.appbar__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.appbar__mark  { width: auto; height: 28px; flex: none; }

.appbar h1 {
  font-family: var(--font-head);
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.appbar__actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* Which data source is live. Deliberately plain rather than alarming -
   local exports are a normal development mode, not a fault. */
.badge--source { background: var(--surface-2); color: var(--text-muted); }

.authuser {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.authuser[hidden], #authBtn[hidden] { display: none; }

/* ----------------------------------------------------------- layout */

.layout { display: flex; height: calc(100% - var(--appbar-h)); min-height: 0; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.panel { background: var(--surface); padding: 14px; }
.panel--grow { flex: 1 0 auto; }

.panel__title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.panel__row { display: flex; gap: 6px; margin-top: 10px; }
.panel__row .btn { flex: 1; }

/* Section 6 (2026-10-06): "Show Unpaid Leases" sits in a row of its
   own, centred rather than stretched edge-to-edge like the two-button
   rows above it - overrides the flex:1 on .panel__row .btn. */
.panel__row--center { justify-content: center; }
.panel__row--center .btn { flex: 0 0 auto; }

.label { display: block; margin: 10px 0 4px; font-size: 12px; color: var(--text-muted); }
.label:first-of-type { margin-top: 0; }

.control {
  width: 100%;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.control:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.control:disabled { opacity: .5; cursor: not-allowed; }

.hint { margin: 10px 0 0; font-size: 12px; line-height: 1.45; color: var(--text-muted); overflow-wrap: anywhere; }
#layerMeta { white-space: pre-line; font-family: var(--mono); font-size: 11px; }

.stat { margin: 0; font-size: 26px; font-weight: 600; line-height: 1.1; }
.stat__unit { font-size: 12px; font-weight: 400; color: var(--text-muted); }

/* Field coverage list - how sparse each attribute is. */
.coverage { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.coverage li { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: 12px; }
.coverage__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coverage__name.is-restricted { color: var(--text-muted); font-style: italic; }
.coverage__count { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
.coverage__bar { grid-column: 1 / -1; height: 3px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.coverage__fill { display: block; height: 100%; background: var(--accent); }
.coverage__fill.is-partial { background: #d98324; }

/* ---------------------------------------------------------- buttons */

.btn {
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:hover { background: var(--accent-weak); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: .45; cursor: not-allowed; background: var(--surface-2); }

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: var(--border); }
.btn--ghost[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn--icon { padding: 7px; background: transparent; border-color: var(--border); }
.btn--icon svg { width: 16px; height: 16px; fill: currentColor; display: block; }

.btn--chip {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 12px;
  padding: 6px 11px;
}
.btn--chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ------------------------------------------------------------ stage */

.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#viewDiv { flex: 1; min-height: 0; }

.measure {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 5;
}

/* Advanced surfaces: the attribute table, the result count and the field
   coverage list. Hidden until the Advanced toggle is switched on. */
/* Scoped to body so it outranks the .tablepanel rule further down,
   whatever order the file ends up in. */
body:not(.is-advanced) .panel--advanced,
body:not(.is-advanced) .tablepanel { display: none; }

/* Live cursor coordinates. */
.readout {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 5;
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 9px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text-muted);
  pointer-events: none;
  white-space: nowrap;
}
body.is-advanced .readout { bottom: calc(var(--table-h) + 12px); }
body.is-advanced .tablepanel.is-collapsed ~ .readout { bottom: 56px; }

/* ------------------------------------------------------ table panel */

.tablepanel {
  flex: none;
  height: var(--table-h);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
  min-height: 0;
}
.tablepanel.is-collapsed { height: auto; }
.tablepanel.is-collapsed #tableDiv { display: none; }
.tablepanel.is-collapsed .chev { transform: rotate(-90deg); }
.tablepanel.is-collapsed .tablepanel__resize { cursor: default; }

/* Drag-to-resize handle, ArcGIS-Online-style: a thin strip along the
   panel's top edge (see setupTableResize in app.js for the drag logic -
   it writes directly to the --table-h custom property this panel's own
   height already reads, so no separate sizing mechanism is needed). */
.tablepanel__resize {
  flex: none;
  height: 7px;
  cursor: ns-resize;
  position: relative;
}
.tablepanel__resize::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
}
.tablepanel__resize:hover::before,
.tablepanel.is-resizing .tablepanel__resize::before {
  background: var(--text-muted);
}
.tablepanel.is-resizing { user-select: none; }

.tablepanel__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.tablepanel__layer { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { display: inline-block; transition: transform .15s ease; }
.spacer { flex: 1; }

#tableDiv { flex: 1; min-height: 0; }
.tablehost { height: 100%; }

/* --------------------------------------------------- popup contents */

.popup-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.popup-table th,
.popup-table td { text-align: left; padding: 4px 8px 4px 0; vertical-align: top; border-bottom: 1px solid var(--border); }
.popup-table th { font-weight: 500; color: var(--text-muted); white-space: nowrap; width: 42%; }
.popup-empty { font-size: 13px; color: var(--text-muted); font-style: italic; }
.popup-coords { margin-top: 10px; font-family: var(--mono); font-size: 11px; color: var(--text-muted); }

/* Computed geometry and record provenance, below the attributes rather
   than among them - present for whoever needs them, quiet for everyone
   else. Same muted register as the coordinates line above. */
.popup-meta {
  margin: 6px 0 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
}
.popup-provenance {
  margin: 6px 0 0;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-muted);
}

/* ------------------------------------------------ SDK panel theming */

/* The popup and the Expand panels are painted from this stylesheet's own
   tokens rather than left to Calcite.
 *
 * Keeping two theming systems in step did not work. Calcite is driven by
 * its own mode classes and the esri/themes stylesheet, this app by
 * data-theme, and any disagreement puts our content - which uses our
 * tokens - on their background. Both directions were reported: dark text
 * on a dark panel, then pale text on a pale one.
 *
 * So one of them is made authoritative instead of synchronised. These
 * panels take var(--surface) and var(--text), which follow data-theme,
 * so the box and the writing inside it cannot disagree: dark box with
 * light writing in dark mode, and the reverse in light.
 *
 * !important is deliberate - Calcite sets these inline from its own
 * custom properties, and specificity alone does not win. */
.esri-popup__main-container,
.esri-popup__header,
.esri-popup__content,
.esri-popup__footer,
.esri-popup__navigation,
.esri-expand__content-container,
.esri-layer-list,
.esri-layer-list__item,
.esri-layer-list__item-container {
  background-color: var(--surface) !important;
  color: var(--text) !important;
}

.esri-popup__header-title,
.esri-layer-list__item-title {
  color: var(--text) !important;
}

/* Icon buttons in the popup chrome - dock, collapse, close - inherit the
   same text colour so they do not vanish into the panel. */
.esri-popup__header-buttons calcite-action,
.esri-popup__button,
.esri-popup__icon {
  color: var(--text) !important;
}

.esri-popup__main-container,
.esri-expand__content-container {
  border-color: var(--border) !important;
}

/* Photos attached to a feature. Same markup in the desktop popup and the
   mobile sheet - one builder feeds both. */
.popup-photos { margin-top: 12px; }
.popup-photos__title {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
/* Scrolls sideways rather than widening the popup, which the SDK sizes
   to its content. */
.popup-photos__strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.popup-photo {
  flex: 0 0 auto;
  display: block;
  width: 92px;
  height: 92px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-2);
}
.popup-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.popup-photo.is-failed {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  font-size: 11px;
  line-height: 1.3;
  text-align: center;
  color: var(--text-muted);
}

/* ------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  max-width: min(560px, 90vw);
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 60;
  overflow-wrap: anywhere;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { border-color: var(--danger); color: var(--danger); }

/* ----------------------------------------------------------- splash */

.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 80; transition: opacity .3s ease; }
.splash.is-hidden { opacity: 0; pointer-events: none; }
.splash__spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .splash__spinner { animation-duration: 2.4s; }
  .toast, .chev, .splash { transition: none; }
}


@media (prefers-reduced-motion: reduce) {
}

/* ------------------------------------------------------------ legend */

/* Hand-built rather than esri/widgets/Legend: that widget's own
   internal layer order always follows map draw order (confirmed both
   against Esri's guidance and by testing every documented workaround),
   which conflicts with the deliberately different order this app wants
   the legend to read in - see the comment beside legendRowsFor in
   app.js. Swatches approximate each renderer (flat colour, no hatch
   pattern) rather than reproducing the exact on-map symbol pixel for
   pixel. */
.ferney-legend {
  width: 260px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 12px;
  font-family: var(--font);
  color: var(--text);
}
.ferney-legend__section + .ferney-legend__section { margin-top: 14px; }
.ferney-legend__title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}
/* Layer-list/legend grouping (2026-10-06 spec): one of these above each
   CFG.layerGroups group, distinct from .ferney-legend__title (which
   labels an individual layer's own section) - bolder, uppercase, and
   with its own top rule so a group reads as a heading over several
   sections rather than another section itself. */
.ferney-legend__group-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.ferney-legend > .ferney-legend__group-title:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
.ferney-legend__rows { display: grid; gap: 5px; }
.ferney-legend__row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.ferney-legend__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.ferney-legend__swatch {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ferney-legend__swatch--fill {
  width: 16px; height: 16px;
  border-width: 1.5px; border-style: solid;
  border-radius: 2px;
}
.ferney-legend__swatch--line {
  width: 18px; height: 0;
  border-top-width: 2px; border-top-style: solid;
}
.ferney-legend__swatch--point {
  width: 12px; height: 12px;
  border-width: 1.5px; border-style: solid;
  border-radius: 50%;
}
/* The arpent conversion, standing at the foot of the legend. Muted and
   separated - it is a reference note, not a legend entry. */
.ferney-legend__note {
  margin: 10px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-muted);
}

.ferney-legend__swatch--icon { width: 18px; height: 18px; }
.ferney-legend__swatch--icon img { width: 100%; height: 100%; object-fit: contain; }

/* ------------------------------------------------------- responsive */

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .stage { flex: 1; min-height: 0; }
  .appbar h1 { display: none; }
  .readout { display: none; }
}

/* ------------------------------------------------- edit and markup modes */

/* Two modes share this panel: "edit" changes attributes on features that
   already exist, "markup" places pins, paths and areas of your own. Only
   one is ever on. The panel exists for the duration of either and not
   otherwise - it is a distinct task, not another always-on section. */
body:not(.is-editing):not(.is-markup) .panel--edit { display: none; }

/* Nothing to place in edit mode. */
body:not(.is-markup) #markupTools { display: none; }

#editPanelHint { margin: -4px 0 12px; }
#editPanelHint:empty { display: none; }

.edit__draw { display: flex; flex-wrap: wrap; gap: 6px; }
.edit__draw .btn { flex: 1 1 auto; font-size: 12px; }
.edit__draw .btn[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Live geodesic measurement while drawing. Monospace so the digits stop
   jumping as the shape changes. */
.edit__measure {
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-muted);
  white-space: pre-line;
  min-height: 1.2em;
}

.edit__form { margin-top: 12px; }
.edit__form:empty { margin-top: 0; }
.edit__formtitle {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.edit__field { margin-bottom: 10px; }
.edit__field .label { margin-top: 0; }

/* Either mode changes what a click does, so say so unmistakably. */
body.is-editing .appbar,
body.is-markup .appbar { box-shadow: inset 0 -2px 0 var(--accent); }
body.is-editing #viewDiv,
body.is-markup #viewDiv { cursor: crosshair; }

/* Edit mode is offered but not currently possible - wrong data source,
   or ArcGIS says this account may not edit. Muted rather than removed:
   clicking still explains why, which a hidden button cannot. */
.btn.is-unavailable { opacity: .5; }
.btn.is-unavailable:hover { background: var(--surface-2); }

/* Staged changes, one row each with its own undo. Discard is all-or-
   nothing, which is no help once you have drawn several things and want
   rid of one of them. */
.edit__list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.edit__list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px 5px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12px;
}
.edit__list li.is-delete { color: var(--danger); }
.edit__itemlabel { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit__remove {
  flex: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  opacity: .6;
}
.edit__remove:hover { opacity: 1; }
.edit__remove:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 3px; }

.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); width: 100%; margin-top: 4px; }
.btn--danger:hover { background: var(--danger); color: #fff; }

/* ==================================================================
   MOBILE
   ==================================================================
   The same app, laid out for a thumb. Breakpoint matches
   config.mobile.breakpoint - tests/checks.js asserts they agree.

   Shape of it: the map is the page. Everything else either overlays it
   or slides in on demand, because on a 375px screen every permanent
   panel is map you cannot see.
   ================================================================== */

@media (max-width: 860px) {

  /* Touch wants 44px. The desktop buttons are around 30. */
  :root { --tap: 44px; }

  .btn { min-height: var(--tap); padding: 10px 14px; font-size: 14px; }
  .btn--icon { min-width: var(--tap); }
  .control { min-height: var(--tap); font-size: 16px; }  /* 16px stops iOS zooming on focus */

  /* ---------------------------------------------------------- shell */

  .layout { flex-direction: column; position: relative; }

  .appbar { gap: 8px; padding: 0 10px; }
  .appbar h1 { display: none; }
  .appbar .badge { display: none; }          /* diagnostics, not field information */
  /* Belt and braces: even after relocating and trimming, the bar must
     never push content off the right edge. min-width:0 lets the brand
     shrink rather than forcing an overflow. */
  .appbar { overflow: hidden; }
  .appbar__brand { min-width: 0; flex-shrink: 1; }
  .appbar__actions { gap: 6px; flex-shrink: 0; }

  /* The map is the page. */
  .stage { flex: 1; min-height: 0; order: 1; }
  #viewDiv { height: 100%; }

  /* ------------------------------------------------- sliding panel */

  /* The sidebar becomes a sheet from the left, over the map rather than
     stealing height from it. Closed by default: the map is why you
     opened the app. */
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    width: min(86vw, 340px);
    max-height: none;
    border-right: 1px solid var(--border);
    border-bottom: none;
    box-shadow: var(--shadow);
    transform: translateX(-102%);
    transition: transform .22s ease;
    overscroll-behavior: contain;
  }
  body.is-panel-open .sidebar { transform: translateX(0); }

  .panel-scrim {
    position: absolute;
    inset: 0;
    z-index: 29;
    background: rgba(0, 0, 0, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
  }
  body.is-panel-open .panel-scrim { opacity: 1; pointer-events: auto; }

  /* ------------------------------------------------------ controls */

  .tablepanel { display: none !important; }   /* advanced surface */
  .readout { display: none; }                 /* the locate readout replaces it */

  /* Measurement chips move off the top centre, where they covered the
     map and sat under the thumb reaching for the layer button. */
  .measure {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
    left: 14px;
    transform: none;
  }

  /* --------------------------------------------------- bottom sheet */

  /* Feature details arrive from the bottom, the standard mobile map
     pattern: reachable by thumb, and costs no map when idle. */
  .esri-popup { display: none !important; }   /* the SDK's own popup is desktop-shaped */

  .sheet {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 28;
    max-height: 62%;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, .18);
    transform: translateY(102%);
    transition: transform .24s ease;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  body.is-sheet-open .sheet { transform: translateY(0); }

  .sheet__grip {
    flex: none;
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 8px auto 4px;
  }
  .sheet__head {
    flex: none;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 14px 8px;
  }
  .sheet__title {
    flex: 1;
    margin: 0;
    font-family: var(--font-head);
    font-size: 17px;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }
  .sheet__close {
    flex: none;
    min-width: var(--tap);
    min-height: var(--tap);
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
  }
  .sheet__body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 14px 14px;
  }
  .sheet__body .popup-table th { width: 40%; }

  /* More room on a phone: the sheet is the full width of the screen, and
     a photo taken in the field is the reason someone opened the pin. */
  .sheet__body .popup-photo { width: 118px; height: 118px; }

  /* --------------------------------------------------------- markup */

  /* Markup only here, narrowed to dropping and photographing a pin -
     see config.mobile.markup. The Edit button is hidden outright by
     config.mobile.hide. */
  .panel--edit .edit__draw .btn { min-height: var(--tap); }

  /* The sidebar paints its 1px dividers by showing its own background
     between panels. On desktop the coverage panel grows to fill what is
     left; that panel is hidden here, so without this the leftover space
     reads as a large slab of divider colour. */
  .sidebar::after { content: ""; flex: 1 0 auto; background: var(--surface); }
}

/* The bar shown between dropping a pin and naming it. Over the map,
   above the attribution, clear of the locate button. */
.placebar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 26px);
  z-index: 28;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.placebar__hint {
  flex: 1 1 140px;
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-muted);
  white-space: pre-line;
}
.placebar__actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* The locate button would sit under the bar; move it above while one is
   being placed. A body class rather than :has(), which the older phone
   browsers this has to work on do not have. */
body.is-placing .mapctl {
  bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
}

/* Desktop keeps the sheet and scrim out of the way entirely. */
@media (min-width: 861px) {
  .sheet, .panel-scrim, .sidebar__toggle { display: none; }
}

/* --------------------------------------------------------- locating */

.locate-readout {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 6;
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text-muted);
  pointer-events: none;
  white-space: nowrap;
}
.locate-readout[hidden] { display: none; }

/* A simulated fix is marked wherever it appears. Someone navigating by
   this needs to know the dot is invented, not merely inaccurate. */
.locate-readout.is-mock {
  border-color: #d98324;
  color: #d98324;
}

#locateBtn.is-working { opacity: .5; }

@media (max-width: 860px) {
  /* Above the measure chips, clear of the bottom sheet. */
  .locate-readout {
    left: 14px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 66px);
    font-size: 11.5px;
  }
  body.is-sheet-open .locate-readout { display: none; }
}

/* ---------------------------------------------------- marker photos */

.edit__photo { padding: 8px; font-size: 12px; }

.edit__thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.edit__thumbs:empty { margin-top: 0; }

.edit__thumb {
  position: relative;
  margin: 0;
  width: 64px;
  height: 64px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.edit__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.edit__thumb button {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .62);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.edit__thumb button:hover { background: rgba(0, 0, 0, .82); }

@media (max-width: 860px) {
  /* Big enough to hit with a thumb, and big enough to recognise the
     photo you just took. */
  .edit__thumb { width: 84px; height: 84px; }
  .edit__thumb button { width: 26px; height: 26px; font-size: 15px; }
}

/* Controls relocated from the app bar into the panel on mobile. */
.extras__row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.extras__row .btn { flex: 0 0 auto; }
.extras__row .authuser { max-width: none; }
@media (min-width: 861px) { .panel--extras { display: none; } }

/* Map controls that sit on the map itself rather than in the app bar. */
.mapctl {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 7;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mapctl:empty { display: none; }
.mapctl .btn {
  box-shadow: var(--shadow);
  background: var(--surface);
  border-color: var(--border);
}

@media (max-width: 860px) {
  /* The SDK's Expand widgets become a full-screen calcite-sheet at this
     width, which competes with the slide-over panel and renders as an
     empty dark box. Their contents are moved into the panel instead
     (relocateWidgets in js/mobile.js), so the originals come off the map. */
  .esri-ui-top-right { display: none !important; }

  /* Clear of the bottom sheet and the attribution strip. */
  .mapctl {
    right: 14px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 30px);
  }
  body.is-sheet-open .mapctl { display: none; }

  /* The layer list needs room to breathe once it is in the panel. */
  #mobileLayersSlot .esri-layer-list { max-height: 46vh; overflow-y: auto; }
  #mobileLegendSlot { max-height: 40vh; overflow-y: auto; }
}

/* Tapping the readout copies the GPS log, so it has to look tappable. */
.locate-readout {
  cursor: pointer;
  /* The base rule sets pointer-events: none so the readout never eats a
     map click. It has to take its own, or the tap does nothing at all. */
  pointer-events: auto;
}



/* ---------------------------------------------------- GPS diagnostics

   Full screen on a phone, because that is where it is used: standing
   in a field, reading a column of numbers, then sending the file on.
   A floating panel you have to scroll inside would be worse. */
.gps-diag {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
}
.gps-diag[hidden] { display: none; }

.gps-diag__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.gps-diag__head h2 {
  margin: 0;
  font-size: 15px;
}

.gps-diag__summary {
  margin: 0;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.gps-diag__summary dt {
  color: var(--text-muted);
  white-space: nowrap;
}
.gps-diag__summary dd {
  margin: 0;
  font-weight: 600;
}

/* The verdict is the first row and the one that matters, so it gets to
   wrap across both columns rather than being squeezed into one. */
.gps-diag__summary dd:first-of-type {
  font-weight: 400;
  line-height: 1.35;
}

.gps-diag__log {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.45;
  white-space: pre;
  color: var(--text-muted);
  -webkit-overflow-scrolling: touch;
}

.gps-diag__foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.gps-diag__foot .btn { flex: 1; }


/* ------------------------------------------------ position quality

   Green, amber, red, judged against plot size rather than against
   nothing: inside 15 m you know which plot you are standing in, by 60 m
   it could be the neighbouring one, past that the dot cannot tell you
   anything at all.

   The three colours are stated once and used on both the button and the
   readout, so those two can never disagree about how good the fix is.
   Declared alongside the rest of the palette's light values here, and
   overridden under data-theme="dark" exactly like every other token in
   this stylesheet. */
:root {
  --fix-good: #1e8e3e;
  --fix-fair: #b06000;
  --fix-poor: #c5221f;
}

:root[data-theme="dark"] {
  --fix-good: #5bb974;
  --fix-fair: #f0b429;
  --fix-poor: #f28b82;
}

#locateBtn.is-good { color: var(--fix-good); border-color: var(--fix-good); }
#locateBtn.is-fair { color: var(--fix-fair); border-color: var(--fix-fair); }
#locateBtn.is-poor { color: var(--fix-poor); border-color: var(--fix-poor); }

/* Stalled outranks the quality colour. A fix that was good and then
   stopped arriving is more misleading than one that was always vague,
   because it looks exactly like standing still. */
#locateBtn.is-stalled {
  color: var(--fix-poor);
  border-color: var(--fix-poor);
  opacity: .6;
}

.locate-readout.is-good { color: var(--fix-good); border-color: var(--fix-good); }
.locate-readout.is-fair { color: var(--fix-fair); border-color: var(--fix-fair); }
.locate-readout.is-poor { color: var(--fix-poor); border-color: var(--fix-poor); }

/* The hint sits under the readout and appears only when the fix is not
   good enough to be useful, so its presence is itself the signal. It
   wraps, because it is a sentence rather than a number. */
.locate-hint {
  position: absolute;
  left: 12px;
  bottom: 44px;
  z-index: 6;
  max-width: 340px;
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--fix-fair);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
}
.locate-hint[hidden] { display: none; }

@media (max-width: 860px) {
  /* Clear of the measurement buttons, which share this corner. The hint
     is advice, not a control, and must never sit on top of one. */
  .locate-hint {
    bottom: 104px;
    max-width: calc(100vw - 24px);
  }
  body.is-sheet-open .locate-hint { display: none; }
}

/* ---------------------------------------------------- guided tour

   Ported from the Clarity drone-photo viewer: a spotlight (a hole whose
   enormous shadow dims everything else) and a card beside it. The card
   takes the app's own tokens so it follows light and dark mode, where
   the drone viewer's was always white. Above every ArcGIS widget and
   the mobile sheet; the block catches clicks so nothing underneath is
   pressed by accident mid-tour. */
.tour-block { position: fixed; inset: 0; z-index: 3000; }

.tour-hole {
  position: fixed;
  z-index: 3001;
  border-radius: 8px;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(10, 24, 16, .62);
  outline: 3px solid #ffd400;
  outline-offset: 2px;
  transition: left .3s ease, top .3s ease, width .3s ease, height .3s ease;
}
.tour-hole--center { outline: 0; }

.tour-card {
  position: fixed;
  z-index: 3002;
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 18px 18px 14px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
  font-family: var(--font);
  transition: top .3s ease, left .3s ease;
}
.tour-card__title {
  margin: 0 0 6px;
  font-size: 16px;
  line-height: 1.3;
  color: var(--accent);
}
.tour-card__text { margin: 0 0 8px; font-size: 13.5px; line-height: 1.5; }
.tour-card__foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.tour-card__count { margin-right: auto; font-size: 12px; color: var(--text-muted); }
.tour-card__skip {
  padding: 6px 4px;
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.tour-card__skip:hover { color: var(--text); text-decoration: underline; }

/* The ? button: a character rather than an icon, sized to sit level
   with the theme toggle beside it. */
.tour-btn {
  min-width: 32px;
  font-weight: 700;
  font-size: 15px;
  line-height: 16px;
}

@media (prefers-reduced-motion: reduce) {
  .tour-hole, .tour-card { transition: none; }
}
