:root {
  --bg: #ffffff;
  --bg-sub: #f5f6f8;
  --text: #16181d;
  --text-sub: #5b6270;
  --border: #e3e6eb;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #c93c37;
  --warn: #d97706;
  --shadow: 0 6px 24px rgba(16, 24, 40, 0.14), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 14px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1e24; --bg-sub: #242832; --text: #eef0f4; --text-sub: #a3aab8; --border: #333946;
    --accent: #4c8dff; --shadow: 0 6px 24px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  --bg: #1b1e24; --bg-sub: #242832; --text: #eef0f4; --text-sub: #a3aab8; --border: #333946;
  --accent: #4c8dff; --shadow: 0 6px 24px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg-sub); color: var(--text); font-family: var(--font); font-size: 14px; }
#map { position: fixed; inset: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--text-sub); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Overview card (top-left) ---------- */
.card {
  position: fixed; z-index: 1000; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
#overview { top: 16px; left: 16px; width: 360px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
#overview header { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px 16px; }
#overview h1 { font-size: 16px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
#overview .subtitle { font-size: 12px; margin-top: 2px; }
.icon-btn {
  margin-left: auto; width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; display: grid; place-items: center; color: var(--text-sub);
}
.icon-btn:hover { background: var(--bg-sub); color: var(--text); }
#overview.collapsed .collapsible { display: none; }
#overview.collapsed #collapseBtn svg { transform: rotate(180deg); }

.search { position: relative; padding: 0 14px 12px; }
.search input {
  width: 100%; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-sub);
  padding: 0 12px 0 36px; outline: none;
}
.search input:focus { border-color: var(--accent); background: var(--bg); }
.search svg { position: absolute; left: 26px; top: 12px; color: var(--text-sub); pointer-events: none; }
.results {
  position: absolute; left: 14px; right: 14px; top: 44px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); max-height: 320px; overflow: auto; z-index: 5;
}
.results button {
  display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; padding: 9px 12px;
  border: 0; background: transparent; border-bottom: 1px solid var(--border);
}
.results button:last-child { border-bottom: 0; }
.results button:hover, .results button.active { background: var(--bg-sub); }
.results .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.results .addr { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .empty { padding: 12px; color: var(--text-sub); }

.section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-sub); padding: 4px 16px 8px; }
.share-bar { display: flex; height: 12px; margin: 0 16px 12px; border-radius: 6px; overflow: hidden; background: var(--bg-sub); }
.share-bar span { display: block; height: 100%; transition: flex-grow .3s; }

.tiers { list-style: none; margin: 0; padding: 0 8px 8px; overflow: auto; }
.tier-row {
  display: grid; grid-template-columns: 18px 1fr auto; gap: 10px; align-items: center; width: 100%;
  padding: 8px; border-radius: 10px; border: 0; background: transparent; text-align: left;
}
.tier-row:hover { background: var(--bg-sub); }
.tier-row .swatch { width: 18px; height: 18px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.tier-row .name { font-weight: 600; }
.tier-row .range { font-size: 12px; color: var(--text-sub); }
.tier-row .pct { font-weight: 600; text-align: right; }
.tier-row .homes { font-size: 12px; color: var(--text-sub); text-align: right; }
.tier-row.off { opacity: 0.4; }
.tier-row.off .swatch { background: transparent !important; box-shadow: inset 0 0 0 2px var(--text-sub); }

#overview footer { border-top: 1px solid var(--border); padding: 10px 16px 12px; font-size: 12px; color: var(--text-sub); display: flex; flex-wrap: wrap; gap: 4px 12px; }

/* ---------- Map tool buttons (bottom-right) ---------- */
#tools { right: 16px; bottom: 28px; display: flex; flex-direction: column; padding: 4px; gap: 2px; }
#tools button {
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; display: grid; place-items: center; color: var(--text);
}
#tools button:hover { background: var(--bg-sub); }
#tools button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
#tools hr { border: 0; border-top: 1px solid var(--border); margin: 2px 6px; }
#sampleAreaBtn {
  position: fixed; z-index: 1000; right: 72px; bottom: 28px; height: 44px; padding: 0 18px 0 14px; border-radius: 22px;
  border: 0; background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow); font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
#sampleAreaBtn:hover { filter: brightness(1.08); }

/* ---------- Side panel (right) ---------- */
#panel { top: 16px; right: 16px; width: 380px; max-height: calc(100vh - 110px); display: flex; flex-direction: column; }
#panel .panel-head { display: flex; align-items: center; padding: 14px 10px 6px 18px; }
#panel h2 { font-size: 15px; margin: 0; font-weight: 650; }
#panel .panel-body { padding: 4px 18px 18px; overflow: auto; }

