/* ==========================================================================
   PSN Media — Accessibility Widget Frontend Styles
   Layout: Gruppen von Feature-Cards im 2-Spalten-Grid, Click-Cycle mit Pill-Bar
   ========================================================================== */

/* --------------------------------------------------------------------------
   Widget Container — sticky via position:fixed (hohe Priorität gegen Themes)
   -------------------------------------------------------------------------- */
#psn-access-widget {
    position: fixed !important;
    z-index: 2147483000;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #1a1a1a;
}

/* --------------------------------------------------------------------------
   Position Desktop (Offsets als CSS-Variablen, gesetzt per inline-Style im PHP)
   -------------------------------------------------------------------------- */
#psn-access-widget.psn-access-right-top    { right: var(--psn-access-x-d, 20px); top:    var(--psn-access-y-d, 20px); }
#psn-access-widget.psn-access-right-center { right: var(--psn-access-x-d, 20px); top: 50%; transform: translateY(-50%); }
#psn-access-widget.psn-access-right-bottom { right: var(--psn-access-x-d, 20px); bottom: var(--psn-access-y-d, 20px); }
#psn-access-widget.psn-access-left-top     { left:  var(--psn-access-x-d, 20px); top:    var(--psn-access-y-d, 20px); }
#psn-access-widget.psn-access-left-center  { left:  var(--psn-access-x-d, 20px); top: 50%; transform: translateY(-50%); }
#psn-access-widget.psn-access-left-bottom  { left:  var(--psn-access-x-d, 20px); bottom: var(--psn-access-y-d, 20px); }

@media (max-width: 768px) {
    #psn-access-widget.psn-access-mobile-right-top    { right: var(--psn-access-x-m, 20px); top:    var(--psn-access-y-m, 20px); left: auto; bottom: auto; transform: none; }
    #psn-access-widget.psn-access-mobile-right-center { right: var(--psn-access-x-m, 20px); top: 50%; left: auto; bottom: auto; transform: translateY(-50%); }
    #psn-access-widget.psn-access-mobile-right-bottom { right: var(--psn-access-x-m, 20px); bottom: var(--psn-access-y-m, 20px); left: auto; top: auto; transform: none; }
    #psn-access-widget.psn-access-mobile-left-top     { left:  var(--psn-access-x-m, 20px); top:    var(--psn-access-y-m, 20px); right: auto; bottom: auto; transform: none; }
    #psn-access-widget.psn-access-mobile-left-center  { left:  var(--psn-access-x-m, 20px); top: 50%; right: auto; bottom: auto; transform: translateY(-50%); }
    #psn-access-widget.psn-access-mobile-left-bottom  { left:  var(--psn-access-x-m, 20px); bottom: var(--psn-access-y-m, 20px); right: auto; top: auto; transform: none; }
}

/* --------------------------------------------------------------------------
   Toggle Button (schwebender Button am Rand)
   -------------------------------------------------------------------------- */
#psn-access-toggle {
    width: 54px;
    height: 54px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    padding: 0;
    position: relative;
    z-index: 2;
}
#psn-access-toggle.psn-access-round  { border-radius: 50%; }
#psn-access-toggle.psn-access-square { border-radius: 0; }

#psn-access-toggle:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    transform: scale(1.06);
}
#psn-access-toggle:focus {
    outline: 3px solid #ffcc00;
    outline-offset: 3px;
}
#psn-access-toggle svg { width: 28px; height: 28px; }

/* Widget komplett verstecken (Header-Button "Auge") — zeigt nur noch den Button */
#psn-access-widget.psn-access-minimized #psn-access-panel { display: none !important; }

/* --------------------------------------------------------------------------
   Panel — absolute zum Widget, öffnet weg vom nächsten Bildschirmrand
   -------------------------------------------------------------------------- */
#psn-access-panel {
    position: absolute;
    width: 560px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 80px);
    overflow: hidden;
    background: #f7f8fb;
    border-radius: 18px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.25);
    z-index: 999998;
    animation: psnAccessSlideIn 0.25s ease forwards;
    display: flex;
    flex-direction: column;

    /* Default: Widget sitzt unten/center → Panel öffnet nach oben */
    bottom: calc(100% + 12px);
    top: auto;
}
#psn-access-panel.psn-access-hidden { display: none; }

