/* =========================================================================
 * SchulBuchManager — Schul-Admin-Layout
 * Sidebar links (sa- = schul-admin), Main-Area rechts.
 * Etwas hellere Farbgebung als das Operator-Portal, damit sich die
 * beiden Bereiche visuell unterscheiden.
 * ========================================================================= */

body.sa-body {
    min-height: 100vh;
    margin: 0;
    background: var(--sbm-gray-50);
}

/* ----- Sidebar -----
 * Layout: `position: fixed` links, Main-Area hat Left-Padding in Sidebar-
 * Breite. Bei Seitenwechsel bleibt die Sidebar visuell bombenfest stehen
 * (keine Grid-Rekomposition), was das bisherige „Flackern" beseitigt.
 * Der innere .sa-nav ist die einzige Scroll-Achse.
 */
.sa-sidebar {
    background: var(--sbm-primary);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 16px 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 224px;
    z-index: 100;
}

.sa-brand {
    padding: 0 20px 14px;
    margin-bottom: 6px;
}
.sa-brand img { width: 100%; max-width: 180px; height: auto; }

.sa-school {
    padding: 10px 20px 14px;
    margin: 0 12px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.sa-school-code {
    display: inline-block;
    padding: 1px 8px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--sbm-secondary-dark);
    background: rgba(107, 199, 209, 0.12);
    border: 1px solid rgba(107, 199, 209, 0.3);
    border-radius: 999px;
    margin-bottom: 6px;
    font-family: var(--sbm-font-mono);
}
.sa-school-name {
    color: #fff;
    font-weight: 500;
    font-size: 14px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sa-nav {
    flex: 1;
    min-height: 0;            /* wichtig in Flex-Context, damit overflow greift */
    overflow-y: auto;
    padding: 0 8px 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.18) transparent;
}
.sa-nav::-webkit-scrollbar { width: 6px; }
.sa-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 3px; }
.sa-nav::-webkit-scrollbar-track { background: transparent; }

.sa-nav-group { margin-bottom: 8px; }
.sa-nav-group:last-child { margin-bottom: 0; }
.sa-nav-group-label {
    padding: 10px 14px 6px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.42);
}

.sa-nav ul { list-style: none; padding: 0; margin: 0; }
.sa-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    margin-bottom: 2px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    border-radius: var(--sbm-radius);
    transition: background 120ms ease, color 120ms ease;
}
.sa-nav a:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
}
.sa-nav a.active {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}
.sa-nav svg { flex-shrink: 0; opacity: 0.85; }
.sa-nav a.active svg { opacity: 1; }

.sa-nav-badge {
    margin-left: auto;
    background: var(--sbm-secondary-dark);
    color: var(--sbm-primary-dark);
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 999px;
    min-width: 18px;
    text-align: center;
}

/* ----- Impersonation-Banner ----- */
.sa-impersonation-banner {
    position: sticky;
    top: 0;
    z-index: 90;
    background: linear-gradient(90deg, #D97706 0%, #DC2626 100%);
    color: #fff;
    font-size: 13px;
    border-bottom: 2px solid rgba(0, 0, 0, 0.15);
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
}
.sa-impersonation-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.sa-impersonation-banner strong { color: #fff; font-weight: 600; }
.sa-impersonation-badge {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}
.sa-impersonation-end {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.95);
    color: #B91C1C;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 600;
    font-size: 12px;
    transition: background 120ms ease;
}
.sa-impersonation-end:hover {
    background: #fff;
    color: #991B1B;
    text-decoration: none;
}
.sa-nav a.active .sa-nav-badge {
    background: #fff;
    color: var(--sbm-primary);
}

/* ----- User-Box unten ----- */
.sa-user-box {
    padding: 14px 16px;
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.12);
}
.sa-user-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
}
.sa-user-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sbm-secondary), var(--sbm-secondary-dark));
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.sa-user-info { flex: 1; min-width: 0; }
.sa-user-name {
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sa-user-email {
    color: rgba(255, 255, 255, 0.55);
    font-size: 11px;
    line-height: 1.3;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sa-user-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 1px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sbm-secondary-dark);
    background: rgba(107, 199, 209, 0.12);
    border: 1px solid rgba(107, 199, 209, 0.35);
    border-radius: 999px;
}
.sa-user-actions {
    display: flex;
    gap: 6px;
}
.sa-user-link {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--sbm-radius-sm);
    color: rgba(255, 255, 255, 0.78);
    background: transparent;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.sa-user-link:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.25);
    color: #fff;
    text-decoration: none;
}
.sa-user-link svg { flex-shrink: 0; }

