/* ==========================================================================
   portal_kopf.css · Der Kopf der Portal Startseite, fuer JEDE Seite des Portals
   (Paket 4, Sammelauftrag 12.11.2026)

   WAS HIER STEHT
   1. Der Abstand fuer die Statusleiste des Geraets (Uhr, Akku, Notch). Er gilt
      fuer ALLE Seiten, auch fuer die ohne sichtbaren Kopf (data-portal-kopf
      "keiner"). Ohne viewport-fit=cover meldet der Browser env() als 0; der
      Baustein (src/kundenportal/portal_rahmen.php) und src/header.php setzen es.
   2. Der Kopf selbst: Logo Leiste, Titelzeile, Reiterleiste, Zaehler. Vorher
      gab es zwei verschiedene Koepfe (Dashboard: Titelzeile ueber den Reitern,
      Unterseiten: Sitzungsleiste darunter) und ein halbes Dutzend Kopien.
   3. Die Hoehe des Kopfes als Variable, an der die feste Leiste links
      (Auftragsseite, Mailseite) und der Chat rechts ihre Oberkante festmachen.

   FARBEN
   Der Kopf liest die Farben der Seite (--text, --card, --border ...) und faellt
   auf die Werte des dunklen Portalthemas zurueck. Die Seite des KI Sekretaers
   (agent_tabs) kennt site.css nicht und hat eigene Namen (--karte, --rand,
   --text-leise): die Ketten unten greifen auch dort, hell wie dunkel.

   TEST DES ABSTANDS
   Playwright kann env() nicht setzen. --portal-test-oben ersetzt es im Test
   (":root{--portal-test-oben:47px}"), so liegt der Abstand nachweisbar an
   jeder Seite an.
   ========================================================================== */

:root {
    /* Abstand oben fuer Uhr und Akku; im Test ersatzweise --portal-test-oben. --portal-oben-ersatz setzt
       js/sichere_flaeche.js nur in der Web App von iOS, wenn iOS den Wert faelschlich als 0 meldet (P-003 A10) */
    --portal-oben: max(env(safe-area-inset-top, 0px), var(--portal-test-oben, 0px), var(--portal-oben-ersatz, 0px));
    /* Von portal_kopf.js gesetzt: Hoehe des Kopfes und der noch sichtbare Teil
       (scrollt der Kopf weg, schrumpft er auf 0) */
    --portal-kopf-hoehe: 0px;
    --portal-oben-sichtbar: 0px;
    /* Oberkante fuer alles Feste: unter dem sichtbaren Kopf, nie unter der Uhr */
    --portal-unter-kopf: max(var(--portal-oben-sichtbar), var(--portal-oben));
}

/* Seiten ohne sichtbaren Kopf: der Abstand sitzt am Rumpf. */
body[data-portal-kopf="keiner"] {
    box-sizing: border-box;
    padding-top: var(--portal-oben);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}

/* Der Kopf der Webseite (header.php ohne Adminrahmen: Kundenportal, Anmeldung, 404) klebt beim Scrollen oben (app.js setzt
   is-sticky); er haelt dabei den Abstand zur Uhr, sonst rutschte er nach dem ersten Scrollen wieder darunter. */
body[data-portal-kopf="keiner"] .site-header.is-sticky { top: var(--portal-oben); }

