:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #1a1d21;
  --muted: #5e6873;
  --line: #e1e5ea;
  --surface: #ffffff;
  --surface-dim: #f5f6f8;
  --accent: #2f6bd8;
  --danger: #c93b3b;
  --radius: 12px;
  --shadow: 0 12px 36px rgb(15 23 32 / 16%);
  --shadow-soft: 0 2px 10px rgb(15 23 32 / 8%), 0 0 0 1px rgb(15 23 32 / 4%);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; color: var(--ink); background: #dfe2e6; font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }

.layout, .map-shell, #map { position: absolute; inset: 0; }
.map-shell { min-width: 0; }

.map-loading { position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center; gap: 10px; background: #e7e9ec; color: var(--muted); font-size: 13px; font-weight: 500; pointer-events: none; transition: opacity .3s ease; }
.map-loading[hidden] { display: none; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; border: 1px solid transparent; border-radius: 9px; padding: 8px 13px; font-size: 13px; font-weight: 600; transition: background .15s ease, border-color .15s ease, box-shadow .15s ease; }
.button.secondary { background: var(--surface); border-color: var(--line); }
.button.secondary:hover { background: var(--surface-dim); border-color: #d0d5db; }
.button.primary { width: 100%; margin-top: 18px; min-height: 44px; color: #fff; background: var(--accent); }
.button.primary:hover { background: #2558b8; }
.button.primary:disabled { opacity: .6; cursor: default; }

/* ---------- Search ---------- */
.search-shell { position: absolute; z-index: 20; top: 16px; left: 88px; width: min(380px, calc(100vw - 112px)); transition: left .24s cubic-bezier(.2, .75, .25, 1); }
.layout:has(.sidebar.open) .search-shell { left: 382px; width: min(380px, calc(100vw - 406px)); }
.map-search { display: flex; align-items: center; gap: 9px; height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-soft); }
.map-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(47 107 216 / 14%), var(--shadow-soft); }
.search-icon { width: 17px; height: 17px; flex: 0 0 auto; color: var(--muted); }
.map-search input { flex: 1; min-width: 0; border: 0; padding: 0; background: transparent; font-size: 14px; }
.map-search input:focus { outline: none; }
.map-search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-kbd { flex: 0 0 auto; padding: 2px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-dim); color: var(--muted); font-size: 11px; font-family: inherit; }
.search-results { margin-top: 6px; display: grid; overflow: hidden; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-soft); }
.search-results:empty { display: none; }
.search-note { margin: 0; padding: 11px 13px; color: var(--muted); font-size: 12px; }
.search-result { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--surface-dim); padding: 10px 13px; background: var(--surface); text-align: left; }
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: var(--surface-dim); }
.search-result strong, .search-result span { display: block; }
.search-result strong { overflow: hidden; font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.search-result span { margin-top: 1px; color: var(--muted); font-size: 11px; }

/* ---------- Sidebar / workspace ---------- */
.sidebar { position: fixed; z-index: 15; top: 16px; left: 16px; width: 58px; overflow: visible; transition: width .24s cubic-bezier(.2, .75, .25, 1); }
.sidebar.open { width: min(352px, calc(100vw - 32px)); }
.drawer-toggle { width: 58px; height: 46px; display: flex; align-items: center; gap: 10px; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; background: var(--surface); box-shadow: var(--shadow-soft); text-align: left; transition: width .22s ease, background .15s ease; }
.sidebar.open .drawer-toggle { width: 148px; }
.drawer-toggle:hover { background: var(--surface-dim); }
.drawer-icon { width: 19px; height: 19px; flex: 0 0 auto; color: var(--accent); }
.drawer-icon svg { width: 100%; height: 100%; }
.drawer-label { opacity: 0; font-size: 13px; font-weight: 600; white-space: nowrap; transition: opacity .12s ease; }
.drawer-chevron { width: 16px; height: 16px; margin-left: auto; flex: 0 0 auto; opacity: 0; color: var(--muted); transition: opacity .12s ease, transform .2s ease; }
.sidebar.open .drawer-label, .sidebar.open .drawer-chevron { opacity: 1; }
.sidebar.open .drawer-chevron { transform: rotate(180deg); }
.sidebar-content { width: 352px; max-width: calc(100vw - 32px); max-height: calc(100dvh - 86px); overflow-y: auto; padding: 0 2px 18px 0; opacity: 0; visibility: hidden; transform: translateY(-5px); scrollbar-width: thin; transition: opacity .16s ease .06s, transform .16s ease .06s, visibility 0s linear .22s; }
.sidebar.open .sidebar-content { opacity: 1; visibility: visible; transform: translateY(0); transition-delay: .06s, .06s, 0s; }

.card { margin-top: 8px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-soft); }