/* ----- Main-Bereich ----- */
.sa-main {
    padding: 24px 32px;
    margin-left: 224px;  /* Platz für die fixed Sidebar */
    min-width: 0;
}

.sa-page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--sbm-gray-200);
}
.sa-page-header h1 { margin: 0; font-size: 22px; }
.sa-page-header .subtitle {
    color: var(--sbm-gray-500);
    font-size: 12.5px;
    margin-top: 3px;
}
.sa-page-header .actions { display: flex; gap: 8px; }

/* ----- Stat-Karten ----- */
.sa-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.sa-stat {
    background: #fff;
    border: 1px solid var(--sbm-gray-200);
    border-radius: var(--sbm-radius-lg);
    padding: 15px 18px;
    box-shadow: var(--sbm-shadow-1);
}
.sa-stat .stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sbm-gray-500);
    font-weight: 600;
}
.sa-stat .stat-value {
    font-size: 26px;
    font-weight: 600;
    color: var(--sbm-gray-900);
    line-height: 1.1;
    margin-top: 3px;
}
.sa-stat .stat-sub {
    font-size: 12px;
    color: var(--sbm-gray-500);
    margin-top: 4px;
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}
.sa-stat-meta {
    font-size: 16px;
    font-weight: 400;
    color: var(--sbm-gray-500);
    margin-left: 4px;
}

/* ----- License Badge + Banner ----- */
.sa-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.6;
}
.sa-badge-warning {
    background: #FBF1DA;
    color: #8A5A10;
    border: 1px solid #ECD5A1;
}
.sa-badge-danger {
    background: #FBE7E6;
    color: #B3261E;
    border: 1px solid #EDBFBB;
}

.sa-license-banner {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--sbm-radius-lg);
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.sa-license-banner .sa-license-title {
    display: flex;
    gap: 6px;
    align-items: center;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}
.sa-license-banner .sa-license-desc {
    font-size: 12.5px;
    line-height: 1.5;
}
.sa-license-warning {
    background: #FBF1DA;
    border-color: #ECD5A1;
    color: #6B4408;
}
.sa-license-warning .sa-license-title { color: #8A5A10; }
.sa-license-danger {
    background: #FBE7E6;
    border-color: #EDBFBB;
    color: #7C1E17;
}
.sa-license-danger .sa-license-title { color: #B3261E; }

/* ----- Dashboard-Grid ----- */
.sa-dash-grid {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 20px;
    align-items: start;
}
@media (max-width: 1000px) {
    .sa-dash-grid { grid-template-columns: 1fr; }
}

/* Activity-Card: kein Card-Padding (weil innen scroll-Container sitzt),
   Card-Header muss deshalb die default-Negativ-Margin aufheben — sonst
   ragt er oben aus der Card hinaus („hängt über der Card"-Effekt). */
.sa-activity-card {
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sa-activity-card > .card-header {
    margin: 0;
    padding: var(--sbm-space-4) var(--sbm-space-5);
}

/* ----- Listen-Toolbar (Filter-Bar + Status-Tabs + Search) -----
 * Wird in students.php, books.php, copies.php, orders.php u.a. genutzt.
 * Alle Form-Controls auf einheitliche kompakte Höhe (padding 7px 10px).
 */
.sa-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--sbm-gray-200);
    background: var(--sbm-gray-50);
    border-top-left-radius: var(--sbm-radius-lg);
    border-top-right-radius: var(--sbm-radius-lg);
}

.sa-status-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.sa-status-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--sbm-radius);
    color: var(--sbm-gray-600);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: background 120ms ease, color 120ms ease;
}
.sa-status-tab:hover {
    background: var(--sbm-gray-100);
    color: var(--sbm-gray-800);
    text-decoration: none;
}
.sa-status-tab.active { background: var(--sbm-primary); color: #fff; }
.sa-status-tab .count {
    display: inline-block;
    min-width: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.08);
    color: inherit;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    line-height: 18px;
}
.sa-status-tab.active .count { background: rgba(255, 255, 255, 0.2); }

