:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1d2a1f;
  --muted: #6b7a6e;
  --line: #dfe4dc;
  --green: #1f6b3a;
  --green-dark: #144a28;
  --accent: #c8a24a;
  --s1: #1a9850; --s2: #a6d96a; --s3: #fdae61; --n: #d73027;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.4 -apple-system, "Segoe UI", Inter, Roboto, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select { font: inherit; }
h2, h3 { margin: 12px 0 6px; font-weight: 600; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
small { color: var(--muted); display: block; margin-top: 6px; }

.topbar { height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--green-dark); color: #fff; }
.brand { font-weight: 600; display: flex; gap: 10px; align-items: center; }
.logo { background: var(--accent); color: var(--green-dark); padding: 2px 8px; border-radius: 4px; font-weight: 800; letter-spacing: .05em; }
.tag { background: rgba(255,255,255,.15); padding: 1px 6px; border-radius: 3px; font-size: 11px; }
.userbox { display: flex; gap: 10px; align-items: center; font-size: 13px; }
.userbox .role { opacity: .7; }
.userbox button { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 4px; padding: 4px 10px; cursor: pointer; }

.layout { display: flex; height: calc(100% - 52px); }
.sidebar { width: 400px; min-width: 320px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 10px 4px; border: 0; background: transparent; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--green); border-bottom-color: var(--green); font-weight: 600; }
.tab { display: none; padding: 12px 14px; overflow: auto; flex: 1; }
.tab.active { display: block; }
.mapwrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }

label { display: block; margin: 6px 0; font-size: 13px; color: var(--muted); }
label select, label input { display: block; width: 100%; margin-top: 3px; }
select, input[type=text], input[type=number], input[type=password], input:not([type]) { padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--ink); width: 100%; }
button { padding: 6px 12px; border: 1px solid var(--line); background: #fff; border-radius: 4px; cursor: pointer; color: var(--ink); }
button:hover { border-color: var(--green); }
button.primary { background: var(--green); color: #fff; border-color: var(--green); }
button.primary:disabled { opacity: .5; cursor: wait; }
button.tiny { padding: 1px 6px; font-size: 11px; }
.row { display: flex; gap: 6px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.row label { flex: 1; margin: 0; }

.domain { margin-top: 10px; }
.domain h4 { margin: 4px 0; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.layer { display: flex; align-items: center; gap: 6px; padding: 4px 2px; border-bottom: 1px dashed var(--line); }
.layer .name { flex: 1; min-width: 0; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .name:hover { color: var(--green); }
.layer .meta { color: var(--muted); font-size: 11px; }
.layer .actions { display: flex; gap: 3px; }
.layer select { width: auto; max-width: 92px; padding: 2px 4px; font-size: 11px; }
.layer.inactive { opacity: .5; }
.import { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 8px; }
.import form > * { margin: 4px 0; display: block; width: 100%; }

.legend { position: absolute; right: 12px; bottom: 30px; background: rgba(255,255,255,.95); padding: 8px 10px; border-radius: 6px; font-size: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.15); max-width: 240px; }
.legend:empty { display: none; }
.legend .li { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.legend .sw { width: 14px; height: 14px; border-radius: 2px; border: 1px solid rgba(0,0,0,.2); }
.legend h5 { margin: 0 0 4px; font-size: 12px; }
.coords { position: absolute; left: 8px; bottom: 8px; font-size: 11px; background: rgba(255,255,255,.8); padding: 2px 6px; border-radius: 3px; font-family: ui-monospace, Menlo, monospace; }

.stats { margin: 8px 0; }
.bar { display: flex; height: 18px; border-radius: 4px; overflow: hidden; margin: 4px 0; }
.bar span { display: block; height: 100%; color: #fff; font-size: 11px; line-height: 18px; text-align: center; overflow: hidden; }
.stat-row { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; }
.an-item { padding: 6px 4px; border-bottom: 1px dashed var(--line); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.an-item .grow { flex: 1; }
.an-item .status { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: #e8efe9; color: var(--green); }
.an-item .status.error { background: #fbe4e1; color: var(--n); }

table.crit { width: 100%; border-collapse: collapse; font-size: 12px; margin: 6px 0; }
table.crit th, table.crit td { border-bottom: 1px solid var(--line); padding: 4px 3px; text-align: left; vertical-align: top; }
table.crit input { padding: 3px 4px; font-size: 12px; }
table.crit .classes { font-family: ui-monospace, Menlo, monospace; font-size: 11px; width: 100%; min-height: 60px; border: 1px solid var(--line); border-radius: 4px; padding: 4px; }
table.crit .w { width: 52px; }
.crit-card { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin: 8px 0; }
.crit-card .head { display: flex; gap: 6px; align-items: center; }
.crit-card .head input.name { flex: 1; }
.class-row { display: grid; grid-template-columns: 1fr 1fr 1fr 24px; gap: 4px; margin: 3px 0; }
.class-row input { padding: 3px 5px; font-size: 12px; }
.class-head { display: grid; grid-template-columns: 1fr 1fr 1fr 24px; gap: 4px; font-size: 10px; color: var(--muted); text-transform: uppercase; margin-top: 6px; }

table.audit { width: 100%; font-size: 11px; border-collapse: collapse; }
table.audit td { border-bottom: 1px solid var(--line); padding: 3px 2px; vertical-align: top; word-break: break-word; }
table.audit td.ts { white-space: nowrap; color: var(--muted); }

dialog { border: 0; border-radius: 8px; padding: 20px; box-shadow: 0 6px 30px rgba(0,0,0,.25); max-width: min(90vw, 900px); }
dialog::backdrop { background: rgba(20,40,25,.5); }
#login form { display: flex; flex-direction: column; gap: 8px; width: 300px; }
.err { color: var(--n); font-size: 12px; min-height: 16px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.scroll { max-height: 60vh; overflow: auto; margin-top: 8px; }
table.attr { border-collapse: collapse; font-size: 11px; }
table.attr th, table.attr td { border: 1px solid var(--line); padding: 2px 5px; white-space: nowrap; }
table.attr th { background: var(--bg); position: sticky; top: 0; }

.maplibregl-popup-content { font-size: 12px; max-height: 320px; overflow: auto; padding: 10px 12px; }
.maplibregl-popup-content table { border-collapse: collapse; }
.maplibregl-popup-content td { padding: 1px 6px 1px 0; }
.maplibregl-popup-content td:first-child { color: var(--muted); }
.maplibregl-popup-content .cls { font-weight: 700; padding: 2px 6px; border-radius: 3px; color: #fff; display: inline-block; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 6px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 80vw; }
#toast.show { opacity: 1; }
#toast.error { background: var(--n); }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: 45%; border-right: 0; border-bottom: 1px solid var(--line); }
  .mapwrap { height: 55%; }
}
.crit-card .head input.w { width: 64px; flex: none; }
.crit-card .row input.param { flex: 1; }
.crit-card .row input.desc { flex: 1; }
