:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f3f5f7;
  --fg: #1b1f24;
  --muted: #586069;
  --border: #d0d7de;
  --accent: #0b5cad;
  --accent-fg: #ffffff;
  --warn-bg: #fff4ce;
  --warn-fg: #5c4400;
  --parcel-stroke: #1a4f8b;
  --parcel-fill: #3b82c4;
  --mine: #e8590c;
  --sel: #d6246e;
  --shadow: 0 2px 10px rgba(0, 0, 0, .25);
  --sb-w: 360px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --panel: #1b2027;
    --panel-2: #242a33;
    --fg: #e6e9ec;
    --muted: #9aa4af;
    --border: #3a424d;
    --accent: #4aa3ff;
    --accent-fg: #0b1522;
    --warn-bg: #4a3b00;
    --warn-fg: #ffe9a6;
    --parcel-stroke: #7fc0ff;
    --parcel-fill: #7fc0ff;
    --mine: #ff922b;
    --sel: #ff5fa2;
    --shadow: 0 2px 10px rgba(0, 0, 0, .6);
  }
  .osm-tiles { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); }
  .leaflet-container { background: #1b2027; }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
code { background: var(--panel-2); padding: 0 .25em; border-radius: 3px; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: -999px; top: 0; z-index: 3000; background: var(--accent); color: var(--accent-fg); padding: .5rem 1rem; }
.skip:focus { left: 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.noscript { padding: 1rem; }

#app { position: relative; height: 100%; display: flex; }
#map { flex: 1; height: 100%; min-width: 0; z-index: 1; }
#map:focus { outline: none; }

/* sidebar */
#sidebar {
  width: var(--sb-w); max-width: 100%; height: 100%; flex: none; z-index: 1100;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem .9rem; border-bottom: 1px solid var(--border); }
.sb-head h1 { margin: 0; font-size: 1.15rem; }
#sheet-toggle { display: none; }
#sb-body { flex: 1; overflow-y: auto; padding: .75rem .9rem 0; display: flex; flex-direction: column; gap: .75rem; }
.icon-btn { background: var(--panel-2); color: var(--fg); border: 1px solid var(--border); border-radius: 6px; width: 2.4rem; height: 2.4rem; font-size: 1.2rem; cursor: pointer; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); }
.tabs [role=tab] {
  flex: 1; background: none; border: none; border-bottom: 3px solid transparent; color: var(--muted);
  padding: .5rem .25rem; font: inherit; font-weight: 600; cursor: pointer;
}
.tabs [role=tab][aria-selected=true] { color: var(--fg); border-bottom-color: var(--accent); }
.badge { background: var(--mine); color: #fff; border-radius: 10px; padding: 0 .45em; font-size: .8em; margin-left: .2em; }

.field { margin-bottom: .6rem; }
label { display: block; font-weight: 600; margin-bottom: .2rem; font-size: .9rem; }
input[type=text], input[type=search] {
  width: 100%; padding: .55rem .6rem; font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
}
.btn {
  display: inline-block; font: inherit; font-weight: 600; cursor: pointer; text-align: center;
  padding: .45rem .8rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--fg); text-decoration: none; margin: 0;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.danger { color: #c92a2a; }
.btn.small { padding: .2rem .5rem; font-size: .85rem; }
.file-btn:focus-within { outline: 3px solid var(--accent); }
#import-csv:focus-visible + * , .file-btn:has(+ #import-csv:focus-visible) { outline: 3px solid var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .4rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .2rem 0 .6rem; }
.hint.small { font-size: .8rem; }
.msg { min-height: 1.2em; margin: .4rem 0; font-size: .9rem; color: var(--muted); }
.msg.err { color: #c92a2a; }

/* combobox */
.combo { position: relative; }
#ko-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: 0; list-style: none;
  max-height: 14rem; overflow-y: auto; background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; box-shadow: var(--shadow);
}
#ko-list li { padding: .4rem .6rem; cursor: pointer; display: flex; justify-content: space-between; gap: .5rem; }
#ko-list li small { color: var(--muted); }
#ko-list li[aria-selected=true], #ko-list li:hover { background: var(--accent); color: var(--accent-fg); }
#ko-list li[aria-selected=true] small, #ko-list li:hover small { color: inherit; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.list li {
  border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem; background: var(--panel-2);
  display: flex; flex-direction: column; gap: .35rem;
}
.list .row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.list .title-btn {
  background: none; border: none; padding: 0; font: inherit; text-align: left; color: var(--fg); cursor: pointer; flex: 1;
}
.list .title-btn:hover strong { text-decoration: underline; }
.list .sub { color: var(--muted); font-size: .85rem; }
.list input.note { font-size: .9rem; padding: .3rem .5rem; }

/* detail card */
.card { border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2); padding: .7rem .8rem; }
.card h2 { margin: 0 0 .3rem; font-size: 1.1rem; display: flex; justify-content: space-between; gap: .5rem; align-items: start; }
.card dl { margin: .4rem 0; display: grid; grid-template-columns: auto 1fr; gap: .15rem .7rem; }
.card dt { color: var(--muted); }
.card dd { margin: 0; }
.card ul.plain { margin: .1rem 0 0; padding-left: 1.1rem; }
.card .actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.card .legal { font-size: .8rem; color: var(--muted); margin: .6rem 0 0; }

.sb-foot { margin-top: auto; padding: .6rem 0 .8rem; font-size: .8rem; color: var(--muted); border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--panel); }

/* map overlays */
.map-msg {
  position: absolute; z-index: 1000; top: .6rem; left: calc(var(--sb-w) + (100% - var(--sb-w)) / 2); transform: translateX(-50%);
  background: var(--panel); color: var(--fg); border: 1px solid var(--border); border-radius: 18px;
  padding: .35rem .9rem; box-shadow: var(--shadow); font-size: .9rem; max-width: min(90%, 34rem); text-align: center; pointer-events: none;
}
.map-msg.warn { top: 3rem; background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-fg); }
.map-msg[hidden] { display: none; }

.plabel {
  background: transparent; border: none; box-shadow: none; color: var(--fg); font-weight: 600; font-size: 11px; padding: 0;
  text-shadow: 0 0 3px var(--bg), 0 0 3px var(--bg), 0 0 3px var(--bg);
}
.plabel::before { display: none; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution a { color: var(--accent); }
.leaflet-container .leaflet-control-attribution { background: color-mix(in srgb, var(--panel) 85%, transparent); color: var(--fg); }

/* mobile: bottom sheet */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  #map { position: absolute; inset: 0; }
  #sidebar {
    position: absolute; left: 0; right: 0; bottom: 0; top: auto; width: 100%; height: auto; max-height: 62vh;
    border-right: none; border-top: 1px solid var(--border); border-radius: 14px 14px 0 0;
  }
  #sidebar[data-open=false] #sb-body { display: none; }
  #sheet-toggle { display: inline-block; }
  .map-msg { left: 50%; }
  .map-msg.warn { top: 3rem; }
  .leaflet-bottom { bottom: 3.4rem; }
  #sidebar[data-open=true] ~ #map .leaflet-bottom { bottom: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
