:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #17202b; --muted: #5d6b7a; --line: #d9dee5;
  --accent: #c1121f; --accent-ink: #ffffff; --ok: #1f8a4c; --warn: #c98a12; --bad: #c1121f;
  --shadow: 0 2px 10px rgba(0, 0, 0, .15);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e141b; --panel: #17202b; --ink: #e8edf2; --muted: #9aa8b6; --line: #2b3744; --shadow: 0 2px 10px rgba(0,0,0,.5); }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { display: flex; flex-direction: column; }

.bar { display: flex; align-items: center; gap: 16px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; letter-spacing: .02em; }
.brand span { color: var(--accent); }
.maptitle { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.status.ok .dot { background: var(--ok); }
.status.bad .dot { background: var(--bad); }

main { position: relative; flex: 1; display: flex; min-height: 0; }
#map { flex: 1; }

.tools { position: absolute; top: 10px; left: 10px; display: flex; gap: 4px; background: var(--panel); padding: 4px; border-radius: 8px; box-shadow: var(--shadow); }
.tools button, .panel button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 10px; border-radius: 6px; font: inherit; font-size: 14px; cursor: pointer; }
.tools button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.hint { position: absolute; top: 58px; left: 10px; background: var(--panel); padding: 6px 10px; border-radius: 6px; box-shadow: var(--shadow); font-size: 13px; }

.tools { z-index: 3; }
.menu { position: relative; }
.mlist { position: absolute; top: calc(100% + 6px); left: 0; min-width: 210px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; display: grid; z-index: 4; }
.tools .mlist button { border: 0; text-align: left; display: flex; justify-content: space-between; gap: 12px; }
.tools .mlist button:hover, .tools .mlist button.on { background: var(--bg); color: var(--ink); }
.mlist.right { left: auto; right: 0; }
.usermenu .mbtn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 5px 10px; border-radius: 6px; font: inherit; font-size: 14px; cursor: pointer; }
.usermenu .mlist a, .usermenu .mlist button { display: block; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px; background: none; color: var(--ink); text-decoration: none; font: inherit; font-size: 14px; cursor: pointer; }
.usermenu .mlist a:hover, .usermenu .mlist button:hover { background: var(--bg); }
kbd { font: 11px ui-monospace, Consolas, monospace; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; }

