/* Online-Gestalter (Entscheidung 51, eingebettet seit Entscheidung 58): das Werkzeug "Online gestalten" der
   Arbeitsflaeche – liegt ueber Flaeche und Panel, die Schritte links bleiben sichtbar (am Handy: unter der Schrittleiste).
   Farben/Ecken aus dem Theme (--pk-primaer, --pk-ecken: Design 2 = eckig). Auswahlfelder ohne Rahmen (Hausregel). */
.pk-gestalter {
    --g-blau: var(--pk-primaer, #1a66d9);
    --g-blau-hell: var(--pk-primaer-hell, #e8f0fc);
    --g-text: #1b2433;
    --g-grau: #4b5567;
    --g-linie: #d5dce6;
    /* Kante bedienbarer Felder/Knoepfe: mind. 3:1 gegen Weiss und --g-flaeche (WCAG 1.4.11, Usability-Test 18.11.:
       vorher --g-linie = 1,38:1) */
    --g-kante: #7a8594;
    --g-flaeche: #f3f6fa;
    --g-r: calc(4px * var(--pk-ecken, 1));
    position: relative;
    z-index: 8;
    grid-column: 2 / -1;
    grid-row: 1 / -1;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: #ffffff;
    color: var(--g-text);
    font-size: 15px;
}
.pk-gestalter:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr); /* sonst bestimmt der breiteste Inhalt die Spalte -> Querscroll am Handy */
    grid-template-rows: auto minmax(0, 1fr);
}
/* Handy und Tablet: die Arbeitsflaeche steht untereinander – der Gestalter nimmt den Platz unter der Schrittleiste ein,
   fensterhoch wie frueher als Dialog: Karte oben, Werkzeugleiste unten, dazwischen scrollt nur die Leiste (sonst wuchs er
   mit dem Inhalt, und wer in der Ebenenliste etwas waehlte, hatte die Karte aus dem Bild gescrollt) */
@media (max-width: 991.98px) {
    .pk-gestalter {
        grid-column: 1;
        grid-row: 2 / -1;
        height: 100vh;
        height: 100dvh;
    }
    /* Flaeche und Panel liegen darunter in denselben Zeilen – sie ragten sonst unter dem Gestalter hervor */
    .pk-werkzeug[data-gestalter="offen"] > .pk-flaeche,
    .pk-werkzeug[data-gestalter="offen"] > .pk-panel {
        display: none;
    }
}
.pk-gestalter * { box-sizing: border-box; }
.pk-gestalter [hidden] { display: none !important; }
.pk-gestalter :focus-visible { outline: 2px solid var(--g-blau); outline-offset: 2px; }
.pk-gestalter h2, .pk-gestalter h3 { margin: 0; }

