/* Enhanced Autoplay Controls Styles - Compact Version */
.autoplay-control label {
    min-height: auto;
}

.autoplay-toggle {
    background: linear-gradient(45deg, #d1d5db, #9ca3af);
    position: relative;
    cursor: pointer;
}

.autoplay-toggle-input:checked + .autoplay-toggle {
    background: linear-gradient(45deg, #3b82f6, #1d4ed8);
}

.autoplay-toggle-input:checked + .autoplay-toggle .autoplay-toggle-thumb {
    transform: translateX(20px);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.autoplay-toggle-thumb {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Affiliate Links Modal Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Mobile-optimized Affiliate Links Modal */
#affiliate-links-modal {
    padding: 8px;
}

#affiliate-links-modal .bg-white {
    max-height: 85vh;
    overflow-y: auto;
}

/* Mobile-first responsive design */
@media (max-width: 640px) {
    #affiliate-links-modal {
        padding: 4px;
        align-items: flex-end;
    }
    
    #affiliate-links-modal .bg-white {
        max-height: 90vh;
        margin-bottom: 0;
        border-radius: 12px 12px 0 0;
        width: 100%;
        max-width: none;
    }
    
    #affiliate-links-modal .grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    #affiliate-links-modal .px-6 {
        padding-left: 16px;
        padding-right: 16px;
    }
    
    #affiliate-links-modal .py-4 {
        padding-top: 12px;
        padding-bottom: 12px;
    }
    
    #affiliate-links-modal h3 {
        font-size: 18px;
    }
    
    #affiliate-links-modal .text-xl {
        font-size: 18px;
    }
    
    /* Card optimizations for mobile */
    .affiliate-card-mobile {
        padding: 12px;
        border-radius: 8px;
    }
    
    .affiliate-card-mobile img,
    .affiliate-card-mobile .w-16 {
        width: 48px;
        height: 48px;
        margin-bottom: 8px;
    }
    
    .affiliate-card-mobile h4 {
        font-size: 14px;
        line-height: 1.3;
        margin-bottom: 6px;
    }
    
    .affiliate-card-mobile p {
        font-size: 12px;
        margin-bottom: 4px;
    }
    
    .affiliate-card-mobile .text-lg {
        font-size: 16px;
    }
    
    .affiliate-card-mobile a {
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* Tablet responsive */
@media (min-width: 641px) and (max-width: 1024px) {
    #affiliate-links-modal .grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop responsive */
@media (min-width: 1025px) {
    #affiliate-links-modal .grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Line clamp utility */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Compact layout adjustments */
@media (max-width: 1024px) {
    .autoplay-control {
        margin-bottom: 0;
    }
}

@media (max-width: 640px) {
    .autoplay-toggle {
        width: 36px;
        height: 18px;
    }
    
    .autoplay-toggle-thumb {
        width: 14px;
        height: 14px;
    }
    
    .autoplay-toggle-input:checked + .autoplay-toggle .autoplay-toggle-thumb {
        transform: translateX(16px);
    }
}

/* Clear History Button Styles */
.clear-history-btn {
    transition: all 0.2s ease;
}

.clear-history-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

.clear-history-btn:active {
    transform: translateY(0);
}

/* Notification Styles */
.notification {
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

/* Responsive button text */
@media (max-width: 480px) {
    .play-next-btn span,
    .clear-history-btn span {
        display: none;
    }
    
    .play-next-btn:after {
        content: "Tiếp";
        margin-left: 4px;
    }
    
    .clear-history-btn:after {
        content: "Xóa";
        margin-left: 4px;
    }
}

/* Mobile Related Videos Optimization */
@media (max-width: 1024px) {
    .related-video-card {
        border-radius: 8px;
        transition: background-color 0.2s ease;
    }
    
    .related-video-card:hover {
        background-color: #f9fafb;
    }
    
    .related-video-card img {
        border-radius: 6px;
    }
    
    /* Compact video thumbnails for mobile */
    .related-video-card .w-32 {
        min-width: 120px;
    }
    
    .related-video-card .h-20 {
        height: 75px;
    }
}

@media (max-width: 640px) {
    .related-video-card .w-32 {
        min-width: 100px;
        width: 100px;
    }
    
    .related-video-card .h-20 {
        height: 60px;
    }
    
    .related-video-card h4 {
        font-size: 13px;
        line-height: 1.3;
    }
    
    .related-video-card .text-xs {
        font-size: 11px;
    }
}

/* Line clamp for mobile video titles */
@media (max-width: 768px) {
    .line-clamp-2 {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
}

/* Touch interactions for mobile */
.related-video-link.touch-active {
    background-color: #f3f4f6;
    transform: scale(0.98);
    transition: all 0.1s ease;
}

/* Loading state for video cards */
.related-video-card {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Mobile video section spacing */
@media (max-width: 1024px) {
    .lg\\:hidden .space-y-3 > * + * {
        margin-top: 12px;
    }
}

/* YouTube-style Layout Optimization */
/* Mobile: Related Videos trước Comments */
@media (max-width: 1023px) {
    .lg\:hidden {
        display: block !important;
        order: 1; /* Hiển thị trước comments */
    }
    
    .related-videos-mobile {
        margin-bottom: 16px;
        background: white;
        border-radius: 12px;
        padding: 16px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
    
    .related-videos-mobile h3 {
        font-size: 18px;
        font-weight: 600;
        color: #111827;
        margin-bottom: 16px;
    }
}

/* Desktop: Sidebar bên phải như YouTube */
@media (min-width: 1024px) {
    .hidden.lg\:block {
        display: block !important;
        position: sticky;
        top: 20px;
        height: fit-content;
        max-height: calc(100vh - 40px);
        overflow-y: auto;
    }
    
    /* YouTube-style sidebar width */
    .lg\:w-80 {
        width: 400px !important;
        max-width: 400px;
    }
    
    .xl\:w-96 {
        width: 420px !important;
        max-width: 420px;
    }
}

/* Related Video Cards Styling */
.related-video-card {
    transition: all 0.2s ease;
    border-radius: 8px;
}

.related-video-card:hover {
    background-color: #f9fafb;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Desktop sidebar related videos */
@media (min-width: 1024px) {
    .related-video-card {
        margin-bottom: 12px;
        padding: 8px;
    }
    
    .related-video-card img {
        border-radius: 6px;
    }
}

/* Mobile related videos */
@media (max-width: 1023px) {
    .related-video-card {
        margin-bottom: 16px;
        padding: 12px;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
    }
    
    .related-video-card:hover {
        border-color: #d1d5db;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
}

/* Ensure proper z-index for loading indicators */
.related-video-link {
    position: relative;
    z-index: 1;
}

/* Layout ordering for mobile */
@media (max-width: 1023px) {
    .main-content-mobile {
        display: flex;
        flex-direction: column;
    }
    
    .mobile-related-videos {
        order: 1;
    }
    
    .mobile-comments {
        order: 2;
    }
}

/* Smooth scrolling for video navigation */
html {
    scroll-behavior: smooth;
}

/* Loading states */
.video-loading {
    opacity: 0.7;
    pointer-events: none;
}

.video-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #3b82f6;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Play Next Button Enhanced Styles */
.play-next-btn {
    position: relative;
    overflow: hidden;
    border: 2px solid #2563eb;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    transition: all 0.3s ease;
}

.play-next-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.play-next-btn:hover::before {
    left: 100%;
}

.play-next-btn:active {
    transform: scale(0.98);
}

.play-next-btn:disabled {
    opacity: 0.7;
    transform: none;
    cursor: not-allowed;
}

.play-next-btn:disabled:hover {
    transform: none;
}

/* Loading animation for buttons */
.play-next-btn .fa-spinner {
    animation: spin 1s linear infinite;
}

.play-next-btn .fa-check {
    color: #10b981;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Clear History Button Styles */
.clear-history-btn {
    position: relative;
    overflow: hidden;
    border: 2px solid #fecaca;
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
}

.clear-history-btn:hover {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-color: #f87171;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(248, 113, 113, 0.15);
}

/* Mobile Responsive Enhancements */
@media (max-width: 640px) {
    .autoplay-control label {
        min-height: 50px;
        padding: 12px;
    }
    
    .autoplay-control .text-sm {
        font-size: 13px;
    }
    
    .autoplay-control .text-xs {
        font-size: 11px;
    }
    
    .play-next-btn {
        min-height: 48px;
        font-size: 13px;
    }
    
    .clear-history-btn {
        min-height: 40px;
        font-size: 13px;
    }
}

/* Extra Small devices (phones, 480px and down) */
@media (max-width: 480px) {
    .autoplay-control label {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        min-height: 60px;
    }
    
    .autoplay-toggle {
        margin-bottom: 4px;
    }
    
    .play-next-btn {
        width: 100%;
        justify-content: center;
        min-height: 52px;
    }
    
    /* Stack buttons vertically on very small screens */
    .flex.flex-col.xs\:flex-row {
        flex-direction: column;
        gap: 12px;
    }
    
    /* Make text more readable on small screens */
    .text-xs {
        font-size: 12px;
        line-height: 1.4;
    }
}

/* Custom xs breakpoint (475px) */
@media (max-width: 475px) {
    .hidden.xs\:inline {
        display: none !important;
    }
    
    .xs\:hidden {
        display: inline !important;
    }
    
    .flex-col.xs\:flex-row {
        flex-direction: column !important;
    }
}

/* Debug Controls (Hidden by default) */
.debug-controls {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.debug-controls.show {
    opacity: 1;
}

/* Animation for smooth transitions */
@keyframes slideInUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.autoplay-control, .play-next-btn, .clear-history-btn {
    animation: slideInUp 0.3s ease;
}
.next-video-recommendation {
    position: absolute;
    bottom: 20px;
    right: 20px;
    max-width: 300px;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 8px;
    padding: 15px;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.next-video-recommendation.show {
    transform: translateY(0);
    opacity: 1;
}

.next-video-card {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.next-video-card:hover {
    transform: scale(1.02);
}

.next-video-thumbnail {
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 10px;
}

.next-video-thumbnail img {
    width: 100%;
    height: 120px;
    object-fit: cover;
}

.play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #333;
}

.next-video-info {
    color: white;
}

.next-video-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.next-video-description {
    font-size: 12px;
    color: #ccc;
    margin-bottom: 10px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Autoplay Prompt Styles */
.autoplay-prompt {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

.autoplay-content {
    background: white;
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.autoplay-content h5 {
    margin-bottom: 20px;
    color: #333;
    font-weight: 600;
}

.next-video-preview {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    text-align: left;
}

.next-video-preview img {
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
}

.next-video-details h6 {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.3;
}

.autoplay-countdown {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #666;
}

.countdown-timer {
    background: #007bff;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.autoplay-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Autoplay Toggle Control */
.autoplay-control {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
}

.autoplay-toggle-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.autoplay-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background-color: #ccc;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.autoplay-toggle-thumb {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Watch History Controls */
.watch-history-controls {
    margin-bottom: 20px;
}

.clear-history-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.clear-history-btn:hover {
    background: #c82333;
}

/* Related Videos Enhanced Styles */
.related-videos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.related-video-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.related-video-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.related-video-thumbnail {
    position: relative;
    overflow: hidden;
}

.related-video-thumbnail img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.related-video-card:hover .related-video-thumbnail img {
    transform: scale(1.05);
}

.related-video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.related-video-card:hover .related-video-overlay {
    opacity: 1;
}

.related-video-play-btn {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #333;
}

.related-video-info {
    padding: 15px;
}

.related-video-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.related-video-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: #666;
}

.video-views {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Notification Styles */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    z-index: 3000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.notification.show {
    transform: translateX(0);
}

.notification-success {
    background: #28a745;
}

.notification-error {
    background: #dc3545;
}

.notification-info {
    background: #17a2b8;
}

/* Responsive Design */
@media (max-width: 768px) {
    .next-video-recommendation {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .autoplay-content {
        margin: 20px;
        padding: 20px;
    }
    
    .related-videos-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .next-video-preview {
        flex-direction: column;
        text-align: center;
    }
    
    .next-video-preview img {
        width: 100%;
        height: 120px;
    }
}

/* Animation Keyframes */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Video Container Enhancements */
.video-container {
    position: relative;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
}

.video-controls-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    padding: 20px;
    color: white;
}

.video-title-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 50%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    pointer-events: none;
    z-index: 10;
}

/* Desktop hover effect */
.video-container:hover .video-title-overlay {
    opacity: 1;
}

/* Mobile touch support */
@media (hover: none) and (pointer: coarse) {
    .video-container {
        cursor: pointer;
    }
    
    .video-container.show-overlay .video-title-overlay {
        opacity: 1;
    }
    
    /* Auto hide after 3 seconds on mobile */
    .video-container.show-overlay .video-title-overlay {
        animation: mobileOverlayFadeOut 3s ease-in-out forwards;
    }
}

@keyframes mobileOverlayFadeOut {
    0%, 70% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

/* Title text styling */
.video-title-overlay h1 {
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    font-weight: 700;
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.video-title-overlay .text-white.text-opacity-90 {
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.6);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .video-title-overlay {
        padding: 8px 12px;
    }
    
    .video-title-overlay h1 {
        font-size: 16px;
        line-height: 1.3;
    }
    
    .video-title-overlay .text-sm {
        font-size: 12px;
    }
    
    .video-title-overlay .flex {
        flex-wrap: wrap;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .video-title-overlay h1 {
        font-size: 14px;
    }
    
    .video-title-overlay .text-sm {
        font-size: 11px;
    }
}

.video-stats {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 14px;
    opacity: 0.9;
}