:root {
  --ink: #1c1712;
  --paper: #efe6d6;
  --paper-2: #f7f1e6;
  --rule: #c9b89a;
  --pine: #1f3d32;
  --pine-2: #2f5c4a;
  --clay: #8a3b22;
  --muted: #6d6254;
  --ok: #2f5c4a;
  --bad: #8a3b22;
  --found: #b4532a;
  --street: #e3b341;
  --deleted: #c43131;
  --toolbar: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #d9cbb3;
  color: var(--ink);
  font-family: "IBM Plex Sans", sans-serif;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  min-height: var(--toolbar);
  padding: 8px 12px;
  background: color-mix(in srgb, var(--paper-2) 92%, white);
  border-bottom: 1px solid var(--rule);
  z-index: 500;
}

.brand {
  display: flex;
  gap: 8px;
  align-items: center;
}

.seal {
  width: 32px;
  height: 32px;
  border: 2px solid var(--clay);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--clay);
}

h1 {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
  max-width: 13.5rem;
  font-weight: 600;
}

.session {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

#session-name {
  font-size: 12px;
  color: var(--muted);
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule);
  padding: 7px 10px;
}

button.ghost:hover { background: #fffdf8; }

dialog {
  width: min(760px, calc(100% - 24px));
  border: 1px solid var(--rule);
  background: var(--paper-2);
  color: var(--ink);
  padding: 0;
}

dialog::backdrop {
  background: rgba(28, 23, 18, 0.45);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule);
}

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

.dialog-error {
  margin: 8px 14px 0;
  color: var(--bad);
  font-size: 13px;
}

.dialog-table { max-height: 36vh; padding: 8px 14px; }

.user-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  padding: 12px 14px 16px;
  border-top: 1px solid var(--rule);
}

.user-form h3 {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 14px;
}

.user-form label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
}

.user-form input,
.user-form select {
  font: 13px/1.3 "IBM Plex Sans", sans-serif;
  padding: 7px 8px;
  border: 1px solid var(--rule);
  background: #fffdf8;
}

.user-actions button {
  padding: 6px 8px;
  font-size: 12px;
}

.search {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 240px;
  max-width: 420px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 600;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-ui {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: #9a8d78;
  position: relative;
  flex: 0 0 auto;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fffdf8;
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-ui {
  background: var(--pine);
}

.switch input:checked + .switch-ui::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-ui {
  outline: 2px solid var(--pine);
  outline-offset: 2px;
}

.switch input:disabled + .switch-ui,
.switch:has(input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

input[id="code"] {
  flex: 1;
  font: 500 14px/1.2 "IBM Plex Mono", monospace;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  background: #fffdf8;
  color: var(--ink);
}

button {
  font: 600 13px/1 "IBM Plex Sans", sans-serif;
  border: 0;
  background: var(--pine);
  color: #f6efe3;
  padding: 9px 12px;
  cursor: pointer;
}

button:hover { background: var(--pine-2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.company {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

.status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  min-width: 12ch;
  flex: 1;
}

.status.error { color: var(--bad); }
.status.ok { color: var(--ok); }

.map-stage {
  position: relative;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
}

.dock-tools {
  display: flex;
  justify-content: flex-end;
  padding: 4px 10px;
  border-bottom: 1px solid var(--rule);
  background: #f3ebe0;
}

.export-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.export-bar button {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 64px;
  padding: 5px 8px 4px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 4px;
}

.export-bar button svg {
  width: 18px;
  height: 18px;
  display: block;
}

.export-bar button span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.export-bar button:hover:not(:disabled) {
  background: #fffdf8;
  border-color: var(--rule);
}

.export-bar button:disabled {
  opacity: 0.38;
}

.export-bar button[data-export="xlsx"]:not(:disabled) { color: #1f6b43; }
.export-bar button[data-export="csv"]:not(:disabled) { color: #4a5a3c; }
.export-bar button[data-export="shp-4326"]:not(:disabled),
.export-bar button[data-export="shp-3059"]:not(:disabled) { color: #3d4d62; }

.dock {
  background: color-mix(in srgb, var(--paper-2) 94%, white);
  border-top: 1px solid var(--rule);
  max-height: 48vh;
  overflow: auto;
}

.dock details {
  border-bottom: 1px solid var(--rule);
}

.dock summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  background: #f3ebe0;
}

.dock summary::-webkit-details-marker { display: none; }
.dock summary::before {
  content: "";
  width: 0.45em;
  height: 0.45em;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: rotate(-45deg);
  margin-right: 4px;
}

.dock details[open] summary::before { transform: rotate(45deg); }

.count {
  margin-left: 4px;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
}

.hint { color: var(--muted); font-size: 13px; margin: 8px 14px; }

.table-wrap {
  overflow: auto;
  max-height: 32vh;
  padding: 0 8px 8px;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { position: sticky; top: 0; background: var(--paper-2); }
.empty td { color: var(--muted); text-align: center; padding: 18px; }

tr.is-deleted {
  color: #8a1f1f;
  background: color-mix(in srgb, #c43131 10%, transparent);
}

tr.is-street {
  color: #6b5308;
  background: color-mix(in srgb, #e3b341 18%, transparent);
}

.match-warn {
  display: inline-grid;
  place-items: center;
  width: 1.2em;
  height: 1.2em;
  margin-right: 6px;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-weight: 700;
  font-size: 12px;
}

select { max-width: 100%; font: 13px/1.3 "IBM Plex Sans", sans-serif; }

.table-wrap button { padding: 7px 10px; }

#raw-frame {
  width: calc(100% - 16px);
  height: 28vh;
  margin: 8px;
  border: 1px solid var(--rule);
  background: white;
}

.leaflet-control-layers {
  border: 1px solid var(--rule) !important;
  border-radius: 0 !important;
  background: color-mix(in srgb, var(--paper-2) 92%, white) !important;
  box-shadow: 0 6px 18px rgba(40, 24, 10, 0.12) !important;
  color: var(--ink);
  font: 12px/1.4 "IBM Plex Sans", sans-serif;
  min-width: 11.5rem;
}

.layers-legend-title {
  padding: 7px 10px 2px;
  font-weight: 600;
  font-size: 12px;
}

.leaflet-control-layers-overlays {
  padding: 2px 6px 8px 8px;
}

.leaflet-control-layers-overlays label > span {
  display: flex;
  align-items: center;
}

.leaflet-control-layers-overlays label {
  display: block;
  margin: 3px 0;
}

.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin: 0 6px 0 4px;
  border-radius: 50%;
  vertical-align: middle;
  flex: 0 0 auto;
}

.legend-swatch.found { background: var(--found); }
.legend-swatch.street { background: var(--street); box-shadow: 0 0 0 1px #8a6a10; }
.legend-swatch.deleted { background: var(--deleted); }

.leaflet-tooltip.addr-label {
  background: color-mix(in srgb, var(--paper-2) 94%, white);
  border: 1px solid var(--rule);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(40, 24, 10, 0.12);
  font: 12px/1.35 "IBM Plex Sans", sans-serif;
}

@media (max-width: 880px) {
  .status { margin-left: 0; width: 100%; }
  .dock { max-height: 42vh; }
  .export-bar button { min-width: 56px; padding: 4px 6px 3px; }
}
