/* === GLOBAL RESETS & DEFAULTS === */
body {
    font-family: 'Inter', sans-serif;
    background-color: #f0f2f5; /* Default background for all pages */
    color: #374151; /* Tailwind's text-gray-700, good default */
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

/* Specific body styling for the index page to center content */
body.page-index {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem; /* Equivalent to Tailwind's p-4 */
}

/* === COMMON CONTAINERS & LAYOUT === */
.app-header {
    background-color: #4a5568; /* Darker gray-blue, consistent header color */
    color: white;
    padding: 1rem 1.5rem; /* Added more horizontal padding */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    width: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header .logo-text { /* If you want to style the title specifically */
    font-size: 1.25rem; /* Tailwind's text-xl */
    font-weight: 700; /* Tailwind's font-bold */
}

.app-header .nav-link { /* For the "Zurück zur Startseite" link */
    font-size: 0.875rem; /* Tailwind's text-sm */
    color: white; /* Ensure it's visible */
}
.app-header .nav-link:hover {
    text-decoration: underline;
}

.main-content { /* For general, photogame, photobooth pages */
    max-width: 1200px;
    width: 95%; /* Use percentage for better responsiveness on small screens */
    margin: 2rem auto;
    padding: 1.5rem;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.1);
}

.main-card { /* Specifically for index.html content card */
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    padding: 2rem;
    text-align: center;
    max-width: 42rem; /* Tailwind's max-w-2xl */
    width: 100%; /* Ensure it takes full width within its constraints */
    margin-top: 1rem; /* Adjust as needed if body handles main centering */
    margin-bottom: 1rem;
}

.upload-section, .gallery-section {
    margin-bottom: 2.5rem;
    padding: 1.5rem;
    border: 1px solid #e5e7eb; /* Tailwind's border-gray-200 */
    border-radius: 8px;
}

footer.app-footer { /* Added class for specificity */
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    padding: 2rem 1rem;
    font-size: 0.875rem; /* Tailwind's text-sm */
    color: #6b7280; /* Tailwind's text-gray-500 */
    margin-top: auto; /* Pushes footer to bottom if body.page-index is flex container */
}

/* === COMMON COMPONENTS === */

/* Buttons */
.btn {
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out, border-color 0.2s ease-in-out, opacity 0.2s ease-in-out;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none; /* Remove underline from button-like links */
}
.btn svg { /* Style for icons inside buttons */
    margin-right: 0.5rem; /* Tailwind's mr-2 */
    height: 1.25rem; /* Tailwind's h-5 */
    width: 1.25rem; /* Tailwind's w-5 */
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary { /* Base primary button, page specific overrides will set background-color */
    color: white;
}

.btn-secondary {
    background-color: #e5e7eb; /* Tailwind's bg-gray-200 */
    color: #374151;       /* Tailwind's text-gray-700 */
    border-color: #d1d5db; /* Tailwind's border-gray-300 */
}
.btn-secondary:hover {
    background-color: #d1d5db; /* Tailwind's bg-gray-300 */
}

/* Forms */
.form-input, .form-textarea {
    border: 1px solid #d1d5db; /* Tailwind's border-gray-300 */
    border-radius: 6px;
    padding: 0.625rem 0.875rem; /* Tailwind's p-2.5ish */
    width: 100%;
    box-sizing: border-box;
    background-color: white;
    color: #374151;
}
.form-input:focus, .form-textarea:focus { /* Base focus, page specific overrides for colors */
    outline: none;
    /* Default focus style, can be overridden by page-specific styles */
    border-color: #4f46e5; /* Tailwind's indigo-500 as a default */
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2); /* Indigo focus ring */
}
label.form-label { /* Added class for specificity */
    display: block;
    margin-bottom: 0.375rem; /* Tailwind's mb-1.5 */
    font-size: 0.875rem; /* Tailwind's text-sm */
    font-weight: 500; /* Tailwind's font-medium */
    color: #4b5563; /* Tailwind's text-gray-600 */
}
.form-hint { /* For text like "Max 10MB pro Bild" */
    font-size: 0.75rem; /* Tailwind's text-xs */
    color: #6b7280; /* Tailwind's text-gray-500 */
    margin-top: 0.25rem;
}


/* Thumbnails & Gallery */
.gallery-grid { /* Replaces inline grid classes for the gallery container */
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)); /* Tailwind's grid-cols-2 */
    gap: 1.5rem; 
    align-items: start;
}
@media (min-width: 640px) { /* Tailwind's sm breakpoint */
    .gallery-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
@media (min-width: 768px) { /* Tailwind's md breakpoint */
    .gallery-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}
@media (min-width: 1024px) { /* Tailwind's lg breakpoint */
    .gallery-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }
}
.gallery-placeholder-text { /* For "Lade Fotos..." or "Noch keine Fotos hier." */
    grid-column: 1 / -1; /* Span all columns */
    text-align: center;
    padding: 2rem 0; /* Tailwind's py-8 */
    color: #6b7280; /* Tailwind's text-gray-500 */
}

