/* General Body Styles */
html {
    scrollbar-gutter: stable;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f2f5;
    margin: 0;
    color: #333;
    min-height: 100vh;
}

/* App Container - Mobile First */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: #fff;
    position: relative;
}

/* Sidebar Styles */
.sidebar {
    position: static;
    width: 100%;
    height: auto;
    background-color: transparent;
    z-index: 100;
    overflow: hidden;
    display: block;
    margin-top: 16px; /* Added spacing from hero */
    margin-bottom: 10px;
    padding: 0;
}

.sidebar-content {
    height: auto;
    padding: 0;
    background-color: transparent;
    overflow: visible;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding: 0 16px; /* Moved padding here for the header text */
    border-bottom: none;
}


.sidebar-header h2 {
    font-size: 1.1rem;
    margin: 0;
    color: #333;
    font-weight: 600;
}

/* Hero Section - Default/Mobile */
.hero-section {
    background: linear-gradient(135deg, #0d1b2a 0%, #1b263b 100%);
    color: white;
    padding: 24px 16px;
    border-radius: 0;
    margin-bottom: 0;
    text-align: center;
}

.hero-content h2 {
    font-size: 1.5rem;
    margin: 0 0 8px 0;
}

.hero-content p {
    font-size: 0.95rem;
    margin: 0;
    opacity: 0.9;
}

/* Search Section - Default/Mobile */
.search-section {
    padding: 0; /* Align with main content */
}

.search-header {
    display: none; /* Hide redundant "Search" title on mobile */
}

.search-controls {
    display: flex;
    gap: 8px;
    width: 100%;
}

#search-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 1rem;
    height: 48px; /* Explicit height match */
}

#search-btn {
    height: 48px; /* Explicit height match */
    white-space: nowrap;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Video List - Horizontal Scrolling (Default/Mobile) */
.video-list {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    gap: 16px;
    padding: 0 16px 10px 16px; /* Added horizontal padding to list items */
    /* Hide scrollbar for cleaner look if desired, but functionality first */
}


.video-item {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s, box-shadow 0.3s, transform 0.2s;
    overflow: hidden;
    min-width: 200px;
    flex: 0 0 auto;
    flex-shrink: 0;
}

#video-player-container:empty::before {
    display: flex;
}

.video-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-4px);
}

.video-item.selected {
    background: #fff;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Specific text color for selected to ensure readability against light blue */
.video-item.selected .video-info h5 {
    color: #007bff;
}

.video-thumbnail-container {
    width: 100%;
    height: 140px;
    /* approx 16:9 ratio */
    position: relative;
    background: #000;
}

.video-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-thumbnail-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #343a40;
    color: #868e96;
    font-size: 2rem;
}

.video-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 0.75rem;
    padding: 3px 6px;
    border-radius: 4px;
}

.video-info {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.video-info h5 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    /* Compatibility */
    color: #333;
}

.status-badge {
    align-self: flex-start;
    font-size: 0.7rem;
    padding: 2px 8px;
    background-color: #e9ecef;
    border-radius: 12px;
    color: #666;
}

/* Video Player */
#video-player-container {
    width: 100%;
    max-width: 1066px;
    /* YouTube-like size */
    aspect-ratio: 16 / 9;
    width: 100%;
    margin: 0 auto;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
    position: relative;
}

video {
    width: 100%;
    display: block;
    border-radius: 10px;
}

/* Video Details */
#video-details-container {
    background: #f8f9fa;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

#video-details-container h4 {
    margin: 0 0 8px 0;
    color: #333;
}

#video-details-container p {
    margin: 4px 0;
    font-size: 0.9rem;
    color: #666;
}

/* Buttons */
.primary-btn {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.3s;
    font-size: 1rem;
    font-weight: 500;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
}

.primary-btn:active {
    transform: translateY(0);
}

.icon-btn {
    background: #007bff;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background-color 0.3s, transform 0.2s;
}

.icon-btn:hover {
    background: #0056b3;
    transform: scale(1.05);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: #fefefe;
    margin: 10% auto;
    padding: 24px;
    border: none;
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-content h3 {
    margin: 0 0 20px 0;
    color: #333;
}

.modal-content input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 16px;
    box-sizing: border-box;
}

.close-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.close-btn:hover,
.close-btn:focus {
    color: #333;
}

/* Play Clip Button */
.play-clip-btn {
    background: linear-gradient(135deg, #28a745 0%, #218838 100%);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    margin-left: 10px;
    transition: transform 0.2s, box-shadow 0.3s;
}

.play-clip-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(40, 167, 69, 0.3);
}