.sidebar-heading, .panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 3px; font-size: 19px; font-weight: 700; letter-spacing: -.015em; }
h2 { margin-bottom: 0; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.sidebar-heading p { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.eyebrow { margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; padding: 0; background: var(--surface); }
.icon-button svg { width: 15px; height: 15px; }
.icon-button:hover { background: var(--surface-dim); }

.field-label { display: block; margin: 15px 0 6px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
select, input, textarea { width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: var(--surface); transition: border-color .15s ease, box-shadow .15s ease; }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgb(47 107 216 / 13%); }
textarea { resize: vertical; }

.control-card > .field-label:first-child { margin-top: 0; }
.zoom-controls { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.control-button { min-height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.control-button svg { width: 17px; height: 17px; }
.control-button:hover { background: var(--surface-dim); }
.map-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.theme-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.theme-swatch { display: flex; align-items: center; gap: 7px; min-height: 38px; border: 1px solid var(--line); border-radius: 9px; padding: 5px 9px; background: var(--surface); font-size: 12px; font-weight: 500; color: var(--muted); }
.theme-swatch:hover { background: var(--surface-dim); }
.theme-swatch.active { border-color: var(--accent); color: var(--ink); box-shadow: 0 0 0 1px var(--accent); }
.theme-swatch span { width: 18px; height: 18px; flex: 0 0 auto; border-radius: 6px; }
.swatch-natural { background: linear-gradient(135deg, #9cc58e, #76a9d4); }
.swatch-mist { background: linear-gradient(135deg, #d9d8cf, #9eb0b4); }
.swatch-mono { background: linear-gradient(135deg, #eee, #6e7377); }

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-dim); font-size: 11px; color: var(--muted); }
.legend-row { display: flex; align-items: center; gap: 7px; }
.legend-swatch { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 3px; }

.pursuit-list { margin-top: 14px; display: grid; gap: 14px; }
.empty-state { margin: 4px 2px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.status-group h3 { display: flex; justify-content: space-between; margin: 0 2px 6px; color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; }
.pursuit-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin-top: 6px; border: 1px solid var(--line); border-left: 4px solid var(--stage-color); border-radius: 10px; padding: 9px 10px; background: var(--surface); box-shadow: var(--shadow-soft); }
.row-main { min-width: 0; border: 0; padding: 0; background: none; text-align: left; }
.row-main strong, .row-main span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main strong { font-size: 13px; font-weight: 600; }
.row-main span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.row-main .overdue { color: var(--danger); font-weight: 600; }
.row-status { width: auto; min-height: 34px; padding: 5px 8px; border-radius: 8px; font-size: 11px; color: var(--muted); background: var(--surface-dim); border-color: transparent; }
.row-status:hover, .row-status:focus { border-color: var(--line); }

/* ---------- Map overlays ---------- */
.zoom-hint { position: absolute; z-index: 5; top: 16px; right: 16px; display: flex; align-items: center; gap: 10px; width: max-content; max-width: min(330px, calc(100vw - 500px)); padding: 8px 13px 8px 9px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-soft); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.zoom-hint.is-hidden { opacity: 0; transform: translateY(-8px); }
.zoom-hint-icon { width: 30px; height: 30px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 8px; background: var(--surface-dim); color: var(--accent); }
.zoom-hint-icon svg { width: 15px; height: 15px; }
.zoom-hint strong, .zoom-hint small { display: block; }
.zoom-hint strong { font-size: 12px; }
.zoom-hint small { margin-top: 1px; color: var(--muted); font-size: 11px; }
#map canvas { transition: filter .25s ease; }

.notice, .map-message { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; font-size: 12px; }
.notice { margin-top: 14px; background: #fdf3d9; }
.map-message { position: absolute; z-index: 7; top: 74px; left: 50%; transform: translateX(-50%); max-width: calc(100vw - 32px); background: var(--surface); box-shadow: var(--shadow); }

/* ---------- Detail panel ---------- */
.detail-panel { position: fixed; z-index: 18; top: 16px; right: 16px; bottom: 16px; width: min(390px, calc(100vw - 32px)); overflow-y: auto; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); scrollbar-width: thin; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.detail-actions:empty { display: none; }
.action-link { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; border: 1px solid var(--line); border-radius: 9px; padding: 6px 11px; background: var(--surface-dim); color: var(--ink); font-size: 12px; font-weight: 600; text-decoration: none; }
.action-link:hover { background: #eceef1; border-color: #d0d5db; }
.county-fields { display: grid; grid-template-columns: 108px 1fr; gap: 7px 12px; margin: 14px 0; padding: 13px 0; border-block: 1px solid var(--line); font-size: 12px; }
.county-fields dt { color: var(--muted); }
.county-fields dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- MapLibre chrome ---------- */
.maplibregl-ctrl-attrib { border-radius: 8px 0 0; background: rgb(255 255 255 / 75%); font-size: 10px; }
.maplibregl-popup-content { padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow-soft); font: 11px/1.5 Inter, ui-sans-serif, system-ui, sans-serif; }
.maplibregl-popup-tip { opacity: .85; }

/* ---------- Mobile: bottom sheets, field-friendly targets ---------- */
@media (max-width: 760px) {
  select, input, textarea, .map-search input { font-size: 16px; }
  .button, .control-button, .icon-button { min-height: 44px; }
  .icon-button { width: 44px; }

  .search-shell { top: calc(10px + env(safe-area-inset-top)); left: 12px; right: 12px; width: auto; }
  .search-kbd { display: none; }
  .search-results { max-height: 40dvh; overflow-y: auto; }

  .zoom-hint { top: auto; bottom: calc(88px + env(safe-area-inset-bottom)); left: 50%; right: auto; transform: translateX(-50%); max-width: calc(100vw - 24px); }
  .zoom-hint.is-hidden { transform: translate(-50%, 8px); }
  .zoom-hint small { display: none; }
  .map-message { top: calc(66px + env(safe-area-inset-top)); }

  .sidebar { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); left: 12px; }
  .sidebar.open { width: 58px; }
  .sidebar.open .drawer-toggle { width: 148px; }
  .sidebar-content { position: fixed; left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); width: auto; max-width: none; max-height: 62dvh; border-radius: 16px; transform: translateY(8px); }
  .sidebar.open .sidebar-content { transform: translateY(0); }

  .detail-panel { top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 76dvh; border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }

  .layout:has(.sidebar.open) .search-shell { left: 12px; width: auto; }
  .maplibregl-ctrl-bottom-left { bottom: calc(64px + env(safe-area-inset-bottom)); }
}
