/* Wissensgraph-Tab (Admin-UI): Canvas-Bühne, Werkzeugleiste, Detail-Panel.
   Knoten-Farben als Tokens - Pakete in Primärgrün, Mitarbeiter Maigrün (CI),
   Abteilungen Orange (CI), Kanten im neutralen Grau-Blau. */
#view-wissensgraph {
    --wg-paket: var(--primary-green);
    --wg-sub: #4a90a4;
    --wg-ma: #7fa022;
    --wg-abt: #d99425;
    --wg-artikel: #9bb0a6;
    --wg-kante: #607d8b;
}

/* Der Graph darf die volle Seite nutzen - das 1100px-Korsett von main
   gilt nur, solange NICHT der Wissensgraph aktiv ist. */
main:has(#view-wissensgraph:not(.hidden)) {
    max-width: none;
}

.wg-leiste {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}
.wg-leiste input[type="search"] {
    width: 240px;
    padding: 7px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--card-bg);
    color: var(--text-dark);
    font: inherit;
    font-size: 13px;
}
.wg-leiste input[type="search"]:focus {
    outline: 2px solid var(--primary-green);
    outline-offset: 1px;
}
/* Auf Desktop lösen sich die Chips aus dem Wrapper und fließen direkt in der
   flex-wrap-Leiste; die Media-Query macht daraus mobil eine Scroll-Reihe. */
.wg-chip-reihe { display: contents; }
.wg-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 11px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    background: var(--card-bg);
    color: var(--text-dark);
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
}
.wg-chip:focus-visible { outline: 2px solid var(--primary-green); outline-offset: 1px; }
.wg-chip[aria-pressed="false"] { opacity: .38; }
.wg-chip .wg-punkt { width: 9px; height: 9px; }
.wg-chip .wg-anzahl { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.wg-stat {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.wg-punkt {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.wg-buehne {
    position: relative;
    height: calc(100vh - 235px);
    min-height: 500px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
    overflow: hidden;
}
#wg-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    /* Ohne dies fängt der Browser Touch-Gesten (Scroll/Pinch der Seite) ab,
       bevor unsere Pointer-Handler den Graphen ziehen/zoomen können. */
    touch-action: none;
}
#wg-canvas.wg-greift { cursor: grabbing; }

/* ---- Zoom-Knöpfe (Touch ohne Mausrad, auch am Desktop nützlich) ---- */
.wg-zoom {
    position: absolute;
    right: 12px;
    bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 4;
}
.wg-zoom button {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--card-bg) 92%, transparent);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    color: var(--text-dark);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-2);
    -webkit-user-select: none;
    user-select: none;
}
.wg-zoom button:hover { background: var(--primary-5); border-color: var(--primary-green); }
.wg-zoom button:active { transform: translateY(1px); }
.wg-zoom button:focus-visible { outline: 2px solid var(--primary-green); outline-offset: 1px; }

.wg-hinweis {
    position: absolute;
    left: 12px;
    bottom: 10px;
    max-width: 360px;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--card-bg) 85%, transparent);
    font-size: 11.5px;
    color: var(--text-muted);
    pointer-events: none;
}