.thumbnail-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.07);
    cursor: pointer;
    aspect-ratio: 1 / 1; /* Square thumbnails */
    background-color: #f3f4f6; /* Placeholder bg */
    width: 100%;
}
.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}
.thumbnail-item:hover img {
    transform: scale(1.05);
}
.thumbnail-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.55);
    color: white;
    padding: 0.5rem;
    font-size: 0.75rem;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none; /* So it doesn't interfere with checkbox click */
}
.thumbnail-item:hover .thumbnail-overlay {
    opacity: 1;
}

/* Loader */
.loader {
    border: 4px solid #e5e7eb; /* Tailwind's border-gray-200 */
    border-radius: 50%;
    width: 24px; /* Slightly smaller */
    height: 24px;
    animation: spin 1s linear infinite;
    display: inline-block;
    vertical-align: middle;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Progress Bar */
.progress-bar-container {
    width: 100%;
    background-color: #e5e7eb; /* Tailwind's bg-gray-200 */
    border-radius: 4px;
    margin-top: 0.5rem;
    display: none; /* Hidden by default */
    overflow: hidden;
}
.progress-bar {
    width: 0%;
    height: 10px;
    text-align: center;
    line-height: 10px;
    color: white;
    font-size: 8px;
    transition: width 0.3s ease;
}

/* Notification Bar */
.notification-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    color: white;
    text-align: center;
    padding: 0.875rem 1rem;
    z-index: 1000;
    display: none; /* Hidden by default */
    font-size: 0.875rem; /* Tailwind's text-sm */
    font-weight: 500;
}
.notification-bar.bg-green-500 { background-color: #22c55e; }
.notification-bar.bg-red-500 { background-color: #ef4444; }
.notification-bar.bg-blue-500 { background-color: #3b82f6; }


/* === Custom File Upload Button Styles === */
.file-upload-input {
    display: none;
}
.file-upload-btn {
    display: inline-flex;
    justify-content: center;
    width: auto;
    cursor: pointer;
}


/* === PAGE-SPECIFIC STYLES === */

/* --- Index Page Specific Styles (body.page-index already defined) --- */
.page-index .main-card .btn-primary { 
    background-color: #4a5568; 
    padding: 0.75rem 1.5rem;
    display: flex; /* Use flex to align icon and text */
    width: 100%;
    margin-bottom: 1rem;
    justify-content: center; /* Center content horizontally */
}
.page-index .main-card .btn-primary:last-child {
    margin-bottom: 0;
}
.page-index .main-card .btn-primary:hover {
    background-color: #2d3748; 
}
.page-index .header-image { 
    width: 150px;
    height: 150px;
    border-radius: 50%;
    object-fit: cover;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 1.5rem;
    border: 4px solid white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* --- General Photos Page Specific Styles --- */
.page-general .btn-primary {
    background-color: #3b82f6;
}
.page-general .btn-primary:hover {
    background-color: #2563eb;
}
.page-general .form-input:focus, .page-general .form-textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}
.page-general .loader {
    border-top-color: #3b82f6; 
}
.page-general .progress-bar {
    background-color: #22c55e;
}

/* --- Photo Game Page Specific Styles --- */
.page-photogame .btn-primary {
    background-color: #8b5cf6;
}
.page-photogame .btn-primary:hover {
    background-color: #7c3aed;
}
.page-photogame .form-input:focus, .page-photogame .form-textarea:focus {
    border-color: #8b5cf6; 
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}
.page-photogame .loader {
    border-top-color: #8b5cf6;
}
.page-photogame .progress-bar {
    background-color: #8b5cf6;
}

.photogame-assignment-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(245, 243, 255, 0.95); /* Lighter, purple-tinted background */
    color: #5b21b6; /* Darker purple text */
    padding: 0.75rem;
    font-size: 0.875rem; /* text-sm */
    font-weight: 600; /* font-semibold */
    text-align: center;
    z-index: 5; /* Sit below checkbox but above image */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1; /* Always visible */
    pointer-events: none; /* Allow clicks to pass through to the image */
    transition: opacity 0.3s ease-in-out;
}
.thumbnail-item:hover .photogame-assignment-overlay {
    opacity: 0; /* Hide assignment on hover to see the image */
}


/* --- Photo Booth Page Specific Styles --- */
.page-photobooth .btn-primary {
    background-color: #10b981;
}
.page-photobooth .btn-primary:hover {
    background-color: #059669;
}
.page-photobooth .loader {
    border-top-color: #10b981;
}
.page-photobooth .thumbnail-overlay {
    background: rgba(0,0,0,0.3); 
    padding: 0.4rem;
    font-size: 0.7rem;
}

/* --- Password Modal --- */
#passwordModal .btn-primary {
    background-color: #4a5568; /* Match index page buttons */
}
#passwordModal .btn-primary:hover {
    background-color: #2d3748;
}
#passwordModal .form-input:focus {
    border-color: #4a5568;
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.3);
}

