/* ==========================================
   1. VARIABLES & RESET
   ========================================== */
:root {
    /* YOUR EXISTING COLORS */
    --primary: #2c3e50;      /* Dark Blue */
    --accent: #3498db;       /* Bright Blue */
    --accent-hover: #2980b9; /* Darker Blue */
    --bg: #f4f7f6;           /* Light Gray Background */
    --card-bg: #ffffff;      /* White */
    --text: #333;            /* Dark Gray Text */
    --text-light: #777;      /* Light Gray Text */
    --border: #ddd;          /* Border Color */
    
    /* NEW: ADMIN & UTILITY COLORS */
    --danger: #e74c3c;       /* Red for delete/errors */
    --success: #2ecc71;      /* Green for success */
    --header-height: 60px;   /* Fixed header height for calculations */
}

/* Global Reset */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-top: var(--header-height); /* Push content down below fixed header */
}

/* ==========================================
   2. HEADER & MOBILE BAR
   ========================================== */
header {
    position: fixed;         /* FIX: Lock header to top */
    top: 0; 
    left: 0;
    width: 100%;
    height: var(--header-height);
    background: var(--primary);
    color: white;
    padding: 0 1rem;         /* Adjusted padding */
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 1000;           /* FIX: Ensure it sits above everything */
}

header h1 {
    margin: 0;
    font-size: 1.3rem;       /* Slightly smaller for better fit */
    cursor: pointer;
    transition: opacity 0.2s;
    line-height: 1;
}

header h1:hover { opacity: 0.8; }

/* User Menu in Header (Login/Logout info) */
.user-menu {
    font-size: 0.9rem;
    display: flex;
    gap: 10px;
    align-items: center;
}
.user-menu a { color: #ecf0f1; text-decoration: none; font-weight: 500; }
.user-menu a:hover { text-decoration: underline; color: white; }

/* Mobile Filter Bar (Hidden on Desktop) */
#mobile-filter-bar {
    display: none;
}

/* ==========================================
   3. SIDEBAR (Filters)
   ========================================== */
aside {
    width: 280px;
    background: white;
    padding: 20px;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    overflow-y: auto; 
    height: calc(100vh - var(--header-height)); /* FIX: Fill only remaining height */
    position: fixed;        /* FIX: Lock sidebar position */
    top: var(--header-height);
    left: 0;
    z-index: 900;
}

aside h3 { margin-top: 0; color: var(--primary); }

aside label {
    display: block;
    margin-top: 15px;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.9rem;
}

aside input[type="text"],
aside select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    background-color: #fff;
}

aside button {
    width: 100%;
    margin-top: 20px;
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

aside button:hover { background: var(--accent-hover); }

/* Toggle Switch */
.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
    padding: 10px 0;
    border-top: 1px solid #eee;
    border-bottom: 1px solid #eee;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px; height: 22px;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px; width: 16px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(18px); }

/* ==========================================
   4. MAIN LAYOUT & GRID
   ========================================== */
.container {
    display: flex;
    flex: 1;
    margin-left: 280px; /* FIX: Push content right to clear fixed sidebar */
    height: 100%;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 0;
    width: 100%;
}

#results-area {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    grid-auto-rows: max-content; 
    gap: 20px;
    padding: 20px;
}

/* ==========================================
   5. CARD STYLES (Kept Original)
   ========================================== */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.card-img-container {
    height: 200px;
    background: #eee;
    overflow: hidden;
    position: relative;
}