/* Der Kopf ----------------------------------------------------------------- */
.portal-kopf {
    /* Ketten: Namen von site.css, dann die des KI Sekretaers (--karte, --rand), dann die des Webphone Fensters (--tel-*), dann das dunkle Portalthema */
    --pk-text: var(--text, var(--tel-text, #E3E5EA));
    --pk-text2: var(--text-secondary, var(--text-leise, var(--tel-text, #B4BBC7)));
    --pk-muted: var(--muted, var(--text-leise, var(--tel-grau, #9AA3B2)));
    --pk-card: var(--card, var(--karte, var(--tel-karte, #242830)));
    --pk-card2: var(--card-elevated, var(--karte, var(--tel-karte, #2C313B)));
    --pk-border: var(--border, var(--rand, var(--tel-rand, rgba(255, 255, 255, .12))));
    --pk-border-strong: var(--border-strong, var(--rand-stark, var(--tel-grau, rgba(255, 255, 255, .28))));
    --pk-accent: var(--accent, var(--tel-blau, #2563EB));
    --pk-accent-rgb: var(--accent-rgb, 37, 99, 235);
    --pk-focus: var(--focus-ring, 0 0 0 3px rgba(96, 165, 250, .65));
    font-family: var(--font-sans, Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    padding: var(--portal-oben) max(clamp(16px, 1.2vw, 40px), env(safe-area-inset-right, 0px)) 0
        max(clamp(16px, 1.2vw, 40px), env(safe-area-inset-left, 0px));
    color: var(--pk-text);
    /* Bewusst OHNE z-index (kein eigener Stapelkontext): das Menue am Handy (z-index 60) liegt so ueber dem Inhalt darunter,
       und Schubladen der Seite (Auftragsseite, z-index 1002 im Rahmen .wrap) liegen ueber dem Kopf statt darunter. */
}
.portal-kopf > * { min-width: 0; }

.portal-kopf .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Zum Inhalt springen: nur bei Tastaturfokus sichtbar */
.portal-sprung {
    position: absolute;
    left: 8px;
    top: -60px;
    z-index: 200;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--pk-card, #242830);
    color: var(--text, #E3E5EA);
    border: 2px solid var(--accent, #2563EB);
    text-decoration: none;
}
.portal-sprung:focus { top: calc(var(--portal-oben) + 8px); }

/* Logo Leiste mit der Marke "Adminbereich" */
.portal-kopf-logo {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 0 6px;
}
.portal-kopf-logolink {
    display: inline-flex;
    align-items: center;
    border-radius: 10px;
    text-decoration: none;
    color: var(--pk-text);
}
.portal-kopf-logolink:focus-visible { outline: 2px solid var(--pk-accent); outline-offset: 3px; }
.portal-kopf-logolink img {
    max-height: 44px;
    max-width: 120px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 10px;
}
.site-adminmarke {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 2px 12px;
    border: 1px solid var(--pk-border-strong);
    border-radius: 999px;
    color: var(--pk-text);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
}

/* Titelzeile: Titel, Version, Sitzungszaehler, Profil, Logout */
.portal-kopf-titelzeile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    margin: 4px 0 8px;
}
.portal-kopf-titelblock { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.portal-kopf-titel {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: .03em;
    line-height: 1.2;
    color: var(--pk-text);
    overflow-wrap: anywhere;
}
.portal-kopf-version { font-size: 11px; color: var(--pk-muted); font-weight: 400; opacity: .9; }
.portal-kopf-zeit { display: flex; align-items: center; gap: 12px; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
.kp-session-timer {
    font-size: 12px;
    color: var(--pk-muted, var(--muted, #9AA3B2));
    font-variant-numeric: tabular-nums;
}
.kp-session-timer a { color: var(--pk-text, inherit); }
.portal-kopf-konto { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.portal-kopf-konto form { margin: 0; }
.kp-logout-form { margin: 0; }
/* Das Kundenportal (dashboard.php) nutzt dieselbe Abmeldung mit dem Knopf rr-btn */
@media (max-width: 760px) { .kp-logout-form .rr-btn { min-height: 44px; } }
.kp-profil-verweis {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid var(--pk-border);
    border-radius: 999px;
    color: var(--pk-text2);
    font-size: 13.5px;
    text-decoration: none;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kp-profil-verweis:hover { color: var(--pk-text); border-color: var(--pk-border-strong); }
.kp-profil-verweis:focus-visible { outline: none; box-shadow: var(--pk-focus); }
.portal-abmelden {
    min-height: 44px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid var(--pk-border-strong);
    background: var(--pk-card);
    color: var(--pk-text);
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
}
.portal-abmelden:hover { border-color: var(--pk-accent); }
.portal-abmelden:focus-visible { outline: none; box-shadow: var(--pk-focus); }

/* Knopf Menue: nur am Handy */
.portal-menue-knopf {
    display: none;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    min-width: 44px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--pk-border-strong);
    background: var(--pk-card);
    color: var(--pk-text);
    font: inherit;
    font-size: 13.5px;
    cursor: pointer;
}
.portal-menue-knopf:focus-visible { outline: none; box-shadow: var(--pk-focus); }

/* Die Reiterleiste (Markup: adminnav_ausgeben in src/kundenportal/_adminnav.php).
   Drei Gruppen statt elf Knoepfe in einer Reihe; der Abstand ist die einzige
   Trennung. Rot nur bei Handlungsbedarf, die Zahl steht immer daneben. */
.kp-adminnav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 22px;
    margin: 8px 0 12px;
}
.kp-adminnav-gruppe { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.kp-adminnav-knopf {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 6px 12px;
    border: 1px solid var(--pk-border);
    border-radius: 999px;
    background: var(--pk-card2);
    color: var(--pk-text2);
    font-size: 13px;
    line-height: 1.2;
    white-space: nowrap;
    text-decoration: none;
    transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.kp-adminnav-knopf:hover { border-color: var(--pk-border-strong); color: var(--pk-text); background: var(--pk-card); }
.kp-adminnav-knopf:focus-visible { outline: none; box-shadow: var(--pk-focus); border-color: var(--pk-accent); }
.kp-adminnav-knopf.is-aktiv {
    background: rgba(var(--pk-accent-rgb), .16);
    border-color: var(--pk-accent);
    color: var(--pk-text);
    font-weight: 600;
}
.kp-nav-symbol { flex: 0 0 auto; width: 16px; height: 16px; }
.kp-adminnav-zahl {
    display: inline-block;
    min-width: 18px;
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(127, 127, 127, .22);
    color: var(--pk-text);
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: center;
}
.kp-adminnav-zahl--dringend { background: rgba(220, 38, 38, .22); color: #FCA5A5; }

/* Handy: schmal. Das Logo faellt weg (es kostete rund 90 px vor dem ersten
   Auftrag), die Titelzeile ist EINE Zeile von 48 px, Profil und Logout liegen
   hinter dem Knopf Menue, die Reiter scrollen waagerecht. */
@media (max-width: 767.98px) {
    .portal-kopf-logo { display: none; }
    .portal-kopf-titelzeile { margin: 0 0 4px; position: relative; flex-wrap: nowrap; }
    .portal-kopf-titel { font-size: 18px; }
    .portal-kopf-version { display: none; }
    .portal-menue-knopf { display: inline-flex; }
    .portal-kopf-konto {
        display: none;
        position: absolute;
        right: 0;
        top: 100%;
        z-index: 60;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        min-width: 220px;
        max-width: calc(100vw - 32px);
        padding: 12px;
        border: 1px solid var(--pk-border-strong);
        border-radius: 12px;
        background: var(--pk-card);
        box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
    }
    .portal-kopf-konto.is-offen { display: flex; }
    .portal-kopf-zeit { flex-wrap: nowrap; gap: 8px; }
    .kp-session-timer { font-size: 11px; white-space: nowrap; }
    .kp-adminnav {
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 6px 14px;
        padding-bottom: 6px;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    .kp-adminnav-gruppe { flex-wrap: nowrap; flex: 0 0 auto; }
    .kp-adminnav-knopf { scroll-snap-align: start; flex: 0 0 auto; min-height: 44px; }
    /* Die Statusleiste braucht am Handy weniger Platz: engere Ampeln, kleinere Schrift (der Grund steht weiter im Tooltip) */
    .portal-kopf .kp-statusleiste-liste { gap: 4px; }
    .portal-kopf .kp-ampel { padding: 3px 8px; font-size: 12px; gap: 5px; }
    .portal-kopf .kp-statusleiste { margin-bottom: 6px; }
}

/* Schmale Fassung (Webphone Fenster, Assistent, Anmeldung): nur die eine Zeile */
.portal-kopf[data-portal-kopf="schmal"] .portal-kopf-titelzeile { margin: 0; padding: 4px 0; }
.portal-kopf[data-portal-kopf="schmal"] .portal-kopf-titel { font-size: 18px; }
.portal-kopf[data-portal-kopf="schmal"] .portal-kopf-version { display: none; }
.portal-kopf-zurueck {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 10px 0 0;
    color: var(--pk-text2);
    text-decoration: none;
    font-size: 14px;
    white-space: nowrap;
}
.portal-kopf-zurueck:hover { color: var(--pk-text); }
.portal-kopf-zurueck:focus-visible { outline: none; box-shadow: var(--pk-focus); border-radius: 8px; }

@media print {
    .portal-kopf, .portal-sprung { display: none !important; }
    body[data-portal-kopf="keiner"] { padding-top: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .kp-adminnav-knopf { transition: none; }
}
