/* Universal Box Sizing for consistent layout */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Specific styles for video.php */
body {
    font-family: 'Roboto', sans-serif;
    background-color: #f9f9f9;
    margin: 0;
    padding: 0;
    color: #333;
    overflow-x: hidden; /* Prevent horizontal scrolling on body */
}

/* Header styling matching index.php */
header {
    background-color: #ff0000;
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%; /* Ensure header takes full width */
    flex-wrap: wrap; /* Allow header items to wrap on smaller screens */
    gap: 10px; /* Consistent gap for flex items */
}

header .logo h1 {
    margin: 0;
    font-size: 24px;
    flex-shrink: 0; /* Prevent logo from shrinking */
}

header .search-bar {
    display: flex;
    flex-grow: 1;
    max-width: 450px;
    margin: 0 20px;
    flex-basis: 300px;
    min-width: 150px; /* Allow shrinking more on smaller screens */
}

header .search-bar input {
    flex-grow: 1;
    padding: 8px 15px;
    border: 1px solid white; /* Added border to match button */
    border-radius: 20px 0 0 20px;
    outline: none;
    font-size: 16px;
    background-color: white;
    color: black;
    min-width: 0;
}

header .search-bar button {
    background-color: white;
    color: black;
    border: 1px solid white; /* Added border to match input */
    border-left: none;
    padding: 8px 15px;
    border-radius: 0 20px 20px 0;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

header .search-bar button:hover {
    background-color: #f0f0f0; /* Lighter hover for white button */
}

header .user-menu {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: flex-end;
    flex-shrink: 0;
}

header .user-menu span,
header .user-menu a {
    color: white;
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s;
    white-space: nowrap; /* Keep items on one line, allow wrapping of the whole menu */
}

header .user-menu a:hover {
    color: #ccc;
}
/* End Header Styling */

.video-page-layout {
    display: flex;
    padding: 20px;
    gap: 20px;
    max-width: 1340px;
    margin: 0 auto; /* Centered layout */
    align-items: flex-start;
    flex-wrap: wrap;
}

.video-main-content {
    flex: 2;
    min-width: 0;
    flex-basis: 60%;
    max-width: 100%;
}

/* Video Player Container - Adjusted for responsive 16:9 aspect ratio and custom controls */
.video-player-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    height: 0;
    background-color: #000;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    /* Ensure custom controls don't push content out */
    display: flex;
    flex-direction: column;
}

.video-player-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    z-index: 1; /* Ensure video is behind controls overlay */
}

.video-unavailable-placeholder {
    position: absolute; /* Added position absolute */
    top: 0; left: 0; right: 0; bottom: 0; /* Fill container */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #2c3e50;
    color: white;
    font-size: 24px;
    text-align: center;
    min-height: 250px;
    z-index: 2; /* Bring placeholder above video if no source */
}

.video-unavailable-placeholder i {
    margin-top: 10px;
    font-size: 40px;
}

/* Custom Controls Overlay */
.custom-video-controls {
    position: absolute;
    /* Positioned at the top to avoid clashes with native controls at the bottom */
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
    background-color: transparent;
    border: none;
    box-shadow: none;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-top-left-radius: 8px; /* Adjusted radius */
    border-top-right-radius: 8px; /* Adjusted radius */
    border-bottom-left-radius: 0; /* No radius at bottom */
    border-bottom-right-radius: 0; /* No radius at bottom */
}

/* Adjusted hover target to the video player container for controls to appear */
.video-player-container:hover .custom-video-controls,
.video-player-container:focus-within .custom-video-controls { /* Added focus-within for keyboard navigation */
    opacity: 1;
}


.custom-control-button {
    background-color: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background-color 0.2s;
}

.custom-control-button:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.custom-control-button.active { /* For CC button when active */
    background-color: #FF0000;
}
.custom-control-button.active:hover {
    background-color: #cc0000;
}

.video-details {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    margin-top: 20px;
}

.video-details h2 {
    margin-top: 0;
    font-size: 24px;
    color: #030303;
    margin-bottom: 10px;
}

/* NEW: Container for channel info, subscribe, and like/dislike/share buttons */
.channel-actions-line {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Pushes channel info left, buttons right */
    margin-bottom: 15px;
    flex-wrap: wrap; /* Allows wrapping on smaller screens */
    gap: 15px; /* Space between channel-meta-left and like-dislike-share-buttons */
}

.channel-meta-left {
    display: flex;
    align-items: center;
    gap: 8px; /* Gap between avatar, name/subs, and subscribe button */
    flex-wrap: wrap; /* Allow wrapping */
}

.channel-link-group {
    display: flex;
    align-items: center;
    text-decoration: none;
    gap: 5px;
    color: inherit;
    flex-shrink: 0;
}

