:root {
  --ink: #16201c;
  --paper: #f6f5f1;
  --panel: #ffffff;
  --line: #dcd9d0;
  --accent: #2c5f4f;       /* deep field-green — surveying/ordnance-survey feel */
  --accent-soft: #e4ede9;
  --warn: #b5502e;
  --muted: #74776f;
  --mono: 'IBM Plex Mono', 'SF Mono', Consolas, monospace;
  --sans: 'IBM Plex Sans', 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
}

#app {
  display: flex;
  height: 100vh;
}

/* ---------- Icon rail ---------- */
#rail {
  width: 48px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0;
  gap: 6px;
  z-index: 6;
}
.rail-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.rail-icon:hover { background: var(--accent-soft); color: var(--accent); }
.rail-icon.active { background: var(--accent); color: #fff; }

/* ---------- Flyout panel ---------- */
/* Collapsed by default (width 0) so the map has the screen; opening it grows the outer width
   while an inner wrapper stays a fixed 300px so content doesn't reflow/word-wrap mid-transition
   — same collapsed-by-default philosophy the mobile bottom sheet already used, now shared by
   both instead of being two different patterns. */
#flyout {
  width: 0;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--line);
  transition: width 0.22s ease;
  z-index: 6;
}
#flyout.open { width: 300px; }
.flyout-inner {
  width: 300px;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sheet-handle { display: none; }

#flyout header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}

#flyout header h1 {
  font-size: 18px;
  margin: 8px 0 0;
  font-weight: 600;
}

/* Brand lockup — logo + "Plan" inline, sized to sit on the logo's own baseline, so it reads as
   one wordmark ("[PHASE360 logo]Plan") rather than repeating "Phase360" as a separate line the
   logo already says. Used on the login screen and the flyout header. */
.brand-lockup { display: flex; align-items: center; gap: 7px; }
.brand-logo { display: block; height: 24px; width: auto; }
.brand-word {
  font-family: var(--sans);
  font-size: 19px;
  font-weight: 600;
  color: var(--ink);
}

.site-select {
  width: 100%;
  margin-top: 10px;
  padding: 7px 9px;
  font-family: var(--sans);
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
}

.tab-panel { display: none; flex: 1; overflow-y: auto; padding: 14px 18px; }
.tab-panel.active { display: block; }

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.layer-row .swatch {
  width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0;
}

.layer-row .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}

.layer-legend {
  display: flex; flex-wrap: wrap; gap: 4px 12px;
  margin: 0 0 8px 26px; font-size: 11px; color: var(--muted);
}
.layer-legend .swatch {
  display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  margin-right: 4px; vertical-align: middle;
}

.feature-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 12.5px;
  cursor: pointer;
  background: var(--paper);
}
.feature-card:hover { border-color: var(--accent); }
.feature-card .fid { font-family: var(--mono); color: var(--accent); font-size: 11px; }
.feature-card .fname { font-weight: 600; margin: 2px 0; }
.feature-card .fattr { color: var(--muted); }

.section-label {
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 4px 0 10px;
}

/* ---------- Import panel ---------- */
.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: 6px;
  padding: 22px 14px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }

