/* ==========================================================================
   Basis & Dark Mode
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body.dark-mode {
    background-color: #0a0a0a;
    color: #eeeeee;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Übersicht / Galerie-Grid (Masonry "Waterfall" Layout im 500px-Style)
   ========================================================================== */
.overview-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    gap: 15px;
}

.controls h1 {
    font-size: 1.5rem;
    color: #fff;
    word-break: break-word;
}

#search-input {
    padding: 10px 15px;
    border-radius: 20px;
    border: 1px solid #333;
    background: #111;
    color: white;
    font-size: 1rem;
    width: 100%;
    max-width: 300px;
}
#search-input:focus { outline: none; border-color: #4CAF50; }

/* Raster statt CSS-Spalten: Reihenfolge läuft zeilenweise von links nach rechts */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
    padding-bottom: 30px;
}

@media (max-width: 800px) { .story-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 15px; } }
@media (max-width: 380px) { .story-grid { grid-template-columns: 1fr; } }

/* Ladebalken oben beim Öffnen einer Galerie (app.js setLoading) */
#loading-bar {
    position: fixed; top: 0; left: 0; height: 3px; width: 0;
    background: #3498db; z-index: 20000; opacity: 0;
    transition: width 0.4s ease, opacity 0.2s;
    pointer-events: none;
}
#loading-bar.active { width: 70%; opacity: 1; transition: width 4s cubic-bezier(0.1, 0.6, 0.3, 1), opacity 0.2s; }

/* Fehler- und Hinweisseiten (Zugriff, nicht gefunden, Verbindung) */
.app-message { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 2rem; box-sizing: border-box; }
.app-message h2 { margin: 0 0 0.8rem 0; color: #fff; }
.app-message p { color: #aaa; max-width: 480px; margin: 0 0 1.5rem 0; line-height: 1.5; }
.app-message-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.app-message-actions a.fm-btn { text-decoration: none; }

/* Sichtbarer Fokus für Tastaturbedienung */
button:focus-visible, a:focus-visible, input:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}


/* ==========================================================================
   Vollbild-Viewer & Scroll-Snapping
   ========================================================================== */
.viewer-wrapper {
    position: fixed;
    top: 0; left: 0;
    /* dvh: sichtbare Höhe auf Mobilgeräten (ohne Adressleiste), vh als Rückfall */
    width: 100vw; height: 100vh; height: 100dvh;
    background: #000;
    z-index: 100;
}

.story-viewer {
    width: 100%; height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
}

.node {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    scroll-snap-align: start;
    position: relative;
    display: flex;
    flex-direction: column;
}

.sequence-wrapper {
    width: 100%;
    height: 100%;
}

.node-sequence {
    position: relative;
    width: 100%; 
    height: 100%;
    overflow: hidden; 
    display: block; 
}

.sequence-item {
    position: absolute;
    top: 0; left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0; 
    transition: opacity 0.15s ease-out;
    pointer-events: none; 
}

.sequence-item.active {
    opacity: 1; 
    pointer-events: auto;
    z-index: 1;
}

.sequence-item img, .sequence-item video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
}

.node-text {
    max-width: 800px;
    margin: auto;
    padding: 20px;
    color: #eee;
    font-size: 1.1rem;
    line-height: 1.7;
}

/* ==========================================================================
   Navigation (Controller) - Vollständig Skalierbar (Mobile First)
   ========================================================================== */
#viewer-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 20, 20, 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid #444;
    padding: 4px 6px;
    border-radius: 40px;
    display: flex;
    flex-wrap: nowrap;
    justify-content: center; 
    align-items: center;
    gap: 3px;
    z-index: 500;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    max-width: 98vw;
    overflow-x: auto; 
    -ms-overflow-style: none;
    scrollbar-width: none;
    transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.25, 1, 0.5, 1), left 0.4s cubic-bezier(0.25, 1, 0.5, 1), padding 0.3s ease, border-radius 0.3s ease;
}

#viewer-controls::-webkit-scrollbar {
    display: none; 
}

#viewer-controls div {
    width: 4px !important;
    flex-shrink: 0;
}

#viewer-controls.collapsed {
    left: 15px;
    transform: translateX(0);
    padding: 5px;
    gap: 0;
    border-radius: 50%;
}

#viewer-controls.collapsed .nav-btn:not(#nav-toggle-collapse),
#viewer-controls.collapsed div {
    display: none !important;
}

