/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

/* Layout */
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Authentication Styles */
#auth-section {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#login-container {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

#login-container h1 {
    margin-bottom: 1rem;
    color: #333;
}

#login-container p {
    margin-bottom: 2rem;
    color: #666;
}

/* Header Styles */
header {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

header h1 {
    color: #333;
    margin-right: 2rem;
}

#user-info {
    position: absolute;
    top: 1rem;
    right: 2rem;
    background: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.user-welcome {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#user-name {
    font-weight: 500;
    color: #333;
}

/* Search Styles */
#search-container {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#search-input {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    width: 300px;
}

#search-input:focus {
    outline: none;
    border-color: #667eea;
}

/* Button Styles */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.btn.primary {
    background-color: #667eea;
    color: white;
}

.btn.primary:hover {
    background-color: #5a6fd8;
}

.btn.secondary {
    background-color: #6c757d;
    color: white;
}

.btn.secondary:hover {
    background-color: #5a6268;
}

.btn:hover {
    background-color: #e9ecef;
}

/* Main Content */
main {
    flex: 1;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Loading and Error States */
#loading {
    text-align: center;
    padding: 4rem 2rem;
    color: #666;
}

.error {
    background-color: #f8d7da;
    color: #721c24;
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 2rem;
}

/* Video Grid */
#video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.video-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

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

.video-thumbnail {
    width: 100%;
    height: 180px;
    background-color: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    position: relative;
    overflow: hidden;
}

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

.play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.play-button:hover {
    background: rgba(0, 0, 0, 0.9);
}

.video-info {
    padding: 1rem;
}

.video-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #333;
    line-height: 1.4;
}

.video-description {
    color: #666;
    font-size: 0.9rem;
    line-height: 1.4;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Special styling for different card description states */
.video-card.has-metadata .video-description {
    color: #555;
    font-weight: 500;
}

.video-card.needs-review .video-description {
    color: #999;
    font-style: italic;
}

.video-card.ambiguous-match .video-description {
    color: #e67e22;
    font-style: italic;
}

.video-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: #888;
    margin-top: 0.5rem;
}

.video-duration {
    background: #667eea;
    color: white;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
}

.share-button {
    background: none;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 0.2rem 0.4rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: #666;
    transition: all 0.2s;
}

.share-button:hover {
    background: #f5f5f5;
    border-color: #667eea;
    color: #667eea;
}

/* Link copied feedback */
.link-copied-feedback {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #4CAF50;
    color: white;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    animation: slideInRight 0.3s ease-out;
}

.feedback-content {
    text-align: center;
}

.feedback-link {
    font-size: 0.8rem;
    opacity: 0.9;
    margin-top: 0.5rem;
    word-break: break-all;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Link fallback modal */
.link-fallback-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.fallback-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    max-width: 500px;
    width: 90%;
}

.fallback-content h3 {
    margin: 0 0 1rem 0;
}

.fallback-content input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.fallback-buttons {
    text-align: right;
}

.fallback-buttons button {
    padding: 0.5rem 1rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* Folder Section Styles */
.folder-section {
    margin-bottom: 2rem;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.folder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    border-bottom: 1px solid #e0e0e0;
    transition: background-color 0.2s;
    user-select: none;
}

.folder-header:hover {
    background-color: #f9f9f9;
}

.folder-header-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.folder-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.video-count {
    background: #f0f0f0;
    color: #666;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.folder-toggle {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.folder-toggle:hover {
    background-color: #e9e9e9;
}

.toggle-icon {
    font-size: 0.875rem;
    color: #666;
    transition: transform 0.2s;
}

.folder-videos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2rem;
    padding: 1.5rem;
    transition: max-height 0.3s ease-out, opacity 0.3s ease-out;
    overflow: hidden;
}

.folder-videos.collapsed {
    display: none;
}

/* Update main video grid for folder layout */
#video-grid {
    display: block; /* Changed from grid to allow folder sections */
    margin-top: 2rem;
}

/* Modal Styles */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal-content {
    background: white;
    border-radius: 8px;
    max-width: min(95vw, 1400px); /* Cap width on ultra-wide screens */
    max-height: 95vh;
    width: 100%;
    overflow-y: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    color: #666;
    z-index: 1001;
    background: white;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close:hover {
    color: #333;
}

#video-container {
    position: relative;
    width: 100%;
    max-width: 1200px; /* Maximum width for ultra-wide screens */
    margin: 0 auto; /* Center the video */
    aspect-ratio: 16 / 9; /* Modern CSS aspect ratio */
}

/* Fallback for browsers that don't support aspect-ratio */
@supports not (aspect-ratio: 16 / 9) {
    #video-container {
        padding-bottom: 56.25%; /* 16:9 aspect ratio fallback */
        height: 0;
    }
}

#video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

#video-metadata {
    padding: 2rem;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
}

#video-metadata h2 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1.3rem;
}

#video-description {
    margin-bottom: 2rem;
    line-height: 1.6;
    color: #555;
}

#video-description .catalogue-link-inline {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

#video-description .catalogue-link-inline:hover {
    color: #5a6fd8;
    text-decoration: underline;
}

#video-description .no-description {
    color: #888;
    font-style: italic;
}

#library-metadata {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#library-metadata h3 {
    margin-bottom: 1rem;
    color: #333;
    font-size: 1.1rem;
    border-bottom: 2px solid #667eea;
    padding-bottom: 0.5rem;
}

#library-metadata p {
    margin-bottom: 0.8rem;
    font-size: 0.95rem;
    color: #555;
    line-height: 1.5;
}

#library-metadata .metadata-field {
    margin-bottom: 1rem;
}

#library-metadata .metadata-field strong {
    color: #333;
    display: inline-block;
    min-width: 120px;
}

#library-metadata .catalogue-link {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.5rem 1rem;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

#library-metadata .catalogue-link:hover {
    background: #5a6fd8;
    text-decoration: none;
}

#library-metadata .search-suggestion {
    font-style: italic;
    color: #888;
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    header h1 {
        margin-right: 0;
    }

    #search-input {
        width: 100%;
        max-width: 300px;
    }

    main {
        padding: 1rem;
    }

    #video-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    #user-info {
        position: static;
        margin-top: 1rem;
    }

    .modal {
        padding: 0.5rem;
    }

    .modal-content {
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }

    #video-metadata {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    #login-container {
        padding: 1.5rem;
    }
    
    .modal-content {
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }
    
    #video-metadata {
        padding: 0.75rem;
    }
    
    .close {
        right: 0.5rem;
        top: 0.5rem;
    }
}