.map-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  align-items: center;
  font-size: 12.5px;
  padding: 5px 0;
}
.map-row select {
  width: 100%;
  padding: 5px 6px;
  font-size: 12.5px;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.map-row .col-name { font-family: var(--mono); font-size: 11.5px; }

button {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: 5px;
  padding: 9px 14px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
button:hover { background: #234a3d; }
button.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
button.secondary:hover { background: var(--accent-soft); }
button.secondary.active { background: var(--accent); color: #fff; }
button:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }

.status-line {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 8px;
}
.status-line.ok { color: var(--accent); }
.status-line.err { color: var(--warn); }

/* ---------- Map ---------- */
/* flex:1 claims all width the rail (fixed) and flyout (0 or 300px) don't use; min-width:0
   overrides a flex item's default min-width:auto, which would otherwise refuse to let this
   shrink below its content's intrinsic width and could squeeze the flyout instead. */
#map-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; }

#map-wrap.picking-mode .maplibregl-canvas {
  cursor: crosshair !important;
}

/* Floating map toolbar — Basemap/Tools/GPS as one icon pill, top-center over the map (clear of
   MapLibre's own zoom/compass controls at top-right and the attribution text bottom-left).
   Replaces the old bottom-left GPS badge + separate Tools dropdown + sidebar Basemap toggle —
   consolidating every "map view" control (as opposed to "event data" controls, which live in
   the rail/flyout) into one place. */
.map-toolbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.toolbar-icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  position: relative;
}
.toolbar-icon-btn:hover { background: var(--accent-soft); }
.toolbar-icon-btn.active { background: var(--accent); color: #fff; }

.toolbar-sep { width: 1px; height: 20px; background: var(--line); margin: 0 3px; flex-shrink: 0; }

.gps-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  border: 1.5px solid var(--panel);
}
.gps-dot.live { background: var(--accent); }

.tools-menu { position: relative; }
.tools-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  min-width: 170px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.14);
}
.tools-dropdown.show { display: block; }
.tools-dropdown button { width: 100%; }

.georef-hint {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12.5px;
  display: none;
}
.georef-hint.show { display: block; }

/* ---------- Login screen ---------- */
#login-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
}
#login-form {
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px 24px;
}
#login-form h1 { font-size: 19px; margin: 4px 0 18px; }
#login-form .brand-lockup { justify-content: center; margin-bottom: 14px; }
#login-form .brand-logo { height: 30px; }
#login-form .brand-word { font-size: 22px; }
#login-form label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
#login-form input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 9px;
  border: 1px solid var(--line); border-radius: 4px; font-size: 13.5px; font-family: var(--sans);
}
#login-form button { width: 100%; margin-top: 4px; }

/* ---------- User badge / admin panel ---------- */
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
button.link {
  background: none; color: var(--accent); padding: 0; font-size: 12px; font-weight: 500;
}
button.link:hover { background: none; text-decoration: underline; }

.inline-form { display: flex; gap: 6px; margin-top: 10px; }
.inline-form input {
  flex: 1; padding: 7px 9px; font-size: 12.5px; border: 1px solid var(--line); border-radius: 4px;
}
.inline-form button { padding: 7px 12px; }

.admin-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12.5px;
}
.admin-row .role-tag {
  font-family: var(--mono); font-size: 10.5px; padding: 2px 6px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); text-transform: uppercase;
}
.admin-row .row-name { font-weight: 600; }
.admin-row .row-meta { color: var(--muted); font-size: 11.5px; }
.admin-row .row-actions { margin-left: auto; display: flex; gap: 8px; }
.admin-row .row-actions button { padding: 4px 9px; font-size: 11.5px; }

/* ---------- User add/edit modal ---------- */
#user-modal-backdrop, #feature-modal-backdrop, #rect-dim-modal-backdrop, #layer-style-modal-backdrop, #duplicate-site-modal-backdrop, #furniture-catalog-modal-backdrop {
  position: fixed; inset: 0; background: rgba(22,32,28,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 20;
}
.user-modal {
  width: min(340px, 92vw); max-height: 80vh; overflow-y: auto;
  background: var(--panel); border-radius: 8px; padding: 22px;
}
.user-modal h2 { font-size: 16px; margin: 0 0 14px; }
.user-modal label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.user-modal input:not([type="checkbox"]), .user-modal select {
  display: block; width: 100%; margin-top: 4px; padding: 7px 8px;
  border: 1px solid var(--line); border-radius: 4px; font-size: 13px; font-family: var(--sans);
}
.muted-hint { color: var(--muted); font-weight: 400; }
.site-check-list { max-height: 130px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; margin-top: 4px; }
.site-check-list label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; margin: 4px 0; color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- Georeferencing modal ---------- */
#georef-modal-backdrop {
  position: fixed; inset: 0; background: rgba(22,32,28,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 25;
  padding: 24px;
}
.georef-modal {
  width: min(720px, 100%);
  max-height: 90vh;
  background: var(--panel);
  border-radius: 8px;
  padding: 22px;
  display: flex;
  flex-direction: column;
}
.georef-modal h2 { font-size: 17px; margin: 0 0 6px; }
.georef-instructions { font-size: 12.5px; color: var(--muted); margin: 0 0 14px; line-height: 1.5; }