.speed-hero { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 2px; }
.speed-hero .value { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.speed-hero .unit { font-size: 15px; color: var(--text-sub); font-weight: 500; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 9px 3px 7px; border-radius: 999px; background: var(--bg-sub); }
.chip i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0; }
.kv dt { color: var(--text-sub); }
.kv dd { margin: 0; text-align: right; font-weight: 500; }
.note { font-size: 12px; color: var(--text-sub); line-height: 1.5; }
.list { list-style: none; padding: 0; margin: 8px 0 0; }
.list li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--border); }
.list .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.list .grow { flex: 1; min-width: 0; }
.list .grow div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-btn { border: 0; background: none; color: var(--accent); padding: 0; font-weight: 500; }

table.plans { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
table.plans th { text-align: left; font-weight: 600; color: var(--text-sub); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; padding: 6px 0; }
table.plans td { padding: 7px 0; border-top: 1px solid var(--border); }
table.plans td.r, table.plans th.r { text-align: right; }

/* ---------- Forms / sampling workflow ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-sub); }
.field input, .field select { height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-sub); padding: 0 12px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg-sub); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button { border: 0; background: transparent; border-radius: 8px; padding: 8px; font-weight: 600; color: var(--text-sub); }
.segmented button[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.btn { height: 42px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); font-weight: 600; padding: 0 16px; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.btn-row .btn { flex: 1; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 4px 0 12px; }
.steps li { counter-increment: s; display: flex; gap: 10px; padding: 6px 0; color: var(--text-sub); }
.steps li::before { content: counter(s); width: 22px; height: 22px; border-radius: 50%; background: var(--bg-sub); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.steps li.current { color: var(--text); font-weight: 600; }
.steps li.current::before { background: var(--accent); color: var(--accent-text); }
.steps li.done::before { content: "✓"; background: #1f883d; color: #fff; }
.alert { border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.45; margin: 10px 0; background: var(--bg-sub); }
.alert.warn { background: rgba(217, 119, 6, .12); color: var(--warn); }
.alert.error { background: rgba(201, 60, 55, .12); color: var(--danger); }
.alert.ok { background: rgba(31, 136, 61, .12); color: #1f883d; }
.progress { height: 8px; border-radius: 4px; background: var(--bg-sub); overflow: hidden; margin: 10px 0 6px; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width .5s; }
details.log summary { cursor: pointer; font-size: 12px; color: var(--text-sub); margin-top: 12px; }
details.log pre {
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: #0f1115; color: #cfd6e4;
  border-radius: 8px; padding: 10px; max-height: 220px; overflow: auto; white-space: pre-wrap; word-break: break-all;
}

/* ---------- Map bits ---------- */
.leaflet-container { background: var(--bg-sub); font-family: var(--font); }
.leaflet-container.drawing, .leaflet-container.drawing .leaflet-interactive { cursor: crosshair !important; }
.leaflet-tooltip.speed-tip { font-family: var(--font); font-size: 12px; font-weight: 600; border-radius: 8px; padding: 4px 8px; border: 0; box-shadow: var(--shadow); }
.leaflet-control-attribution { font-size: 10px; }
#toast {
  position: fixed; z-index: 2000; left: 50%; bottom: 28px; transform: translateX(-50%); background: #16181d; color: #fff;
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; max-width: calc(100vw - 32px);
}
.draw-hint {
  position: fixed; z-index: 1001; bottom: 88px; left: 50%; transform: translateX(-50%); background: #16181d; color: #fff;
  padding: 10px 16px; border-radius: 999px; font-size: 13px; font-weight: 500; box-shadow: var(--shadow);
}

/* ---------- Small screens: overview on top, panel as bottom sheet ---------- */
@media (max-width: 760px) {
  #overview { left: 12px; right: 12px; width: auto; top: 12px; max-height: 50vh; }
  #overview header { padding: 10px 10px 6px 14px; }
  #overview .subtitle, .section-title { display: none; }
  .search { padding-bottom: 8px; }
  .share-bar { margin-bottom: 6px; }
  .tiers { display: grid; grid-template-columns: 1fr 1fr; padding: 0 6px 6px; }
  .tier-row { grid-template-columns: 14px 1fr auto; gap: 6px; padding: 5px 6px; }
  .tier-row .swatch { width: 14px; height: 14px; }
  .tier-row .name { font-size: 13px; }
  .tier-row .range { font-size: 11px; }
  .tier-row .homes { display: none; }
  #overview footer { padding: 8px 14px; }
  #panel { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 62vh; border-radius: var(--radius) var(--radius) 0 0; }
  #sampleAreaBtn { right: 72px; bottom: 24px; }
  #tools { bottom: 24px; }
  .draw-hint { bottom: 80px; white-space: nowrap; font-size: 12px; }
}