.sa-filter-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin: 0;
}
.sa-filter-form select {
    width: auto;
    min-width: 140px;
    max-width: 200px;
    font-size: 13px;
    padding: 7px 10px;
    flex: 0 0 auto;
}

.sa-search {
    position: relative;
    display: flex;
    align-items: center;
    flex: 0 0 auto;
}
.sa-search svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--sbm-gray-400);
    pointer-events: none;
}
.sa-search input[type="search"] {
    width: 220px;
    padding: 7px 10px 7px 34px;
    background: #fff;
    font-size: 13px;
}

/* ----- Onboarding-Checkliste ----- */
.sa-onboarding {
    display: grid;
    gap: 12px;
}
.sa-onboarding-step {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid var(--sbm-gray-200);
    border-radius: var(--sbm-radius);
    transition: border-color 120ms ease, box-shadow 120ms ease;
}
.sa-onboarding-step:hover { border-color: var(--sbm-gray-300); }
.sa-onboarding-step.done { background: var(--sbm-success-bg); border-color: #B4DCC6; }
.sa-onboarding-step .sa-step-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--sbm-gray-100);
    color: var(--sbm-gray-600);
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sa-onboarding-step.done .sa-step-num {
    background: var(--sbm-success);
    color: #fff;
}
.sa-onboarding-step .sa-step-body { flex: 1; min-width: 0; }
.sa-onboarding-step .sa-step-title {
    font-weight: 600;
    color: var(--sbm-gray-900);
    margin-bottom: 2px;
}
.sa-onboarding-step .sa-step-desc {
    font-size: 13px;
    color: var(--sbm-gray-500);
    line-height: 1.4;
}

/* ----- Aktivitäten-Feed ----- */
.sa-activity { max-height: 460px; overflow-y: auto; }
.sa-activity-item {
    display: flex;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--sbm-gray-200);
    font-size: 13px;
    align-items: flex-start;
}
.sa-activity-item:last-child { border-bottom: none; }
.sa-activity-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--sbm-gray-100);
    color: var(--sbm-gray-600);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}
.sa-activity-body { flex: 1; min-width: 0; }
.sa-activity-who { font-weight: 600; }
.sa-activity-action { color: var(--sbm-gray-500); }
.sa-activity-time {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--sbm-gray-400);
    padding-top: 3px;
    white-space: nowrap;
}

/* ----- Login-Seite (SchulAdmin) ----- */
body.sa-login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background: linear-gradient(160deg, var(--sbm-gray-50) 0%, #E6EEF8 50%, #D6E3F0 100%);
}

.sa-login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border: 1px solid var(--sbm-gray-200);
    border-radius: var(--sbm-radius-lg);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.1), 0 2px 8px rgba(15, 23, 42, 0.04);
    padding: 36px 32px;
}

.sa-login-brand {
    display: block;
    text-align: center;
    margin-bottom: 22px;
    text-decoration: none;
    transition: opacity 0.15s ease;
}
.sa-login-brand:hover { opacity: 0.8; }
.sa-login-brand:focus-visible {
    outline: 2px solid var(--sbm-secondary-dark);
    outline-offset: 4px;
    border-radius: 4px;
}
.sa-login-brand img { margin: 0 auto; max-width: 240px; }
.sa-login-hint-sep {
    color: var(--sbm-gray-300);
    margin: 0 6px;
}
.sa-login-subtitle {
    text-align: center;
    color: var(--sbm-gray-500);
    font-size: 13px;
    margin-bottom: 24px;
}

