:root {
  --papier: #f3eee1; --flaeche: #fffdf8; --tinte: #2a2622; --blass: #6c645a; --linie: #d9d0bb;
  --akzent: #7a3b1d; --akzent-hell: #f1e2d5; --blau: #2f5d7c; --warn: #b07a12; --fehler: #a3261e; --gut: #3d6b35;
  --schrift: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 var(--schrift); color: var(--tinte); background: var(--papier); display: flex; flex-direction: column; overflow: hidden; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: normal; margin: 0 0 .4em; }
h2 { font-size: 1.35rem; } h3 { font-size: 1.08rem; margin-top: 1.1em; border-bottom: 1px solid var(--linie); padding-bottom: .15em; } h4 { font-size: 1rem; }
p { margin: .4em 0; }
a { color: var(--blau); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--linie); background: var(--flaeche); border-radius: 6px; padding: .35em .8em; min-height: 36px; }
button:hover { border-color: var(--akzent); }
button.haupt { background: var(--akzent); border-color: var(--akzent); color: #fff; }
button.leise { background: transparent; }
button.gefahr { color: var(--fehler); }
button.link { border: 0; background: none; padding: 0; min-height: 0; color: var(--blau); text-decoration: underline; text-align: left; }
button:disabled { opacity: .5; cursor: default; }
.symbolknopf { min-width: 38px; padding: .2em .4em; font-size: 1.1rem; line-height: 1; }
input[type=text], input[type=search], input[type=number], input[type=password], select, textarea { border: 1px solid #c9bfa8; border-radius: 5px; padding: .35em .5em; background: #fff; min-height: 36px; max-width: 100%; }
textarea { width: 100%; min-height: 5.5em; resize: vertical; }
:focus-visible { outline: 3px solid #3b82c4; outline-offset: 1px; }

/* Kopf */
#kopf { display: flex; align-items: center; gap: .7rem; padding: .45rem .8rem; background: var(--flaeche); border-bottom: 1px solid var(--linie); flex-wrap: wrap; }
.marke { font-family: var(--serif); font-size: 1.3rem; color: var(--akzent); white-space: nowrap; }
#suchfeld { position: relative; flex: 1 1 260px; min-width: 180px; max-width: 520px; }
#suche { width: 100%; }
#treffer { position: absolute; z-index: 3000; left: 0; right: 0; top: calc(100% + 3px); background: var(--flaeche); border: 1px solid var(--linie); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.18); max-height: 60vh; overflow: auto; }
#treffer button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid #eee6d4; border-radius: 0; padding: .45em .7em; }
#treffer button small { color: var(--blass); display: block; }
#treffer .leer { padding: .6em .8em; color: var(--blass); }
#ansichten { display: flex; gap: .3rem; margin-left: auto; flex-wrap: wrap; }
#ansichten button.aktiv { background: var(--akzent-hell); border-color: var(--akzent); }
#beispielHinweis { background: #fbf0c9; border-bottom: 1px solid #e3cf86; padding: .3rem .8rem; font-size: .88rem; }

/* Aufbau */
#haupt { flex: 1; display: flex; min-height: 0; position: relative; }
#links, #rechts { background: var(--flaeche); overflow: auto; padding: .7rem .8rem 2rem; flex: none; }
#links { width: 290px; border-right: 1px solid var(--linie); }
#rechts { width: 380px; border-left: 1px solid var(--linie); }
#mitte { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#kartenrahmen { flex: 1; position: relative; min-height: 0; }
#karte { position: absolute; inset: 0; background: #e9e3d3; }
#kartenhinweis { position: absolute; z-index: 800; left: 50%; top: 12px; transform: translateX(-50%); background: rgba(255,253,248,.95); border: 1px solid var(--linie); border-radius: 6px; padding: .4em .8em; max-width: 90%; font-size: .9rem; }
#stammbaum, #verwaltung { flex: 1; overflow: auto; background: var(--papier); padding: 1rem; min-width: 0; }
.nurSchmal { display: none; }

#links details { border-bottom: 1px solid var(--linie); padding: .35rem 0 .6rem; }
#links summary { font-family: var(--serif); font-size: 1.05rem; cursor: pointer; padding: .25rem 0; }
#links label { display: flex; gap: .45em; align-items: center; padding: .16em 0; }
#links label.block { display: block; }
#links select, #links input[type=text] { width: 100%; }
.kartenliste label { align-items: flex-start; }
.kartenliste small { color: var(--blass); display: block; }
.umschalter { display: flex; margin: .4rem 0; }
.umschalter button { flex: 1; border-radius: 0; font-size: .9rem; padding: .3em .4em; }
.umschalter button:first-child { border-radius: 6px 0 0 6px; } .umschalter button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.umschalter button.aktiv { background: var(--akzent-hell); border-color: var(--akzent); }
.zweispaltig { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; }
.legende td { padding: .15em .4em .15em 0; vertical-align: middle; font-size: .9rem; }
.legende svg { vertical-align: middle; }
.hinweis { color: var(--blass); font-size: .88rem; }
.kuerzel { display: inline-block; min-width: 1.7em; text-align: center; font-size: .72rem; font-weight: 600; border: 1px solid #8d8474; border-radius: 3px; background: #fff; padding: 0 .15em; line-height: 1.3; }

/* Leisten über der Karte */
#herrschaft { display: flex; flex-wrap: wrap; gap: .35rem .5rem; align-items: center; padding: .4rem .7rem; background: var(--flaeche); border-bottom: 1px solid var(--linie); min-height: 44px; }
#herrschaft .ortjahr { font-family: var(--serif); font-size: 1.1rem; margin-right: .4rem; }
.hchip { border-left: 5px solid #666; border-radius: 4px; padding: .12em .55em; text-align: left; line-height: 1.25; min-height: 0; font-size: .9rem; }
.hchip small { display: block; color: var(--blass); font-size: .74rem; }
.hchip.unsicher { border-style: dashed; border-left-style: dashed; }
.echip { background: #fbf0c9; border: 1px solid #e3cf86; border-radius: 4px; padding: .12em .55em; font-size: .88rem; }
#filterleiste { background: #e6eef4; border-bottom: 1px solid #b9cbd8; padding: .3rem .7rem; font-size: .9rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
#filterleiste[hidden], #werkzeugleiste[hidden] { display: none; }
#werkzeugleiste { background: #fbf0c9; border-bottom: 2px solid var(--warn); padding: .4rem .7rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* Zeitleiste */
#zeit { background: var(--flaeche); border-top: 1px solid var(--linie); padding: .45rem .7rem .5rem; }
.zeitzeile { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.zeitzeile.klein { font-size: .86rem; color: var(--blass); margin-top: .3rem; gap: .4rem 1.1rem; }
.zeitzeile.klein input[type=number] { width: 5.2em; min-height: 30px; padding: .15em .3em; }
.zeitzeile.klein select { min-height: 30px; padding: .1em .3em; }
#jahrZahl { width: 5.6em; font-family: var(--serif); font-size: 1.35rem; text-align: center; padding: .1em; }
.reglerbox { flex: 1; min-width: 200px; position: relative; padding-bottom: 14px; }
#regler { width: 100%; margin: 0; accent-color: var(--akzent); height: 28px; }
#marken { position: absolute; left: 9px; right: 9px; bottom: 0; height: 14px; pointer-events: none; }
#marken span { position: absolute; top: 0; transform: translateX(-50%); font-size: 10px; line-height: 14px; color: var(--blau); pointer-events: auto; cursor: pointer; white-space: nowrap; }
#marken span.h { color: var(--akzent); }
#zaehler { margin-left: auto; }

/* Kartenzeichen */
.hauszeichen { background: none; border: 0; }
.hz { position: absolute; width: max-content; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.hz-sym { min-width: 30px; min-height: 30px; align-items: center; display: flex; flex-wrap: wrap; justify-content: center; gap: 1px; max-width: 108px; background: rgba(255,253,248,.88); border: 1px solid #6b6256; border-radius: 5px; padding: 2px 3px; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.hz.leer .hz-sym { padding: 1px; border-color: #8d8474; background: rgba(255,253,248,.7); box-shadow: none; }
.hz.gewaehlt .hz-sym { outline: 3px solid #3b82c4; outline-offset: 1px; }
.hz-name { position: absolute; top: calc(100% + 1px); left: 50%; transform: translateX(-50%); font-size: 11px; line-height: 1.2; background: rgba(255,253,248,.85); padding: 0 3px; border-radius: 3px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.ps { display: inline-flex; flex-direction: column; align-items: center; line-height: 1; }
.ps.gewaehlt svg { filter: drop-shadow(0 0 2px #1d6fc0) drop-shadow(0 0 2px #1d6fc0); }
.ps small { font-size: 9px; font-weight: 600; margin-top: -1px; }
.fam { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; border: 1px solid #6b6256; border-radius: 9px; padding: 0 5px; background: #fff; white-space: nowrap; }
.mehr { font-size: 10px; align-self: center; padding: 0 2px; }
img.planbild { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none !important; max-height: none !important; pointer-events: none; }
.leaflet-container { font: inherit; }
.ppnr { background: #1d6fc0; color: #fff; border-radius: 50%; width: 22px; height: 22px; line-height: 22px; text-align: center; font-size: 12px; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.5); }

/* Detailansicht */
.kopfzeile { display: flex; gap: .6rem; align-items: flex-start; }
.kopfzeile h2 { margin: 0; }
.unter { color: var(--blass); }
.knopfreihe { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
.knopfreihe button { font-size: .9rem; padding: .25em .6em; }
.kasten { background: var(--akzent-hell); border-radius: 6px; padding: .5rem .7rem; margin: .6rem 0; }
.kasten.neutral { background: #eee9db; }
.kasten.warn { background: #fbf0c9; border: 1px solid #e3cf86; }
ul.schlicht { list-style: none; margin: .2em 0; padding: 0; }
ul.schlicht li { padding: .22em 0; border-bottom: 1px dotted #e4dcc8; }
ul.schlicht li:last-child { border: 0; }
.zr { color: var(--blass); font-size: .88rem; white-space: nowrap; }
.marke-unsicher { color: var(--warn); font-weight: 600; cursor: help; }
.marke-belegt { color: var(--gut); cursor: help; }
.q { font-size: .8rem; color: var(--blau); cursor: pointer; white-space: nowrap; border: 0; background: none; padding: 0; min-height: 0; text-decoration: underline dotted; }
.pzeile { display: flex; gap: .45rem; align-items: center; }
.pzeile .name { flex: 1; }
.medien { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.medien figure { margin: 0; font-size: .8rem; }
.medien img { width: 100%; height: 90px; object-fit: cover; border: 1px solid var(--linie); border-radius: 4px; background: #fff; }
.schliessen { margin-left: auto; }
.schloss { font-size: .8rem; background: #eee9db; border-radius: 4px; padding: 0 .4em; white-space: nowrap; }

/* Stammbaum */
.sb-kopf { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.sb-flaeche { position: relative; margin: 1rem auto; }
.sb-flaeche > svg { position: absolute; left: 0; top: 0; pointer-events: none; }
.sb-karte { position: absolute; width: 168px; height: 58px; background: var(--flaeche); border: 1px solid #a99f8a; border-radius: 6px; padding: 4px 6px; display: flex; gap: 6px; align-items: center; text-align: left; line-height: 1.2; font-size: .84rem; overflow: hidden; }
.sb-karte.fokus { border: 2px solid var(--akzent); background: var(--akzent-hell); }
.sb-karte b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 128px; }
.sb-karte small { color: var(--blass); white-space: nowrap; }
.sb-ehe { position: absolute; font-size: 11px; color: var(--blass); text-align: center; width: 60px; }

/* Verwaltung */
.reiter { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 2px solid var(--akzent); margin-bottom: .8rem; }
.reiter button { border-radius: 6px 6px 0 0; border-bottom: 0; }
.reiter button.aktiv { background: var(--akzent); color: #fff; border-color: var(--akzent); }
.vw-kopf { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
table.liste { border-collapse: collapse; width: 100%; background: var(--flaeche); }
table.liste th, table.liste td { text-align: left; padding: .4em .6em; border-bottom: 1px solid var(--linie); vertical-align: top; }
table.liste th { font-weight: 600; background: #eee9db; position: sticky; top: -1rem; }
table.liste tbody tr { cursor: pointer; }
table.liste tbody tr:hover { background: var(--akzent-hell); }
.karteik { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; max-width: 900px; }
pre.ergebnis { background: #fff; border: 1px solid var(--linie); border-radius: 6px; padding: .6rem; white-space: pre-wrap; max-height: 300px; overflow: auto; font: .85rem/1.4 Consolas, monospace; }

/* Dialoge und Formulare */
dialog { border: 1px solid var(--linie); border-radius: 10px; padding: 0; background: var(--flaeche); color: var(--tinte); max-width: min(880px, 96vw); width: 880px; max-height: 94vh; box-shadow: 0 12px 40px rgba(0,0,0,.35); }
dialog.schmal { width: 460px; }
dialog::backdrop { background: rgba(40,34,26,.45); }
#grossdialog { width: 98vw; max-width: 98vw; height: 94vh; }
.dlg { display: flex; flex-direction: column; max-height: 94vh; height: 100%; }
.dlg > header { padding: .7rem 1rem; border-bottom: 1px solid var(--linie); display: flex; align-items: center; gap: .6rem; }
.dlg > header h2 { margin: 0; flex: 1; }
.dlg > .inhalt { padding: .8rem 1rem; overflow: auto; flex: 1; }
.dlg > footer { padding: .6rem 1rem; border-top: 1px solid var(--linie); display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.dlg > footer .platz { flex: 1; }
fieldset { border: 1px solid var(--linie); border-radius: 8px; margin: 0 0 .9rem; padding: .5rem .8rem .7rem; min-width: 0; }
legend { font-family: var(--serif); font-size: 1.05rem; padding: 0 .4em; }
.raster { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .5rem .8rem; }
.feld { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.feld.breit { grid-column: 1 / -1; }
.feld > span.l { font-size: .84rem; color: var(--blass); }
.feld input[type=text], .feld select { width: 100%; }
.feld.ja { flex-direction: row; align-items: center; gap: .45em; padding-top: 1.3em; }
.feld .dh { font-size: .78rem; min-height: 1.1em; }
.dh.ok { color: var(--gut); } .dh.un { color: var(--warn); } .dh.nein { color: var(--fehler); }
.listenzeile { border: 1px solid #e4dcc8; background: #fbf8ef; border-radius: 6px; padding: .45rem .6rem; margin-bottom: .45rem; position: relative; }
.listenzeile .weg { position: absolute; right: 4px; top: 4px; min-height: 28px; padding: 0 .5em; font-size: .85rem; }
.listenzeile .raster { padding-right: 2.2rem; }
.fehlerkasten { background: #fbe4e1; border: 1px solid #e0a59f; border-radius: 6px; padding: .5rem .8rem; margin-bottom: .8rem; }
.fehlerkasten ul { margin: .2em 0; padding-left: 1.2em; }
.georef { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; height: 100%; min-height: 300px; }
.georef > div { display: flex; flex-direction: column; min-height: 0; }
.georef .k { flex: 1; min-height: 240px; border: 1px solid var(--linie); background: #e9e3d3; }
.pp-liste { display: flex; flex-wrap: wrap; gap: .3rem; margin: .4rem 0; }
.pp-liste span { background: #e6eef4; border-radius: 12px; padding: .1em .3em .1em .7em; font-size: .88rem; display: inline-flex; align-items: center; gap: .3em; }
.pp-liste button { min-height: 24px; padding: 0 .4em; border-radius: 12px; }

#meldung { position: fixed; z-index: 99999; left: 50%; bottom: 96px; transform: translateX(-50%); display: flex; flex-direction: column; gap: .4rem; align-items: center; pointer-events: none; }
#meldung div { background: #2a2622; color: #fff; padding: .55em 1em; border-radius: 8px; max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.3); pointer-events: auto; }
#meldung div.fehler { background: var(--fehler); }

/* Tablet und schmale Fenster: Seitenleisten als Schubladen */
@media (max-width: 1180px) {
  .nurSchmal { display: inline-block; }
  #links, #rechts { position: absolute; top: 0; bottom: 0; z-index: 1500; box-shadow: 0 0 24px rgba(0,0,0,.3); display: none; max-width: 92vw; }
  #links { left: 0; } #rechts { right: 0; width: 400px; }
  body.linksOffen #links, body.rechtsOffen #rechts { display: block; }
}
@media (max-width: 700px) {
  .georef { grid-template-columns: 1fr; }
  .marke { display: none; }
}
@media print {
  #kopf, #links, #zeit, #beispielHinweis { display: none; }
  body { overflow: visible; }
}
