:root {
  --paper: #f5f2ea;
  --paper-2: #ebe6d9;
  --ink: #1d241f;
  --muted: #5d665f;
  --line: #d3ccba;
  --forest: #1f3d2b;
  --forest-2: #2c5a3e;
  --accent: #c2410c;
  --accent-2: #9a3412;
  --danger: #a11d1d;
  --ok: #17603a;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13.5px/1.45 var(--sans); color: var(--ink); background: var(--paper); }

#app { display: grid; grid-template-columns: 384px 1fr; height: 100vh; }
#app.collapsed { grid-template-columns: 0 1fr; }
#app.collapsed #side { display: none; }

/* ------------------------------------------------------------ sidebar */
#side {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--paper); border-right: 1px solid var(--line);
}
#side > header { background: var(--forest); color: #f3efe2; padding: 14px 14px 12px; }
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 11px; }
.brand svg { color: #f0b27a; flex: none; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }
.brand p { margin: 0; font-size: 11.5px; color: #b9c9bd; }
#search-form { display: flex; gap: 6px; }
#locate { padding: 6px 9px; background: #ffffff1c; border-color: #ffffff38; color: #f3efe2; }
#locate:hover { background: #ffffff30; }
#search-form input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 6px; border: 1px solid #0003;
  font: inherit; background: #fffdf7; color: var(--ink);
}
.results {
  list-style: none; margin: 8px 0 0; padding: 0; background: #fffdf7; color: var(--ink);
  border-radius: 6px; max-height: 210px; overflow: auto; border: 1px solid #0002;
}
.results li { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--paper-2); font-size: 12.5px; }
.results li:last-child { border-bottom: 0; }
.results li:hover, .results li:focus { background: #f1e8d6; outline: none; }
.results li small { color: var(--muted); display: block; }

#panels { flex: 1; overflow-y: auto; padding: 4px 14px 14px; min-height: 0; }
details { border-bottom: 1px solid var(--line); padding: 2px 0 12px; }
details:not([open]) { padding-bottom: 2px; }
summary {
  cursor: pointer; padding: 10px 0 8px; font-weight: 650; font-size: 11.5px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--forest); list-style: none; display: flex; align-items: center; gap: 8px;
}
summary::-webkit-details-marker { display: none; }
summary::before { content: "+"; width: 12px; font-size: 14px; color: var(--accent); font-weight: 700; }
details[open] > summary::before { content: "–"; }
summary small { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); }

