/* =========================================
   1. CORE STYLES & TYPOGRAPHY
   ========================================= */
:root {
    --primary-maroon: #800000;
    --dark-maroon: #5c0000;
    --accent-gray: #2c2c2c;
    --light-gray: #f4f6f8;
    --text-dark: #333;
    --text-light: #666;
    --white: #ffffff;
    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: 'Segoe UI', 'Roboto', Helvetica, Arial, sans-serif;
    background-color: var(--light-gray);
    color: var(--text-dark);
    margin: 0;
    padding: 0;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.container { 
    max-width: 1200px; 
    margin: 0 auto; 
    padding: 30px 20px; 
    box-sizing: border-box; 
}

/* =========================================
   2. HEADER & NAVIGATION
   ========================================= */
.header {
    background: var(--white);
    padding: 15px 40px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    border-top: 4px solid var(--primary-maroon);
}

.header h2 {
    margin: 0;
    color: var(--primary-maroon);
    font-size: 1.5rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* =========================================
   3. LOGIN PAGE
   ========================================= */
.login-container {
    max-width: 400px;
    margin: 100px auto;
    background: var(--white);
    padding: 50px;
    border-radius: 8px;
    box-shadow: var(--shadow-hover);
    text-align: center;
    border-top: 5px solid var(--primary-maroon);
}

.login-container h1 { margin-bottom: 30px; color: var(--text-dark); font-weight: 800; letter-spacing: -0.5px; }

.login-container input {
    width: 100%; padding: 14px 15px; margin: 10px 0;
    border: 1px solid #e2e8f0; border-radius: 6px;
    box-sizing: border-box; font-size: 16px;
    background: #f8fafc;
    transition: all 0.2s ease;
}

.login-container input:focus { 
    border-color: var(--primary-maroon); 
    background: var(--white); 
    outline: none; 
    box-shadow: 0 0 0 3px rgba(128, 0, 0, 0.1); 
}

.login-container button {
    width: 100%; padding: 14px; margin-top: 25px;
    background: var(--primary-maroon); 
    color: var(--white); border: none;
    border-radius: 6px; font-size: 16px; font-weight: 700;
    cursor: pointer; transition: background 0.3s;
    text-transform: uppercase; letter-spacing: 1px;
}

.login-container button:hover { background: var(--dark-maroon); }

/* =========================================
   4. PROVINCE DASHBOARD (Professional Card)
   ========================================= */
.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 30px;
    margin-top: 30px;
}

.card {
    background: var(--white);
    border-radius: 12px;
    overflow: hidden; 
    box-shadow: var(--shadow-soft);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
}

.card:hover { 
    transform: translateY(-5px); 
    box-shadow: var(--shadow-hover); 
    border-color: #cbd5e1;
}

.card h4 {
    margin: 0;
    padding: 20px;
    background: var(--white);
    color: var(--text-dark);
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #f1f5f9;
    text-align: center;
}

.preview-img {
    width: 100%;
    height: 220px; 
    object-fit: cover;
    display: block;
    background: #e2e8f0;
    border-bottom: 1px solid #f1f5f9;
}

.status-text {
    font-size: 0.85rem; font-weight: 600;
    color: var(--text-light); 
    margin: 15px 0 5px 0; 
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card button {
    margin: 0 20px 20px 20px; 
    width: calc(100% - 40px);
}

.action-btn {
    background: var(--accent-gray); color: var(--white);
    padding: 12px; border: none;
    border-radius: 6px; cursor: pointer; font-weight: 600;
    transition: all 0.2s;
    text-transform: uppercase;
    font-size: 0.9rem;
}

.action-btn:hover { background: #000; }
.action-btn:disabled { background: #e2e8f0; color: #a0aec0; cursor: not-allowed; }

/* =========================================
   5. JUDGE & ADMIN DASHBOARD TABLES
   ========================================= */
/* New Class for Vertical Stacking of Result Tables */
.results-stack {
    display: flex;
    flex-direction: column;
    gap: 30px; /* Space between the full-width tables */
    margin-top: 20px;
}

.section-container {
    background: var(--white);
    padding: 30px;
    border-radius: 12px;
    margin-bottom: 30px;
    box-shadow: var(--shadow-soft);
    border-left: 5px solid var(--primary-maroon);
    overflow-x: auto;
}

.section-title {
    margin-top: 0;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 15px;
    color: var(--primary-maroon);
    font-size: 1.25rem;
    display: flex; align-items: center; gap: 12px;
    font-weight: 700;
}

.judge-table { width: 100%; border-collapse: collapse; margin-top: 20px; min-width: 600px; }

.judge-table th {
    text-align: left; padding: 16px;
    background: #f8fafc; color: var(--text-dark);
    font-weight: 700; font-size: 0.9rem;
    text-transform: uppercase; letter-spacing: 0.5px;
    border-bottom: 2px solid #e2e8f0;
}

.judge-table td {
    padding: 16px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    color: #4a5568;
}

.judge-table tr:hover td { background-color: #f8fafc; }
.judge-table tr:last-child td { border-bottom: none; }

.view-entries-btn {
    background: var(--primary-maroon); color: var(--white);
    padding: 8px 16px; border-radius: 4px;
    border: none; cursor: pointer; font-size: 0.85rem;
    font-weight: 600; white-space: nowrap;
    transition: background 0.2s;
}
.view-entries-btn:hover { background: var(--dark-maroon); }
.btn-disabled { background: #e2e8f0 !important; color: #a0aec0 !important; cursor: not-allowed; }

/* =========================================
   6. VIDEO GRID
   ========================================= */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 30px;
}

.video-card {
    background: var(--white);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
    transition: transform 0.3s;
    border: 1px solid #e2e8f0;
}
.video-card:hover { 
    transform: translateY(-5px); 
    box-shadow: var(--shadow-hover); 
    border-color: var(--primary-maroon); 
}

.video-thumb-container {
    position: relative;
    width: 100%; height: 160px;
    background: #000;
    cursor: pointer;
    overflow: hidden;
}

.video-thumb {
    width: 100%; height: 100%;
    object-fit: cover;
    opacity: 0.8;
    transition: opacity 0.3s, transform 0.5s;
}
.video-thumb-container:hover .video-thumb { opacity: 0.5; transform: scale(1.05); }

.play-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: var(--white); font-size: 3rem;
    text-shadow: 0 4px 10px rgba(0,0,0,0.5);
    pointer-events: none;
}

.video-info { 
    padding: 15px; text-align: center; 
    font-weight: 700; color: var(--text-dark); 
    background: var(--white);
}

/* =========================================
   7. MODALS
   ========================================= */
.modal {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.75);
    display: flex; justify-content: center; align-items: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
    padding: 20px;
    box-sizing: border-box;
}

.modal-content {
    background: var(--white); padding: 40px;
    border-radius: 12px; width: 100%; max-width: 550px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border-top: 5px solid var(--primary-maroon);
    position: relative;
    max-height: 90vh; overflow-y: auto;
}
.large-modal { max-width: 900px; }

.modal-footer {
    margin-top: 30px; padding-top: 20px;
    border-top: 1px solid #e2e8f0;
    display: flex; justify-content: flex-end; gap: 15px;
    flex-wrap: wrap;
}

.cancel-btn {
    background: #f1f5f9; color: var(--text-dark);
    padding: 12px 24px; border-radius: 6px;
    border: 1px solid #e2e8f0; cursor: pointer; font-weight: 600;
    transition: background 0.2s;
}
.cancel-btn:hover { background: #e2e8f0; }

.submit-vote-btn {
    background: var(--primary-maroon); color: var(--white);
    padding: 12px 30px; border-radius: 6px;
    border: none; cursor: pointer; font-weight: 700;
    transition: background 0.2s;
}
.submit-vote-btn:hover { background: var(--dark-maroon); }
.submit-vote-btn:disabled { background: #cbd5e1; cursor: not-allowed; }

/* BOOK MODAL (Immersive) */
.book-modal {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(20, 20, 20, 0.98);
    display: flex; justify-content: center; align-items: center;
    z-index: 2100;
    padding: 20px;
    box-sizing: border-box;
}

.book-content {
    display: flex;
    width: 100%; max-width: 1200px; height: 85vh;
    background: #1a1a1a;
    border-radius: 16px; overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
    flex-direction: row;
}

.book-left {
    flex: 2;
    background: #000;
    position: relative;
    display: flex; justify-content: center; align-items: center;
    overflow: hidden;
}
.book-left img { 
    max-width: 100%; max-height: 100%; 
    object-fit: contain; 
}

.nav-arrow {
    position: absolute; top: 50%; transform: translateY(-50%);
    background: rgba(255,255,255,0.1); color: white;
    border: none; padding: 20px; font-size: 24px;
    cursor: pointer; transition: 0.3s;
    z-index: 10; border-radius: 50%;
}
.nav-arrow:hover { background: rgba(128, 0, 0, 0.8); } 
.nav-prev { left: 20px; }
.nav-next { right: 20px; }

.book-right {
    flex: 1; min-width: 350px;
    background: #f8fafc;
    padding: 40px;
    display: flex; flex-direction: column;
    overflow-y: auto;
}

.book-header {
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 20px; margin-bottom: 25px;
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 10px;
}
.book-header h3 { margin: 0; font-size: 1.5rem; color: var(--text-dark); }
.book-category-badge {
    background: var(--primary-maroon); color: white;
    padding: 6px 15px; border-radius: 20px;
    font-size: 0.85rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px;
}

/* Range Sliders */
.range-container { margin-bottom: 30px; }
.range-label {
    display: flex; justify-content: space-between;
    font-weight: 700; margin-bottom: 10px; color: var(--text-dark); font-size: 0.95rem;
}
.range-input {
    width: 100%; --webkit-appearance: none;
    height: 6px; background: #cbd5e1; border-radius: 5px; outline: none;
}
.range-input::-webkit-slider-thumb {
    -webkit-appearance: none; width: 24px; height: 24px;
    border-radius: 50%; background: var(--primary-maroon);
    cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform 0.1s;
}
.range-input::-webkit-slider-thumb:hover { transform: scale(1.1); }

.book-footer {
    margin-top: auto; padding-top: 25px;
    border-top: 1px solid #e2e8f0;
    display: flex; justify-content: space-between; gap: 15px;
    flex-wrap: wrap;
}
.book-cancel { 
    background: white; color: var(--text-dark); 
    border: 1px solid #cbd5e1; 
    padding: 12px 24px; border-radius: 6px; 
    cursor: pointer; font-weight: 600; flex: 1;
}
.book-submit { 
    background: var(--primary-maroon); color: white; 
    border: none; flex: 2;
    padding: 12px; border-radius: 6px; 
    cursor: pointer; font-weight: 700;
    font-size: 1.1rem;
    transition: background 0.3s;
}
.book-submit:hover { background: var(--dark-maroon); }
.book-submit:disabled { background: #cbd5e1; cursor: not-allowed; }

/* =========================================
   8. ADMIN PANEL STYLES
   ========================================= */
.admin-body { display: flex; height: 100vh; overflow: hidden; background: #e2e8f0; }

.admin-sidebar {
    width: 280px; background: #1a202c; /* Darker Gray */
    color: white; padding: 30px;
    display: flex; flex-direction: column; flex-shrink: 0;
    box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    z-index: 10;
}

.admin-sidebar h2 { color: #fff; border-bottom: 1px solid #2d3748; padding-bottom: 25px; margin-top: 0; font-size: 1.4rem; }
.user-info { color: var(--primary-maroon); font-weight: bold; margin-bottom: 30px; font-size: 1.1rem; }

.admin-sidebar nav a {
    display: block; color: #a0aec0;
    text-decoration: none; padding: 14px 10px;
    margin-bottom: 8px; border-radius: 6px;
    transition: 0.2s; font-weight: 500;
}
.admin-sidebar nav a:hover { 
    background: var(--primary-maroon);
    color: white; 
    transform: translateX(5px);
}

.admin-main { flex: 1; padding: 30px; overflow-y: auto; }

.admin-section {
    background: white; padding: 30px;
    border-radius: 12px; margin-bottom: 30px;
    box-shadow: var(--shadow-soft);
}
.admin-section h3 { margin-top: 0; border-bottom: 1px solid #e2e8f0; padding-bottom: 15px; color: #2d3748; }

/* Controls */
.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 25px;
}
.control-card {
    background: #f8fafc; padding: 20px;
    border-radius: 8px; border: 1px solid #e2e8f0; text-align: center;
}
.highlight-card { border: 2px solid var(--primary-maroon); background: #fff5f5; }

.toggle-btn {
    margin-top: 15px; width: 100%; padding: 12px;
    border: none; border-radius: 6px; font-weight: bold; cursor: pointer;
    font-size: 0.9rem;
}
.btn-on { background: #27ae60; color: white; }
.btn-off { background: #e53e3e; color: white; }

/* Criteria Setup */
.criteria-group {
    background: #f8fafc; border: 1px solid #e2e8f0;
    padding: 20px; border-radius: 8px; margin-bottom: 20px;
}
.criteria-item { display: flex; gap: 15px; margin-bottom: 15px; flex-wrap: wrap; }
.criteria-item input { flex: 1; min-width: 150px; padding: 10px; border: 1px solid #cbd5e1; border-radius: 6px; }
.add-btn { background: #4a5568; color: white; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; margin-top: 10px; }
.save-btn { background: var(--primary-maroon); color: white; border: none; padding: 14px; width: 100%; border-radius: 6px; cursor: pointer; font-weight: bold; margin-top: 15px; }

/* Leaderboard */
.leaderboard-container { overflow-x: auto; }
.leaderboard-container table { width: 100%; border-collapse: collapse; margin-top: 15px; min-width: 600px; }
.leaderboard-container th { text-align: left; background: #2d3748; color: white; padding: 15px; }
.leaderboard-container td { padding: 15px; border-bottom: 1px solid #e2e8f0; }
.leaderboard-container tr:first-child { background: #fffbeb; font-weight: bold; border-left: 5px solid #d4af37; }

/* =========================================
   9. LIVE PREVIEW PAGE (Photocard Style)
   ========================================= */
.live-body {
    background: #000;
    overflow: hidden; 
    height: 100vh;
    width: 100vw;
    position: relative;
    font-family: 'Montserrat', sans-serif;
}

.video-background {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0;
    z-index: -1; overflow: hidden;
}
#bgVideo { width: 100%; height: 100%; object-fit: cover; }
.video-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(to top, rgba(92, 0, 0, 0.95) 0%, rgba(0,0,0,0.4) 60%);
}

.live-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 10;
    padding-bottom: 20px;
}

.live-header { text-align: center; margin-bottom: 2vh; flex-shrink: 0; }
.live-header h1 {
    color: #fff; font-size: 3.5vw; margin: 0;
    text-transform: uppercase; text-shadow: 0 4px 15px rgba(0,0,0,0.8);
    letter-spacing: 3px; border-bottom: 4px solid #d4af37;
    display: inline-block; padding-bottom: 10px;
}
.live-subtitle {
    color: #ddd; font-size: 1.8vw; margin-top: 10px;
    letter-spacing: 2px; font-weight: 300; text-transform: uppercase;
}

/* PODIUM PHOTOCARDS */
.podium-container {
    display: flex; justify-content: center; align-items: flex-end;
    gap: 30px; width: 95%; max-width: 1400px;
    height: 65vh; perspective: 1000px;
}

.rank-card {
    background: #fff; /* White Photo Border */
    padding: 12px 12px 60px 12px; /* Bottom padding for Polaroid look */
    border-radius: 4px;
    width: 25%; max-width: 320px;
    height: 75%; /* Height relative to container */
    position: relative;
    display: flex; flex-direction: column;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    transition: all 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
    transform-origin: bottom center;
}

.rank-1 {
    width: 30%; max-width: 400px; height: 90%;
    z-index: 5; 
    border: 4px solid #d4af37; /* Gold rim */
    box-shadow: 0 0 80px rgba(212, 175, 55, 0.6);
    order: 2; /* Center */
}

.podium-container .rank-card:nth-child(1) { order: 2; }
.podium-container .rank-card:nth-child(2) { order: 1; }
.podium-container .rank-card:nth-child(3) { order: 3; }

.card-image { 
    flex: 1; width: 100%; 
    overflow: hidden; position: relative; 
    background: #000; border: 1px solid #eee;
}
.card-image img { 
    width: 100%; height: 100%; 
    object-fit: cover; object-position: top center; 
}

/* Rank Badge */
.rank-badge {
    position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
    background: var(--primary-maroon); color: white;
    width: 50px; height: 50px; border-radius: 50%;
    display: flex; justify-content: center; align-items: center;
    font-size: 1.8rem; font-weight: bold;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    z-index: 10; border: 3px solid #fff;
}
.rank-1 .rank-badge { 
    background: #d4af37; width: 70px; height: 70px; 
    font-size: 3rem; top: -35px; color: #000; 
}

.card-info { text-align: center; padding-top: 15px; color: #222; }
.province-name { 
    margin: 0; font-size: 1.6rem; font-weight: 900; 
    text-transform: uppercase; font-family: 'Segoe UI Condensed', sans-serif;
    line-height: 1.1; letter-spacing: -0.5px;
}
.province-score { 
    color: var(--primary-maroon); font-size: 1.4rem; 
    font-weight: 800; margin-top: 5px; 
}
.rank-1 .province-score { color: #d4af37; font-size: 1.8rem; text-shadow: 0 1px 0 #000; }

.live-nav {
    position: fixed; top: 50%; transform: translateY(-50%);
    background: rgba(255,255,255,0.1); color: white;
    border: none; font-size: 3rem; padding: 20px;
    cursor: pointer; z-index: 100; transition: 0.3s;
    border-radius: 50%;
}
.live-nav:hover { background: rgba(128,0,0,0.8); transform: translateY(-50%) scale(1.1); }
.live-prev { left: 30px; } .live-next { right: 30px; }

/* Responsive Media Queries */
@media (max-width: 900px) {
    .login-container { width: 90%; padding: 30px; }
    .book-content { flex-direction: column; height: 95vh; }
    .book-left { height: 40%; }
    .book-right { height: 60%; min-width: auto; padding: 20px; }
    .admin-body { flex-direction: column; height: auto; overflow: auto; }
    .admin-sidebar { width: 100%; padding: 20px; box-sizing: border-box; }
    
    /* Live Page Mobile */
    .live-header h1 { font-size: 2rem; }
    .podium-container { flex-direction: column; align-items: center; height: auto; padding-top: 20px; }
    .rank-card { width: 80%; height: auto; aspect-ratio: 3/4; margin-bottom: 30px; order: unset !important; }
    .rank-1 { width: 90%; height: auto; order: unset !important; }
    .live-nav { font-size: 1.5rem; width: 50px; height: 50px; padding: 10px; }
}

@media (max-width: 480px) {
    .header { padding: 10px 20px; flex-direction: column; gap: 10px; }
    .grid-container { grid-template-columns: 1fr; }
    .card h4 { font-size: 1rem; }
    .modal-content { padding: 25px; }
    .judge-table th, .judge-table td { padding: 10px; font-size: 0.8rem; }
    .view-entries-btn { padding: 6px 12px; font-size: 0.8rem; }
    .range-label { flex-direction: column; }
}

/* Semi-Admin Landscape View: Side-by-Side */
.results-row {
    display: flex;
    gap: 20px;
    width: 100%;
    margin-bottom: 20px;
}

.results-row .section-container {
    flex: 1; /* Take equal width */
    margin-bottom: 0; /* Remove bottom margin in row */
}

/* Compact Table for Side-by-Side */
.compact-table table {
    min-width: auto; /* Allow shrinking */
    width: 100%;
}
.compact-table th, .compact-table td {
    padding: 10px 5px; /* Tighter padding */
    font-size: 0.85rem;
}

/* Admin Vertical Stack View */
.results-stack {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.results-stack-item {
    background: #f8fafc;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.results-stack-item table {
    width: 100%;
    border-collapse: collapse;
}

/* Responsive Results */
@media (max-width: 900px) {
    .results-row {
        flex-direction: column; /* Stack on mobile */
    }
}