#viewer-controls.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: translateX(-50%) translateY(20px);
}

.nav-btn {
    background: #333;
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 0.8rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0; 
    touch-action: manipulation;
    transition: background 0.2s, opacity 0.2s, transform 0.1s;
}

.nav-btn:hover:not(:disabled) {
    background: #555;
    transform: scale(1.05);
}

.nav-btn:disabled {
    opacity: 0.15;
    cursor: not-allowed;
    background: #222;
}

.nav-btn.hi-res {
    background: #3498db;
    color: white;
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.8);
}
.nav-btn.hi-res:hover:not(:disabled) {
    background: #2980b9;
    transform: scale(1.05);
}

.nav-close { background: #ff5555; margin-left: 2px; }
.nav-close:hover:not(:disabled) { background: #ff3333; }

#nav-toggle-collapse { background: #2a2a2a; border: 1px solid #555; margin-left: 2px; }
#nav-toggle-collapse:hover { background: #444; }

@media (min-width: 450px) {
    #viewer-controls { gap: 5px; padding: 6px 10px; }
    .nav-btn { width: 34px; height: 34px; font-size: 0.95rem; }
    #viewer-controls div { width: 8px !important; }
    #viewer-controls.collapsed { left: 20px; }
}

@media (min-width: 800px) {
    #viewer-controls { gap: 8px; padding: 8px 16px; }
    .nav-btn { width: 40px; height: 40px; font-size: 1.1rem; }
    #viewer-controls div { width: 12px !important; }
}

/* ==========================================================================
   Overlays & Captions
   ========================================================================== */
.media-caption {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.95rem;
    text-align: center;
    width: 90%;
    max-width: 600px;
    z-index: 10;
    pointer-events: none;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s ease;
    border: 1px solid rgba(255,255,255,0.1);
}

body.hide-captions .media-caption { opacity: 0 !important; }

#info-overlay {
    position: fixed;
    top: 20px; left: 20px;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    padding: 20px;
    border-radius: 8px;
    color: white;
    z-index: 1000;
    border: 1px solid #444;
    max-width: calc(100vw - 40px);
    pointer-events: none;
    transition: opacity 0.2s ease;
}

#info-overlay.hidden { opacity: 0 !important; pointer-events: none !important; }

#help-overlay {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    padding: 30px;
    border-radius: 8px;
    color: white;
    z-index: 10050;
    border: 1px solid #444;
    min-width: min(320px, 90vw);
    max-width: 90vw;
    max-height: 80vh;
    max-height: 80dvh;
    overflow-y: auto;
    box-sizing: border-box;
    transition: opacity 0.2s ease;
}

#help-overlay.hidden { opacity: 0 !important; pointer-events: none !important; }

