:root {
  --ink: #1c2a3a;
  --muted: #5d6b7d;
  --line: #dde4ec;
  --paper: #ffffff;
  --wash: #eef2f7;
  --navy: #1b3a5c;
  --navy-dark: #142d49;
  --green: #43a047;
  --green-dark: #38883c;
  --blue: #2f80c9;
  --blue-dark: #266aa8;
  --selected: #f0b429;
  --confirmed: #2e8b57;
  --approximate: #d97c1a;
  --placed: #7a4fc9;
  --danger: #b03a2e;
  --badge: #34495e;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--wash);
}

#app {
  display: flex;
  height: 100%;
}

#sidebar {
  width: 400px;
  max-width: 46vw;
  flex: none;
  overflow-y: auto;
  background: var(--wash);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding-bottom: 8px;
}

#map {
  flex: 1;
  min-width: 0;
  background: #0b1d2a;
}

/* ---- AgOptics brand header ---- */

.brand-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
}

.brand-logo {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.brand-logo img {
  width: 44px;
  height: auto;
  display: block;
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: #c4d3e2;
}

/* ---- cards ---- */

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin: 10px 12px 0;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(16, 42, 67, 0.06);
}

.step {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--navy);
}

.panel h2 { margin: 0; font-size: 16px; }

.panel-lede { margin: 0 0 10px; }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 12px 0 4px;
}

.apn-row {
  display: flex;
  gap: 8px;
}

#apn-input {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

#apn-input:focus {
  outline: 2px solid var(--blue);
  outline-offset: -1px;
}

/* ---- buttons ---- */