/* ---- Detail-Panel (rechts über der Bühne, wie in Obsidian) ---- */
.wg-panel {
    position: absolute;
    right: 12px;
    top: 12px;
    width: min(420px, calc(100% - 24px));
    max-height: calc(100% - 24px);
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    overflow: hidden;
}
.wg-panel[hidden] { display: none; }
.wg-p-kopf {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 13px 10px;
    border-bottom: 1px solid var(--border-color);
}
.wg-p-kopf .wg-punkt { width: 12px; height: 12px; margin-top: 4px; }
.wg-p-kopf h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    text-wrap: balance;
}
.wg-p-typ {
    margin: 3px 0 0;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.wg-p-kopf button {
    margin-left: auto;
    flex: none;
    border: 0;
    background: none;
    color: var(--text-muted);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 5px;
    border-radius: var(--radius-sm);
}
.wg-p-kopf button:focus-visible { outline: 2px solid var(--primary-green); }
.wg-p-meta {
    display: flex;
    gap: 16px;
    padding: 9px 13px;
    border-bottom: 1px solid var(--border-color);
    font-size: 11.5px;
    color: var(--text-muted);
}
.wg-p-meta b {
    display: block;
    font-size: 14px;
    color: var(--text-dark);
    font-variant-numeric: tabular-nums;
}
.wg-p-koerper { overflow-y: auto; display: flex; flex-direction: column; }

/* ---- Lesbarer Inhalt des gewählten Knotens ---- */
.wg-p-inhalt { padding: 10px 14px; font-size: 12.5px; line-height: 1.5; }
.wg-p-inhalt:empty { display: none; }
.wg-p-inhalt:not(:empty) { border-bottom: 1px solid var(--border-color); }
.wg-p-inhalt h1, .wg-p-inhalt h2, .wg-p-inhalt h3 {
    font-size: 13px;
    margin: 10px 0 4px;
}
.wg-p-inhalt p { margin: 6px 0; }
.wg-p-inhalt ul, .wg-p-inhalt ol { margin: 6px 0; padding-left: 18px; }
.wg-p-inhalt table { max-width: 100%; overflow-x: auto; display: block; }
.wg-p-inhalt img { max-width: 100%; height: auto; border-radius: var(--radius-md); }
.wg-i-meta { color: var(--text-muted); font-size: 11.5px; }
.wg-i-quelle a { color: var(--primary-green); font-size: 12px; }
.wg-i-text { max-height: 340px; overflow-y: auto; padding-right: 4px; }
.wg-i-sub { margin: 5px 0; }
.wg-i-sub summary { cursor: pointer; font-weight: 600; font-size: 12.5px; }
.wg-i-sub ul { margin: 4px 0 8px; }
.wg-i-bild {
    width: 76px;
    height: 76px;
    object-fit: cover;
    border-radius: 50%;
    float: right;
    margin: 0 0 8px 10px;
}
.wg-i-kontakt { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.wg-i-kontakt dt { color: var(--text-muted); font-size: 11.5px; }
.wg-i-kontakt dd { margin: 0; }
.wg-i-kontakt a { color: var(--primary-green); }

.wg-p-liste { padding: 6px 6px 9px; }
.wg-gr {
    margin: 8px 8px 3px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.wg-eintrag {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 6px 9px;
    border: 0;
    border-radius: var(--radius-md);
    background: none;
    color: var(--text-dark);
    font: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
}
.wg-eintrag:hover { background: var(--primary-5); }
.wg-eintrag:focus-visible { outline: 2px solid var(--primary-green); outline-offset: -2px; }
.wg-sub { display: block; font-size: 11px; color: var(--text-muted); }

/* ---- Entwurfs-Kasten (ausstehende Zuordnungen), kollabierbar ---- */
.wg-entwuerfe {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 5;
    width: min(320px, calc(100% - 24px));
    background: var(--card-bg, #fff);
    border: 2px solid var(--lk-orange, #E9A840);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
    font-size: 13px;
    overflow: hidden;
}
.wg-entw-kopf {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    cursor: pointer;
    font-weight: 700;
    color: #B26A00;
    list-style: none;
}
.wg-entw-kopf::-webkit-details-marker { display: none; }
.wg-entw-kopf::before {
    content: "▸";
    font-size: 11px;
    transition: transform .15s;
}
.wg-entwuerfe[open] .wg-entw-kopf::before { transform: rotate(90deg); }
.wg-entw-titel { flex: 1; min-width: 0; }
.wg-entw-zahl {
    flex: none;
    background: var(--lk-orange, #E9A840);
    color: #fff;
    font-size: 11px;
    padding: 1px 8px;
    border-radius: 999px;
}
.wg-entwuerfe > *:not(summary) { padding-left: 12px; padding-right: 12px; }
.wg-entw-info { color: var(--text-muted, #666); margin-bottom: 8px; line-height: 1.35; }
#wg-entw-liste { max-height: 46vh; overflow: auto; padding-bottom: 10px; }
.wg-entw-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    padding: 3px 0;
    cursor: pointer;
    color: var(--text-dark, #111);
    font-size: 13px;
}
.wg-entw-item:hover { color: var(--primary-green); }
.wg-entw-punkt { color: var(--lk-orange, #E9A840); }
.wg-entw-neu { color: #B26A00; font-size: 11px; }

/* Zeile aus Paket-Titel (wählt Knoten) + Übernehmen-Knopf (veröffentlicht). */
.wg-entw-row { display: flex; align-items: center; gap: 6px; }
.wg-entw-row .wg-entw-item { width: auto; flex: 1; min-width: 0; }
.wg-entw-ok {
    flex: none;
    border: 1px solid var(--primary-green, #007E46);
    background: none;
    color: var(--primary-green, #007E46);
    border-radius: 5px;
    padding: 2px 8px;
    font-size: 12px;
    cursor: pointer;
}
.wg-entw-ok:hover { background: var(--primary-green, #007E46); color: #fff; }
.wg-entw-ok:disabled { opacity: .6; cursor: default; }
.wg-entw-aktion { margin-bottom: 8px; }
.wg-entw-alle {
    width: 100%;
    border: 0;
    background: var(--primary-green, #007E46);
    color: #fff;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.wg-entw-alle:hover { filter: brightness(1.08); }
.wg-entw-alle:disabled { opacity: .6; cursor: default; }

@media (max-width: 760px) {
    /* Zugeklappt sitzt der Kasten als schmaler Balken oben, offen deckelt er
       höchstens die obere Bühnenhälfte ab (Liste scrollt). */
    .wg-entwuerfe { right: 12px; width: auto; }
    .wg-entwuerfe[open] { max-height: 60%; display: flex; flex-direction: column; }
    #wg-entw-liste { max-height: none; }
    /* Suche volle Breite in eigener Zeile, Typ-Chips als eine horizontal
       scrollbare Reihe darunter - statt 5 umbrechender Chips (fraßen die
       halbe Bühne). */
    .wg-leiste {
        flex-wrap: wrap;
        gap: var(--space-2) 8px;
        margin-bottom: var(--space-2);
    }
    .wg-leiste input[type="search"] {
        width: 100%;
        flex: 1 1 100%;
        order: -1;
    }
    .wg-chip-reihe {
        display: flex;
        gap: 8px;
        flex: 1 1 100%;
        overflow-x: auto;
        scrollbar-width: none;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
    }
    .wg-chip-reihe::-webkit-scrollbar { display: none; }
    .wg-chip { flex: 0 0 auto; }
    .wg-stat { flex: 1 1 100%; margin-left: 0; }
    /* Bühne nutzt fast den ganzen Rest des Viewports; feste 100vh-Rechnung
       statt der Desktop-Formel, die die (jetzt schlanke) Leiste falsch schätzt. */
    .wg-buehne { height: calc(100vh - 190px); min-height: 340px; }
    /* Zoom-Knöpfe nach oben, damit das unten andockende Panel sie nicht verdeckt. */
    .wg-zoom { top: 12px; bottom: auto; }
    .wg-panel { left: 10px; right: 10px; top: auto; bottom: 10px; width: auto; max-height: 55%; }
    .wg-hinweis { display: none; }
}