/* Search Result Item */
.search-result-item {
    padding: 14px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    margin-bottom: 10px;
    transition: box-shadow 0.3s, transform 0.2s;
}

.search-result-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.search-result-item p {
    margin: 4px 0;
}

/* Main Content - Mobile */
.main-content {
    padding: 0 16px 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ========================================
    Desktop Styles (769px and up)
    ======================================== */
@media (min-width: 769px) {
    body {
        display: block; /* Removed flex center alignment that was causing issues */
        overflow-y: auto;
    }

    /* Hide mobile header on desktop */
    .mobile-header {
        display: none;
    }

    /* App Container */
    .app-container {
        display: flex;
        flex-direction: column;
        width: 100%;
        max-width: 1400px;
        min-height: 100vh;
        height: auto;
        border-radius: 0;
        box-shadow: none;
        overflow: visible;
        margin: 0 auto; /* Center the container */
    }

    /* Hero Section */
    .hero-section {
        border-radius: 12px;
        margin: 20px 20px 0 20px;
        padding: 40px 32px;
    }

    .hero-content h2 {
        font-size: 1.8rem;
    }

    .hero-content p {
        font-size: 1.1rem;
    }

    /* Horizontal Video Gallery Section (Tablet default) */
    .sidebar {
        position: static;
        width: auto;
        height: auto;
        border: none;
        background: transparent;
        margin: 0 20px;
        padding: 20px 0;
        border-bottom: 1px solid #dee2e6;
        left: auto; /* Reset mobile styles */
    }

    .sidebar-overlay {
        display: none !important;
    }

    .sidebar-content {
        padding: 0;
        background: transparent;
        overflow: visible;
    }

    .sidebar-header {
        border-bottom: none;
        margin-bottom: 15px;
        padding-bottom: 0;
    }

    .sidebar-header h2 {
        font-size: 1.25rem;
        font-weight: 700;
        color: #333;
    }

    /* Horizontal List for Videos (Tablet default) */
    .video-list {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 15px;
        gap: 16px;
    }

    /* Main Content */
    .main-content {
        padding: 20px 20px 40px 20px; /* More bottom padding */
        gap: 24px;
        overflow: visible;
    }

    .search-section {
        padding: 20px;
    }
}

/* ========================================
    Desktop GRID Layout (1025px and up)
    ======================================== */
@media (min-width: 1025px) {
    .app-container {
        display: grid;
        grid-template-columns: 280px 1fr;
        grid-template-rows: auto auto 1fr; /* Header(hidden), Hero, Main */
        gap: 0 32px; /* Row gap handled by margins, Col gap 32px */
        padding: 0 32px;
        max-width: 1600px;
    }

    /* Hero spans full width */
    .hero-section {
        grid-column: 1 / -1;
        grid-row: 1;
        margin: 20px 0 30px 0;
        padding: 60px 32px;
    }

    /* Sidebar (Gallery) becomes vertical column */
    .sidebar {
        grid-column: 1;
        grid-row: 2;
        position: sticky;
        top: 20px;
        height: calc(100vh - 40px); /* Full height minus margins */
        max-height: 800px;
        overflow-y: auto;
        margin: 0;
        padding: 0;
        border-bottom: none;
        border-right: 1px solid #eee; /* Subtle separator */
        padding-right: 20px;
    }

    .sidebar-content {
        height: auto; /* Let content determine height */
        padding-bottom: 40px;
    }

    /* Vertical List for Videos */
    .video-list {
        display: flex;
        flex-direction: column; /* Stack vertically */
        gap: 16px;
        overflow-x: visible; /* No horizontal scroll */
        padding-bottom: 0;
    }

    .video-item {
        min-width: 0; /* Allow shrinking */
        width: 100%;
    }

    /* Main Content Area */
    .main-content {
        grid-column: 2;
        grid-row: 2;
        padding: 0;
        display: flex;
        flex-direction: column;
        gap: 24px;
        min-height: 50vh; /* Ensure some height even if empty */
        padding-right: 16px; /* Add explicit right padding for visual balance */
    }

    /* Order: Search -> Player -> Details -> Results */
    .search-section {
        order: 1;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        padding-top: 20px;
        padding-bottom: 20px;
        border-bottom: 1px solid #f0f2f5;
        margin: -20px -20px 0 -20px; /* Counteract padding to go full width */
        padding-left: 20px;
        padding-right: 20px;
    }

    #video-player-container {
        order: 2;
        max-width: 100%; /* Use full available column width */
        margin: 0;
    }
    #video-details-container { order: 3; }
    #search-results-container { order: 4; }
}

/* Spinner */
.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    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);
    }
}