label { display: block; font-size: 11.5px; color: var(--muted); margin: 7px 0 0; }
label > input[type=text], label > input[type=date], label > input[type=number], label > select, textarea, .inline input {
  display: block; width: 100%; margin-top: 3px; padding: 6px 8px; font: inherit; font-size: 13px; color: var(--ink);
  background: #fffdf7; border: 1px solid var(--line); border-radius: 5px;
}
select:focus, input:focus, textarea:focus, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { resize: vertical; min-height: 74px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.inline { display: flex; align-items: center; gap: 6px; }
.inline input { margin-top: 3px; text-align: center; }
.inline span { color: var(--muted); }
.checks { display: grid; gap: 1px; margin-top: 2px; }
label.check { display: flex; align-items: center; gap: 7px; color: var(--ink); font-size: 13px; margin: 4px 0 0; cursor: pointer; }
label.check input { accent-color: var(--forest-2); width: 15px; height: 15px; margin: 0; flex: none; }
label.check small { color: var(--muted); font-size: 11px; }
.hint { color: var(--muted); font-size: 11.5px; margin: 7px 0 0; }
.hint b { color: var(--ink); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; align-items: center; }

.btn {
  font: inherit; font-size: 12.5px; padding: 6px 10px; border-radius: 5px; border: 1px solid var(--line);
  background: #fffdf7; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 5px; white-space: nowrap;
}
.btn:hover { border-color: #b3a98f; background: #fff; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent-2); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.toggle.on { background: var(--forest); border-color: var(--forest); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.big { padding: 9px 18px; font-size: 14px; flex: 1; justify-content: center; }
.btn.file { margin: 0; color: var(--ink); }

.items { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 5px; }
.items li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 7px; align-items: center;
  background: #fffdf7; border: 1px solid var(--line); border-radius: 6px; padding: 6px 7px;
}
.items li.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.items input[type=text] { border: 0; background: transparent; font: inherit; font-weight: 600; padding: 2px; min-width: 0; width: 100%; color: var(--ink); }
.items input[type=text]:focus { background: #fff; }
.items input[type=color] { width: 22px; height: 22px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; }
.items .meta { grid-column: 2 / 4; font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.items .note { grid-column: 2 / 4; font-size: 11.5px; }
.items .note input { font-weight: 400; color: var(--muted); }
.items .acts { display: flex; gap: 3px; }
.items .acts button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px 5px; border-radius: 4px; font-size: 12px; }
.items .acts button:hover { background: var(--paper-2); color: var(--ink); }
.num { width: 20px; height: 20px; border-radius: 50%; background: #ff9900; border: 1px solid #000; display: grid; place-items: center; font-size: 10.5px; font-weight: 700; }
#profile-chart { width: 100%; height: auto; margin-top: 8px; background: #fffdf7; border: 1px solid var(--line); border-radius: 6px; }

.log { margin-top: 9px; font-size: 11.5px; color: var(--muted); max-height: 130px; overflow: auto; border-left: 2px solid var(--line); padding-left: 8px; }
.log div { padding: 1px 0; }
.log .think { font-style: italic; opacity: .8; white-space: pre-wrap; }
.prose { margin-top: 10px; background: #fffdf7; border: 1px solid var(--line); border-radius: 6px; padding: 4px 11px 9px; font-size: 12.5px; max-height: 420px; overflow: auto; }
.prose h3, .prose h4 { margin: 10px 0 3px; font-size: 13px; color: var(--forest); }
.prose h4 { font-size: 12.5px; }
.prose p { margin: 5px 0; }
.prose ul { margin: 4px 0; padding-left: 18px; }
.prose code { font-family: var(--mono); font-size: 11.5px; }
.prose a { color: var(--accent-2); }

.wx { margin-top: 8px; font-size: 11.5px; overflow-x: auto; }
.wx table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.wx th, .wx td { text-align: left; padding: 3px 6px 3px 0; border-bottom: 1px solid var(--paper-2); white-space: nowrap; }
.wx th { color: var(--muted); font-weight: 600; }

#side > footer { border-top: 1px solid var(--line); padding: 10px 14px 12px; background: var(--paper-2); }
.actions { margin-top: 0; }
#status { font-size: 12px; min-height: 0; }
#status:not(:empty) { margin-bottom: 9px; }
#status .msg { display: flex; gap: 8px; align-items: flex-start; }
#status .spin { width: 13px; height: 13px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; flex: none; margin-top: 2px; }
#status .ok { color: var(--ok); font-weight: 600; }
#status .err { color: var(--danger); }
#status ul { margin: 5px 0 0; padding-left: 17px; color: #7a4a00; }
#status a { color: var(--accent-2); font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #status .spin { animation-duration: 2.5s; } }

/* ----------------------------------------------------------------- map */
main { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #e9e6dd; }
#map.drawing { cursor: crosshair; }
.coords {
  position: absolute; left: 10px; bottom: 10px; z-index: 500; background: #fffdf7e8; border: 1px solid var(--line);
  border-radius: 5px; padding: 3px 8px; font: 11.5px var(--mono); pointer-events: none;
}
.coords:empty { display: none; }
#toggle-side { position: absolute; top: 10px; left: 54px; z-index: 500; box-shadow: 0 1px 4px #0003; }
.leaflet-container { font-family: var(--sans); }
.frame-label { background: #fffdf7; border: 1px solid #b00; color: #b00; font-weight: 700; font-size: 13px; padding: 1px 6px; border-radius: 3px; box-shadow: none; }
.frame-label::before { display: none; }
.center-handle { cursor: move; }
.center-handle svg { display: block; filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 1px #fff); }
.pt { border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #0008; }
.wp-icon { width: 22px; height: 22px; border-radius: 50%; background: #ff9900; border: 1.5px solid #000; display: grid; place-items: center; font: 700 11px var(--sans); color: #000; }
.poi-tip { font-size: 11px; }
.info-pop { font: 12px var(--mono); line-height: 1.55; }
.info-pop b { font-family: var(--sans); }

/* --------------------------------------------------------------- modal */
#modal { position: fixed; inset: 0; background: #101512cc; z-index: 2000; display: grid; place-items: center; padding: 20px; }
#modal[hidden] { display: none; }
.modal-box { background: var(--paper); border-radius: 8px; max-width: min(1100px, 96vw); max-height: 94vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; gap: 8px; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
.modal-body { overflow: auto; background: #777; padding: 14px; }
.modal-body img { display: block; max-width: 100%; height: auto; margin: 0 auto; background: #fff; box-shadow: 0 2px 14px #0006; }

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  #side { position: absolute; z-index: 1000; width: min(384px, 92vw); height: 100vh; box-shadow: 4px 0 18px #0004; }
  #toggle-side { left: 54px; }
}

.engine { background: #fff4d6; border-bottom: 1px solid #e3c877; color: #5c4300; font-size: 12px; padding: 7px 14px; }
.engine.err { background: #fde4e1; border-color: #e4a39b; color: var(--danger); }
#modal-pdf { display: block; width: min(1000px, 88vw); height: 80vh; border: 0; background: #fff; }
#modal-pdf[hidden], #modal-img[hidden] { display: none; }