.exif-list { list-style: none; padding: 0; margin-top: 15px; font-size: 0.9rem; }
.exif-list li { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #333; padding: 6px 0; }
.exif-list span { color: #aaa; }

kbd {
    background: #222;
    border: 1px solid #555;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 0.85rem;
    color: #fff;
    box-shadow: 0 2px 0 #111;
    margin: 0 2px;
}

.fm-btn { 
    padding: 10px 20px; 
    background: #333; 
    color: white; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-weight: bold; 
    touch-action: manipulation; 
}
.fm-btn:hover { background: #444; }
.fm-btn.primary { background: white; color: black; }

#toast-notification {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    color: white;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: bold;
    z-index: 10500;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    border: 1px solid #444;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

#toast-notification.show { opacity: 1; }

.dark-map-popup .leaflet-popup-content-wrapper { background: #1a1a1a; color: #eee; border: 1px solid #444; border-radius: 8px; }
.dark-map-popup .leaflet-popup-tip { background: #1a1a1a; border: 1px solid #444; }
.dark-map-popup .leaflet-popup-close-button { color: #aaa !important; }
.dark-map-popup .leaflet-popup-close-button:hover { color: #fff !important; }
.dark-map-popup .leaflet-popup-content { margin: 15px; line-height: 1.5; font-size: 1rem; }
.dark-map-popup .leaflet-popup-content img { max-width: 100%; height: auto; border-radius: 4px; }

.transparent-text-marker { display: flex; justify-content: center; align-items: center; width: 0 !important; height: 0 !important; overflow: visible; }
.text-marker-content {
    background: rgba(255, 255, 255, 0.75); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); color: #111; padding: 8px 14px;
    border-radius: 8px; font-size: 0.95rem; box-shadow: 0 4px 15px rgba(0,0,0,0.3); min-width: 100px; max-width: 280px; cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.4); transform: translate(-50%, -50%); white-space: normal; width: max-content;
    overflow-wrap: break-word; pointer-events: auto; transition: transform 0.2s, background 0.2s;
}
.text-marker-content:hover { background: rgba(255, 255, 255, 0.95); transform: translate(-50%, -50%) scale(1.02); }
.text-marker-content * { margin: 0; padding: 0; }
.text-marker-content p { margin-bottom: 6px; line-height: 1.3; }
.text-marker-content p:last-child { margin-bottom: 0; }
.text-marker-content a { color: #2980b9; text-decoration: underline; font-weight: 500; }

/* ==========================================================================
   Floating "Weiter" Button
   ========================================================================== */
/* Aussehen wie bisher (stand vorher inline in viewer-controls.js und überschrieb diese Regeln) */
#floating-next-btn {
    position: fixed;
    bottom: 100px;
    right: 20px;
    z-index: 10400;
    background: rgba(15, 15, 15, 0.9);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    color: white;
    border: 1px solid #444;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 5px 20px rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: opacity 0.3s ease, transform 0.3s ease, background 0.2s;
}

#floating-next-btn span { font-size: 1.2rem; }
#floating-next-btn:hover { background: rgba(40, 40, 40, 0.95); transform: translateY(-3px); }
#floating-next-btn:active { transform: translateY(1px); }

#floating-next-btn.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

/* ==========================================================================
   Übersicht (app-overview)
   ========================================================================== */
.overview-container { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.overview-main { flex-grow: 1; }
.overview-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 15px; }
.overview-heading { display: flex; align-items: center; min-width: 0; }
.overview-title { margin: 0; }
.overview-back { margin-right: 1.5rem; display: flex; align-items: center; justify-content: center; background: #333; color: white; border: 1px solid #555; border-radius: 50%; width: 44px; height: 44px; flex-shrink: 0; font-size: 1.4rem; cursor: pointer; transition: all 0.2s; }
.overview-back:hover { background: #555; transform: scale(1.05); }
.overview-tools { display: flex; gap: 15px; align-items: center; flex-grow: 1; justify-content: flex-end; flex-wrap: wrap; }

.selection-bar { display: flex; gap: 10px; align-items: center; background: rgba(241, 196, 15, 0.1); padding: 6px 12px; border-radius: 6px; border: 1px solid rgba(241, 196, 15, 0.3); }
.selection-bar[hidden] { display: none; }
.selection-count { color: #f1c40f; font-size: 0.95rem; font-weight: bold; margin-right: 5px; }
.selection-btn { background: transparent; color: #aaa; border: 1px solid #555; padding: 7px 14px; border-radius: 4px; cursor: pointer; font-size: 0.85rem; transition: all 0.2s; }
.selection-btn:hover { color: #fff; border-color: #fff; }
.selection-btn.primary { background: #f1c40f; color: #111; border-color: #f1c40f; font-weight: bold; }
.selection-btn.primary:hover { opacity: 0.8; color: #111; }

.search-box { display: flex; flex-direction: column; align-items: flex-end; max-width: 100%; }
.search-row { display: flex; gap: 5px; max-width: 100%; }
.search-row #search-input { width: 250px; max-width: 100%; margin: 0; box-sizing: border-box; padding: 8px; }
/* Startzustand verborgen; app-overview blendet den Button im KI-Modus per style.display ein */
#btn-search { display: none; background: #3498db; color: white; border: none; padding: 0 15px; border-radius: 4px; cursor: pointer; font-size: 1rem; }
.search-options { margin-top: 8px; font-size: 0.8em; color: #888; display: flex; gap: 12px; align-items: center; }
.search-options[hidden] { display: none; }
.search-options label { cursor: pointer; display: flex; align-items: center; gap: 4px; }
.search-options .search-mode-ai { color: #3498db; }

#search-spinner { display: none; text-align: center; margin: 40px auto; padding: 40px 20px; background: rgba(52, 152, 219, 0.05); border: 1px dashed #3498db; border-radius: 8px; max-width: 600px; }
#search-spinner .spinner-icon { font-size: 2.5rem; margin-bottom: 15px; display: inline-block; animation: pulse 1.5s infinite; }
#spinner-text { margin: 0 0 10px 0; color: #3498db; font-weight: 300; }
#spinner-subtext { margin: 0; color: #888; font-size: 0.9rem; }
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.2); opacity: 0.7; } 100% { transform: scale(1); opacity: 1; } }

#ai-search-container { display: none; margin-bottom: 40px; }
.ai-results-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #333; padding-bottom: 10px; margin-bottom: 15px; flex-wrap: wrap; gap: 15px; }
.ai-results-head h3 { color: #aaa; margin: 0; font-weight: 300; }
.confidence-box { display: flex; align-items: center; gap: 10px; background: #111; padding: 5px 12px; border-radius: 20px; border: 1px solid #222; }
.confidence-box label { color: #888; font-size: 0.85rem; margin: 0; }
#confidence-val { color: #3498db; }
#confidence-slider { width: 120px; cursor: pointer; accent-color: #3498db; }
#ai-search-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; align-items: start; }
/* Hinweise im Trefferraster (keine Treffer / alle ausgeblendet) */
.ai-grid-hint { color: #aaa; grid-column: 1 / -1; padding: 20px; text-align: center; }
#search-empty { display: none; color: #888; text-align: center; padding: 2rem 1rem; }

.overview-footer { text-align: center; padding: 2rem 0; margin-top: 3rem; border-top: 1px solid #333; }
.inline-form { display: inline; margin: 0; }
.footer-link { color: #888; margin: 0 15px; padding: 0; background: none; border: none; font: inherit; font-size: 0.9rem; text-decoration: none; cursor: pointer; transition: color 0.2s; }
.footer-link:hover { color: white; }

/* ==========================================================================
   Viewer: Admin-Sichtbarkeitsanzeige und leere Galerie
   ========================================================================== */
/* Startzustand verborgen; app-viewer blendet per style.display ein, Rahmen/Schatten blinken beim Speichern */
#admin-visibility-badge { position: fixed; top: 20px; right: 20px; background: rgba(15,15,15,0.9); color: #fff; padding: 10px 14px; border-radius: 6px; border: 1px solid #444; font-size: 0.9rem; z-index: 10001; display: none; backdrop-filter: blur(4px); pointer-events: none; box-shadow: 0 4px 20px rgba(0,0,0,0.6); transition: all 0.2s; }
#admin-vis-text { color: #4CAF50; }
.admin-vis-keys { font-size: 0.75rem; color: #888; margin-top: 4px; border-top: 1px solid #333; padding-top: 4px; }
.viewer-empty { height: 100vh; height: 100dvh; display: flex; align-items: center; justify-content: center; color: #888; text-align: center; padding: 20px; box-sizing: border-box; }

/* ==========================================================================
   Kundenauswahl, Diashow und TV-Modus (app-viewer)
   ========================================================================== */
#selection-mode-bar {
    position: fixed; top: 15px; left: 50%; transform: translateX(-50%);
    z-index: 10350; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center;
    background: rgba(15, 15, 15, 0.92); border: 1px solid #f1c40f; border-radius: 10px;
    padding: 8px 14px; color: #f1c40f; font-size: 0.9rem; box-shadow: 0 6px 20px rgba(0,0,0,0.6);
    max-width: calc(100vw - 30px); box-sizing: border-box; backdrop-filter: blur(6px);
}
#selection-mode-bar[hidden] { display: none; }
#selection-mode-send { background: #f1c40f; color: #111; border: none; border-radius: 6px; padding: 7px 14px; font-weight: bold; cursor: pointer; }
#selection-mode-send:hover { background: #f5d33f; }

/* TV-Modus: Bedienelemente nur kurz nach einer Eingabe, größere Schrift, kein Mauszeiger */
body.tv-mode:not(.tv-ui-visible) #viewer-controls,
body.tv-mode:not(.tv-ui-visible) #floating-next-btn,
body.tv-mode:not(.tv-ui-visible) #selection-mode-bar { opacity: 0 !important; pointer-events: none !important; }
body.tv-mode:not(.tv-ui-visible) .viewer-wrapper { cursor: none; }
body.tv-mode .media-caption { font-size: 1.5rem; }
body.tv-mode story-card:focus { outline: 4px solid #3498db; outline-offset: 4px; border-radius: 8px; }
body.tv-mode .overview-title { font-size: 2.4rem; }
