:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --border: #dde1e7;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --warn-bg: #fffaeb;
  --warn-text: #93370d;
  --ok-bg: #ecfdf3;
  --ok-text: #05603a;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121417;
    --surface: #1a1d21;
    --surface-2: #22262b;
    --text: #e6e8eb;
    --muted: #9aa4b2;
    --border: #2e333a;
    --accent: #5fb38a;
    --accent-text: #0d1a13;
    --danger: #f97066;
    --danger-bg: #2a1614;
    --warn-bg: #2a2110;
    --warn-text: #fdb022;
    --ok-bg: #0f2419;
    --ok-text: #6ce9a6;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 650; }
.topbar .brand a { color: inherit; text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; margin-left: 12px; }
.nav a { padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.topbar .brand small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.topbar .who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }

main { max-width: 1040px; margin: 0 auto; padding: 24px 16px 64px; }

h1 { font-size: 24px; margin: 0 0 4px; }
.lead { color: var(--muted); margin: 0 0 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { font-size: 17px; margin: 0 0 4px; }
.card > p.help { color: var(--muted); margin: 0 0 16px; font-size: 14px; }

.notice {
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 16px;
  background: var(--warn-bg);
  color: var(--warn-text);
}
.notice.ok { background: var(--ok-bg); color: var(--ok-text); }
.notice.error { background: var(--danger-bg); color: var(--danger); }

label { display: block; font-weight: 550; font-size: 14px; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.field .error-text { color: var(--danger); font-size: 13px; margin-top: 4px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"], input[type="tel"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[aria-invalid="true"] { border-color: var(--danger); }

.money { position: relative; }
.money::before { content: "$"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money input { padding-left: 22px; }

button {
  font: inherit;
  font-weight: 550;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.link { background: none; border: none; padding: 0; color: var(--accent); font-weight: 500; }
button.danger-link { background: none; border: none; padding: 0; color: var(--danger); font-weight: 500; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }

.actions { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.status { font-size: 14px; color: var(--muted); }
.status.ok { color: var(--ok-text); }
.status.error { color: var(--danger); }

.levels { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.levels th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 550; padding: 0 8px 8px 0; }
.levels td { padding: 8px 8px 8px 0; border-top: 1px solid var(--border); vertical-align: middle; }
.levels td.price { width: 150px; }
.levels td.avail { width: 90px; text-align: center; }
.levels .lvl { font-weight: 600; }
.levels .desc { color: var(--muted); font-size: 13px; }

.radio-row { display: flex; gap: 18px; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-weight: 500; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

.login { max-width: 380px; margin: 48px auto; }

.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }

[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
textarea { resize: vertical; line-height: 1.45; }

.back { display: inline-block; margin-bottom: 8px; font-size: 14px; text-decoration: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.page-head .badge { margin-top: 6px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar input[type="search"] { flex: 1; }
.toolbar select { width: auto; }
.field.narrow { max-width: 420px; }
.grid-2.tight { gap: 0 10px; }
fieldset.field { border: 0; padding: 0; margin: 0 0 14px; }
fieldset.field legend { font-weight: 550; font-size: 14px; margin-bottom: 6px; padding: 0; }
label.choice { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-bottom: 6px; }

.card.flush { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 550; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.table tbody tr:first-child td { border-top: 0; }
.card:not(.flush) .table { margin-bottom: 12px; }
.card:not(.flush) .table th, .card:not(.flush) .table td { padding-left: 0; }
.table a { text-decoration: none; }
.table a:hover { text-decoration: underline; }
.table td.empty { color: var(--muted); padding: 20px 12px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions button { margin-left: 12px; font-size: 13px; }

.badge.status-active, .badge.map-published { background: var(--ok-bg); color: var(--ok-text); }
.badge.status-suspended, .badge.map-client_review { background: var(--warn-bg); color: var(--warn-text); }
.badge.status-closed, .badge.map-archived { background: var(--surface-2); color: var(--muted); }
.badge.map-approved { background: var(--ok-bg); color: var(--ok-text); }

.dialog { width: min(560px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 10px; padding: 20px; background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(15, 18, 22, .45); }
.dialog h2 { font-size: 18px; margin: 0 0 16px; }
.dialog-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.dialog-actions .status { margin-right: auto; }

.notes, .activity { list-style: none; margin: 0 0 14px; padding: 0; }
.notes li, .activity li { padding: 10px 0; border-top: 1px solid var(--border); }
.notes li:first-child, .activity li:first-child { border-top: 0; padding-top: 0; }
.note-text { white-space: pre-wrap; }
.note-meta { color: var(--muted); font-size: 13px; margin-top: 4px; display: flex; gap: 10px; align-items: center; }

.danger-zone { border-color: var(--danger); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

.roles { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; }
.roles dt { font-weight: 600; }
.roles dd { margin: 0; color: var(--muted); }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; }
  .nav { order: 3; flex-basis: 100%; margin-left: -10px; overflow-x: auto; }
}

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; gap: 8px; }
  .toolbar { flex-direction: column; }
  .toolbar select { width: 100%; }
  .roles { grid-template-columns: 1fr; }
  .roles dd { margin-bottom: 8px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 12px; border-top: 1px solid var(--border); }
  .table tbody tr:first-child { border-top: 0; }
  .card:not(.flush) .table tr { padding-left: 0; padding-right: 0; }
  .table td { border: 0; padding: 2px 0; }
  .table td[data-label]:not([data-label="Client"]):not([data-label="Name"]):not([data-label="Map"])::before { content: attr(data-label) ": "; color: var(--muted); font-size: 13px; }
  .row-actions { text-align: left; white-space: normal; padding-top: 6px !important; }
  .row-actions button { margin: 0 14px 0 0; }
  .levels thead { display: none; }
  .levels tr { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); }
  .levels td { border: none; padding: 0; }
  .levels td.price { grid-column: 1; width: auto; }
  .levels td.avail { grid-column: 2; grid-row: 1; width: auto; }
}

/* ---------------------------------------------------------- map builder */

main.wide { max-width: none; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.dialog-wide { width: min(760px, calc(100vw - 32px)); }
a.button {
  display: inline-block; font-weight: 550; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); text-decoration: none;
}
code { font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.warn-text { color: var(--warn-text); }
.head-badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.narrow-panel { max-width: 880px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; }

.workflow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 4px 0 4px;
}
.workflow-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 8px 0 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 14px; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.editor { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.editor-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.editor-toolbar .spacer { flex: 1; }
.tool-group { display: flex; gap: 2px; }
.tool-group button { padding: 6px 10px; }
.tool-group button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tool-opts { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.tool-opts input[type="number"] { width: 70px; padding: 5px 6px; }
.tool-opts input[type="color"] { width: 34px; height: 30px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.tool-opts select { width: auto; padding: 5px 6px; }
.tool-opts label { font-weight: 500; margin: 0; display: inline-flex; align-items: center; gap: 4px; }
.editor-body { display: grid; grid-template-columns: 1fr 280px; height: calc(100vh - 260px); min-height: 480px; }
.editor-canvas { position: relative; background: #f4f2ec; overflow: hidden; }
#editor-svg { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; cursor: grab; }
#editor-svg.pm-panning { cursor: grabbing; }
#editor-svg[data-tool="lot"], #editor-svg[data-tool="road"], #editor-svg[data-tool="shape"], #editor-svg[data-tool="label"] { cursor: crosshair; }
.editor-panel { border-left: 1px solid var(--border); padding: 12px 14px; overflow: auto; font-size: 14px; }
.editor-panel h3 { margin: 0 0 6px; font-size: 16px; }
.editor-panel .field { margin-top: 12px; }
.editor-panel textarea { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; margin-bottom: 6px; }
.editor-panel details summary { cursor: pointer; font-weight: 550; margin-bottom: 6px; }
.editor-hint { color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 16px; }
.panel-actions { display: flex; gap: 16px; margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--border); }

.ed-lot-shape { fill: var(--lot); fill-opacity: .35; stroke: #2f343a; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.ed-lot:hover .ed-lot-shape { fill-opacity: .5; }
.ed-lot.ed-selected .ed-lot-shape { fill-opacity: .55; stroke: #0b6bcb; stroke-width: 2.5; }
.ed-lot-label { fill: #1f2328; font-weight: 600; pointer-events: none; }
.ed-selected:not(g) { outline: none; filter: drop-shadow(0 0 2px #0b6bcb) drop-shadow(0 0 2px #0b6bcb); }
#editor-svg .pm-obj { pointer-events: visiblePainted; cursor: pointer; }
.ed-handle { fill: #fff; stroke: #0b6bcb; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: move; }
.ed-label-handle { fill: rgba(11, 107, 203, .15); stroke: #0b6bcb; stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: move; }
.ed-draft { fill: rgba(11, 107, 203, .12); stroke: #0b6bcb; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.ed-draft-road { fill: none; stroke: rgba(11, 107, 203, .35); stroke-linecap: round; stroke-linejoin: round; vector-effect: none; }
.ed-draft-close { fill: none; stroke: #0b6bcb; stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.ed-draft-pt { fill: #0b6bcb; pointer-events: none; }
.ed-draft-pt.ed-first { fill: #fff; stroke: #0b6bcb; stroke-width: 2; vector-effect: non-scaling-stroke; }
.ed-snap { fill: none; stroke: #e5484d; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.ed-underlay image { pointer-events: none; }

.lots-table select { padding: 4px 6px; width: auto; }

.detail-fields { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px 4px; margin: 0 0 14px; }
.detail-fields legend { font-weight: 600; padding: 0 6px; }

.level-options { display: flex; flex-direction: column; gap: 6px; }
.level-option { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.level-option > span { display: flex; flex-direction: column; gap: 2px; }
.level-option:has(input:checked) { border-color: var(--accent); background: var(--surface-2); }
.downgrade-warning {
  border: 2px solid var(--danger); background: var(--danger-bg); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0;
}
.downgrade-warning h3 { color: var(--danger); margin: 0 0 8px; font-size: 18px; }
.downgrade-warning ul { margin: 0 0 10px; padding-left: 20px; }
.downgrade-warning .field { margin: 10px 0 0; }

.preview-bar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.preview-bar h1 { margin: 0; }
.preview-bar p { margin: 4px 0 0; }
.preview-map { height: calc(100vh - 200px); min-height: 480px; }

@media (max-width: 900px) {
  .editor-body { grid-template-columns: 1fr; height: auto; }
  .editor-canvas { height: 65vh; }
  .editor-panel { border-left: 0; border-top: 1px solid var(--border); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .grid-3 { grid-template-columns: 1fr; }
  .workflow { flex-direction: column; align-items: stretch; }
}
textarea.code { font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; margin-bottom: 6px; background: var(--surface-2); }

/* ---------------------------------------------------------- client portal */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 0 0 20px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
a.stat:hover { border-color: var(--accent); }
.stat-value { font-size: 24px; font-weight: 650; }
.stat-label { color: var(--muted); font-size: 13px; }
.review-notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.overview { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.portal-preview { height: calc(100vh - 300px); min-height: 460px; }
.portal-preview > p { padding: 40px; text-align: center; }

.lead-message { max-width: 380px; white-space: pre-wrap; }
.table tfoot td { border-top: 2px solid var(--border); padding-top: 10px; }
.card:not(.flush) .table tfoot td { padding-left: 0; }
details.small summary { cursor: pointer; color: var(--muted); }

/* Lot dialog: photos and links */
.media { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 12px; }
.media h3 { font-size: 16px; margin: 0 0 10px; }
.photo-grid { list-style: none; margin: 0 0 10px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.photo-grid li { position: relative; display: flex; flex-direction: column; gap: 6px; }
.photo-grid img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.photo-grid input { padding: 5px 8px; font-size: 13px; }
.photo-main { position: absolute; top: 6px; left: 6px; background: var(--accent); color: var(--accent-text); }
.photo-actions { display: flex; justify-content: space-between; font-size: 13px; }
.photo-actions button { font-size: 13px; }
label.button { cursor: pointer; margin: 0; font-weight: 550; }
.link-list { list-style: none; margin: 0 0 10px; padding: 0; }
.link-list li { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; padding: 6px 0; border-top: 1px solid var(--border); }
.link-list li:first-child { border-top: 0; }
.link-list .danger-link { margin-left: auto; font-size: 13px; }
.link-form { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; }

@media (max-width: 900px) {
  .overview { grid-template-columns: 1fr; }
  .portal-preview { height: 65vh; }
}
@media (max-width: 640px) {
  .link-form { grid-template-columns: 1fr; }
}
.setup-steps { margin: 0 0 14px; font-size: 14px; }
.setup-steps summary { cursor: pointer; font-weight: 550; color: var(--accent); }
.setup-steps ol { padding-left: 20px; }
.setup-steps li { margin-bottom: 6px; }
.badge.status-failed { background: var(--danger-bg); color: var(--danger); }
.row-actions a { margin-left: 12px; font-size: 13px; }
.ed-frame { fill: none; stroke: #0b6bcb; stroke-width: 1.5; stroke-dasharray: 8 6; vector-effect: non-scaling-stroke; pointer-events: none; }
.ed-frame-label { fill: #0b6bcb; font-weight: 600; pointer-events: none; }

/* Planned maintenance (private/maintenance.txt) */
.maintenance-banner { background: var(--warn-bg); color: var(--warn-text); border-bottom: 1px solid var(--border); padding: 8px 16px; font-size: 14px; text-align: center; }
.level-option.locked { opacity: .55; cursor: not-allowed; }

/* Symbol picker */
.symbol-grid { max-height: 60vh; overflow: auto; }
.symbol-grid h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); }
.symbol-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.symbol-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.symbol-pick { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; padding: 8px 4px; font-weight: 500; font-size: 12px; background: var(--surface); }
.symbol-pick:hover { border-color: var(--accent); }
.symbol-pick svg { background: #f4f2ec; border-radius: 6px; }
.symbol-delete { font-size: 12px; }
.symbol-paste-row { display: grid; grid-template-columns: 110px 1fr; gap: 14px; align-items: start; }
.symbol-preview { width: 104px; min-height: 104px; border: 1px dashed var(--border); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--danger); padding: 4px; text-align: center; background: #f4f2ec; }
#editor-svg g.pm-obj.ed-selected { filter: drop-shadow(0 0 2px #0b6bcb) drop-shadow(0 0 2px #0b6bcb); }
