/* ============================================================================
   BIBLIOTHEK - Professionelle Bibliothek-Seite (Clean Version v2)
   ============================================================================ */

/* Variables */
:root {
    --bibliothek-primary: #667eea;
    --bibliothek-secondary: #764ba2;
    --bibliothek-accent: #f093fb;
    --bibliothek-bg: #f5f5f7;
    --bibliothek-card-bg: #ffffff;
    --bibliothek-text: #1d1d1f;
    --bibliothek-text-secondary: #86868b;
    --bibliothek-border: #d2d2d7;
    --bibliothek-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    --bibliothek-shadow-hover: 0 10px 20px rgba(0, 0, 0, 0.1);
    --bibliothek-radius: 12px;
    --rating-star-color: #ffa41c;
    --rating-star-empty: #ddd;
}

body.dark-mode {
    --bibliothek-bg: #1a1a1a;
    --bibliothek-card-bg: #2a2a2a;
    --bibliothek-text: #f5f5f7;
    --bibliothek-text-secondary: #a1a1a6;
    --bibliothek-border: #424245;
    --bibliothek-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --bibliothek-shadow-hover: 0 10px 20px rgba(0, 0, 0, 0.5);
    --rating-star-empty: #555;
}

/* Base Layout */
.bibliothek-main {
    display: flex;
    min-height: calc(100vh - 60px);
    height: calc(100vh - 60px);
    max-height: calc(100vh - 60px);
    background: var(--bibliothek-bg);
    padding-top: 80px;
    overflow-y: auto;
    overflow-x: hidden;
    /* Touch-Scrolling für mobile Geräte aktivieren */
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: auto !important;
    /* Scrollbar Styles */
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: rgba(102, 126, 234, 0.5) rgba(0, 0, 0, 0.05); /* Firefox */
}

/* Scrollbar Styles für Webkit-Browser (Chrome, Safari, Edge) */
.bibliothek-main::-webkit-scrollbar {
    width: 12px;
}

.bibliothek-main::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
}

.bibliothek-main::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 6px;
}

.bibliothek-main::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.7);
}

/* Dark Mode: Scrollbar Styles für bibliothek-main */
body.dark-mode .bibliothek-main,
html.dark-mode .bibliothek-main {
    scrollbar-color: rgba(102, 126, 234, 0.6) rgba(0, 0, 0, 0.3); /* Firefox - dunklerer Track */
}

body.dark-mode .bibliothek-main::-webkit-scrollbar-track,
html.dark-mode .bibliothek-main::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3); /* Dunklerer Track im Dark Mode */
    border-radius: 6px;
}

body.dark-mode .bibliothek-main::-webkit-scrollbar-thumb,
html.dark-mode .bibliothek-main::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.6); /* Hellerer Thumb im Dark Mode */
    border-radius: 6px;
}

body.dark-mode .bibliothek-main::-webkit-scrollbar-thumb:hover,
html.dark-mode .bibliothek-main::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.8); /* Hellerer Thumb beim Hover im Dark Mode */
}

.bibliothek-content {
    flex: 1;
    padding: 20px 40px;
    width: 100%;
    max-width: 1600px; /* Begrenzung für sehr große Bildschirme */
    margin: 0 auto;
}

/* Sidebar */
.bibliothek-sidebar {
    width: 280px;
    background: var(--bibliothek-card-bg);
    border-right: 1px solid var(--bibliothek-border);
    padding: 20px;
    max-height: calc(100vh - 60px);
    position: sticky;
    top: 60px;
    align-self: flex-start;
    overflow-y: auto;
    flex-shrink: 0;
    /* Scrollbar Styles */
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: rgba(102, 126, 234, 0.5) rgba(0, 0, 0, 0.05); /* Firefox */
}

/* Scrollbar Styles für Webkit-Browser (Chrome, Safari, Edge) */
.bibliothek-sidebar::-webkit-scrollbar {
    width: 12px;
}

.bibliothek-sidebar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
}

.bibliothek-sidebar::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 6px;
}

.bibliothek-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.7);
}

/* Dark Mode: Scrollbar Styles für Sidebar */
body.dark-mode .bibliothek-sidebar,
html.dark-mode .bibliothek-sidebar {
    scrollbar-color: rgba(102, 126, 234, 0.6) rgba(0, 0, 0, 0.3); /* Firefox - dunklerer Track */
}