/* Horizontale Ausrichtung: rechts am Widget-Rand */
#psn-access-widget.psn-access-right-top    #psn-access-panel,
#psn-access-widget.psn-access-right-center #psn-access-panel,
#psn-access-widget.psn-access-right-bottom #psn-access-panel {
    right: 0;
    left: auto;
}
/* Links */
#psn-access-widget.psn-access-left-top    #psn-access-panel,
#psn-access-widget.psn-access-left-center #psn-access-panel,
#psn-access-widget.psn-access-left-bottom #psn-access-panel {
    left: 0;
    right: auto;
}
/* Widget oben → Panel öffnet nach unten */
#psn-access-widget.psn-access-right-top #psn-access-panel,
#psn-access-widget.psn-access-left-top  #psn-access-panel {
    top: calc(100% + 12px);
    bottom: auto;
}

@keyframes psnAccessSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Scrollbar-Styling (nur für den scrollbaren Body, nicht den Header) */
.psn-access-body::-webkit-scrollbar         { width: 8px; }
.psn-access-body::-webkit-scrollbar-track   { background: transparent; }
.psn-access-body::-webkit-scrollbar-thumb   { background: #c9ced8; border-radius: 4px; }
.psn-access-body::-webkit-scrollbar-thumb:hover { background: #98a0ad; }

/* --------------------------------------------------------------------------
   Header — blauer Balken (bg-color aus Settings) mit Titel + Icon-Toolbar
   -------------------------------------------------------------------------- */
.psn-access-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    color: #fff;
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
    flex-shrink: 0;
}
.psn-access-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.psn-access-header-badge {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #fff;
    color: #2271b1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.psn-access-header-badge svg { width: 20px; height: 20px; }
.psn-access-header-title {
    font-size: 20px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.psn-access-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.psn-access-icon-btn {
    width: 38px;
    height: 38px;
    border: none;
    background: transparent;
    color: #fff;
    cursor: pointer;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    padding: 0;
}
.psn-access-icon-btn:hover  { background: rgba(255, 255, 255, 0.18); }
.psn-access-icon-btn:focus  { outline: 3px solid #ffcc00; outline-offset: 2px; }
.psn-access-header-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.4);
    margin: 0 4px;
}

/* --------------------------------------------------------------------------
   Body — scrollbare Gruppen-Sektion
   -------------------------------------------------------------------------- */
.psn-access-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* --------------------------------------------------------------------------
   Gruppen-Container (weiße Karte mit Überschrift und Card-Grid)
   -------------------------------------------------------------------------- */
.psn-access-group {
    background: #ffffff;
    border-radius: 14px;
    padding: 18px 18px 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.psn-access-group-title {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin: 0 0 12px;
    padding: 0;
}

.psn-access-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
@media (max-width: 480px) {
    .psn-access-cards { grid-template-columns: 1fr; }
}

/* --------------------------------------------------------------------------
   Card — Icon-Kreis links + Label rechts (+ Pill-Bar wenn type=level)
   -------------------------------------------------------------------------- */
.psn-access-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 14px;
    background: #f2f4f8;
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s ease, border-color 0.15s ease;
    font: inherit;
    color: inherit;
    width: 100%;
    min-height: 64px;
}
.psn-access-card:hover { background: #eaedf2; }
.psn-access-card:focus {
    outline: none;
    border-color: #2271b1;
}

/* Icon-Kreis */
.psn-access-card-icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fff;
    color: #334;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Body (Label + Pill-Bar) */
.psn-access-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.psn-access-card-label {
    font-size: 15px;
    line-height: 1.2;
    color: #1a1a1a;
    font-weight: 500;
    word-break: break-word;
}

/* Pill-Bar (Fortschritts-Indikator bei Level-Features) */
.psn-access-pills {
    display: flex;
    gap: 4px;
    width: 100%;
}
.psn-access-pill {
    flex: 1;
    height: 6px;
    background: #d5d9e0;
    border-radius: 3px;
    transition: background 0.15s ease;
}

/* Aktive Card — blauer Rahmen, blauer Icon, blaue Pills */
.psn-access-card.is-active {
    background: #eaf1fb;
    border-color: #2563eb;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.15);
}
.psn-access-card.is-active .psn-access-card-icon {
    background: #fff;
    color: #2271b1;
}
.psn-access-card.is-active .psn-access-card-label {
    color: #1a1a1a;
    font-weight: 600;
}
.psn-access-card.is-active .psn-access-pill.is-on {
    background: #2563eb;
}

/* Link-Card (Barrierefreiheit/Einfache Sprache etc.) */
.psn-access-card.psn-access-card-link {
    text-decoration: none;
    color: inherit;
}

/* Reset-Flash — gruener Puls, wenn Feature auf Original zurueckgesetzt wird */
.psn-access-card.is-reset {
    animation: psnAccessResetFlash 0.9s ease;
    border-color: #2ea84a !important;
    background: #e5f7ea !important;
}
.psn-access-card.is-reset .psn-access-card-icon {
    background: #2ea84a !important;
    color: #fff !important;
}
.psn-access-card.is-reset .psn-access-card-label {
    color: #1e7a35 !important;
    font-weight: 600 !important;
}
@keyframes psnAccessResetFlash {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.03); }
    100% { transform: scale(1); }
}

/* --------------------------------------------------------------------------
   Font Size Levels — wirken über JS, das per inline style auf Text-Elementen
   skaliert. Hier nur Fallback für rem-basierte Themes:
   -------------------------------------------------------------------------- */
html.psn-access-font-1 { font-size: 120%; }
html.psn-access-font-2 { font-size: 140%; }
html.psn-access-font-3 { font-size: 160%; }
html.psn-access-font-4 { font-size: 180%; }
html.psn-access-font-5 { font-size: 200%; }

/* --------------------------------------------------------------------------
   Line Height Levels
   -------------------------------------------------------------------------- */
body.psn-access-lh-1 *:not(#psn-access-widget):not(#psn-access-widget *) { line-height: 1.8 !important; }
body.psn-access-lh-2 *:not(#psn-access-widget):not(#psn-access-widget *) { line-height: 2.2 !important; }
body.psn-access-lh-3 *:not(#psn-access-widget):not(#psn-access-widget *) { line-height: 2.6 !important; }
body.psn-access-lh-4 *:not(#psn-access-widget):not(#psn-access-widget *) { line-height: 3.0 !important; }
body.psn-access-lh-5 *:not(#psn-access-widget):not(#psn-access-widget *) { line-height: 3.5 !important; }

/* --------------------------------------------------------------------------
   Text Align
   -------------------------------------------------------------------------- */
body.psn-access-align-left   p, body.psn-access-align-left   li, body.psn-access-align-left   h1,
body.psn-access-align-left   h2, body.psn-access-align-left  h3, body.psn-access-align-left   h4,
body.psn-access-align-left   h5, body.psn-access-align-left  h6, body.psn-access-align-left   td,
body.psn-access-align-left   th { text-align: left   !important; }

body.psn-access-align-center p, body.psn-access-align-center li, body.psn-access-align-center h1,
body.psn-access-align-center h2, body.psn-access-align-center h3, body.psn-access-align-center h4,
body.psn-access-align-center h5, body.psn-access-align-center h6, body.psn-access-align-center td,
body.psn-access-align-center th { text-align: center !important; }

body.psn-access-align-right  p, body.psn-access-align-right  li, body.psn-access-align-right  h1,
body.psn-access-align-right  h2, body.psn-access-align-right h3, body.psn-access-align-right  h4,
body.psn-access-align-right  h5, body.psn-access-align-right h6, body.psn-access-align-right  td,
body.psn-access-align-right  th { text-align: right  !important; }

/* --------------------------------------------------------------------------
   Lesbare Schriftart — Level 1: Arial (sans-serif), Level 2: Times (serif)
   -------------------------------------------------------------------------- */
body.psn-access-font-arial *:not(#psn-access-widget):not(#psn-access-widget *) {
    font-family: Arial, Helvetica, "Liberation Sans", sans-serif !important;
}
body.psn-access-font-times *:not(#psn-access-widget):not(#psn-access-widget *) {
    font-family: "Times New Roman", Times, "Liberation Serif", serif !important;
}

/* --------------------------------------------------------------------------
   Bilder ausblenden
   -------------------------------------------------------------------------- */
body.psn-access-hide-images img:not(#psn-access-widget img),
body.psn-access-hide-images video:not(#psn-access-widget video),
body.psn-access-hide-images iframe:not(#psn-access-widget iframe) {
    visibility: hidden !important;
}

/* --------------------------------------------------------------------------
   Animationen anhalten
   -------------------------------------------------------------------------- */
body.psn-access-stop-animations *,
body.psn-access-stop-animations *::before,
body.psn-access-stop-animations *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
}

/* --------------------------------------------------------------------------
   Links hervorheben
   -------------------------------------------------------------------------- */
body.psn-access-highlight-links a:not(#psn-access-widget a) {
    text-decoration: underline !important;
    background: #fff59d !important;
    color: #1a1a1a !important;
    padding: 0 2px !important;
    box-shadow: 0 0 0 2px #fbc02d !important;
}

/* --------------------------------------------------------------------------
   Fokusumriss — markiert permanent alle interaktiven Elemente, damit der
   Effekt sofort sichtbar ist (nicht erst beim Tabben).
   -------------------------------------------------------------------------- */
body.psn-access-focus-outline a:not(#psn-access-widget a),
body.psn-access-focus-outline button:not(#psn-access-widget button),
body.psn-access-focus-outline input:not(#psn-access-widget input),
body.psn-access-focus-outline textarea:not(#psn-access-widget textarea),
body.psn-access-focus-outline select:not(#psn-access-widget select),
body.psn-access-focus-outline [tabindex]:not([tabindex="-1"]):not(#psn-access-widget [tabindex]) {
    outline: 2px dashed #ff9800 !important;
    outline-offset: 2px !important;
}
body.psn-access-focus-outline *:focus:not(#psn-access-widget *) {
    outline: 4px solid #ff9800 !important;
    outline-offset: 3px !important;
}

/* --------------------------------------------------------------------------
   Farbfilter (Sepia, Invertiert, Graustufen)
   Widget + Overlays werden per JS ans <html> verschoben (nicht body-Kinder),
   damit body-Filter sie nicht beeinflussen. Deshalb reicht hier ein einfacher
   Filter auf <body>.
   -------------------------------------------------------------------------- */
body.psn-access-color-sepia  { filter: sepia(0.8) !important; }
body.psn-access-color-invert { filter: invert(0.92) hue-rotate(180deg) !important; }
body.psn-access-grayscale    { filter: grayscale(1) !important; }

/* --------------------------------------------------------------------------
   Kontrast — Schwarz/Weiß-Modi
   -------------------------------------------------------------------------- */
/* Schwarz auf Weiß */
body.psn-access-contrast-bw *:not(#psn-access-widget):not(#psn-access-widget *) {
    background-color: #ffffff !important;
    color: #000000 !important;
    border-color: #000000 !important;
}
body.psn-access-contrast-bw a:not(#psn-access-widget a) { color: #0000ee !important; }

/* Weiß auf Schwarz */
body.psn-access-contrast-wb *:not(#psn-access-widget):not(#psn-access-widget *) {
    background-color: #000000 !important;
    color: #ffffff !important;
    border-color: #ffffff !important;
}
body.psn-access-contrast-wb a:not(#psn-access-widget a) { color: #ffff00 !important; }

/* ==========================================================================
   Reading Mask (unverändert)
   ========================================================================== */
#psn-access-reading-mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 999995;
}
.psn-access-mask-top, .psn-access-mask-bottom {
    position: absolute;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.6);
}
.psn-access-mask-top    { top: 0; }
.psn-access-mask-bottom { bottom: 0; }

/* ==========================================================================
   Structure Overlay
   ========================================================================== */
#psn-access-structure-backdrop {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999996;
}
#psn-access-structure-overlay {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 480px; max-width: 90vw;
    max-height: 80vh;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
    z-index: 999997;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.psn-access-structure-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e5e5;
}
.psn-access-structure-title { font-size: 18px; font-weight: 700; }
.psn-access-structure-close {
    width: 34px; height: 34px; border: none; background: #f0f0f0;
    border-radius: 50%; cursor: pointer; font-size: 20px; color: #555;
}
.psn-access-structure-close:hover { background: #ddd; }
.psn-access-structure-list {
    list-style: none; margin: 0; padding: 8px 0;
    overflow-y: auto;
}
.psn-access-structure-item {
    padding: 10px 20px; cursor: pointer;
    transition: background 0.15s ease;
    font-size: 15px;
}
.psn-access-structure-item:hover { background: #f3f6fb; }
.psn-access-structure-item[data-level="2"] { padding-left: 34px; font-size: 14px; }
.psn-access-structure-item[data-level="3"] { padding-left: 48px; font-size: 13px; color: #444; }
.psn-access-structure-item[data-level="4"] { padding-left: 62px; font-size: 13px; color: #555; }
.psn-access-structure-item[data-level="5"],
.psn-access-structure-item[data-level="6"] { padding-left: 76px; font-size: 12px; color: #666; }

/* ==========================================================================
   Vorlesen (speechSynthesis) — schwebendes Bedien-Panel
   ========================================================================== */
#psn-access-speech-panel {
    position: fixed;
    left: 50%; bottom: 24px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: #1a1a1a;
    color: #fff;
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    z-index: 2147483000;
    font-size: 15px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
#psn-access-speech-panel button {
    background: #fff; color: #1a1a1a; border: none;
    padding: 6px 14px; border-radius: 999px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    transition: background 0.15s ease;
}
#psn-access-speech-panel button:hover { background: #e8e8e8; }
#psn-access-speech-panel button:focus { outline: 3px solid #ffcc00; outline-offset: 2px; }

@media (max-width: 480px) {
    #psn-access-speech-panel {
        left: 10px; right: 10px; transform: none;
        border-radius: 12px; flex-wrap: wrap; justify-content: center;
    }
}
