/* Professional Dark Theme */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --success: #3fb950;
    --danger: #f85149;
    --shadow: 0 8px 24px rgba(1, 4, 9, 0.5);
    --radius: 12px;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Navbar */
.navbar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(8px);
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px;
}

.navbar .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    display: flex;
    align-items: center;
}

.logo-image {
    height: 80px;
    width: auto;
    object-fit: contain;
}

.nav-actions {
    display: flex;
    gap: 8px;
}

/* Buttons */
.btn-primary, .btn-ghost, .btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    background: transparent;
    color: var(--text-primary);
}

.btn-primary {
    background: var(--accent);
    color: #0d1117;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.3);
}

.btn-ghost {
    border-color: var(--border);
}

.btn-ghost:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

.btn-ghost.danger {
    color: var(--danger);
}

.btn-icon {
    padding: 8px;
    border: none;
}

.btn-icon:hover {
    background: var(--bg-tertiary);
}

button svg {
    width: 18px;
    height: 18px;
}

/* Page Header */
.page-header {
    padding: 48px 0 32px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.page-header h1 {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.sort-controls {
    display: flex;
    gap: 8px;
}

.sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sort-btn svg {
    width: 16px;
    height: 16px;
}

.sort-btn:hover {
    border-color: var(--text-secondary);
    background: var(--bg-tertiary);
}

.sort-btn.active {
    background: var(--accent);
    color: #0d1117;
    border-color: var(--accent);
}

.sort-btn.active:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

/* Grid */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    padding-bottom: 64px;
}

/* Video Card */
.video-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.video-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--text-secondary);
}

.video-thumbnail {
    width: 100%;
    aspect-ratio: 16/9;
    background-size: cover;
    background-position: center;
    background-color: var(--bg-tertiary);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.4s ease-out;
}

.video-thumbnail::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 0%,
        rgba(48, 54, 61, 0.5) 50%,
        var(--bg-tertiary) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    z-index: 1;
}

.video-thumbnail.loaded {
    opacity: 1;
}

.video-thumbnail.loaded::before {
    display: none;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.video-thumbnail::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, transparent 0%, rgba(13, 17, 23, 0.3) 100%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.video-card:hover .video-thumbnail::after {
    opacity: 1;
}

.play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 2;
}

.video-card:hover .play-icon {
    opacity: 1;
}

.play-icon svg {
    width: 24px;
    height: 24px;
    color: #0d1117;
    margin-left: 4px;
}

.reorder-buttons {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 3;
}

.btn-icon-small {
    width: 32px;
    height: 32px;
    padding: 0;
    display: grid;
    place-items: center;
    background: rgba(13, 17, 23, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon-small:hover {
    background: rgba(13, 17, 23, 0.95);
    border-color: var(--accent);
    transform: scale(1.05);
}

.btn-icon-small svg {
    width: 16px;
    height: 16px;
}

.video-info {
    padding: 16px;
}

.video-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    line-height: 1.4;
}

.video-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
}

.video-actions .btn-ghost {
    padding: 6px 12px;
    font-size: 13px;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(1, 4, 9, 0.8);
    backdrop-filter: blur(4px);
    z-index: 20;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-backdrop:not(.hidden) {
    opacity: 1;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 21;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal-dialog {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 540px;
    box-shadow: 0 16px 48px rgba(1, 4, 9, 0.7);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.modal:not(.hidden) .modal-dialog {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
}

.form-field {
    margin-bottom: 20px;
}

.form-field label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.form-field input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.form-field input[type="password"] {
    font-size: 18px;
    letter-spacing: 4px;
    text-align: center;
}

.form-field input::placeholder {
    color: var(--text-secondary);
}

.form-field input[type="file"] {
    padding: 8px 12px;
    cursor: pointer;
}

.form-field input[type="file"]::file-selector-button {
    background: var(--accent);
    color: #0d1117;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    margin-right: 12px;
}

.form-field input[type="file"]::file-selector-button:hover {
    background: var(--accent-hover);
}

.thumbnail-preview {
    background: var(--bg-primary);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    overflow: hidden;
}

.thumbnail-preview svg {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

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

.thumbnail-preview.has-image {
    border-style: solid;
    padding: 0;
}

.thumbnail-preview.has-image svg,
.thumbnail-preview.has-image span {
    display: none;
}

.modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(13, 17, 23, 0.3);
    border-top-color: #0d1117;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 400px;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    transform: translateX(400px);
    transition: transform 0.3s ease;
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left: 3px solid var(--success);
}

.toast.error {
    border-left: 3px solid var(--danger);
    color: var(--danger);
}

/* Loading */
.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 64px auto;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 64px 24px;
    color: var(--text-secondary);
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Auth Page */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-header .logo-circle {
    width: auto;
    height: 80px;
    background: transparent;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.auth-logo {
    height: 100%;
    width: auto;
    object-fit: contain;
}

.auth-header h1 {
    font-size: 14px !important;
    margin-bottom: 8px;
    font-weight: 500;
}

.auth-header p {
    color: var(--text-secondary);
}

.pin-input {
    width: 100%;
    padding: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 28px;
    text-align: center;
    letter-spacing: 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.pin-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.auth-message {
    text-align: center;
    margin-top: 16px;
    min-height: 24px;
    color: var(--text-secondary);
}

.auth-message.error {
    color: var(--danger);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Animations */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

.shake {
    animation: shake 0.3s ease;
    border-color: var(--danger) !important;
}

/* Responsive */
@media (max-width: 768px) {
    .grid {
        grid-template-columns: 1fr;
    }
    
    .page-header {
        padding: 32px 0 24px;
        flex-direction: column;
        align-items: flex-start;
    }
    
    .page-header h1 {
        font-size: 24px;
    }

    .page-header > button {
        width: 100%;
    }

    .sort-controls {
        width: 100%;
    }

    .sort-btn {
        flex: 1;
        justify-content: center;
        font-size: 13px;
        padding: 8px 10px;
    }
    
    .sort-btn svg {
        width: 14px;
        height: 14px;
    }
    
    #toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }
    
    .auth-header h1 {
        font-size: 14px !important;
    }
}

@media (min-width: 769px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    }

    .auth-header h1 {
        font-size: 12px !important;
    }
}
