:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #18212b; --quiet: #5f6b78; --line: #e1e5ea; --line-strong: #c9d0d8;
  --hover: #f0f2f5; --accent: #2563c9; --accent-soft: #e8f0fc; --accent-ink: #fff; --good: #2e8b57; --warn: #d39b00; --bad: #c8412e;
  --r: 8px; --h: 32px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 12px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, select, input { font: inherit; }
button { border: 1px solid var(--line); background: var(--panel); border-radius: var(--r); padding: 5px 10px; cursor: pointer; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; transition: background .12s, border-color .12s; }
button:hover { border-color: var(--line-strong); background: var(--hover); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { background: #1f55ad; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--hover); }
button.icon { width: var(--h); height: var(--h); padding: 0; justify-content: center; flex: none; }
button .ti { font-size: 16px; line-height: 1; }
select, input[type=text], input:not([type]), input[type=number] { border: 1px solid var(--line); border-radius: var(--r); padding: 5px 8px; background: #fff; }

#top { display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); height: 52px; }
#top > button, #top .menu > button { height: var(--h); }
.brand { font-weight: 650; font-size: 15px; margin-right: 6px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.brand .ti { color: var(--accent); font-size: 20px; }
.plansw { display: flex; align-items: center; gap: 6px; min-width: 0; }
#planSelect { max-width: 280px; min-width: 120px; flex-shrink: 1; height: var(--h); font-weight: 600; }
.hgroup { display: flex; gap: 2px; padding-left: 6px; border-left: 1px solid var(--line); }
.hgroup button { border-color: transparent; background: transparent; }
.cmdbtn { color: var(--quiet); background: var(--bg) !important; min-width: 210px; }
.cmdbtn span { flex: 1; text-align: left; }
kbd { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--quiet); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; }
button.avatar { width: var(--h); padding: 0; justify-content: center; border-radius: 50%; background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 650; font-size: 12px; }
.menu-head { padding: 6px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; }
.menu-head small { color: var(--quiet); }
.menu-items button.danger { color: var(--bad); }
#top > button, #top .menu > button, #userBox { white-space: nowrap; }
.badge { font-size: 11px; padding: 2px 6px; border-radius: 10px; background: #eef1f5; color: var(--quiet); }
.spacer { flex: 1; }
.menu { position: relative; }
.menu-items { display: none; position: absolute; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); z-index: 40; min-width: 260px; padding: 4px; }
.menu.open .menu-items { display: block; }
.menu.open > button { background: var(--hover); }
.menu-items button { display: flex; width: 100%; text-align: left; border: 0; padding: 7px 10px; border-radius: 6px; background: transparent; }
.menu-items button .ti { color: var(--quiet); width: 18px; }
.menu-items button:hover { background: var(--hover); }
.menu.left .menu-items { left: 0; right: auto; }
.menu-items hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }
.savestate { font-size: 11px; color: var(--quiet); white-space: nowrap; }
.savestate.err { color: #b42318; }
.plantbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.plantbl th, .plantbl td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.plantbl tbody tr { cursor: pointer; }
.plantbl tbody tr:hover { background: #eef1f5; }
.plantbl tr.cur td { font-weight: 600; }
.plantbl .sub { color: var(--quiet); font-size: 11px; }

main { display: flex; height: calc(100% - 52px); }
#rail { width: 68px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; }
#rail button { flex-direction: column; gap: 3px; width: 58px; padding: 7px 0 6px; border: 0; background: transparent; color: var(--quiet); font-size: 11px; border-radius: var(--r); }
#rail button .ti { font-size: 20px; }
#rail button:hover { background: var(--hover); color: var(--ink); }
#rail button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#rail .spacer { flex: 1; }
#side { width: 360px; min-width: 300px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.tabpane { display: none; padding: 10px 12px; overflow: auto; flex: 1; }
.tabpane.active { display: block; }
.tabpane h4 { margin: 14px 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--quiet); display: flex; align-items: center; gap: 6px; }
.tabpane h4:first-child { margin-top: 4px; }
button.act { display: flex; width: 100%; text-align: left; gap: 10px; padding: 8px 10px; border-color: transparent; background: transparent; margin: 1px 0; align-items: flex-start; }
button.act:hover { background: var(--hover); border-color: transparent; }
button.act .ti { font-size: 18px; color: var(--accent); margin-top: 1px; }
button.act span { display: flex; flex-direction: column; }
button.act b { font-weight: 600; }
button.act small { color: var(--quiet); font-size: 12px; }
#tab-nodes .row .menu .menu-items { right: 0; }
.tabpane label { display: block; margin: 3px 0; }
.row { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.row label { flex: 1; display: flex; flex-direction: column; font-size: 11px; color: var(--quiet); }
.row select { width: 100%; }
#search { flex: 1; }

#summary { font-size: 12px; color: var(--quiet); margin: 4px 0 6px; }
.node { display: grid; grid-template-columns: 14px 1fr auto; gap: 2px 8px; align-items: center; padding: 6px 6px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.node:hover { background: var(--hover); }
.node.active { border-color: transparent; background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.swatch { width: 14px; height: 14px; border-radius: 3px; grid-row: span 2; }
.node .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .sub { grid-column: 2 / 4; font-size: 11px; color: var(--quiet); display: flex; gap: 8px; align-items: center; }
.node .val { font-variant-numeric: tabular-nums; text-align: right; }
.bar { flex: 1; height: 6px; background: #edf0f3; border-radius: 3px; position: relative; min-width: 60px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; }
.bar b { position: absolute; left: 66.6%; top: -2px; bottom: -2px; width: 1px; background: #8994a0; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.good { background: var(--good); } .warn { background: var(--warn); } .bad { background: var(--bad); }
.node .edit { visibility: hidden; padding: 0 6px; border: 0; background: transparent; }
.node:hover .edit { visibility: visible; }

#mapWrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }
#tools { position: absolute; top: 12px; left: 12px; display: flex; flex-direction: column; gap: 2px; background: var(--panel); padding: 4px; border-radius: 10px; box-shadow: var(--shadow); border: 1px solid var(--line); z-index: 3; }
#tools button { width: 34px; height: 34px; padding: 0; justify-content: center; border-color: transparent; background: transparent; color: var(--quiet); }
#tools button .ti { font-size: 18px; }
#tools button:hover { background: var(--hover); color: var(--ink); }
#tools button.active { background: var(--accent); color: #fff; }
#toolhint { position: absolute; top: 12px; left: 62px; max-width: calc(100% - 140px); font-size: 12px; color: var(--quiet); background: rgba(255,255,255,.92); padding: 5px 10px; border-radius: var(--r); border: 1px solid var(--line); pointer-events: none; z-index: 2; }
#active { position: absolute; top: 46px; left: 62px; background: var(--panel); padding: 5px 10px; border-radius: var(--r); box-shadow: var(--shadow); border: 1px solid var(--line); font-size: 12px; z-index: 2; }
#active:empty { display: none; }
#selbar { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); background: #18212b; color: #fff; padding: 6px 6px 6px 12px; border-radius: 10px; display: flex; gap: 4px; align-items: center; box-shadow: var(--shadow); z-index: 3; }
#selbar button { background: transparent; color: #fff; border-color: transparent; }
#selbar button:hover { background: #2c3744; }
#info { position: absolute; top: 10px; right: 50px; width: 300px; max-height: 70%; overflow: auto; background: var(--panel); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.18); padding: 10px 12px; }
#info h3 { margin: 0 0 6px; font-size: 14px; }
#info table { width: 100%; border-collapse: collapse; }
#info td { padding: 2px 0; border-bottom: 1px solid #f0f2f4; }
#info td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
#info .close { position: absolute; right: 6px; top: 6px; border: 0; }
#busy { position: absolute; inset: 0; background: rgba(255,255,255,.55); display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 600; z-index: 30; }
#busy[hidden], #selbar[hidden], #info[hidden] { display: none; }
.selrect { position: absolute; border: 1.5px dashed var(--accent); background: rgba(36,99,184,.08); pointer-events: none; z-index: 10; }
svg.lasso { position: absolute; inset: 0; pointer-events: none; z-index: 10; }

#legend { font-size: 12px; margin-top: 6px; }
#legend div { display: flex; align-items: center; gap: 6px; }
#legend span.sw { width: 18px; height: 12px; border-radius: 2px; display: inline-block; }
.ext { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.ext span { flex: 1; }
.ext button { padding: 1px 6px; font-size: 11px; }

dialog { border: 0; border-radius: 10px; padding: 0; box-shadow: 0 10px 40px rgba(0,0,0,.25); max-width: 92vw; }
dialog form { padding: 16px 18px; min-width: 420px; max-height: 85vh; overflow: auto; }
dialog h3 { margin: 0 0 10px; }
dialog label { display: block; margin: 8px 0 2px; font-size: 12px; color: var(--quiet); }
dialog input:not([type=checkbox]):not([type=radio]):not([type=range]), dialog select { width: 100%; }
dialog .check { display: flex; gap: 6px; align-items: center; color: var(--ink); font-size: 13px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
dialog .note { font-size: 12px; color: var(--quiet); margin: 6px 0; }
dialog table { border-collapse: collapse; width: 100%; font-size: 12px; }
dialog th, dialog td { border-bottom: 1px solid #eef0f2; padding: 4px 6px; text-align: left; white-space: nowrap; }
dialog th { position: sticky; top: 0; background: #fff; cursor: pointer; }
dialog td.num { text-align: right; font-variant-numeric: tabular-nums; }
dialog .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.weights { display: block; }
.wrow { display: grid; grid-template-columns: 1fr 80px 28px; gap: 6px; align-items: center; margin-bottom: 4px; }
.wrow button { padding: 2px 6px; }
.weights select.wadd { margin: 2px 0 4px; }
.sample { max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; margin-top: 8px; }

#toast { position: fixed; bottom: 20px; right: 20px; background: #1d2733; color: #fff; padding: 10px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 420px; z-index: 50; }
#toast.show { opacity: .95; }

@media print {
  #top, #rail, #side, #tools, #toolhint, #selbar, #active, .maplibregl-ctrl { display: none !important; }
  main { height: 100vh; }
}

/* Nur-Lesen-Rollen: Bearbeiten ausblenden */
body.readonly .edit-only, body.readonly .node .edit, body.readonly #selbar,
body.readonly #extLayers, body.readonly [data-act="undo"], body.readonly [data-act^="info"]:not([data-act="infoSelect"]) { display: none !important; }
[hidden] { display: none !important; }

.mchart { display: inline-flex; width: max-content; gap: 2px; align-items: flex-end; height: 34px; padding: 2px 3px; background: rgba(255,255,255,.85); border-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.25); pointer-events: none; position: relative; }
.mchart i { width: 7px; display: block; border-radius: 1px; }
.mchart b { position: absolute; left: 2px; right: 2px; height: 1px; background: #333; }
#chartMetrics label { display: inline-flex; gap: 4px; margin-right: 8px; font-size: 12px; }
.mpie { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); pointer-events: none; }
#inset { position: absolute; left: 10px; bottom: 34px; width: 190px; height: 210px; border: 1px solid #9aa5b1; border-radius: 6px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.2); background: #fff; }
#inset[hidden] { display: none; }
.notes-row { display: flex; gap: 6px; align-items: center; font-size: 12px; margin: 2px 0; }
.notes-row span { flex: 1; }
.mstack { display: flex; flex-direction: column-reverse; width: 10px; border: 1px solid #fff; }
.mstack i { width: 100% !important; display: block; min-height: 0; }
body.readonly [data-act="redo"] { display: none !important; }
.orgtree ul { list-style: none; margin: 0; padding-left: 18px; border-left: 1px dashed #c5ccd4; }
.orgtree > ul { border-left: none; padding-left: 0; }
.orgtree li { margin: 3px 0; }
.org { cursor: pointer; padding: 1px 4px; border-radius: 4px; }
.org:hover { background: #eef3fa; }
body.locked [data-mode="assign"], body.locked [data-act="addNode"], body.locked [data-act="assignList"], body.locked .node .edit,
body.locked [data-act="undo"], body.locked [data-act="redo"], body.locked [data-mode="note"], body.locked [data-mode="draw"] { display: none !important; }
.fmtrow td { padding: 2px 3px; background: var(--bg); }
.fmtrow select { font-size: 11px; padding: 1px 2px; max-width: 150px; }
.note.ok { color: var(--good); }
.warnbox { margin-top: 8px; padding: 8px 10px; border: 1px solid var(--warn); background: #fff8e1; border-radius: 6px; font-size: 12px; }
.warnbox details { margin-top: 4px; }
.warnbox table { font-size: 11px; margin: 4px 0 0 12px; }
button.mini { font-size: 11px; padding: 1px 6px; margin-left: 6px; font-weight: normal; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.chips button { font-size: 11px; padding: 2px 7px; border-radius: 10px; }
#dlgForm .styletbl td { padding: 3px 6px; white-space: nowrap; font-size: 12px; }
#dlgForm .styletbl input[type=range] { width: 90px; margin: 0; vertical-align: middle; }
#dlgForm .styletbl input[type=color] { width: 32px; margin: 0; height: 20px; padding: 0; vertical-align: middle; }
.styletbl .v { display: inline-block; width: 40px; color: var(--quiet); }
.name .code { font-weight: 400; color: var(--quiet); font-variant-numeric: tabular-nums; }
#dlgForm input.cell { width: auto; min-width: 70px; padding: 2px 4px; font-size: 12px; border: 1px solid transparent; background: transparent; }
#dlgForm input.cell:hover, #dlgForm input.cell:focus { border-color: var(--line); background: #fff; }
#dlgForm input.cell.saved { background: #e6f4ea; }
#dlgForm input.cell.bad { border-color: var(--bad); }
.tablewrap th { position: sticky; top: 0; background: var(--panel); z-index: 1; }
#dlgForm .kindtbl select { width: auto; max-width: 260px; font-size: 12px; }

#dlgForm .aggtbl td:nth-child(2) { color: var(--quiet); text-align: right; padding-right: 10px; }
#dlgForm .aggtbl select { width: 100%; }
#dlgForm .weights .each { margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: #eef1f5; border-radius: 10px; padding: 2px 4px 2px 8px; font-size: 12px; }
.cityhead { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; }

/* KI-Assistent */
#kiPanel { position: absolute; top: 0; right: 0; bottom: 0; width: 400px; max-width: 100%; z-index: 5; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -4px 0 12px rgba(0,0,0,.08); }
#kiPanel[hidden] { display: none; }
.kihead { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.kihead .spacer { flex: 1; }
#kiLog { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.kimsg { padding: 8px 10px; border-radius: 8px; line-height: 1.45; }
.kimsg.user { background: #e8f0fb; align-self: flex-end; max-width: 85%; white-space: pre-wrap; }
.kimsg.bot { background: #f6f6f6; }
.kimsg.bot ul { margin: 4px 0; padding-left: 18px; }
.kimsg.bot table, .kicard table { border-collapse: collapse; margin: 4px 0; font-size: 12px; }
.kimsg.bot td, .kimsg.bot th, .kicard td, .kicard th { border-bottom: 1px solid var(--line); padding: 2px 6px; text-align: left; }
.kimsg .kicost { color: #888; font-size: 11px; margin-top: 4px; }
.kimsg.err { background: #fdecec; }
.kicard { border: 1px solid #c9d8ef; border-radius: 8px; padding: 8px 10px; background: #fff; }
.kicard .kibtns { display: flex; gap: 6px; margin-top: 8px; }
.kicard.done { opacity: .6; }
.kiwait { color: #666; font-style: italic; }
#kiForm { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); }
#kiForm textarea { flex: 1; resize: vertical; font: inherit; }

/* Auswahl je Gebiet in Export-Dialogen */
.nodepick { border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.pickbar { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.pickbar .pickq { flex: 1; }
.pickbar .pickn { color: #666; font-size: 12px; white-space: nowrap; }
.picklist { max-height: 200px; overflow-y: auto; columns: 2; column-gap: 12px; }
.picklist label.check { display: block; break-inside: avoid; margin: 1px 0; }
.picklist .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; }

/* Befehlssuche (⌘K) */
#cmd { position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 60; display: flex; justify-content: center; align-items: flex-start; padding-top: 12vh; }
.cmdbox { width: 600px; max-width: 92vw; background: var(--panel); border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.25); overflow: hidden; }
.cmdin { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.cmdin .ti { font-size: 18px; color: var(--quiet); }
.cmdin input { flex: 1; border: 0 !important; outline: none; font-size: 15px; padding: 2px 0 !important; }
#cmdList { max-height: 50vh; overflow-y: auto; padding: 6px; }
.cmdrow { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r); cursor: pointer; }
.cmdrow .ti { font-size: 18px; color: var(--accent); width: 20px; }
.cmdrow span { flex: 1; display: flex; flex-direction: column; }
.cmdrow small { color: var(--quiet); font-size: 12px; }
.cmdrow em { font-style: normal; font-size: 11px; color: var(--quiet); background: var(--bg); border-radius: 10px; padding: 1px 8px; }
.cmdrow.sel, .cmdrow:hover { background: var(--accent-soft); }
.cmdempty { padding: 14px; color: var(--quiet); }
.cmdfoot { padding: 7px 14px; border-top: 1px solid var(--line); font-size: 11px; color: var(--quiet); background: var(--bg); }

@media (max-width: 1250px) { .cmdbtn span, .cmdbtn kbd { display: none; } .cmdbtn { min-width: 0; } #savestate, .savestate { display: none; } }
@media (max-width: 1000px) { .brand { font-size: 0; } .brand .ti { font-size: 22px; } #side { width: 300px; } }
.row button { white-space: nowrap; }
#tplSelect { min-width: 0; flex: 1; }
#selbar button, #selbar span { white-space: nowrap; }
#toolhint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