/* Modal Styles (from utils.js, now centralized) */
#imageModal {
    background-color: rgba(0,0,0,0.75);
}
#imageModal .modal-content-area {
    background-color: white;
    padding: 0.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    max-width: 56rem;
    max-height: 90vh;
    position: relative;
    display: flex;
    flex-direction: column;
}
#imageModal img#modalImage {
    max-width: 100%;
    max-height: calc(90vh - 120px); /* Adjust based on button/details height */
    object-fit: contain;
    border-radius: 0.25rem;
}
#imageModal button#modalClose {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background-color: #4b5563;
    color: white;
    border-radius: 9999px;
    padding: 0.375rem;
}
#imageModal button#modalClose:hover {
    background-color: #1f2937;
}
#imageModal #modalDetails {
    padding: 0.5rem 0.25rem;
    margin-top: 0.5rem;
    text-align: center;
    font-size: 0.875rem;
    color: #4b5563;
}
/* Style for assignment text within the modal */
#imageModal #modalDetails .photo-game-assignment {
    color: #7c3aed;
    font-size: 1.125rem; /* text-lg */
    font-weight: 600;
    margin-bottom: 0.75rem; /* space below assignment */
    padding: 0.75rem;
    background-color: #f5f3ff;
    border-radius: 0.375rem;
    border: 1px solid #ddd6fe;
}
#imageModal .modal-actions {
    margin-top: 0.75rem;
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}
#imageModal .modal-actions #modalDownload {
    background-color: #3b82f6;
}
#imageModal .modal-actions #modalDownload:hover {
    background-color: #2563eb;
}