body.dark-mode .bibliothek-sidebar::-webkit-scrollbar-track,
html.dark-mode .bibliothek-sidebar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3); /* Dunklerer Track im Dark Mode */
    border-radius: 6px;
}

body.dark-mode .bibliothek-sidebar::-webkit-scrollbar-thumb,
html.dark-mode .bibliothek-sidebar::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.6); /* Hellerer Thumb im Dark Mode */
    border-radius: 6px;
}

body.dark-mode .bibliothek-sidebar::-webkit-scrollbar-thumb:hover,
html.dark-mode .bibliothek-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(102, 126, 234, 0.8); /* Hellerer Thumb beim Hover im Dark Mode */
}

/* Filter Styles */
.filter-section {
    margin-bottom: 24px;
}

.filter-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--bibliothek-text-secondary);
    margin-bottom: 10px;
    letter-spacing: 0.5px;
}

.filter-input, .filter-select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--bibliothek-border);
    border-radius: 8px;
    background: var(--bibliothek-bg);
    color: var(--bibliothek-text);
    font-family: inherit;
    box-sizing: border-box;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    cursor: pointer;
    font-size: 14px;
    color: var(--bibliothek-text);
}

.filter-checkbox input[type="checkbox"] {
    accent-color: var(--bibliothek-primary);
    width: 16px;
    height: 16px;
}

.filter-reset {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid var(--bibliothek-border);
    border-radius: 8px;
    color: var(--bibliothek-text);
    cursor: pointer;
    font-weight: 600;
    margin-top: 10px;
    margin-bottom: 50px;
}

.filter-reset:hover {
    background: var(--bibliothek-bg);
    border-color: var(--bibliothek-text-secondary);
}

.filter-more-btn {
    background: none;
    border: none;
    color: var(--bibliothek-primary);
    font-size: 13px;
    cursor: pointer;
    padding: 5px 0;
    margin-top: 5px;
}

/* Toolbar Elements */
.filter-toggle {
    display: none; /* Standardmäßig aus auf Desktop (Sidebar ist da) */
    padding: 8px 16px;
    background: transparent;
    color: var(--bibliothek-text);
    border: 1px solid var(--bibliothek-border);
    border-radius: 8px;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
}

.filter-toggle:hover {
    background: var(--bibliothek-bg);
}

.toolbar-info {
    font-size: 14px;
    color: var(--bibliothek-text-secondary);
    font-weight: 600;
}

.view-toggle {
    display: flex;
    gap: 8px;
}

.view-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--bibliothek-border);
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bibliothek-text);
}

.view-btn:hover {
    background: var(--bibliothek-bg);
}

.view-btn.active {
    background: var(--bibliothek-text);
    color: var(--bibliothek-card-bg);
    border-color: var(--bibliothek-text);
}

/* Sidebar Close Button (Mobile) */
.sidebar-close {
    display: none; /* Nur Mobile */
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--bibliothek-text);
    position: absolute;
    top: 15px;
    right: 15px;
}

/* GRID LAYOUT - Kompakt & 3 Spalten auf Mobile */
.bibliothek-grid {
    display: grid;
    /* 30% kleiner auf Desktop (140px Basis) */
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
    padding: 10px 0 40px 0;
}

/* BOOK CARD - Grid View */
.bibliothek-book-card {
    background: var(--bibliothek-card-bg);
    border-radius: var(--bibliothek-radius);
    box-shadow: var(--bibliothek-shadow);
    border: 1px solid var(--bibliothek-border);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    position: relative;
    cursor: pointer;
    max-width: 240px; /* Kompakter */
    margin: 0 auto;
    width: 100%;
}

.bibliothek-book-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--bibliothek-shadow-hover);
}

/* 1. Das Bild (3:4 Format) */
.book-cover-container {
    position: relative;
    width: 100%;
    padding-top: 133.33%; /* 3:4 Aspect Ratio (4/3 = 1.333) */
    overflow: hidden;
    background: #eee;
}

.book-cover-container img,
.book-cover-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.bibliothek-book-card:hover .book-cover-container img {
    transform: scale(1.05);
}

