:root {
  --bg: #0b1020; --panel: #0f1730; --card: #16203f; --border: #263457;
  --fg: #e8edf7; --muted: #9fb0d0; --brand: #7c5cff; --brand-2: #29c7ac;
  --err: #ff6b6b; --ok: #37d29b; --radius: 14px;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #eef2fb; --panel: #ffffff; --card: #ffffff; --border: #dbe3f4;
    --fg: #10192e; --muted: #56648a;
    /* Darker accents so text/links/status meet WCAG AA (≥4.5:1) on white. */
    --brand: #5a3ff0; --brand-2: #0f8f7d; --err: #d13a3a; --ok: #0f9d6b; }
}
* { box-sizing: border-box; }
.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; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--fg); background: var(--bg); display: flex; flex-direction: column;
}
a { color: var(--brand-2); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.hidden { display: none !important; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--border); background: var(--panel);
  flex: 0 0 auto;
}
.brand { font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.brand-sub { font-size: .7rem; font-weight: 700; color: #fff; background: var(--brand); padding: 2px 7px; border-radius: 999px; }
.top-actions { display: flex; align-items: center; gap: 16px; }
.privacy { color: var(--muted); font-size: .82rem; }
.ghlink { font-weight: 700; text-decoration: none; }
@media (max-width: 640px) { .privacy { display: none; } }

.layout { flex: 1 1 auto; display: grid; grid-template-columns: 380px 1fr; min-height: 0; }
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; } }

.panel {
  overflow-y: auto; padding: 16px; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 14px;
}
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 10px; font-size: 1rem; letter-spacing: -.01em; }
.card h4 { margin: 14px 0 4px; font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.drop {
  display: block; border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 22px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, transparent); }
.drop.loaded { border-style: solid; border-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, transparent); }
.drop-ic { font-size: 1.6rem; margin-bottom: 6px; }
.filemeta { margin-top: 10px; padding: 8px 12px; background: color-mix(in srgb, var(--ok) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 34%, transparent); border-radius: 10px; font-size: .9rem; }
.filemeta .ok-tick { color: var(--ok); font-weight: 800; }

.field { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; font-size: .86rem; }
.field span { color: var(--muted); }
.field select, .field input, .adv input {
  padding: 8px 10px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--fg); font: inherit;
}
.adv { margin-top: 12px; }
.adv summary { cursor: pointer; color: var(--muted); font-size: .86rem; }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: .88rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; width: 100%;
  margin-top: 14px; padding: 11px 16px; border: none; border-radius: 11px; font-weight: 700; font-size: .95rem;
  cursor: pointer; color: #fff; background: linear-gradient(135deg, var(--brand), #5b73ff); }
@media (prefers-color-scheme: light) {
  /* Deeper gradient so the white label keeps ≥4.5:1 contrast. */
  .btn { background: linear-gradient(135deg, #5a3ff0, #3f52e0); }
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:not(:disabled):hover { filter: brightness(1.06); }
.btn.secondary { background: none; border: 1px solid var(--border); color: var(--fg); margin-top: 10px; }
.btn.secondary:not(:disabled):hover { border-color: var(--brand); filter: none; }
.btn.loading { position: relative; color: transparent; }
.btn.loading::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; animation: spin .7s linear infinite;
}

.status { margin-top: 10px; font-size: .86rem; min-height: 1.2em; }
.status.err { color: var(--err); } .status.ok { color: var(--ok); } .status.busy { color: var(--muted); }

.stat-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
.stat b { display: block; font-size: 1.4rem; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: .78rem; }
table.rep { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.rep td { padding: 3px 6px; border-bottom: 1px solid var(--border); }
table.rep td:nth-child(2) { text-align: right; font-variant-numeric: tabular-nums; width: 3em; }
ul.warn { margin: 4px 0 0; padding-left: 18px; font-size: .82rem; color: var(--muted); }
.panel-foot { margin-top: auto; padding-top: 8px; }

.map { position: relative; min-height: 320px; }
#map { position: absolute; inset: 0; }
/* #map is now an inner element of the positioned .map wrapper, so it fills the
   grid cell instead of escaping to the viewport. */
.maplibregl-map { font: inherit; }
.emptymap { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 1; }
.emptymap-inner { text-align: center; }
.emptymap-ic { font-size: 2.4rem; }

.busy { position: absolute; inset: 0; display: grid; place-items: center; z-index: 5;
  background: color-mix(in srgb, var(--bg) 62%, transparent); backdrop-filter: blur(2px); }
.busy-inner { text-align: center; max-width: 300px; padding: 22px 26px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--border); box-shadow: 0 12px 40px rgba(0,0,0,.28); }
.busy-text { font-weight: 700; margin: 12px 0 4px; }
.spinner { width: 40px; height: 40px; margin: 0 auto; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
table.pop { border-collapse: collapse; font-size: .8rem; }
table.pop td { padding: 2px 6px; }
table.pop td:first-child { color: #56648a; font-weight: 600; }

/* Floating layers menu over the map */
.layersmenu { position: absolute; top: 12px; left: 12px; z-index: 3; max-width: min(320px, calc(100% - 70px)); }
.layersbtn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--fg);
  font: inherit; font-weight: 700; font-size: .86rem; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
.layersbtn:hover { border-color: var(--brand); }
.layerspanel {
  margin-top: 6px; background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; box-shadow: 0 10px 32px rgba(0,0,0,.24); font-size: .84rem;
}
.layers-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.layers-head .check { margin: 0; font-size: .84rem; }
.linkbtn { background: none; border: none; color: var(--brand-2); cursor: pointer; padding: 0; font: inherit; font-weight: 600; }
.linkbtn:hover { text-decoration: underline; }
.layer-actions { color: var(--muted); }
.layerlist { max-height: min(46vh, 340px); overflow-y: auto; margin-top: 8px; display: flex; flex-direction: column; gap: 2px;
  border: 1px solid var(--border); border-radius: 10px; padding: 6px; background: var(--bg); }
.layer-row { display: flex; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 7px; cursor: pointer; font-size: .84rem; }
.layer-row:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); }
.layer-row input { margin: 0; }
.layer-sw { width: 13px; height: 13px; border-radius: 3px; border: 1px solid var(--border); flex: 0 0 auto; }
.layer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Basemap switch (Streets / Satellite) */
.basemapctl {
  position: absolute; bottom: 26px; right: 12px; z-index: 3; display: flex;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: var(--card); box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
.basemapctl button {
  border: none; background: none; color: var(--fg); font: inherit; font-size: .82rem;
  font-weight: 600; padding: 7px 12px; cursor: pointer;
}
.basemapctl button + button { border-left: 1px solid var(--border); }
.basemapctl button.active { background: var(--brand); color: #fff; }

/* Bundled examples (CCSF basemap sheets) */
.examples { margin-top: 12px; }
.example-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 4px; }
.btn.example {
  background: none; border: 1px dashed var(--border); color: var(--fg);
  font-size: .85rem; font-weight: 500; padding: 8px 10px; text-align: left;
}
.btn.example:not(:disabled):hover { border-color: var(--brand); filter: none; }
.tiny { font-size: .72rem; line-height: 1.35; }

/* CRS suggestion hint (heuristic — suggests, never assumes) */
.crshint {
  margin: 2px 0 8px; padding: 8px 10px; border-radius: 8px; font-size: .8rem;
  line-height: 1.45; background: rgba(90, 63, 240, .08);
  border: 1px solid rgba(90, 63, 240, .35);
}
.crshint .linkbtn { font-weight: 600; }