.sa-login-step { display: none; flex-direction: column; }
.sa-login-step.active { display: flex; }

.sa-email-display {
    background: var(--sbm-gray-50);
    border: 1px solid var(--sbm-gray-200);
    padding: 10px 14px;
    border-radius: var(--sbm-radius);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}
.sa-email-display-info { flex: 1; min-width: 0; }
.sa-email-display-label {
    font-size: 10.5px;
    color: var(--sbm-gray-500);
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 2px;
}
.sa-email-display-value {
    font-weight: 600;
    font-size: 13px;
    line-height: 1.3;
    word-break: break-all;
}
.sa-email-display-school {
    font-size: 12px;
    color: var(--sbm-gray-500);
    margin-top: 2px;
    font-family: var(--sbm-font);
}
.sa-change-link {
    color: var(--sbm-primary);
    font-size: 12px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
    font-family: inherit;
    flex-shrink: 0;
}
.sa-change-link:hover { color: var(--sbm-primary-soft); }

/* ----- OTP / 2FA Code-Input ----- */
.sa-otp-input {
    font-family: var(--sbm-font-mono);
    font-size: 28px;
    letter-spacing: 0.4em;
    text-align: center;
    padding: 14px 16px;
    text-indent: 0.4em; /* kompensiert letter-spacing rechts */
}
.sa-otp-input::placeholder {
    color: var(--sbm-gray-300);
    letter-spacing: 0.2em;
}

.sa-login-hint {
    text-align: center;
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--sbm-gray-200);
    font-size: 12px;
    color: var(--sbm-gray-500);
}
.sa-login-hint a { color: var(--sbm-primary); }

/* ----- Profil-/Settings-Tabs ----- */
.profile-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--sbm-gray-200);
    flex-wrap: wrap;
}
.profile-tab {
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    color: var(--sbm-gray-500);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 120ms ease, border-color 120ms ease;
}
.profile-tab:hover { color: var(--sbm-gray-800); text-decoration: none; }
.profile-tab.active {
    color: var(--sbm-primary);
    border-bottom-color: var(--sbm-primary);
}

/* ----- Responsive -----
 * Auf Tablets/Phones ist die Sidebar per Default ausgeblendet (translateX(-100%))
 * und kann per Burger-Button reingeschoben werden. Siehe sa-mobile-menu-btn +
 * sa-sidebar-backdrop im Header-Template.
 */
@media (max-width: 860px) {
    .sa-sidebar {
        width: 280px;
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
    }
    .sa-sidebar.is-open { transform: translateX(0); }
    .sa-main { margin-left: 0; padding: 16px; padding-top: 60px; }
}

.sa-mobile-menu-btn { display: none; }
.sa-sidebar-backdrop { display: none; }

@media (max-width: 860px) {
    .sa-mobile-menu-btn {
        display: inline-flex;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 110;
        background: #fff;
        border: 1px solid var(--sbm-gray-200);
        border-radius: 8px;
        width: 42px;
        height: 42px;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
        color: var(--sbm-gray-800);
    }
    .sa-sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s ease;
        z-index: 99;
    }
    body.sa-sidebar-visible .sa-sidebar-backdrop {
        opacity: 1;
        visibility: visible;
        display: block;
    }
}

/* View Transitions haben wir bewusst entfernt — sie erzeugten in der Praxis
 * einen unschönen Neu-Scroll der Sidebar beim Seitenwechsel. Das stabile
 * Layout liefert allein `position: fixed` auf .sa-sidebar plus die inline
 * sessionStorage-Scroll-Restauration im Header-Template.
 */