/* Overlay Titel (oben im Bild) - Optimierte Lesbarkeit */
.book-title-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 10px 6px 30px 6px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.6) 50%, rgba(0,0,0,0) 100%);
    color: white !important; /* Erzwinge Weiß */
    text-align: center;
    z-index: 2;
    pointer-events: none;
}

.book-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 800; /* Extra Fett */
    margin: 0;
    color: white !important; /* Erzwinge Weiß */
    text-shadow: 0 1px 3px rgba(0,0,0,1); /* Harter schwarzer Schatten für Kontrast */
    line-height: 1.2;
    letter-spacing: 0.3px;
    -webkit-font-smoothing: antialiased; /* Schärferes Rendering in Webkit */
    -moz-osx-font-smoothing: grayscale; /* Schärferes Rendering in Firefox Mac */
}

/* Badges */
.book-badges-container {
    position: absolute;
    top: 6px; /* Etwas höher */
    right: 6px;
    z-index: 3;
}

.book-badge {
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 3px 6px;
    border-radius: 8px;
    font-size: 10px;
}

/* Favoriten-Button */
.book-favorite-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: transparent;
    border: none;
    border-radius: 0;
    width: auto;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 28px;
    z-index: 4;
    transition: transform 0.2s ease;
    box-shadow: none;
    padding: 0;
    line-height: 1;
}

.book-favorite-btn:hover {
    background: transparent;
    transform: scale(1.2);
    box-shadow: none;
}

.book-favorite-btn.favorite {
    background: transparent;
    border: none;
    color: #ffd700;
}

.book-favorite-btn.favorite:hover {
    background: transparent;
    transform: scale(1.3);
}

/* Dark Mode: Favoriten-Button */
body.dark-mode .book-favorite-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
}

body.dark-mode .book-favorite-btn:hover {
    background: transparent;
    color: rgba(255, 255, 255, 0.9);
}

body.dark-mode .book-favorite-btn.favorite {
    background: transparent;
    border: none;
    color: #ffd700;
}

body.dark-mode .book-favorite-btn.favorite:hover {
    background: transparent;
    color: #ffed4e;
}

/* 2. Info Bereich (unter dem Bild) - Kompakt */
.book-info-area {
    padding: 8px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-align: center;
}

