:root {
    --bg-color: #111827;
    --surface-color: #1f2937;
    --primary-color: #ef4444;
    --primary-hover-color: #dc2626;
    --text-color: #f9fafb;
    --text-muted-color: #9ca3af;
    --border-color: #374151;
    --error-color: #ef4444;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --border-radius: 8px;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    overscroll-behavior: none;
}

#root {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

button {
    font-family: inherit;
    border: none;
    border-radius: var(--border-radius);
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    background-color: var(--primary-color);
    color: white;
}

button:hover:not(:disabled) {
    background-color: var(--primary-hover-color);
}

button:active:not(:disabled) {
    transform: scale(0.98);
}

button:disabled {
    background-color: #374151;
    color: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

input, select, textarea {
    font-family: inherit;
    width: 100%;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--text-color);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.4);
}

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

/* Login Page */
.login-container {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    background-color: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
}

.login-container h1 {
    text-align: center;
    margin-bottom: 2rem;
    font-size: 2rem;
    font-weight: 700;
}

.login-form .form-group {
    margin-bottom: 1.5rem;
}

.login-form label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.error-message {
    color: var(--error-color);
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--border-radius);
    text-align: center;
    margin-top: 1.5rem;
    padding: 0.75rem;
    min-height: 1.2em;
    display: none;
}
.error-message.visible {
    display: block;
}

/* Dashboard */
.dashboard-container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.dashboard-header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.dashboard-header h1 {
    font-size: 1.5rem;
}
.dashboard-header-left #select-mode-button {
    background-color: transparent;
    border: 1px solid var(--border-color);
}
.dashboard-header-left #select-mode-button.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}
.dashboard-header-left #select-mode-button.active:hover {
    background-color: var(--primary-hover-color);
}


.dashboard-header #logout-button {
    background-color: transparent;
    border: 1px solid var(--border-color);
}
.dashboard-header #logout-button:hover {
    background-color: var(--border-color);
}


.dashboard-main {
    flex-grow: 1;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
}

/* Selection Mode Action Bar */
.selection-action-bar {
    position: fixed;
    bottom: -100px; /* Initially hidden */
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--surface-color);
    padding: 1rem 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: bottom 0.3s ease-in-out;
}
.selection-action-bar.visible {
    bottom: 2rem;
}
.selection-action-bar button {
    padding: 0.5rem 1rem;
}
.selection-action-bar .cancel-btn {
    background-color: var(--border-color);
}
.selection-action-bar .cancel-btn:hover {
     background-color: #4b5563;
}


/* Uploader */
.uploader-container {
    background-color: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 3rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}

.drop-zone.drag-over {
    border-color: var(--primary-color);
    background-color: rgba(239, 68, 68, 0.1);
}

.drop-zone p {
    color: var(--text-muted-color);
}

.upload-list {
    margin-top: 1.5rem;
}

.upload-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background-color: var(--bg-color);
    border-radius: var(--border-radius);
    margin-bottom: 0.5rem;
}

.upload-item-info {
    flex-grow: 1;
}

.upload-item-name {
    font-weight: 500;
}

.upload-item-progress-container {
    width: 100%;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.upload-item-progress-bar {
    height: 100%;
    width: 0;
    background-color: var(--primary-color);
    transition: width 0.2s ease, background-color 0.3s ease;
}

.upload-item-status {
    width: 36px;
    font-size: 1rem;
    text-align: right;
    color: var(--text-muted-color);
}

.upload-actions {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
}

/* Media Grid */
.media-grid-container h2 {
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.media-card {
    background-color: var(--surface-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    outline: 2px solid transparent;
    transition: outline-color 0.2s ease;
}

.media-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.media-card.selection-mode {
    cursor: pointer;
}
.media-card.selected {
    outline-color: var(--primary-color);
    transform: translateY(-2px) scale(0.98);
    box-shadow: 0 0 0 4px var(--primary-color);
}


.media-card-thumbnail-wrapper {
    width: 100%;
    padding-top: 56.25%; /* 16:9 Aspect Ratio */
    position: relative;
    background-color: var(--bg-color);
}

.media-grid.selection-mode .media-card-thumbnail-wrapper {
    cursor: pointer;
}
.media-grid:not(.selection-mode) .media-card-thumbnail-wrapper {
     cursor: pointer;
}


.media-card-thumbnail {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3.5rem;
    color: var(--text-muted-color);
    object-fit: cover;
}

.media-card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 60%);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}
.media-card:hover .media-card-overlay {
    opacity: 1;
}

/* Selection Checkbox */
.media-card-selection-checkbox {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 24px;
    height: 24px;
    background-color: rgba(31, 41, 55, 0.7);
    border: 2px solid white;
    border-radius: 50%;
    z-index: 15;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}
.media-card.selection-mode .media-card-selection-checkbox {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}
.media-card.selected .media-card-selection-checkbox {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}
.media-card-selection-checkbox svg {
    width: 16px;
    height: 16px;
    fill: white;
    opacity: 0;
    transition: opacity 0.1s;
}
.media-card.selected .media-card-selection-checkbox svg {
    opacity: 1;
}


.media-card-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10;
}