.channel-name-subscribers {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.video-details .channel-avatar-main {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background-color: #f0f0f0;
}

.video-details strong.channel-name-main {
    color: #030303;
    text-decoration: none;
    font-size: 15px;
    font-weight: bold;
    white-space: nowrap;
}
.video-details strong.channel-name-main a:hover {
    text-decoration: underline;
}

.subscriber-count {
    font-size: 12px;
    color: #606060;
    white-space: nowrap;
}

/* Adjusted subscribe button styling for new placement */
.subscribe-btn-inline {
    background-color: #c00;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.subscribe-btn-inline:hover {
    background-color: #a00;
}

.subscribe-btn-inline.subscribed {
    background-color: #e5e5e5;
    color: #606060;
    font-weight: bold;
}

.subscribe-btn-inline.subscribed:hover {
    background-color: #d0d0d0;
}

.subscribe-btn-inline.disabled {
    background-color: #ccc;
    cursor: not-allowed;
    color: #999;
}
/* End Subscribe button adjustments */

/* NEW: Container for views and date */
.video-info-stats-line {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    border-top: 1px solid #eee;
    padding-top: 15px;
    margin-top: 15px; /* Adjusted margin-top to separate from channel-actions-line */
    flex-wrap: wrap; /* Allows wrapping */
    padding-bottom: 5px;
    color: #606060;
    font-size: 15px;
}

.views-and-date {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 0; /* Remove default paragraph margin */
    white-space: nowrap;
}

.views-count {
    font-weight: bold;
}

.upload-date-text {
    /* Style for the time_elapsed_string */
    font-size: 15px; /* Inherits from parent, but explicitly set for clarity */
    color: #606060;
}


/* Like/Dislike/Share Buttons */
.like-dislike-share-buttons {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.like-btn, .dislike-btn, .share-btn {
    background-color: #f2f2f2;
    border: none;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #606060;
    transition: background-color 0.2s, color 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.like-btn:hover, .dislike-btn:hover, .share-btn:hover {
    background-color: #e5e5e5;
}

.like-btn.active, .dislike-btn.active {
    background-color: #030303;
    color: white;
}
.like-btn.active:hover, .dislike-btn.active:hover {
    background-color: #1a1a1a;
}

.channel-owner-message-small {
    font-size: 12px;
    color: #606060;
}

.video-description-box {
    margin-bottom: 20px;
}
.video-description-box p {
    font-size: 14px;
    color: #333;
    line-height: 1.6;
    margin: 0; /* Remove default paragraph margin */
    white-space: pre-wrap; /* Preserves line breaks */
}


.comments-section {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    margin-top: 20px;
}

.comments-section h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 20px;
    color: #030303;
}

/* Main comment form prompt - ensure it is displayed by default */
.comment-prompt-area {
    cursor: pointer;
    padding: 10px 0;
    color: #606060;
    font-size: 1.1em;
    border-bottom: 1px solid #eee;
    margin-bottom: 20px;
    display: flex !important; /* Force display flex by default */
    align-items: center;
    gap: 10px;
}
.comment-prompt-area:hover {
    color: #030303;
}
.comment-prompt-area .comment-avatar-small {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background-color: #ddd;
    flex-shrink: 0;
}

/* Hidden main comment form - ensure it is hidden by default */
.comment-form-hidden {
    display: none !important; /* Force display none by default */
}

.comment-form { /* This now applies to both main and reply forms */
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.comment-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #333;
}

.comment-form textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    resize: vertical;
    min-height: 80px;
    box-sizing: border-box;
    font-size: 14px;
    margin-bottom: 10px;
}

.comment-form button[type="submit"] {
    background-color: #065fd4;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.2s;
}
.comment-form button[type="submit"]:hover {
    background-color: #044baf;
}

/* Reply form specific styles */
.reply-form-container {
    margin-top: 15px;
    margin-left: 15px; /* Adjusted indentation to align reply avatar closer to parent text */
    border-left: 2px solid #eee; /* Visual alignment */
    padding-left: 15px; /* Spacing */
    display: none; /* Hidden by default */
}
.reply-form-container .comment-form-cancel-btn {
    background-color: #f2f2f2;
    color: #606060;
    margin-left: 10px;
}
.reply-form-container .comment-form-cancel-btn:hover {
    background-color: #e5e5e5;
}
.reply-form-wrapper { /* Style for the content INSIDE the reply-form-container */
    padding-top: 10px; /* Add some padding at the top of the actual form content */
}


.comment-list {
    list-style: none;
    padding: 0;
}

/* --- Comment Styling (Updated for helpers.php structure) --- */
.comment-item {
    display: flex;
    margin-bottom: 20px;
    align-items: flex-start;
}

.comment-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #ddd;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #666;
    font-weight: bold;
    flex-shrink: 0;
    margin-right: 15px;
    overflow: hidden;
}