.book-author {
    font-size: 12px;
    font-weight: 600;
    color: var(--bibliothek-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.book-rating {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.stars {
    color: var(--rating-star-empty);
    font-size: 11px;
    position: relative;
    display: inline-block;
    letter-spacing: 1px;
}

.stars-fill {
    color: var(--rating-star-color);
    position: absolute;
    top: 0;
    left: 0;
    white-space: nowrap;
    overflow: hidden;
}

.rating-count {
    font-size: 10px;
    color: var(--bibliothek-text-secondary);
}

/* WICHTIG: Listen-Infos im Grid ausblenden! */
.book-list-details {
    display: none !important;
}

/* ============================================================================
   LISTENANSICHT (TABELLE)
   ============================================================================ */

.bibliothek-grid.list-view {
    display: block; /* Kein Grid mehr */
    grid-template-columns: none;
    gap: 0;
}

.bibliothek-table-container {
    background: var(--bibliothek-card-bg);
    border-radius: var(--bibliothek-radius);
    box-shadow: var(--bibliothek-shadow);
    overflow-x: auto;
    width: 100%;
}

.bibliothek-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.bibliothek-table th {
    text-align: left;
    padding: 16px;
    border-bottom: 1px solid var(--bibliothek-border);
    color: var(--bibliothek-text-secondary);
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 600;
    background: var(--bibliothek-bg);
}

.bibliothek-table td {
    padding: 16px;
    border-bottom: 1px solid var(--bibliothek-border);
    color: var(--bibliothek-text);
    font-size: 14px;
    vertical-align: middle;
}

.bibliothek-table tr:last-child td {
    border-bottom: none;
}

.bibliothek-table tr:hover {
    background-color: rgba(0,0,0,0.02);
}

/* Zellen-Styles */
.cell-title { font-weight: 600; }
.cell-author { color: var(--bibliothek-primary); }
.cell-rating { white-space: nowrap; }
.cell-rating .stars { font-size: 12px; letter-spacing: 1px; }

/* ============================================================================
   MOBILE ANPASSUNGEN
   ============================================================================ */
@media (max-width: 768px) {
    .bibliothek-main {
        padding-top: 60px; /* WICHTIG: Platz für den Header lassen! */
        flex-direction: column;
        height: calc(100vh - 60px);
        max-height: calc(100vh - 60px);
    }
    
    .bibliothek-sidebar {
        display: none;
    }
    
    .bibliothek-sidebar.open {
        display: block;
        position: fixed;
        top: 60px;
        left: 0;
        z-index: 100;
        width: 100%;
        height: calc(100vh - 60px);
        overflow-y: auto;
        box-shadow: 4px 0 10px rgba(0,0,0,0.1);
    }

    /* Zeige Filter-Button und Close-Button auf Mobile */
    .filter-toggle, .sidebar-close {
        display: block;
    }

    .toolbar-info {
        display: none; /* Platz sparen */
    }

    .bibliothek-content {
        padding: 10px;
    }

    .bibliothek-grid {
        /* Mobile: 3 Spalten möglich machen */
        /* minmax 90px erlaubt 3 Spalten auch auf kleinen Screens (320px - Padding) */
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 8px; /* Enger Gap für mehr Platz */
    }

    .book-title {
        font-size: 12px; /* Kleiner auf Mobile */
        line-height: 1.1;
    }
    
    .book-author {
        font-size: 11px;
    }
    
    .book-info-area {
        padding: 6px 4px;
    }
}

/* Toolbar (Filter, Sortierung) */
.bibliothek-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

/* Scroll Indicator Fix */
#scrollIndicatorContainer .scroll-indicator {
    position: fixed;
    right: 32.8px; /* 12.8px + 20px Padding rechts für größere Ansichten */
    top: 50%;
    transform: translateY(-50%);
    z-index: 9999;
}

/* Kindermodus: Orange Hintergrund mit 50% Transparenz für Scroll-Indikator - NUR Farben ändern, keine Layout-Änderungen */
body.kids-mode-active .scroll-indicator,
html.kids-mode-active .scroll-indicator,
body.kids-mode-active #scrollIndicatorContainer .scroll-indicator,
html.kids-mode-active #scrollIndicatorContainer .scroll-indicator,
body.kids-mode-active.dark-mode .scroll-indicator,
html.kids-mode-active.dark-mode .scroll-indicator,
body.kids-mode-active.dark-mode #scrollIndicatorContainer .scroll-indicator,
html.kids-mode-active.dark-mode #scrollIndicatorContainer .scroll-indicator {
    background: linear-gradient(135deg, rgba(var(--kids-mode-primary-rgb), 0.5) 0%, rgba(var(--kids-mode-secondary-rgb), 0.5) 50%, rgba(var(--kids-mode-primary-rgb), 0.5) 100%) !important;
    backdrop-filter: blur(20px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
    border-color: rgba(var(--kids-mode-primary-rgb), 0.9) !important;
    box-shadow: 0 8px 24px rgba(var(--kids-mode-primary-rgb), 0.5), 0 4px 12px rgba(var(--kids-mode-secondary-rgb), 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3), inset 0 0 30px rgba(var(--kids-mode-primary-rgb), 0.2) !important;
}

/* Dark Mode: Scroll Indicator */
body.dark-mode .scroll-indicator,
html.dark-mode .scroll-indicator,
body.dark-mode #scrollIndicatorContainer .scroll-indicator,
html.dark-mode #scrollIndicatorContainer .scroll-indicator {
    background: linear-gradient(135deg, rgba(255, 107, 157, 0.6) 0%, rgba(102, 126, 234, 0.6) 100%) !important;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4), 0 4px 12px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.1), inset 0 0 100px rgba(0,0,0,0.3) !important;
}

body.dark-mode .scroll-indicator button,
body.dark-mode .scroll-indicator .scroll-indicator-item,
html.dark-mode .scroll-indicator button,
html.dark-mode .scroll-indicator .scroll-indicator-item,
body.dark-mode #scrollIndicatorContainer .scroll-indicator button,
body.dark-mode #scrollIndicatorContainer .scroll-indicator .scroll-indicator-item,
html.dark-mode #scrollIndicatorContainer .scroll-indicator button,
html.dark-mode #scrollIndicatorContainer .scroll-indicator .scroll-indicator-item {
    color: #ffffff !important;
}