.media-card:hover .media-card-actions {
    opacity: 1;
    transform: translateY(0);
}
.media-card.selection-mode .media-card-actions {
    display: none;
}


.media-card-action-btn {
    background-color: rgba(31, 41, 55, 0.7);
    backdrop-filter: blur(4px);
    color: white;
    padding: 0.5rem;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid rgba(255,255,255,0.1);
}
.media-card-action-btn:hover {
    background-color: var(--primary-color);
}
.media-card-action-btn svg {
    width: 18px;
    height: 18px;
}


.media-card-info {
    padding: 1rem;
    flex-grow: 1;
    min-height: 0; /* Fix for flexbox overflow */
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.media-card-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.media-card-meta {
    font-size: 0.875rem;
    color: var(--text-muted-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    overflow: hidden;
}

.media-card-meta-filename {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.media-card-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 99px;
    flex-shrink: 0;
}
.media-card-status.published { background-color: rgba(34, 197, 94, 0.1); color: #6ee7b7; }
.media-card-status.unpublished { background-color: rgba(156, 163, 175, 0.1); color: var(--text-muted-color); }
.media-card-status.scheduled { background-color: rgba(245, 158, 11, 0.1); color: #fcd34d; }


.media-card-processing {
    font-size: 0.8rem;
    color: var(--text-muted-color);
    padding: 0.5rem 0;
    animation: pulse 2s infinite ease-in-out;
}
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(17, 24, 39, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    padding: 1rem;
}

.modal-content {
    background-color: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

.modal-close-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: var(--border-color);
    color: var(--text-muted-color);
    border: none;
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    padding: 0;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background-color 0.2s, transform 0.2s;
    z-index: 1010;
}
.modal-close-btn:hover {
    color: white;
    background-color: var(--primary-color);
    transform: scale(1.1);
}


.modal-content h2 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    padding-right: 40px; /* Space for close button */
    font-size: 1.5rem;
}

.modal-content p {
    margin-bottom: 1.5rem;
}

.modal-body-content {
    flex-grow: 1;
    min-height: 0;
}

.modal-form-group {
    margin-bottom: 1.5rem;
}
.modal-form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.modal-actions button.cancel-btn {
    background-color: var(--border-color);
    color: var(--text-color);
}
.modal-actions button.cancel-btn:hover {
    background-color: #4b5563;
}

.status-message {
    margin-top: 1rem;
    min-height: 1.2em;
    text-align: center;
    font-weight: 500;
}

/* Transcode Modal */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem 1rem;
    background-color: var(--bg-color);
    padding: 1rem;
    border-radius: var(--border-radius);
}
.checkbox-grid div {
    display: flex;
    align-items: center;
}
.checkbox-grid input[type="checkbox"] {
    width: auto;
    margin-right: 0.75rem;
    accent-color: var(--primary-color);
}
.checkbox-grid label {
    margin-bottom: 0;
    font-weight: 400;
}
.checkbox-grid label.disabled {
    color: var(--text-muted-color);
    cursor: not-allowed;
    text-decoration: line-through;
}


/* Share Modal */
#share-link-input, #share-embed-code {
    background-color: var(--bg-color);
}
#share-embed-code {
    height: 100px;
    resize: vertical;
}

/* Edit Modal specific */
.poster-preview {
    width: 100%;
    max-width: 200px;
    height: auto;
    border-radius: var(--border-radius);
    margin-top: 0.5rem;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
}
.poster-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
}
.poster-actions button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
}
.poster-actions button:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background-color: var(--surface-color);
}

/* --- Player & Viewer --- */
.modal-overlay.viewer-modal {
    padding: 0;
}
.modal-overlay.viewer-modal .modal-content {
    background: #000;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
}
.modal-overlay.viewer-modal.contained-viewer .modal-content {
    max-width: 95vw;
    max-height: 90vh;
    border-radius: var(--border-radius);
}

/* Hide the default h2 title in fullscreen viewer mode */
.modal-overlay.viewer-modal .modal-content h2 {
    display: none;
}
/* Make the body content fill the entire modal to contain the player */
.modal-overlay.viewer-modal .modal-body-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}


.modal-overlay.viewer-modal .modal-close-btn {
    position: fixed; /* Use fixed to ensure it's relative to viewport */
    top: 20px;
    right: 20px;
    z-index: 1050; /* Higher than player controls */
    background-color: rgba(31, 41, 55, 0.7);
    color: white;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}
.modal-overlay.viewer-modal .modal-close-btn:hover {
    background-color: var(--primary-color);
}
.modal-overlay.contained-viewer .modal-close-btn {
    position: absolute; /* relative to modal content */
}

/* The audio player is NOT a viewer, just a styled modal */
.modal-overlay.audio-viewer .modal-content {
    background: transparent;
    padding: 0;
    box-shadow: none;
    max-width: 960px; /* match player width */
    overflow: visible; /* Let player be itself */
}


/* Cropper Modal Styles */
.cropper-modal .modal-content {
    max-width: 80vw;
}
.cropper-modal-body {
    width: 100%;
    height: 60vh;
    background-color: var(--bg-color);
}
.cropper-modal-body img {
    display: block;
    max-width: 100%;
    max-height: 100%;
}