:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #15202b;
  --muted: #5b6875;
  --line: #dde3ea;
  --accent: #2f6fdf;
  --accent-ink: #ffffff;
  --warn: #b45309;
  --warn-bg: #fff4e5;
  --ok: #15803d;
  --error: #b42318;
  --radius: 10px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --surface: #171e26; --text: #e6edf3; --muted: #9aa7b4; --line: #2a3542;
    --accent: #6ea0ff; --accent-ink: #0b1220; --warn: #f5a524; --warn-bg: #2b2112; --ok: #4ade80; --error: #ff8a80;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #171e26; --text: #e6edf3; --muted: #9aa7b4; --line: #2a3542;
  --accent: #6ea0ff; --accent-ink: #0b1220; --warn: #f5a524; --warn-bg: #2b2112; --ok: #4ade80; --error: #ff8a80;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.2em; }
[hidden] { display: none !important; }

.bar { display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 56px; background: var(--surface); border-bottom: 1px solid var(--line); position: relative; z-index: 1000; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; letter-spacing: .2px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, #7cc4ff, var(--accent)); display: inline-block; }
.title { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bar nav { margin-left: auto; display: flex; gap: 4px; overflow-x: auto; flex: none; max-width: 100%; }
.bar nav button { background: none; border: 0; color: var(--muted); min-height: 44px; padding: 8px 12px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.bar nav button[aria-current="page"] { color: var(--text); background: var(--bg); font-weight: 600; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--warn); color: #fff; font-size: 12px; font-weight: 700; text-align: center; margin-left: 4px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; cursor: pointer; }
.btn.secondary { background: transparent; color: var(--accent); }
.btn.quiet { background: transparent; color: var(--muted); border-color: var(--line); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: default; }
input, textarea, select { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
input:not([type="checkbox"]):not([type="radio"]), select { min-height: 44px; }
textarea { min-height: 180px; resize: vertical; }
label { display: block; font-weight: 600; margin: 12px 0 6px; }

.gate { display: grid; place-items: center; min-height: calc(100% - 56px); padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 440px; }
.card h1 { font-size: 20px; margin: 0 0 8px; }
.card form { margin-top: 12px; }
.card form .btn { margin-top: 12px; width: 100%; }

.viewer { position: relative; height: calc(100% - 56px); }
#map, .map { width: 100%; height: 100%; }
.panel { position: absolute; top: 12px; right: 12px; z-index: 900; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); width: 260px; max-width: calc(100% - 24px); box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.panel-toggle { width: 100%; text-align: left; padding: 10px 14px; background: none; border: 0; font: inherit; font-weight: 600; color: var(--text); cursor: pointer; }
.panel.closed .layers { display: none; }
.layers { padding: 0 8px 8px; max-height: 50vh; overflow: auto; }
.layer-row { display: flex; align-items: center; gap: 10px; padding: 8px 6px; margin: 0; font-weight: 500; cursor: pointer; border-radius: 6px; }
.layer-row input { width: 18px; height: 18px; }
.swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.count { margin-left: auto; color: var(--muted); font-size: 13px; }

/* sign-up */
a.brand { color: inherit; text-decoration: none; }
.card.wide { max-width: 560px; }
.card h2 { font-size: 16px; margin: 24px 0 4px; }
.card p { margin: 8px 0; }
.card .alt { margin: 16px 0 0; text-align: center; }
.field-error { color: var(--error); font-size: 13px; margin: 4px 0 0; }
.field-error:empty { display: none; }
input[aria-invalid="true"] { border-color: var(--error); }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 10px 12px; font-weight: 600; }
.copyrow { display: flex; gap: 8px; align-items: stretch; }
.copyrow input { flex: 1; min-width: 0; }
.copyrow .btn { flex: none; min-width: 84px; }
.mono-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--bg); text-overflow: ellipsis; }
.btn.full { width: 100%; margin-top: 24px; }
@media (max-width: 420px) {
  .copyrow { flex-direction: column; }
  .copyrow .btn { width: 100%; }
}

/* owner app */
.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.tile h2, .section h2 { font-size: 16px; margin: 0 0 8px; }
.stat { font-size: 28px; font-weight: 700; }
.section { margin-top: 24px; }
.next { border-left: 4px solid var(--warn); background: var(--warn-bg); }
.list { display: grid; gap: 12px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.item header { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; justify-content: space-between; }
.item .meta { color: var(--muted); font-size: 13px; }
.item pre { white-space: pre-wrap; font: inherit; background: var(--bg); padding: 12px; border-radius: 8px; margin: 12px 0; }
.item .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: var(--bg); color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.pill.escalated { background: var(--warn-bg); color: var(--warn); }
.pill.pending { color: var(--accent); }
.pill.sent { color: var(--ok); }
.pill.approved { background: var(--warn-bg); color: var(--warn); }
.mailnote { margin: 6px 0; font-size: 14px; color: var(--warn); }
.mailnote.failed { font-weight: 700; }
.item .actions .btn { min-height: 44px; }
.item.just { border-color: var(--warn); box-shadow: 0 0 0 2px var(--warn); }
.history > summary { cursor: pointer; padding: 11px 0; min-height: 44px; font-weight: 600; }
#unsentWrap h2, #unsureWrap h2 { margin-bottom: 4px; }
.item .confirm { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.item .confirm .mailnote { margin: 0 0 8px; }
/* the real control sits on the right, away from the button that opened the box */
.item .confirm .actions { justify-content: flex-end; }
.links { list-style: none; margin: 12px 0 0; padding: 0; }
.links li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.links .who { flex: 0 0 auto; max-width: 100%; overflow-wrap: anywhere; }
.links a { flex: 1 1 240px; min-width: 0; min-height: 44px; display: inline-flex; align-items: center; overflow-wrap: anywhere; word-break: break-all; }
#nextUp a { min-height: 44px; display: inline-flex; align-items: center; }
.links .btn { flex: none; }
.reason { color: var(--warn); font-weight: 500; }
.guess { margin: 8px 0 0; padding: 8px 12px; background: var(--bg); border-radius: 8px; font-size: 14px; overflow-wrap: anywhere; }
.guess .src { display: block; margin-top: 2px; font-style: italic; }
.item .actions .why { flex: 1 1 220px; width: auto; min-width: 0; min-height: 44px; }
.trace { margin-top: 12px; border-top: 1px solid var(--line); min-width: 0; }
.trace summary { cursor: pointer; padding: 12px 0; min-height: 44px; color: var(--muted); font-weight: 600; font-size: 14px; }
.trace[open] summary { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.trace ol { list-style: none; margin: 0 0 4px; padding: 0; display: grid; gap: 8px; font-size: 13px; }
.trace ol > li { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 8px; }
.trace .n { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.trace .what { overflow-wrap: anywhere; min-width: 0; }
.trace .tool { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; }
.trace .res { color: var(--muted); }
.trace li.warn .what { color: var(--warn); }
.trace li.end .what { font-weight: 600; }
.trace li.end .res { font-weight: 400; }
.trace ul { margin: 4px 0 0; padding-left: 18px; }
.mapbox { height: 520px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--bg); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
table { width: 100%; border-collapse: collapse; }
td, th { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
@media (max-width: 640px) {
  .bar { height: auto; flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  .bar nav { margin-left: 0; width: 100%; }
  /* owner app: the tabs wrap under the name so every one is on screen */
  .appbar .title { flex: 1 1 0; min-width: 0; }
  .appbar nav { flex-wrap: wrap; overflow-x: visible; gap: 4px; }
  .appbar nav button { padding: 8px 10px; }
  .viewer { height: calc(100% - 96px); }
  .mapbox { height: 380px; }
}