.layerpanel { position: absolute; top: 58px; left: 10px; width: min(340px, calc(100vw - 32px)); max-height: calc(100% - 110px); overflow-y: auto; background: var(--panel); border-radius: 8px; box-shadow: var(--shadow); padding: 10px 12px; font-size: 13px; z-index: 2; }
.lhead { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.lhint { font-size: 11px; color: var(--muted); }
.llist { list-style: none; margin: 0 0 8px; padding: 0; }
.llist li { border-bottom: 1px solid var(--line); padding: 6px 0; }
.llist li:not(.on) { color: var(--muted); }
.lrow { display: flex; align-items: center; gap: 6px; }
.lrow label { flex: 1; cursor: pointer; }
.lrow em { font-style: normal; font-size: 10px; color: var(--warn); border: 1px solid var(--warn); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.lbtns { display: flex; gap: 2px; }
.lbtns button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 4px; font-size: 10px; padding: 2px 5px; cursor: pointer; }
.lbtns button:disabled { opacity: .35; cursor: default; }
.lopac { display: flex; align-items: center; gap: 8px; margin: 4px 0 0 22px; }
.lopac input { flex: 1; accent-color: var(--accent); }
.lopac span { width: 34px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.lnote { margin: 4px 0 0 22px; font-size: 11px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 6px 0 0 22px; font-size: 11px; }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.lgroup { border-top: 1px solid var(--line); padding: 4px 0; }
.lgroup summary { cursor: pointer; font-weight: 600; padding: 4px 0; display: flex; justify-content: space-between; }
.lcount { color: var(--muted); font-weight: 400; font-size: 11px; }
.lcat { list-style: none; margin: 0 0 4px; padding: 0 0 0 4px; }
.lcat li { padding: 4px 0; }
.lcat label { cursor: pointer; display: flex; align-items: center; gap: 4px; }
.lcat .lx { margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; }
.lcat .lnote { margin-left: 22px; }
.laddwrap summary { cursor: pointer; color: var(--accent); padding: 4px 0; }
.ladd { display: grid; gap: 6px; margin-top: 6px; }
.ladd input, .ladd select { font: inherit; font-size: 13px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.ladd button { justify-self: start; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.lerr { color: var(--bad); font-size: 12px; }

.measurebox { position: absolute; bottom: 40px; left: 50%; transform: translateX(-50%); background: var(--panel); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 12px; font-size: 13px; display: flex; gap: 14px; align-items: center; z-index: 2; }
.mrow { display: flex; gap: 8px; justify-content: space-between; }
.mrow span { color: var(--muted); }
.mrow strong { font-variant-numeric: tabular-nums; }
.mact { display: flex; gap: 6px; }
.mact button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 5px 9px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px; }
.coords { position: absolute; bottom: 8px; left: 10px; font: 12px ui-monospace, Consolas, monospace; background: var(--panel); padding: 3px 8px; border-radius: 4px; box-shadow: var(--shadow); }

.panel { width: 300px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 10px 14px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
.panel ul { list-style: none; margin: 0; padding: 0; }
.panel li { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.panel li:hover { background: var(--bg); }
.panel li.empty { color: var(--muted); cursor: default; }
.panel li .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.panel li .k { margin-left: auto; font-size: 11px; color: var(--muted); }
.panel li.pending .k::after { content: " · unsynced"; color: var(--warn); }
.sechead { display: flex; align-items: center; justify-content: space-between; border-radius: 6px; }
.sechead button { font-size: 12px; padding: 3px 8px; }
.sechead.drop, .tree li.drop { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--bg); }
.tree li.sel { background: var(--bg); box-shadow: inset 3px 0 0 var(--accent); }
.tree .tw { border: 0; background: none; color: var(--muted); width: 16px; padding: 0; font-size: 12px; cursor: pointer; }
.tree li.hiddenf { opacity: .45; }
.tree li[draggable=true] { cursor: grab; }
#editor select { font: inherit; font-size: 14px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); width: 100%; }
#editor label { display: grid; gap: 3px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
#editor input:not([type=color]), #editor textarea { font: inherit; font-size: 14px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); width: 100%; }
#editor .row { display: flex; gap: 8px; }
#editor .danger { color: var(--bad); border-color: var(--bad); }
.meta { font-size: 12px; color: var(--muted); }

.io { display: flex; gap: 8px; padding-top: 4px; }
.io .btn, .io select { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 10px; border-radius: 6px; font: inherit; font-size: 14px; cursor: pointer; }

#addKey { display: flex; gap: 6px; margin-top: 8px; }
#addKey input { flex: 1; min-width: 0; font: inherit; font-size: 14px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
#keys li .k { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 3px 8px; cursor: pointer; }

.trk-label { font: 600 12px system-ui, sans-serif; }

@media (max-width: 720px) {
  .panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(85vw, 300px); transform: translateX(100%); transition: transform .2s; z-index: 5; }
  .panel.open { transform: none; }
}

/* ── sharing ─────────────────────────────────────────────────────────── */
.sharebtn { border: 0; background: var(--accent); color: var(--accent-ink); padding: 6px 14px; border-radius: 6px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; }
.sharedlg { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 40px); border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 0; box-shadow: var(--shadow); }
.sharedlg::backdrop { background: rgba(0, 0, 0, .45); }
.sharedlg.small { width: min(360px, calc(100vw - 32px)); text-align: center; }
.dlghead { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); margin: 0; }
.dlghead h2 { font-size: 17px; margin: 0; }
.dlghead button { border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.sharedlg section { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sharedlg section:last-child { border-bottom: 0; }
.sharedlg h3 { margin: 0 0 4px; font-size: 14px; }
.sharedlg .row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.sharedlg input, .sharedlg select { font: inherit; font-size: 14px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.sharedlg input[type=search] { flex: 1 1 220px; }
.sharedlg button { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 10px; border-radius: 6px; font: inherit; font-size: 13px; cursor: pointer; }
.sharedlg ul { list-style: none; margin: 6px 0 0; padding: 0; }
.sharedlg li { display: flex; align-items: center; gap: 8px; padding: 7px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.sharedlg li > strong, .sharedlg li > span:first-child { flex: 1; min-width: 0; }
.sharedlg li .k { color: var(--muted); font-size: 12px; }
.sharedlg li.empty { color: var(--muted); }
.pick:empty { display: none; }
.qrrow { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.qr { width: 128px; height: 128px; background: #fff; padding: 4px; border-radius: 6px; flex: none; }
.qr.big { width: min(280px, 70vw); height: min(280px, 70vw); margin: 16px auto 8px; }
.qr svg { width: 100%; height: 100%; display: block; }
.sharedlg code { font-size: 11px; word-break: break-all; color: var(--muted); }
.sharedlg.small code { display: block; padding: 0 16px 16px; }
.guestbar { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 6px 12px; font-size: 13px; z-index: 2; }
.myloc { margin: 4px 0 8px; }
.primarybtn { width: 100%; border: 0 !important; background: var(--accent) !important; color: var(--accent-ink) !important; padding: 9px 12px !important; font-weight: 600; }
.primarybtn.on { background: var(--ink) !important; color: var(--panel) !important; }
.paneltoggle { display: none; }

@media (max-width: 720px) {
  .bar { gap: 8px; padding: 6px 10px; }
  .bar .maptitle { font-size: 13px; }
  .status #statusText { display: none; }
  .paneltoggle { display: block; position: absolute; right: 10px; bottom: 34px; z-index: 6; border: 0; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 22px; font: inherit; font-weight: 600; box-shadow: var(--shadow); }
  .tools { flex-wrap: wrap; max-width: calc(100% - 70px); }
  .tools button { padding: 8px 10px; }
  .guestbar { top: auto; bottom: 84px; }
  .measurebox { bottom: 84px; flex-wrap: wrap; justify-content: center; }
  .coords { display: none; }
}

.barbtn { margin-left: 8px; border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 4px 10px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.sharedlg .field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; text-align: left; }
.sharedlg .primarybtn { width: auto; }
.shapetools { margin: 4px 0 8px; }
.shapetools .row { flex-wrap: wrap; gap: 6px; }
.shapetools button { font-size: 13px; padding: 5px 9px; }

.photos { margin: 6px 0 10px; }
.photohead { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.photohead .btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 4px 9px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.thumb { padding: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; aspect-ratio: 1; background: var(--bg); cursor: zoom-in; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photodlg { width: min(900px, calc(100vw - 24px)); max-height: calc(100vh - 24px); border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 0; }
.photodlg::backdrop { background: rgba(0,0,0,.6); }
.photodlg img { display: block; width: 100%; max-height: 65vh; object-fit: contain; background: #000; }
.photometa { padding: 10px 16px 14px; }
.photometa .field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.photometa input { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.photometa .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.photometa a { color: var(--accent); }
.photometa .danger { border: 1px solid var(--bad); color: var(--bad); background: var(--panel); border-radius: 6px; padding: 5px 10px; cursor: pointer; }

/* ── map images (overlays.js) ── */
.overlayrow { display: grid; gap: 6px; margin: 4px 0 8px; }
.overlayrow input[type=range] { width: 100%; }
.overlayrow #edAlign.on { background: #c1121f; color: #fff; border-color: #c1121f; }
.aligntools { display: grid; gap: 6px; padding: 8px; border: 1px dashed #c1121f; border-radius: 6px; }
.ovh { box-sizing: border-box; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.5), 0 1px 4px rgba(0,0,0,.4); }
.ovh-corner { width: 16px; height: 16px; background: #c1121f; cursor: nwse-resize; }
.ovh-move { width: 26px; height: 26px; border-radius: 50%; background: rgba(193,18,31,.85); cursor: move; }
.ovh-move::after { content: '✥'; display: block; color: #fff; font: 16px/22px system-ui, sans-serif; text-align: center; }
.ovh-rotate { width: 20px; height: 20px; border-radius: 50%; background: #1d4ed8; cursor: grab; }
.ovh-pin { min-width: 22px; height: 22px; padding: 0 4px; border-radius: 11px 11px 11px 0; background: #f59e0b; color: #111; font: 700 12px/18px system-ui, sans-serif; text-align: center; cursor: grab; }
.ovh-pin.pending { background: #fff; border-color: #f59e0b; border-style: dashed; }
@media (pointer: coarse) { .ovh-corner { width: 24px; height: 24px; } .ovh-rotate { width: 28px; height: 28px; } .ovh-move { width: 34px; height: 34px; } .ovh-move::after { line-height: 30px; } }

/* ── feature list: folders as coloured boxes ── */
.tree li.item .it { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree li.fbox { display: block; padding: 0; margin: 8px 0; border: 1px solid color-mix(in srgb, var(--fc) 45%, var(--line)); border-radius: 8px;
  background: color-mix(in srgb, var(--fc) 6%, var(--panel)); overflow: hidden; cursor: default; }
.tree li.fbox:hover { background: color-mix(in srgb, var(--fc) 6%, var(--panel)); }
.tree .fkids .fbox { margin: 6px 6px 6px 0; }
.tree .fhead { display: flex; align-items: center; gap: 6px; padding: 7px 8px; cursor: pointer; font-weight: 700; font-size: 14px;
  background: color-mix(in srgb, var(--fc) 18%, var(--panel)); border-left: 5px solid var(--fc); }
.tree .fhead:hover { background: color-mix(in srgb, var(--fc) 26%, var(--panel)); }
.tree .fhead.sel { box-shadow: inset 0 0 0 2px var(--fc); }
.tree .fhead input[type=checkbox] { margin: 0; accent-color: var(--fc); }
.tree .fhead .ft { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree .ficon { font-size: 15px; line-height: 1; }
.tree .fcount { font-size: 11px; font-weight: 700; min-width: 20px; text-align: center; padding: 1px 7px; border-radius: 10px; background: var(--fc); color: #fff; }
.tree .fkids { list-style: none; margin: 0; padding: 0 0 2px 12px; border-left: 5px solid color-mix(in srgb, var(--fc) 45%, transparent); }
.tree .fkids li.item { border-bottom: 1px solid color-mix(in srgb, var(--fc) 15%, var(--line)); }
.tree .fkids li.item:last-child { border-bottom: 0; }
.tree li.fempty { color: var(--muted); font-style: italic; font-size: 12px; cursor: default; border: 0; }
.tree li.fbox.fhidden > .fhead { opacity: .55; }
.tree li.fbox.fhidden > .fkids { opacity: .45; }
.tree li.fbox.drop { outline: 2px dashed var(--fc); outline-offset: -2px; }
.tree li.looseh { margin-top: 12px; padding: 4px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 2px solid var(--line); cursor: default; }
.tree li.looseh:hover { background: none; }

/* ── right-click menu ── */
.ctxmenu { position: fixed; z-index: 50; min-width: 210px; max-width: 290px; max-height: 80vh; overflow-y: auto; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.25); padding: 4px 0; font-size: 14px; }
.ctxmenu .cmhead { display: flex; flex-direction: column; padding: 6px 12px 7px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.ctxmenu .cmhead b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctxmenu .cmhead span { font-size: 12px; color: var(--muted); }
.ctxmenu .cmitem { display: flex; width: 100%; align-items: center; gap: 8px; text-align: left; border: 0; background: none; color: inherit; font: inherit; padding: 7px 12px; cursor: pointer; }
.ctxmenu .cmitem:hover, .ctxmenu .cmitem:focus-visible { background: var(--bg); outline: none; }
.ctxmenu .cmitem.danger { color: var(--bad); }
.ctxmenu .cmitem kbd { margin-left: auto; font-size: 11px; color: var(--muted); }
.ctxmenu .cmsub.open { background: var(--bg); font-weight: 600; }
.ctxmenu .cmsubbox { background: var(--bg); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.ctxmenu .cmsubbox .cmitem { padding-left: 24px; font-size: 13px; }
.ctxmenu .cmsep { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.ctxmenu .cmcolors { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 12px 8px; }
.ctxmenu .cmswatch { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.ctxmenu .cmswatch.on { box-shadow: 0 0 0 2px var(--ink); }
@media (pointer: coarse) { .ctxmenu .cmitem { padding: 11px 14px; } .ctxmenu .cmswatch { width: 28px; height: 28px; } }

/* ── coordinates: format picker, location box ── */
.coordbar { position: absolute; bottom: 8px; left: 10px; display: flex; align-items: center; gap: 0; background: var(--panel); border-radius: 4px; box-shadow: var(--shadow); max-width: calc(100% - 120px); }
.coordbar .coords { position: static; box-shadow: none; padding: 3px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.coordbar select { border: 0; border-right: 1px solid var(--line); background: var(--bg); color: var(--ink); font: 600 12px system-ui, sans-serif; padding: 3px 4px; border-radius: 4px 0 0 4px; cursor: pointer; }
.locrow input { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.locrow input.bad, #coordIn:invalid:not(:placeholder-shown) { outline: 2px solid var(--bad); }
.locrow .fmtname { display: inline-block; width: auto; justify-self: start; vertical-align: 1px; font-size: 11px; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; margin-left: 4px; }
#coordIn { font-family: ui-monospace, Consolas, monospace; }
#coordOut.bad { color: var(--bad); }