.btn {
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.btn:hover { background: var(--wash); }

.btn-primary {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.btn-primary:hover { background: var(--navy-dark); }

.btn-success {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.btn-success:hover { background: var(--green-dark); }

.btn-info {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.btn-info:hover { background: var(--blue-dark); }

.btn-danger {
  color: var(--danger);
  border-color: #e3b9b4;
  background: var(--paper);
}

.btn-danger:hover { background: #faf0ee; }

.btn-small {
  padding: 4px 8px;
  font-size: 12px;
}

.btn[disabled] {
  opacity: 0.5;
  cursor: default;
}

.upload-row { margin: 0; }

.upload-btn {
  display: block;
  text-align: center;
  cursor: pointer;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin: 8px 0 0;
}

.hint.error { color: var(--danger); }

.code-hint {
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.demo-banner {
  margin: 10px 12px 0;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #6b4d04;
  background: #fdf3d7;
  border: 1px solid #ecd699;
  border-radius: 10px;
}

.demo-banner code {
  background: rgba(255, 255, 255, 0.7);
  padding: 0 4px;
  border-radius: 4px;
}

/* ---- parcels list ---- */

.swatch {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  vertical-align: -1px;
}

.swatch-blue { background: var(--blue); }
.swatch-selected { background: var(--selected); }

.parcel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-top: 7px;
  cursor: pointer;
  background: var(--paper);
}

.parcel-row:hover { background: var(--wash); }

.parcel-row.is-active {
  border-color: var(--selected);
  background: #fdf6e3;
  box-shadow: 0 0 0 1px var(--selected);
}

.parcel-apn {
  font-weight: 700;
  font-size: 13px;
}

.parcel-apn::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--blue);
  margin-right: 7px;
  vertical-align: 0;
}

.parcel-row.is-active .parcel-apn::before { background: var(--selected); }

.parcel-counts {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.parcel-error {
  margin: 2px 2px 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--danger);
}

.chip-loading { background: var(--wash); color: var(--muted); }
.chip-muted { background: var(--wash); color: var(--muted); }

.parcel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.draft-note {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.stat {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--wash);
  border: 1px solid var(--line);
  color: var(--muted);
}

.stat strong { color: var(--ink); }

/* ---- well cards ---- */

.well-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
  background: var(--paper);
}

.well-card.is-active { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.well-card.is-deleted { opacity: 0.65; background: var(--wash); }

.well-card-top {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.well-id {
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  color: var(--blue-dark);
  background: none;
  border: none;
  padding: 0;
}

.well-id:hover { text-decoration: underline; }

.chip {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.chip-confirmed-location { background: #e2eef5; color: var(--navy); }
.chip-approximate { background: #faeeda; color: #9c5a0f; }
.chip-placed { background: #efe7fb; color: #5b3a99; }
.chip-status-confirmed { background: #e2f3e9; color: #1d6b41; }
.chip-status-deleted { background: #f6e4e1; color: var(--danger); }
.chip-moved { background: #fdf6dd; color: #8a6d0b; }
.chip-located { background: #def0ec; color: #0f6b5c; }
.chip-flag { background: #fdeaea; color: var(--danger); }

.well-meta {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.well-meta a { color: var(--blue-dark); }

.well-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* ---- section candidates ---- */

.section-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
}

.section-card h4 {
  margin: 0;
  font-size: 13px;
}

.section-card .trs {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}

.section-well {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px dashed var(--line);
  margin-top: 6px;
  font-size: 12px;
}

.section-well .who { color: var(--muted); }
.section-well .who strong { color: var(--ink); }

.action-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.action-row:first-of-type { margin-top: 0; }
.action-row .btn { flex: 1; }

.action-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.action-stack .btn { width: 100%; }

/* ---- legend ---- */

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
  color: var(--muted);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.legend-pin {
  width: 14px;
  height: 14px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  flex: none;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.pin-confirmed-location { background: #1f6f8b; opacity: 0.85; }
.pin-approximate { background: var(--approximate); opacity: 0.85; }
.pin-placed { background: var(--placed); opacity: 0.85; }
.pin-confirmed { background: var(--confirmed); }

.legend-badge {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.app-footer {
  margin-top: auto;
  padding: 14px 18px 10px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.app-footer p { margin: 0 0 6px; }

.brand-line {
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--navy);
  text-transform: uppercase;
  font-size: 10px;
}

/* ---- Time Machine control ---- */

.timemachine {
  background: #fff;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 132px;
}

.timemachine label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--slate, #5b6b7a);
}

.timemachine select {
  font-size: 12px;
  padding: 3px 4px;
  border: 1px solid #d8dee3;
  border-radius: 4px;
}

.timemachine input[type="range"] { width: 100%; }

/* ---- map markers (divIcons) ---- */

.ghost-pin {
  background: none;
  border: none;
}

.ghost-pin svg {
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.ghost-pin .pin-body { opacity: 0.78; }
.ghost-pin.status-confirmed .pin-body { opacity: 1; }

/* Year + depth chip under a pin: the two facts a grower matches wells by.
 * Rendered inside the divIcon so it pans/zooms with the pin. */
.ghost-pin .pin-tag {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 1px);
  background: rgba(255, 255, 255, 0.94);
  color: #1d2731;
  border: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 6px;
  padding: 0 4px;
  font: 700 10px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.section-badge-icon {
  background: var(--badge);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.section-badge-icon .count { font-size: 14px; }
.section-badge-icon .label { font-size: 7px; font-weight: 600; opacity: 0.85; }

/* ---- popups ---- */

.leaflet-popup-content { margin: 12px 14px; }

.popup h4 {
  margin: 0 0 2px;
  font-size: 14px;
}

.popup .popup-sub {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 6px;
}

.popup dl {
  margin: 6px 0;
  font-size: 12px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
}

.popup dt { color: var(--muted); }
.popup dd { margin: 0; }

.popup .well-actions { margin-top: 10px; }

.popup .note {
  font-size: 11px;
  color: var(--danger);
  margin: 6px 0 0;
}

.popup .note.info { color: var(--muted); }

/* ---- WCR PDF preview modal ---- */

.pdf-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(13, 24, 33, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

/* display:flex above would otherwise defeat the hidden attribute. */
.pdf-modal[hidden] { display: none; }

.pdf-modal-box {
  background: var(--paper);
  border-radius: 12px;
  width: min(960px, 100%);
  height: min(86vh, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.pdf-modal-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.pdf-modal-bar strong { font-size: 14px; }

.pdf-modal-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pdf-modal-actions a { text-decoration: none; }

#pdf-modal-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #525659;
}

.pdf-modal-note {
  margin: 0;
  padding: 7px 12px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

@media (max-width: 720px) {
  #app { flex-direction: column-reverse; }
  #sidebar {
    width: 100%;
    max-width: none;
    height: 55%;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  #map { height: 45%; flex: none; }
}

/* ------------------------------------------------------- add-well modal */
.addwell-box {
  background: #fff;
  border-radius: 12px;
  width: min(560px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  padding: 22px 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}
.addwell-box h3 { margin: 0 0 10px; font-size: 20px; }
.addwell-context { margin: 0 0 4px; }
.addwell-chip {
  display: inline-block;
  background: #e7f3e7;
  color: #2c5f2d;
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 13px;
  font-weight: 600;
}
.addwell-loc {
  margin: 0 0 14px;
  color: var(--ink-soft, #51606e);
  font-size: 13px;
}
.addwell-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.addwell-field {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #33414e;
  margin-bottom: 10px;
}
.addwell-field input,
.addwell-field select,
.addwell-field textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid #cfd8e0;
  border-radius: 8px;
  font: inherit;
  font-weight: 400;
}
.addwell-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 6px;
}
.addwell-actions .btn { padding: 11px 0; }
.pin-section { background: #64748b; opacity: 0.85; }
.owner-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.pin-known { background: #0b7a55; }
.pin-known-open { background: #fff; border: 2px solid #0b7a55; }

/* ----------------------------------------------------------- map tools */
.map-tools {
  background: var(--paper);
  border-radius: 8px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.35);
  padding: 6px;
  font-family: inherit;
}
.map-tools-row { display: flex; gap: 4px; }
.map-tool-btn {
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  line-height: 1.2;
}
.map-tool-btn:hover { background: var(--wash); }
.map-tool-btn.active {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}
.map-tool-btn:disabled { opacity: 0.45; cursor: default; }
.map-tools-status {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  max-width: 190px;
  min-height: 0;
}
.map-tools-status:empty { display: none; }

/* PLSS section number labels */
.trs-label { background: none; border: none; }
.trs-label span {
  font-size: 11px;
  font-weight: 700;
  color: #7a5500;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff;
}

/* Measuring ruler */
.leaflet-container.measuring,
.leaflet-container.measuring .leaflet-interactive { cursor: crosshair; }
.measure-tip {
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 7px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.measure-tip::before { display: none; }

/* Undo toast */
.map-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 1500;
}
.map-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.known-row .well-card-top { margin-bottom: 0; }

/* ---- claim-a-field (portal mode) ---- */

.claim-row { margin-top: 10px; }

.claim-lede { margin: 0 0 6px; }

.claim-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.claim-btn {
  flex: 1;
  min-width: 96px;
  padding: 7px 10px;
  font-size: 12.5px;
}

#claim-mine.is-on {
  background: var(--confirmed);
  border-color: var(--confirmed);
  color: #fff;
}

#claim-not-mine.is-on {
  background: var(--muted);
  border-color: var(--muted);
  color: #fff;
}

#claim-no-wells.is-on {
  background: var(--approximate);
  border-color: var(--approximate);
  color: #fff;
}

/* ---- portal casing pins ---- */

.casing-pin {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 4px;
  background: var(--danger); color: #fff; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
}

.casing-pin.sent { background: var(--confirmed); }

.mark-pop { font-size: 13px; }

.mark-title { margin: 0 0 6px; font-weight: 700; color: var(--navy); }

.mark-types { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }

.mark-type {
  font: inherit; font-size: 11.5px; padding: 4px 8px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  color: var(--muted);
}

.mark-type.is-on { background: var(--danger); border-color: var(--danger); color: #fff; }

.mark-note { width: 100%; font: inherit; font-size: 12.5px; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; box-sizing: border-box; }

.mark-status { margin: 4px 0; }

.mark-btns { display: flex; gap: 6px; }

.mark-btns .mark-send { flex: 1; }

.chip-status-maybe { background: #fdf3dc; color: #8a5b00; }

.btn-flag { color: #8a5b00; border-color: #e8d9b8; }