.comment-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.comment-content {
    flex-grow: 1;
    /* Ensure content takes full available width within its flex parent */
    min-width: 0; 
}

.comment-meta {
    display: flex;
    align-items: baseline; /* Align at the bottom of the text */
    gap: 8px; /* Space between username and date */
    margin-bottom: 5px;
    flex-wrap: wrap; /* Allow meta info to wrap if too long */
}

.comment-username {
    font-weight: bold;
    color: #030303;
    font-size: 14px; /* Consistent font size */
    white-space: nowrap; /* Keep username on one line */
}

.comment-date {
    font-size: 12px;
    color: #606060;
    white-space: nowrap; /* Keep date on one line */
}

.comment-text {
    font-size: 14px;
    color: #333;
    margin-bottom: 10px;
    line-height: 1.5;
    white-space: pre-wrap; /* Preserves line breaks from PHP nl2br */
    word-wrap: break-word; /* Old CSS property for breaking words */
    overflow-wrap: break-word; /* Modern CSS property for breaking words */
}

.comment-actions button {
    background: none;
    border: none;
    color: #606060;
    font-size: 13px;
    cursor: pointer;
    margin-right: 15px;
    transition: color 0.2s;
}

.comment-actions button:hover {
    color: #030303;
}

.comment-replies {
    margin-left: 15px; /* Adjusted indentation to align reply avatar closer to parent text */
    border-left: 2px solid #eee;
    padding-left: 15px;
    margin-top: 15px;
}

.view-replies-btn {
    background: none;
    border: none;
    color: #065fd4;
    font-size: 14px;
    cursor: pointer;
    margin-top: 5px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    font-weight: 500;
}
.view-replies-btn:hover {
    text-decoration: underline;
}

.view-replies-btn .reply-arrow {
    margin-left: 5px;
}
/* --- End Comment Styling --- */


/* --- Sidebar Styling (Updated for Responsiveness and Desktop Aesthetics) --- */
.video-sidebar {
    flex: 1;
    min-width: 395px; /* Increased min-width for sidebar on desktop */
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Styles for dynamic video cards in the sidebar */
.video-card-sidebar {
    display: flex;
    gap: 10px;
    background-color: #fff;
    padding: 15px; /* Increased padding for more white space on desktop */
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s, background-color 0.2s;
    text-decoration: none;
    color: inherit;
    width: 380px;
}

.video-card-sidebar:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.1);
    background-color: #f5f5f5;
}

.video-card-sidebar .video-thumbnail-sidebar {
    flex-shrink: 0;
    width: 160px;
    height: 90px;
    position: relative;
    overflow: hidden;
    border-radius: 4px;
}

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

.video-card-sidebar .video-duration-sidebar {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 2px 5px;
    border-radius: 2px;
    font-size: 11px;
}

.video-card-sidebar .video-info-sidebar {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.video-card-sidebar .video-title-sidebar {
    font-size: 14px;
    font-weight: bold;
    color: #030303;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 3; /* Increased to 3 lines for longer titles on desktop */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.video-card-sidebar .channel-name-sidebar {
    font-size: 12px;
    color: #606060;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
}

.video-card-sidebar .channel-avatar-sidebar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 5px;
    background-color: #f0f0f0;
    flex-shrink: 0;
}

.video-card-sidebar .video-metadata-sidebar {
    font-size: 11px;
    color: #606060;
    margin-top: 4px;
}

/* --- End Sidebar Styling --- */


/* Responsive adjustments */