/* === Responsive Adjustments for Mobile === */
@media (max-width: 768px) {
    /* Target the container for the gallery title and refresh button */
    .gallery-section .flex.justify-between.items-center {
        flex-direction: column;   /* Stack the title and button vertically */
        align-items: flex-start;  /* Align both to the left */
        gap: 1rem;                /* Add space between the title and button */
    }

    /* Target all bulk action button containers (general, photogame, etc.) */
    [id^="bulkActionContainer"] {
        padding-top: 0.5rem;       /* Add padding on top */
        padding-bottom: 0.5rem;    /* Add padding on the bottom */
        text-align: left;        /* Override the default "text-right" */
        display: flex;
        flex-direction: column;  /* Stack the buttons vertically */
        gap: 0.5rem;            /* Add space between each button */
    }

    /* Style the individual buttons within the bulk action container */
    [id^="bulkActionContainer"] .btn {
        margin-right: 0;         /* Remove the right margin on buttons */
        width: 100%;             /* Make each button take the full width */
    }
    
    /* NEW: Ensure exit button is stacked nicely on mobile */
    [id^="bulkActionContainer"] .btn-exit-selection {
        margin-top: 0;
        order: -1; /* Place the exit button at the top of the stack */
    }
    #adminUploadBtn {
        display: none;
    }
}

/* === Collapsible Section Header Styles === */
.collapsible-header {
    cursor: pointer;
    position: relative;
    user-select: none;
}
/*
.collapsible-header::after {
    content: '▼';
    font-size: 1rem;
    color: #6b7280;
    position: absolute;
    right: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.2s ease-in-out;
}
.collapsible-header.collapsed::after {
    transform: translateY(-50%) rotate(-90deg);
}
*/

/* Reduces the large white space when an upload section is collapsed */
.collapsible-header.collapsed {
    margin-bottom: 0;
}

/* === BUGFIX & REFINEMENT for Selection Mode Styles === */

/* --- Default hidden state for the checkbox --- */
.photo-select-checkbox {
    display: none; /* Hide it completely by default */
    position: absolute;
    z-index: 10;
    cursor: pointer;
}

/* --- Mouse Behavior --- */
/* On mouse devices, show checkbox on hover or when selected */
.mouse-device .thumbnail-item:hover .photo-select-checkbox,
.mouse-device .thumbnail-item.is-selected .photo-select-checkbox {
    display: block;
    top: 0.5rem;
    right: 0.5rem;
    height: 1.25rem;
    width: 1.25rem;
}
/* Style the selection overlay for mouse devices */
.mouse-device .thumbnail-item.is-selected::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(59, 130, 246, 0.2); /* Lighter, less intrusive overlay */
    z-index: 1;
    pointer-events: none;
}

/* --- Touch Behavior --- */
/* On touch devices, only show the checkbox when selection mode is active on the body */
body.selection-mode-active.touch-device .photo-select-checkbox {
    display: block;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    height: 2.5rem; /* Larger touch target */
    width: 2.5rem;
    border-radius: 50%;
    border: 2px solid white;
    background-color: rgba(0,0,0,0.3);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
/* Style the checkmark for touch devices */
body.selection-mode-active.touch-device .photo-select-checkbox:checked::after {
    content: '✔';
    display: block;
    color: white;
    font-size: 1.5rem;
    line-height: 2.5rem; /* Vertically center */
    text-align: center;
}
/* Style the checkbox's checked state for touch devices */
body.selection-mode-active.touch-device .photo-select-checkbox:checked {
    background-color: rgba(59, 130, 246, 0.7);
    border-color: white;
}
/* Style the selection overlay for touch devices */
.touch-device .thumbnail-item.is-selected::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(59, 130, 246, 0.5); /* Blue overlay */
    z-index: 1;
    pointer-events: none;
}

/* --- General Selection State Adjustments --- */
/* Hide overlays when any item is selected to avoid visual clutter */
.thumbnail-item.is-selected .thumbnail-overlay,
.thumbnail-item.is-selected .photogame-assignment-overlay {
    opacity: 0 !important;
}
/* Disable hover zoom effect when selection mode is active */
body.selection-mode-active .thumbnail-item:hover img {
    transform: none;
}

/* --- Exit Button --- */
.btn-exit-selection {
    background-color: #6b7280;
    color: white;
}
.btn-exit-selection:hover {
    background-color: #4b5563;
}