.pk-g-knopf {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    min-width: 36px;
    padding: 0 12px;
    border: 1px solid var(--g-blau);
    border-radius: var(--g-r);
    background: #ffffff;
    color: var(--g-blau);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
}
.pk-g-knopf:hover { background: var(--g-blau-hell); }
.pk-g-knopf:disabled { opacity: 0.45; cursor: default; background: #ffffff; }
.pk-g-knopf.pk-g-primaer { background: var(--g-blau); color: #ffffff; }
.pk-g-knopf.pk-g-primaer:hover { filter: brightness(0.92); }
.pk-g-knopf.pk-g-still { border-color: var(--g-kante); color: var(--g-text); }
.pk-g-knopf[aria-pressed="true"] { background: var(--g-blau-hell); border-color: var(--g-blau); color: var(--g-blau); }

/* ---------- Kopf ---------- */
.pk-g-kopf {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--g-linie);
}
.pk-g-kopf h2 { font-size: 17px; font-weight: 800; }
.pk-g-seitenwahl { display: inline-flex; border: 1px solid var(--g-blau); border-radius: var(--g-r); overflow: hidden; }
.pk-g-seitenwahl button { border: 0; background: #ffffff; color: var(--g-blau); font-weight: 700; padding: 0 14px; min-height: 36px; cursor: pointer; }
.pk-g-seitenwahl button[aria-pressed="true"] { background: var(--g-blau); color: #ffffff; }
.pk-g-kurz { display: none; }
.pk-g-kopf-rechts { display: flex; gap: 8px; align-items: center; }

/* ---------- Rumpf: Werkzeuge | Karte | Eigenschaften ---------- */
.pk-g-rumpf { display: grid; grid-template-columns: 92px minmax(0, 1fr) 320px; min-height: 0; }
.pk-g-werkzeuge { border-right: 1px solid var(--g-linie); display: flex; flex-direction: column; gap: 2px; padding: 8px 6px; overflow: auto; }
.pk-g-werkzeug {
    border: 0;
    border-radius: var(--g-r);
    background: none;
    display: grid;
    justify-items: center;
    gap: 3px;
    padding: 9px 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--g-text);
    min-height: 56px;
    cursor: pointer;
}
.pk-g-werkzeug svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pk-g-werkzeug:hover, .pk-g-werkzeug[aria-pressed="true"] { background: var(--g-blau-hell); color: var(--g-blau); }

.pk-g-flaeche {
    background: repeating-conic-gradient(#eef2f7 0 25%, #f7f9fc 0 50%) 0 0 / 16px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 36px 28px;
    min-width: 0;
    overflow: auto;
}
.pk-g-karte {
    position: relative;
    width: min(100%, 680px);
    aspect-ratio: 85.6 / 54;
    background: #ffffff;
    border-radius: calc(3.18 / 85.6 * 100%) / calc(3.18 / 54 * 100%);
    box-shadow: 0 0 0 1px #8c959c, 0 4px 14px rgba(19, 33, 58, 0.14);
    touch-action: none;
    user-select: none;
    flex: none;
}
.pk-g-svg, .pk-g-sicher { position: absolute; inset: 0; width: 100%; height: 100%; display: block; border-radius: inherit; }
.pk-g-svg { overflow: hidden; clip-path: inset(0 round calc(3.18 / 85.6 * 100%) / calc(3.18 / 54 * 100%)); }
.pk-g-svg [data-uid] { cursor: move; }
.pk-g-sicher { pointer-events: none; }
.pk-g-sicher-linie { fill: none; stroke: #e8590c; stroke-width: 0.25; stroke-dasharray: 1 0.8; }
.pk-g-auswahl { position: absolute; outline: 1.5px solid var(--g-blau); outline-offset: 1px; pointer-events: none; transform-origin: center; }
.pk-g-griff, .pk-g-drehgriff { position: absolute; pointer-events: auto; touch-action: none; }
.pk-g-griff { width: 14px; height: 14px; right: -9px; bottom: -9px; background: #ffffff; border: 2px solid var(--g-blau); cursor: nwse-resize; }
.pk-g-drehgriff { left: 50%; top: -26px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--g-blau); cursor: grab; }
/* groessere Greifflaeche fuer Finger, ohne die Darstellung zu vergroessern */
.pk-g-griff::after, .pk-g-drehgriff::after { content: ""; position: absolute; inset: -8px; }
.pk-g-linien { position: absolute; inset: 0; pointer-events: none; }
/* Text direkt auf der Karte bearbeiten: deckungsgleich ueber dem Text, durchsichtig */
.pk-g-inline {
    position: absolute;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    outline: 1.5px dashed var(--g-blau);
    outline-offset: 1px;
    resize: none;
    overflow: hidden;
    white-space: pre;
    transform-origin: center;
    z-index: 1;
    caret-color: currentColor;
}
.pk-g-inline:focus-visible { outline: 1.5px dashed var(--g-blau); outline-offset: 1px; }
.pk-g-linie { position: absolute; background: #e8590c; }
.pk-g-senkrecht { top: 0; bottom: 0; width: 1px; }
.pk-g-waagrecht { left: 0; right: 0; height: 1px; }
.pk-g-hinweis { margin: 0; font-size: 12px; color: var(--g-grau); text-align: center; }
.pk-g-meldung { margin: 0; min-height: 1.2em; font-size: 14px; font-weight: 600; color: #b3261e; text-align: center; }

.pk-g-leiste { border-left: 1px solid var(--g-linie); display: flex; flex-direction: column; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.pk-g-tafel { padding: 14px 16px; border-bottom: 1px solid var(--g-linie); display: grid; gap: 10px; align-content: start; }
.pk-g-tafel h3 { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--g-grau); }
.pk-g-feld { display: grid; gap: 4px; font-size: 13px; min-width: 0; }
.pk-g-feld textarea, .pk-g-feld input[type="number"] {
    width: 100%;
    border: 1px solid var(--g-kante);
    border-radius: var(--g-r);
    padding: 6px 8px;
    background: #ffffff;
    min-height: 36px;
    font: inherit;
    color: inherit;
}
.pk-g-feld textarea { resize: vertical; }
/* Hausregel: Auswahlfelder ohne Rahmen */
.pk-g-auswahl-feld { width: 100%; border: 0; border-radius: var(--g-r); background: var(--g-flaeche); min-height: 36px; padding: 6px 8px; font: inherit; color: inherit; }
.pk-g-zeile { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pk-g-zeile.pk-g-zwischen { justify-content: space-between; }
.pk-g-zeile.pk-g-unten { align-items: end; }
.pk-g-zeile.pk-g-unten .pk-g-feld { flex: 1; }
.pk-g-schrift-reihe { display: grid; grid-template-columns: minmax(0, 1fr) 92px; }
.pk-g-masse { display: grid; grid-template-columns: 1fr 1fr; }
.pk-g-zeile .pk-g-knopf { min-height: 32px; padding: 0 10px; font-size: 13px; }
.pk-g-stil-fett { font-weight: 800; }
.pk-g-stil-kursiv { font-style: italic; }
.pk-g-stil-unterstrichen { text-decoration: underline; }
.pk-g-zeile input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--g-blau); }
.pk-g-farben { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pk-g-farbe { width: 28px; height: 28px; border: 1px solid #6b7280; color: transparent; border-radius: var(--g-r); padding: 0; cursor: pointer; }
.pk-g-farbe[aria-pressed="true"] { outline: 2px solid var(--g-blau); outline-offset: 2px; }
.pk-g-farbwahl { width: 36px; height: 30px; border: 1px solid #6b7280; padding: 0; background: none; cursor: pointer; }
.pk-g-farben .pk-g-knopf { min-height: 30px; padding: 0 8px; font-size: 13px; }
.pk-g-leer { font-size: 13px; color: var(--g-grau); margin: 0; }
.pk-g-warnung { color: #9a3412; font-weight: 600; }
.pk-g-warnung:empty { display: none; }
.pk-g-ebenen { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.pk-g-ebenen li { display: flex; gap: 4px; align-items: center; }
.pk-g-ebene-name {
    flex: 1;
    min-width: 0;
    border: 0;
    border-radius: var(--g-r);
    background: var(--g-flaeche);
    text-align: left;
    padding: 6px 8px;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-height: 32px;
    cursor: pointer;
    color: inherit;
}
.pk-g-ebene-name[aria-pressed="true"] { background: var(--g-blau-hell); color: var(--g-blau); font-weight: 700; }
.pk-g-mini { border: 1px solid var(--g-linie); border-radius: var(--g-r); background: #ffffff; width: 30px; height: 32px; padding: 0; font-size: 14px; cursor: pointer; color: inherit; }
.pk-g-symbole { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.pk-g-symbole button { border: 1px solid var(--g-linie); border-radius: var(--g-r); background: #ffffff; aspect-ratio: 1; padding: 7px; cursor: pointer; min-width: 0; }
.pk-g-symbole button:hover { border-color: var(--g-blau); }
.pk-g-symbole svg { width: 100%; height: 100%; stroke: var(--g-text); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Vorlagenwahl ---------- */
.pk-g-vorlagen { position: absolute; inset: 0; background: rgba(19, 33, 58, 0.55); display: grid; place-items: center; padding: 20px; z-index: 2; }
.pk-g-vorlagen-fenster { background: #ffffff; width: min(1000px, 100%); max-height: 100%; overflow: auto; padding: 20px; display: grid; gap: 14px; }
.pk-g-vorlagen-fenster h3 { font-size: 20px; font-weight: 800; }
.pk-g-vorlagen-fenster p { margin: 0; color: var(--g-grau); }
.pk-g-vorlagen-gitter { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.pk-g-vorlage { border: 1px solid var(--g-linie); border-radius: var(--g-r); background: #ffffff; padding: 10px; display: grid; gap: 8px; text-align: left; cursor: pointer; color: inherit; font-size: 14px; }
.pk-g-vorlage:hover { border-color: var(--g-blau); }
.pk-g-mini-karte { display: block; aspect-ratio: 85.6 / 54; border-radius: calc(3.18 / 85.6 * 100%) / calc(3.18 / 54 * 100%); overflow: hidden; box-shadow: 0 0 0 1px #c4cbd1; background: #ffffff; }
.pk-g-mini-karte svg { width: 100%; height: 100%; display: block; }
.pk-g-mini-leer { display: grid; place-items: center; color: var(--g-grau); font-size: 13px; }

/* ---------- Handy: Karte oben, Eigenschaften darunter, Werkzeugleiste unten ---------- */
@media (max-width: 760px) {
    /* eine Kopfzeile: Seitenwahl links, Rueckgaengig/Wiederholen/Fertig rechts; Ueberschrift nur fuer Screenreader */
    .pk-g-kopf { padding: 8px 10px; gap: 6px; flex-wrap: nowrap; }
    .pk-g-kopf h2 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .pk-g-seitenwahl button { padding: 0 9px; font-size: 14px; }
    .pk-g-kopf-rechts { gap: 6px; }
    .pk-g-kopf-rechts .pk-g-knopf { padding: 0 10px; }
    /* eingebettet ist der Gestalter am Handy schmaler als das Fenster: "Vorne"/"Hinten"/"Weiter" statt
       "Vorderseite"/"Rückseite"/"Weiter: Veredelung" (sonst schnitt die Kopfzeile "Rüc" ab); der Name fuer Screenreader
       bleibt der volle */
    .pk-g-kurz { display: inline; }
    .pk-g-voll { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .pk-g-rumpf { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
    .pk-g-flaeche { order: 1; padding: 16px 12px 8px; justify-content: flex-start; overflow: visible; }
    .pk-g-hinweis { font-size: 11px; }
    .pk-g-werkzeuge { order: 3; flex-direction: row; border-right: 0; border-top: 1px solid var(--g-linie); padding: 4px; overflow: visible; }
    .pk-g-werkzeug { flex: 1; min-height: 52px; padding: 6px 2px; font-size: 11px; min-width: 0; }
    .pk-g-leiste { order: 2; border-left: 0; border-top: 1px solid var(--g-linie); }
    .pk-g-vorlagen-gitter { grid-template-columns: 1fr 1fr; gap: 8px; }
    .pk-g-vorlagen-fenster { padding: 14px; }
    .pk-g-vorlagen { padding: 10px; }
    .pk-g-symbole { grid-template-columns: repeat(8, 1fr); }
}
@media (max-width: 380px) {
    .pk-g-symbole { grid-template-columns: repeat(6, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
    .pk-gestalter * { transition: none !important; }
}

/* ---------- Im Werkzeug: Gestaltung auf der Kartenvorschau ---------- */
/* kleine SVG-Schrift: ohne Glyphen-Rundung (sonst ungleiche Buchstabenabstaende in Vorschauen) */
.pk-g-svg text, .pk-g-mini-karte text, .pk-gestaltung text { text-rendering: geometricPrecision; }
.pk-gestaltung { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.pk-gestaltung-aktion { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pk-gestaltung-hinweis { margin: 0; font-size: 0.875rem; color: #8a4b00; text-align: center; }
.pk-gestaltung-hinweis:empty { display: none; }
/* Klassen mit eigener display-Regel: hidden muss gewinnen (Bootstrap-Knopf, Kasten "Keine Vorlage?") */
.pk-datei-knopf[hidden], .pk-gestaltung-aktion[hidden] { display: none !important; }

/* --- Usability-Test 18.11.2026 --- */
/* Hinweiszeile unter der Karte: am Touch-Geraet ohne Doppelklick/Pfeiltasten */
.pk-g-hinweis-touch { display: none; }
@media (pointer: coarse) {
    .pk-g-hinweis-maus { display: none; }
    .pk-g-hinweis-touch { display: inline; }
}
/* bedruckte Kartenseite: Punkt am Seitenknopf (z. B. Vorlage mit Rueckseite) */
.pk-g-seitenwahl button[data-belegt="1"]::after {
    content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
    background: currentColor; margin-left: 6px; vertical-align: middle;
}
/* Symbolsuche */
.pk-g-symbolsuche {
    width: 100%; border: 1px solid var(--g-kante); border-radius: var(--g-r); padding: 6px 8px;
    min-height: 36px; font: inherit; color: inherit; background: #ffffff;
}
.pk-g-symbole button[hidden] { display: none; }
/* Knopf in Linkform (Wechsel zur Druckdatei) */
.pk-g-knopf.pk-g-link {
    border: 0; background: none; padding: 0; min-height: 24px; color: var(--g-blau);
    text-decoration: underline; font-weight: 600; cursor: pointer;
}
/* Hinweis, der nur informiert (Schrift verkleinert) */
.pk-g-warnung.pk-g-info { color: var(--g-grau); font-weight: 400; }
/* Handy quer (UEBERGABE Z. 710, Usability-Test 18.11.: bei 667x375 war die Karte hoeher als das Fenster, Werkzeugleiste und
   "Weiter" ausserhalb): niedrige Querformate nebeneinander wie am Rechner – Werkzeuge links, Karte nach der Fensterhoehe,
   Eigenschaften rechts scrollend */
@media (max-width: 991.98px) and (orientation: landscape) and (max-height: 520px) {
    .pk-g-rumpf { grid-template-columns: 64px minmax(0, 1fr) minmax(180px, 34%); grid-template-rows: minmax(0, 1fr); }
    .pk-g-werkzeuge { order: 0; flex-direction: column; border-top: 0; border-right: 1px solid var(--g-linie); overflow: auto; }
    .pk-g-werkzeug { flex: 0 0 auto; min-height: 46px; }
    .pk-g-flaeche { order: 1; padding: 6px 8px; overflow: auto; justify-content: center; }
    .pk-g-karte { width: min(100%, calc((100dvh - 96px) * 85.6 / 54)); }
    .pk-g-hinweis { display: none; }
    .pk-g-leiste { order: 2; border-top: 0; border-left: 1px solid var(--g-linie); }
}