/* Breakpoint 1: Tablets and smaller desktops (1024px and below) */
@media (max-width: 1024px) {
    .video-page-layout {
        flex-direction: column;
        padding: 15px;
        margin: 15px auto;
    }

    .video-main-content {
        width: 100%;
        flex-basis: auto;
    }

    .video-sidebar {
        width: 100%;
        min-width: unset;
        flex-direction: row; /* Keep sidebar items horizontally arranged */
        overflow-x: auto; /* Enable horizontal scrolling for sidebar items */
        padding-bottom: 10px;
        white-space: nowrap;
        margin-top: 20px;
        justify-content: flex-start;
    }
    /* Hide scrollbar for aesthetic purposes on scrollable sidebar */
    .video-sidebar::-webkit-scrollbar {
        height: 5px;
    }

    .video-sidebar::-webkit-scrollbar-thumb {
        background-color: #ccc;
        border-radius: 5px;
    }

    .video-sidebar::-webkit-scrollbar-track {
        background-color: #f2f2f2;
    }

    .video-card-sidebar {
        flex-shrink: 0;
        width: 220px;
        display: inline-flex;
        flex-direction: column;
        vertical-align: top;
        margin-right: 15px;
        padding: 10px; /* Revert sidebar card padding for smaller screens */
    }
    .video-card-sidebar .video-thumbnail-sidebar {
        width: 100%;
        height: 124px;
    }
    .video-card-sidebar .video-info-sidebar {
        margin-top: 8px;
    }
    .video-card-sidebar .video-title-sidebar {
        -webkit-line-clamp: 2; /* Revert title clamp to 2 for smaller screens */
    }

    /* Custom controls on smaller screens: make them slightly smaller */
    .custom-control-button {
        padding: 6px 10px;
        font-size: 0.9em;
    }
    .custom-video-controls {
        gap: 10px;
    }

    .channel-actions-line {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .like-dislike-share-buttons {
        width: 100%;
        justify-content: flex-start;
    }
}

/* Breakpoint 2: Mobile phones (768px and below) */
@media (max-width: 768px) {
    header {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
        padding: 10px;
    }
    header .logo, header .user-menu {
        flex-basis: 100%;
        justify-content: center;
    }
    header .search-bar {
        order: 3;
        flex-basis: 100%;
        margin: 10px 0;
        max-width: 100%; /* Allow it to take full width */
    }
    header .search-bar input,
    header .search-bar button {
        border-radius: 0; /* Remove rounded corners for full width fill */
    }
    header .search-bar input {
        border-radius: 20px 0 0 20px; /* Re-add rounded corners for the input on mobile */
    }
    header .search-bar button {
        border-radius: 0 20px 20px 0; /* Re-add rounded corners for the button on mobile */
    }
    header .user-menu {
        gap: 10px;
    }
    header .user-menu span,
    header .user-menu a {
        white-space: normal; /* Allow user menu items to wrap */
    }

    .video-page-layout {
        padding: 10px;
        margin: 10px auto;
    }
    .video-details h2 {
        font-size: 20px;
    }
    .comment-item {
        flex-direction: column; /* Stack avatar and content vertically */
        align-items: flex-start;
    }
    .comment-avatar {
        margin-bottom: 10px;
        margin-right: 0; /* Remove right margin when stacked */
    }
    .comment-reply {
        margin-left: 0 !important; /* Remove all indentation for replies on very small mobile */
        padding-left: 10px; /* Maintain a small left padding for border */
        border-left: 2px solid #eee; /* Keep the border for visual hierarchy */
    }
    .reply-form-container {
        margin-left: 0 !important; /* Remove indentation for reply forms on mobile */
        padding-left: 10px; /* Keep padding for alignment */
        border-left: 2px solid #eee; /* Keep border for visual hierarchy */
    }


    .video-sidebar {
        flex-direction: column; /* Explicitly stack sidebar items vertically on mobile */
        white-space: normal;
        overflow-x: hidden;
        padding-bottom: 0;
    }
    .video-card-sidebar {
        width: 100%;
        display: flex;
        flex-direction: row;
        margin-right: 0;
        justify-content: flex-start;
    }
    .video-card-sidebar .video-thumbnail-sidebar {
        width: 120px;
        height: 67.5px;
    }
    .video-card-sidebar .video-info-sidebar {
        flex-grow: 1;
        margin-top: 0;
    }

    /* Adjust stats bar for very small screens: Keep views/like/dislike on same line */
    .video-info-stats-line {
        flex-direction: row; /* Keep elements in a row */
        flex-wrap: wrap; /* Allow wrapping if needed */
        justify-content: flex-start; /* Align to left */
        align-items: center; /* Align items centrally in the row */
        gap: 8px; /* Smaller gap */
    }
    .views-and-date {
        padding-right: 10px;
        border-right: 1px solid #eee;
        margin-right: 5px;
        width: auto;
    }
    .like-btn, .dislike-btn, .share-btn {
        width: auto;
        flex-grow: 0;
        max-width: unset;
    }

    /* Custom controls on mobile: even smaller and hidden by default (as per PHP's style block) */
    /* This section is largely handled by the <style> block in video.php, but adding here for completeness */
    .custom-control-button {
        padding: 5px 8px;
        font-size: 0.8em;
        background-color: transparent;
        border: none;
        box-shadow: none;
    }
    .custom-video-controls {
        gap: 8px;
    }

    .channel-actions-line {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .like-dislike-share-buttons {
        width: 100%;
        justify-content: flex-start;
    }
}

/* Adjustments for the ad banner for smaller screens */
iframe[src*="banner.html"] {
    width: 100% !important;
    max-width: 468px;
    height: auto !important;
    min-height: 60px;
}