:root {
  --bg: #f6f5f1; --card: #ffffff; --ink: #1f2a24; --muted: #5f6b64; --line: #dcdad2;
  --green: #2e7d4f; --blue: #2b5fa8; --grey: #7b8580; --amber: #c7851a; --purple: #6d4fa6; --red: #b43b3b; --dark: #3b3f3d;
  --accent: #1f5e3f; --accent-ink: #ffffff; --warn-bg: #fff4d6; --warn-ink: #6b4a00;
  --radius: 10px; --shadow: 0 1px 3px rgba(0,0,0,.08), 0 6px 18px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15201a; --card: #1e2b24; --ink: #eef2ee; --muted: #a3b0a8; --line: #2f3d35; --accent: #58b386; --accent-ink: #0f1a14;
    --warn-bg: #3d2f0d; --warn-ink: #ffd98a; --shadow: 0 1px 3px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

.demo-banner { background: var(--warn-bg); color: var(--warn-ink); font-size: .85rem; padding: 6px 16px; text-align: center; }
header.top { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
header.top .title { flex: 1; min-width: 0; }
header.top .title h1 { font-size: 1.1rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top .title .muted { font-size: .8rem; }
.seal { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; flex: none; }

nav.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; position: sticky; top: 61px; z-index: 19; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs button { flex: 1 0 auto; border: 0; background: none; padding: 12px 14px; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
nav.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 16px; max-width: 980px; margin: 0 auto; }
main.full { padding: 0; max-width: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

input[type=text], input[type=search], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink);
  /* Never below 16px: iOS Safari zooms the whole page in when a smaller field is focused,
     which left the public sheet looking cut off on the right while typing. */
  font-size: max(16px, 1rem);
}
textarea { min-height: 70px; resize: vertical; }
label.field { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
label.field > span { display: block; margin-bottom: 3px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .95rem; color: var(--ink); }
.check input { width: 18px; height: 18px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }

.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; color: #fff; background: var(--grey); vertical-align: middle; }
.chip.available { background: var(--green); } .chip.sold { background: var(--blue); } .chip.occupied { background: var(--grey); }
.chip.reserved { background: var(--amber); } .chip.reclaimable { background: var(--purple); } .chip.not_for_sale { background: var(--dark); }
.chip.unknown { background: var(--red); } .chip.retired { background: #999; }
.chip.open, .chip.requested { background: var(--amber); } .chip.responded, .chip.location_confirmed, .chip.approved { background: var(--blue); }
.chip.poured, .chip.placed, .chip.closed { background: var(--green); } .chip.expired, .chip.cancelled { background: var(--red); }
.chip.vet { background: #1d4e89; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list li.clickable { cursor: pointer; }
.list li.clickable:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.list .name { font-weight: 600; }
.list .sub { color: var(--muted); font-size: .85rem; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* map */
.map-wrap { position: relative; height: calc(100dvh - 61px - 46px); min-height: 380px; }
.map-wrap.with-banner { height: calc(100dvh - 61px - 46px - 30px); }
#map, #adminMap { position: absolute; inset: 0; background: #202a24; }
.map-ui { position: absolute; left: 10px; right: 10px; top: 10px; z-index: 500; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.map-ui > * { pointer-events: auto; }
.map-ui .tools { flex-basis: 100%; display: flex; gap: 8px; pointer-events: none; }
.map-ui .tools > * { pointer-events: auto; box-shadow: var(--shadow); }
.btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.lot-label .price { display: block; font-size: 9px; line-height: 11px; color: #ffe066; }
.seclist li { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.seclist .lotnums { flex-basis: 100%; margin-top: 6px; }
.seclist .lotnums summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.seclist .lotnums .nums { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 8px; }
.seclist .lotnums .nums button { padding: 3px 8px; font-size: .8rem; }
.map-ui select { width: auto; max-width: 60%; box-shadow: var(--shadow); }
.legend { position: absolute; left: 10px; bottom: 24px; z-index: 500; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: .78rem; box-shadow: var(--shadow); display: grid; grid-template-columns: auto auto; gap: 3px 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -2px; }
.legend .attr { grid-column: 1 / -1; color: var(--muted); font-size: .68rem; margin-top: 2px; }
.sheet-open .legend, .sheet-open .leaflet-bottom, .sheet-open .map-ui { display: none; }
@media (min-width: 900px) { .sheet-open .legend, .sheet-open .leaflet-bottom, .sheet-open .map-ui { display: flex; } .sheet-open .legend { display: grid; } }
.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 10px 12px; font-size: .9rem; }
.leaflet-popup-content h3 { margin-bottom: 4px; }
.leaflet-popup-content .list li { padding: 5px 0; }
.lot-label { background: none; border: 0; box-shadow: none; color: #fff; font-size: 10px; font-weight: 700; text-shadow: 0 0 3px #000, 0 0 3px #000; text-align: center; line-height: 14px; pointer-events: none; white-space: nowrap; }

/* drawer / sheet */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 70dvh; background: var(--card); border-top-left-radius: 16px; border-top-right-radius: 16px; box-shadow: 0 -8px 30px rgba(0,0,0,.2); z-index: 600; transform: translateY(105%); transition: transform .25s; display: flex; flex-direction: column; }
.sheet.open { transform: none; }
.sheet .handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; }
/* Never scroll sideways: long names, URLs and notes wrap inside the sheet instead. */
.sheet .body { padding: 10px 16px calc(20px + env(safe-area-inset-bottom, 0px)); overflow-x: hidden; overflow-y: auto; overflow-wrap: anywhere; min-width: 0; }
.sheet .body > *, .sheet .where, .sheet .callout { min-width: 0; max-width: 100%; }
.sheet .close { position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 1.4rem; color: var(--muted); }
@media (min-width: 900px) {
  .sheet { left: auto; right: 16px; bottom: 16px; width: 420px; border-radius: 16px; max-height: 80dvh; }
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .n { font-size: 1.6rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .8rem; }

.empty { color: var(--muted); padding: 20px 0; text-align: center; }
.print-only { display: none; }
@media print {
  header.top, nav.tabs, .no-print, .demo-banner { display: none !important; }
  .print-only { display: block; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; color: #000; }
}

/* admin layout */
.admin { display: grid; grid-template-columns: 220px 1fr; min-height: 100dvh; }
.admin aside { background: var(--card); border-right: 1px solid var(--line); padding: 14px 10px; position: sticky; top: 0; height: 100dvh; overflow: auto; }
.admin aside .brand { padding: 4px 8px 12px; }
.admin aside a.nav { display: block; padding: 9px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.admin aside a.nav.active { background: color-mix(in srgb, var(--accent) 14%, transparent); font-weight: 600; }
.admin section.content { padding: 16px; min-width: 0; }
.admin .content > h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.admin .content > h1 .row { margin-left: auto; }
@media (max-width: 820px) {
  .admin { grid-template-columns: 1fr; grid-template-rows: auto 1fr; align-content: start; }
  .admin aside { position: sticky; top: 0; z-index: 20; height: auto; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .admin aside::-webkit-scrollbar { display: none; }
  .admin aside a.nav { flex: 0 0 auto; }
  .admin section.content { padding: 12px; }
  .admin-map-wrap { height: calc(100dvh - 150px); min-height: 320px; }
  .admin aside .brand { display: none; }
  .admin aside a.nav { white-space: nowrap; padding: 8px 10px; }
  .admin aside .signout { margin-left: auto; }
}
.login { max-width: 380px; margin: 10vh auto; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 1000; font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; pointer-events: auto; }
.toast .btn { background: var(--bg); color: var(--ink); border-color: var(--bg); }
.history { font-size: .82rem; }
.history li { padding: 6px 0; }
.history code { font-size: .78rem; background: color-mix(in srgb, var(--ink) 6%, transparent); padding: 1px 4px; border-radius: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 12px; }
.form-grid .wide { grid-column: 1 / -1; }
dialog { border: 0; border-radius: 14px; padding: 0; max-width: 560px; width: calc(100% - 24px); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 18px; }
dialog h2 { margin-bottom: 12px; }
.admin-map-wrap { position: relative; height: calc(100dvh - 120px); min-height: 400px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
/* Plat overlay panel and the drag handles for positioning a plat scan on the map. */
.plat-panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; display: grid; gap: 8px; }
.plat-panel p { margin: 0; }
.plat-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.plat-row .check { flex: 1 1 160px; min-width: 0; margin: 0; }
.plat-opacity { display: flex; align-items: center; gap: 6px; } .plat-opacity input { width: 110px; }
.plat-handle { border-radius: 50%; background: #ffe066; border: 3px solid #222; box-shadow: 0 1px 4px rgba(0,0,0,.5); box-sizing: border-box; cursor: grab; }
.plat-handle.move { background: #fff; display: grid; place-items: center; font-size: 17px; line-height: 1; color: #222; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { width: auto; }
/* Veterans are marked with a small US flag (an inline SVG, so it also renders on Windows PCs where flag emoji does not). */
:root { --flag: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 19 13'%3E%3Crect width='19' height='13' fill='%23fff'/%3E%3Cpath d='M0 0h19v1H0zM0 2h19v1H0zM0 4h19v1H0zM0 6h19v1H0zM0 8h19v1H0zM0 10h19v1H0zM0 12h19v1H0z' fill='%23b22234'/%3E%3Crect width='8' height='7' fill='%233c3b6e'/%3E%3C/svg%3E"); }
.flag { display: inline-block; width: 15px; height: 10px; background: var(--flag) no-repeat center / contain; vertical-align: -1px; }
.lot-label .flag { width: 11px; height: 8px; margin-left: 2px; vertical-align: 0; filter: drop-shadow(0 0 1px #000); }
.chip.vet::before { content: ''; display: inline-block; width: 13px; height: 9px; margin-right: 4px; background: var(--flag) no-repeat center / contain; vertical-align: -1px; }
.legend .flag { width: 12px; margin-right: 5px; vertical-align: -1px; }
.leaflet-container.drawing { cursor: crosshair; touch-action: none; }
.leaflet-container.drawing .leaflet-interactive { cursor: crosshair; pointer-events: none; }

/* Long-press on the map must not select text or show the iOS copy menu. */
.leaflet-container, .leaflet-container .leaflet-control { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* public: one-box search entry on the map, record cards, inquiry form */
.map-ui .find { flex: 1 1 100%; justify-content: flex-start; color: var(--muted); box-shadow: var(--shadow); order: -1; }
.map-ui .find span { font-size: 1.1rem; color: var(--ink); }
@media (min-width: 700px) { .map-ui .find { flex: 0 1 300px; } }
.eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
.sheet h3 { font-size: 1.2rem; padding-right: 28px; }
.sheet h4 { margin: 14px 0 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.callout { background: color-mix(in srgb, var(--green) 10%, var(--card)); border: 1px solid color-mix(in srgb, var(--green) 35%, var(--line)); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.where { background: color-mix(in srgb, var(--ink) 4%, transparent); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-weight: 600; }
.crumbs i { color: var(--muted); font-style: normal; }
.facts { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 4px 12px; margin: 10px 0; font-size: .95rem; }
.facts .fact { display: contents; }
.facts .fact > * { min-width: 0; overflow-wrap: anywhere; }
.facts .k { color: var(--muted); font-size: .85rem; padding-top: 2px; }
.list.people li { position: relative; padding-right: 22px; }
.list.people .chev { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 1.3rem; }
.where-line { color: var(--ink); opacity: .85; }
.sheet .actions { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.photos { display: flex; gap: 8px; overflow-x: auto; margin: 10px 0 4px; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.photos img { height: 96px; width: auto; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; flex: none; object-fit: cover; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 2000; display: none; place-items: center; cursor: zoom-out; }
.lightbox.show { display: grid; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lightbox .cap { position: absolute; left: 0; right: 0; bottom: env(safe-area-inset-bottom, 0px); padding: 10px 16px; color: #fff; font-size: .9rem; text-align: center; background: rgba(0,0,0,.5); }
.hp { position: absolute; left: -9999px; top: -9999px; height: 0; overflow: hidden; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--red); color: #fff; font-size: .7rem; line-height: 18px; text-align: center; vertical-align: middle; font-weight: 700; }
a.stat { text-decoration: none; color: inherit; display: block; }
.stat.attention { border-color: var(--red); background: color-mix(in srgb, var(--red) 8%, var(--card)); }
.chip.new { background: var(--red); } .chip.in_progress { background: var(--amber); }
.photos img.private { outline: 2px dashed var(--amber); outline-offset: -2px; }
.qr { background: #fff; padding: 6px; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.qr svg { display: block; width: 150px; height: 150px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; max-width: 320px; }
.stack label.field { margin-bottom: 0; }
