:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dfe4ea;
  --text: #1c2430;
  --muted: #66717f;
  --accent: #1f6f4f;
  --accent-soft: #e6f2ec;
  --warn: #9a5b00;
  --warn-soft: #fdf3e2;
  --match: #1f6f4f;
  --selected: #c2410c;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a1f27;
    --surface-2: #202631;
    --border: #2c343f;
    --text: #e7ecf2;
    --muted: #96a1b0;
    --accent: #4ade80;
    --accent-soft: #16281f;
    --warn: #fbbf24;
    --warn-soft: #2a2113;
    --match: #4ade80;
    --selected: #fb923c;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

/* ── Top bar ─────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: none;
}

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

.mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  letter-spacing: .5px;
}
@media (prefers-color-scheme: dark) { .mark { color: #0d1512; } }

.brand h1 { font-size: 16px; letter-spacing: -.01em; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }

.topbar-actions { display: flex; align-items: center; gap: 12px; }
.build-info { font-size: 11px; color: var(--muted); }

/* ── Layout ──────────────────────────────────────────────── */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 380px;
  gap: 1px;
  background: var(--border);
}

.panel {
  background: var(--surface);
  overflow-y: auto;
  min-height: 0;
}

.panel-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ── Filters ─────────────────────────────────────────────── */

.filters { padding-bottom: 16px; }

.fieldset {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.fieldset h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }

input[type=number], input[type=text], select, textarea {
  width: 100%;
  margin-top: 3px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
select[multiple] { padding: 2px; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.inline-input { display: inline-flex; align-items: baseline; gap: 4px; }
.inline-input input { width: 80px; }

.checks { display: flex; flex-direction: column; gap: 2px; }
.checks label, .switch {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--text); margin-bottom: 0; padding: 3px 0;
  cursor: pointer;
}
input[type=checkbox] { accent-color: var(--accent); margin: 0; flex: none; }

.hint { margin: 4px 0 8px; font-size: 11px; color: var(--muted); }
.hint code { background: var(--surface-2); padding: 0 3px; border-radius: 3px; }

.disabled-field { opacity: .55; }
.disabled-field select { cursor: not-allowed; }

.frequent summary { font-size: 12px; color: var(--accent); cursor: pointer; padding: 4px 0; }
.frequent div { max-height: 160px; overflow-y: auto; margin-top: 4px; }
.frequent button {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; padding: 3px 4px;
  font: inherit; font-size: 12px; color: var(--text);
  border-radius: 4px; cursor: pointer;
}
.frequent button:hover { background: var(--surface-2); color: var(--accent); }

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
@media (prefers-color-scheme: dark) { .btn-primary { color: #0d1512; } }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary:hover:not(:disabled) { color: #0d1512; } }

.btn-block { width: calc(100% - 28px); margin: 14px; display: block; padding: 10px; }
.btn-link { background: none; border: 0; color: var(--accent); padding: 2px 4px; font-size: 12px; }
.btn-ghost { padding: 5px 10px; font-size: 12px; }

/* ── Map ─────────────────────────────────────────────────── */

.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

.map-legend {
  position: absolute;
  left: 10px; bottom: 22px;
  z-index: 500;
  display: flex; gap: 12px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  box-shadow: var(--shadow);
}
.map-legend span { display: flex; align-items: center; gap: 5px; }
.swatch { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }
.swatch-match { background: var(--match); opacity: .6; border: 1px solid var(--match); }
.swatch-selected { background: var(--selected); opacity: .6; border: 1px solid var(--selected); }

/* ── Results ─────────────────────────────────────────────── */

.pill {
  font-size: 12px; font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.notes {
  margin: 10px 14px;
  padding: 8px 10px;
  font-size: 12px;
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 6px;
}

.results-list { padding: 6px 0; }
.empty { padding: 24px 16px; color: var(--muted); font-size: 13px; text-align: center; }

.result {
  display: block; width: 100%; text-align: left;
  padding: 10px 14px;
  border: 0; border-left: 3px solid transparent;
  border-bottom: 1px solid var(--border);
  background: none;
  font: inherit;
  cursor: pointer;
}
.result:hover { background: var(--surface-2); }
.result.active { border-left-color: var(--selected); background: var(--surface-2); }

.result-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.result-addr { font-weight: 600; font-size: 13px; }
.result-acres { font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }
.result-owner { font-size: 12px; color: var(--muted); margin-top: 2px; }
.result-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }

.tag {
  font-size: 10px; font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
}
.tag-good { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.tag-warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }

/* ── Detail ──────────────────────────────────────────────── */

.detail { padding: 0 0 24px; }

.detail-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.detail-head h3 { font-size: 15px; }
.detail-head .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.detail-section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.detail-section h4 {
  margin: 0 0 8px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.owner-card {
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.owner-name { font-weight: 600; font-size: 14px; }
.owner-mail {
  margin: 6px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-line;
  color: var(--muted);
}
.owner-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.owner-actions .btn { font-size: 12px; padding: 5px 9px; }

.links { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.links a { color: var(--accent); }

/* ── Sign-in ─────────────────────────────────────────────── */

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.auth-brand h1 { font-size: 18px; }
.auth-brand p { margin: 0; font-size: 12px; color: var(--muted); }

.auth-card label { margin-bottom: 14px; }
.auth-card input { font-size: 14px; padding: 9px 10px; }
.auth-card .btn-block { width: 100%; margin: 4px 0 0; }

.auth-error {
  margin: 0 0 12px;
  padding: 8px 10px;
  font-size: 12px;
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 6px;
}

.auth-foot {
  margin: 18px 0 0;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

/* ── Top bar additions ───────────────────────────────────── */

.topbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}
.topbar-actions a.btn { text-decoration: none; }

/* ── Admin ───────────────────────────────────────────────── */

.admin-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-content: start;
}

.admin-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.admin-panel .panel-head { position: static; }

.table-scroll { overflow-x: auto; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table .right { text-align: right; white-space: nowrap; }
.admin-table .muted { color: var(--muted); }
.user-name { font-weight: 600; margin-right: 6px; }
.row-disabled { opacity: .55; }

.admin-form { padding: 14px; }
.admin-form .btn { width: 100%; margin-top: 8px; }
.optional { color: var(--muted); font-weight: 400; }
.admin-hint { padding: 0 14px 12px; margin: 0; }

.btn-danger:hover:not(:disabled) { border-color: #dc2626; color: #dc2626; }

.notes-ok {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ── Dialog ──────────────────────────────────────────────── */

.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.dialog::backdrop { background: rgba(0, 0, 0, .5); }
.dialog h3 { font-size: 16px; margin-bottom: 16px; }
.dialog label { margin-bottom: 12px; }
.dialog input[type=text], .dialog input[type=password], .dialog input[type=email] {
  font-size: 14px; padding: 8px 10px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

@media (max-width: 800px) {
  .admin-wrap { grid-template-columns: 1fr; }
}

/* ── Narrow screens ──────────────────────────────────────── */

@media (max-width: 1100px) {
  body { height: auto; }
  .layout { grid-template-columns: 1fr; }
  .panel { max-height: 480px; }
  .map-wrap { height: 420px; }
}