#georef-image-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
  max-height: 55vh;
  cursor: crosshair;
  line-height: 0;
}
#georef-image { display: block; max-width: 100%; user-select: none; }
#georef-image-markers { position: absolute; inset: 0; pointer-events: none; }
.point-marker {
  position: absolute;
  width: 22px; height: 22px;
  margin-left: -11px; margin-top: -11px;
  border-radius: 50%;
  background: var(--warn);
  color: #fff;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.map-point-marker {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--warn);
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* Edit-shape mode: draggable vertex and rotate handles (see startEditFeature in app.js) */
.edit-vertex-handle {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #b5502e;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  cursor: grab;
}
.edit-vertex-handle:active { cursor: grabbing; }

.edit-rotate-handle {
  width: 18px; height: 18px;
  cursor: grab;
  /* Diamond shape via a rotated pseudo-element, since maplibregl.Marker owns the outer
     element's transform (for positioning) and would clobber a transform set here directly. */
  display: flex; align-items: center; justify-content: center;
}
.edit-rotate-handle::after {
  content: '';
  width: 13px; height: 13px;
  background: #2c5f4f;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  transform: rotate(45deg);
}

/* Feature-popup action buttons — icon-only (see the actions row in renderMapLayers) instead of
   text labels, so 4-5 actions fit in a MapLibre popup without crowding it; a real class instead
   of inline styles so the mobile breakpoint below can bump their size. */
.popup-action-btn {
  width: 26px; height: 26px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12.5px; border-radius: 5px;
}

/* ---------------------------------------------------------------------------
   Mobile: the rail becomes a bottom icon bar and the flyout becomes a bottom sheet,
   instead of a side rail + side panel. Planned on desktop, used in the field on a
   phone — the map needs the screen, and event data is reachable on demand rather
   than always-on. Same collapsed-by-default philosophy as desktop, just a different
   axis (height instead of width) and triggered by the same rail-icon clicks.
   --------------------------------------------------------------------------- */
@media (max-width: 768px) {
  #rail {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    width: auto; height: 56px;
    flex-direction: row;
    justify-content: space-around;
    border-right: none;
    border-top: 1px solid var(--line);
    z-index: 16;
  }
  .rail-icon { width: 42px; height: 42px; font-size: 19px; }

  #flyout {
    position: fixed;
    left: 0; right: 0; bottom: 56px;
    width: auto;
    max-height: 26px; /* just enough to show the handle — collapsed by default */
    border-right: none;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -2px 16px rgba(0,0,0,0.15);
    z-index: 15;
    transition: max-height 0.22s ease;
  }
  #flyout.open { max-height: 75vh; }
  .flyout-inner { width: auto; }

  .sheet-handle {
    display: block;
    width: 40px; height: 5px;
    margin: 10px auto 6px;
    border-radius: 3px;
    background: var(--line);
    flex-shrink: 0;
  }

  /* Touch-target pass, scoped to what's actually used in the field: tapping a feature's
     popup is the primary mobile interaction, so its action buttons get the most room; the
     hint-banner's inline text-link actions (Undo/Cancel/Finish) and the layer-row draw/Style
     buttons get a smaller bump since they're used less often on a phone. */
  .popup-action-btn { width: 36px; height: 36px; font-size: 15px; }
  .georef-hint .link, .draw-hint .link { padding: 6px 4px; font-size: 13px; }
  .layer-row button { padding: 6px 10px; font-size: 12px; }
}