.card-img-container img {
    width: 100%; height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.card-img-container:hover img { transform: scale(1.05); }

.card-img-container .badge {
    position: absolute;
    bottom: 5px; right: 5px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 4px;
    font-weight: bold;
}

/* Text Only Placeholder */
.text-only {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    background-color: #e0e0e0;
    color: #95a5a6;
    font-weight: bold;
    font-size: 1.1rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    user-select: none;
}

/* Card Body */
.card-body {
    padding: 15px;
    padding-bottom: 35px;
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.card-meta { font-size: 0.85rem; color: var(--text-light); margin-bottom: 5px; }
.card-title { font-weight: bold; margin-bottom: 5px; color: var(--primary); font-size: 1.1rem; }
.card-desc { font-size: 0.9rem; margin-bottom: 10px; flex: 1; color: #555; }
/* Clickable Metadata & Tags */
.clickable-meta {
    cursor: pointer;
    color: var(--text-light);
    border-bottom: 1px dotted #ccc;
    transition: color 0.2s, border-color 0.2s;
}

.clickable-meta:hover {
    color: var(--accent);
    border-bottom: 1px solid var(--accent);
}
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: auto; }

.tag {
    background: #eff2f5; 
    color: #666; 
    font-size: 0.75rem; 
    padding: 3px 8px; 
    border-radius: 4px;
    cursor: pointer; /* Change to pointer */
    transition: background 0.2s, color 0.2s;
}

.tag:hover {
    background: var(--accent);
    color: white;
}

/* The Subtle Report Link */
.report-text-btn {
    position: absolute;
    bottom: 10px; right: 15px;
    font-size: 0.75rem; color: #bdc3c7;
    cursor: pointer; font-family: monospace;
    transition: color 0.2s; user-select: none; z-index: 5;
}
.report-text-btn:hover { color: #e74c3c; text-decoration: underline; }

/* ==========================================
   6. PAGINATION & LOADING
   ========================================== */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: #fff;
    border-top: 1px solid #ddd;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.pagination-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}
.pagination-btn:disabled { background: #ccc; cursor: not-allowed; }

.pagination-input-group { display: flex; align-items: center; gap: 5px; font-size: 14px; }
.page-input { width: 50px; text-align: center; padding: 5px; border: 1px solid #ddd; border-radius: 4px; }
#limit-select { padding: 6px; border: 1px solid #ccc; border-radius: 4px; cursor: pointer; }

/* Loader */
.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 30px; height: 30px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Back to Top */
#back-to-top {
    display: none;
    position: fixed;
    bottom: 30px; right: 30px;
    z-index: 995;
    border: none;
    background-color: var(--accent);
    color: white;
    cursor: pointer;
    width: 50px; height: 50px;
    border-radius: 50%;
    font-size: 18px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    align-items: center; justify-content: center;
}
#back-to-top:hover { background-color: var(--accent-hover); transform: translateY(-3px); }

/* ==========================================
   7. MODALS
   ========================================== */
.modal {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: #000000;
    align-items: center; justify-content: center;
    flex-direction: column;
}
.modal.active { display: flex; }

.modal-content {
    max-width: 100%; max-height: 80vh;
    object-fit: contain; cursor: grab; user-select: none;
}
.modal-content:active { cursor: grabbing; }

#modal-caption { color: #fff; text-align: center; margin-top: 15px; max-width: 90%; z-index: 3001; }
#modal-caption h4 { margin: 0; font-size: 1.1rem; }
#modal-caption p { margin: 5px 0 0; font-size: 0.9rem; color: #ccc; }

.modal-nav { margin-top: 15px; display: flex; gap: 20px; z-index: 3001; }
.modal-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
}
.modal-btn:hover { background: rgba(255, 255, 255, 0.2); }

.close-modal {
    position: absolute;
    top: 15px; right: 25px;
    color: white;
    font-size: 35px;
    cursor: pointer;
    z-index: 3002;
}

/* Report Modal Styles */
.modal-content-report {
    background-color: #fefefe;
    margin: 10% auto;
    padding: 25px;
    border-radius: 8px;
    width: 90%; max-width: 450px;
    position: relative;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

#report-comment {
    width: 100%; height: 100px;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    resize: vertical;
    font-family: inherit;
}

#submit-report-btn {
    background-color: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}
#submit-report-btn:hover { background-color: #c0392b; }

/* ==========================================
   8. ADMIN & DASHBOARD STYLES (THE NEW STUFF)
   ========================================== */

/* Utility class to reset layout for Admin pages */
body.auto-scroll {
    height: auto !important;
    overflow-y: auto !important;
    display: block !important;
    padding: 0; /* Header spacing is handled inside body now */
}

/* Only apply header padding on Admin pages if needed */
body.auto-scroll header {
    padding-right: 20px;
}

/* Login Wrapper */
.login-wrapper {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: 100px; /* Clear fixed header */
}

.login-box { 
    background: white; 
    padding: 40px; 
    border-radius: 8px; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.1); 
    width: 100%; 
    max-width: 400px; 
}
.login-box input {
    width: 100%;
    margin-bottom: 15px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}
.login-box button {
    width: 100%;
    padding: 10px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* Dashboard Container */
.dash-container { 
    max-width: 900px; 
    margin: 40px auto; 
    margin-top: 100px; /* Clear fixed header */
    background: white; 
    border-radius: 8px; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.1); 
    padding: 20px;
}

/* Dashboard Sections */
.dash-section { 
    margin-bottom: 30px; 
    padding-bottom: 20px; 
    border-bottom: 1px solid #eee; 
}

.dash-section h2 { 
    margin-top: 0; 
    color: var(--primary); 
    border-left: 5px solid var(--accent); 
    padding-left: 10px; 
}

/* Dashboard Forms */
.dash-form {
    display: flex; 
    gap: 10px; 
    align-items: center; 
    flex-wrap: wrap;
}

.dash-form input, .dash-form select {
    padding: 8px; 
    border: 1px solid #ddd; 
    border-radius: 4px;
}

/* Status Boxes */
.success-box { 
    background:#d4edda; color:#155724; padding:15px; 
    margin-bottom:20px; border-radius:4px; border:1px solid #c3e6cb; 
}
.error-box { 
    background:#f8d7da; color:#721c24; padding:15px; 
    margin-bottom:20px; border-radius:4px; border:1px solid #f5c6cb;
}

/* Tables */
.dash-table { width:100%; border-collapse: collapse; margin-top:10px; }
.dash-table th, .dash-table td { padding: 10px; text-align: left; border-bottom: 1px solid #eee; }
.dash-table th { color: var(--text-light); font-size: 0.85rem; text-transform: uppercase; }

/* Buttons */
.btn-danger { background-color: var(--danger) !important; color: white; }
.btn-danger:hover { background-color: #c0392b !important; }
.btn-small { padding: 4px 8px; font-size: 0.8rem; }

/* ==========================================
   9. GUEST PROTECTION
   ========================================== */
body.guest-mode img {
    -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none;   /* Safari */
    user-select: none;           /* Standard */
    pointer-events: auto;        /* Allow clicking */
}

/* ==========================================
   10. RESPONSIVE LOGIC
   ========================================== */
@media screen and (max-width: 768px) {
    
    header h1 { font-size: 1.2rem; }

    /* Reset Layout for Mobile */
    .container { margin-left: 0; display: block; }
    
    /* Mobile Filter Bar (Sticky) */
    #mobile-filter-bar {
        display: block;
        position: sticky;
        top: var(--header-height);
        z-index: 950;
        background-color: var(--primary);
        padding: 10px 15px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    }
    
    #filter-toggle-btn {
        width: 100%;
        background-color: white;
        color: var(--primary);
        border: none;
        padding: 10px;
        border-radius: 4px;
        font-weight: bold;
        font-size: 1rem;
        cursor: pointer;
    }

    /* Sidebar as Drawer */
    aside {
        display: none; /* Hidden by default */
        top: 105px; /* Below header + filter bar */
        width: 100%;
        max-height: calc(100vh - 105px);
        box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
        border-bottom: 4px solid var(--accent);
    }
    aside.active { display: block; }

    /* Results */
    #results-area {
        grid-template-columns: 1fr; /* Single column */
        gap: 15px;
        padding: 15px;
    }
    
    /* Admin Mobile Adjustments */
    .dash-form { flex-direction: column; align-items: stretch; }
    .dash-table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ==========================================
   11. FILTER BUTTONS (Apply vs Reset)
   ========================================== */
.filter-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

/* Base styles for both buttons */
.filter-actions button {
    flex: 1; /* Make them equal width */
    padding: 12px;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.9rem;
    margin-top: 0; /* Override generic sidebar margin */
}

/* Reset Button (Warning Color) */
.btn-reset {
    background-color: #e74c3c; /* Red */
    color: white;
}
.btn-reset:hover {
    background-color: #c0392b;
}

/* Apply Button (Success/Primary Color) */
.btn-apply {
    background-color: var(--success); /* Green */
    color: white;
}
.btn-apply:hover {
    background-color: #27ae60;
}