:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface-hover: #243044;
    --border: #2d3a4f;
    --text: #e8edf4;
    --text-muted: #8b9cb3;
    --primary: #4f8cff;
    --primary-hover: #3a7aef;
    --success: #34d399;
    --error: #f87171;
    --info: #60a5fa;
    --radius: 10px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

code {
    background: var(--surface-hover);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

/* Navbar */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text);
}

.nav-user {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Layout */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.75rem;
    margin-bottom: 0.25rem;
}

.text-muted {
    color: var(--text-muted);
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card h2 {
    font-size: 1.15rem;
    margin-bottom: 1rem;
}

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

/* Forms */
.form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-inline {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
}

.form-group label {
    font-size: 0.875rem;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select,
textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    color: var(--text);
    font-size: 0.95rem;
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.inline-form {
    display: inline;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.btn-danger {
    color: var(--error) !important;
    border-color: var(--error) !important;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
}

.btn-block {
    width: 100%;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

.alert-error {
    background: rgba(248, 113, 113, 0.15);
    border: 1px solid var(--error);
    color: var(--error);
}

.alert-info {
    background: rgba(96, 165, 250, 0.15);
    border: 1px solid var(--info);
    color: var(--info);
}

.alert-success {
    background: rgba(52, 211, 153, 0.15);
    border: 1px solid var(--success);
    color: var(--success);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    background: var(--surface-hover);
    color: var(--text-muted);
}

.badge-success {
    background: rgba(52, 211, 153, 0.15);
    color: var(--success);
}

.badge-muted {
    background: var(--surface-hover);
    color: var(--text-muted);
}

.badge-info {
    background: rgba(96, 165, 250, 0.15);
    color: var(--info);
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Table */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.table th,
.table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.85rem;
}

.truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* File list */
.bundle-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.bundle-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.bundle-header-main h2 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.file-card {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.file-card-preview {
    display: block;
    aspect-ratio: 4 / 3;
    background: #111;
    overflow: hidden;
    position: relative;
}

.file-card-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.file-card-preview--video,
.file-card-preview--file {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #1a1f2e, #0d1117);
    color: var(--text-muted);
    font-size: 2rem;
}

.file-card-preview--video {
    background: linear-gradient(145deg, #1e293b, #0f172a);
}

.file-card-play {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: rgba(79, 140, 255, 0.9);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    padding-left: 0.2rem;
}

.file-card-body {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
}

.file-card-title {
    font-size: 0.9rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.file-card-title:hover {
    color: var(--primary);
}

.file-card-actions {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-top: 0.25rem;
}

.viewer-page {
    max-width: 1100px;
    margin: 0 auto;
}

.viewer-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.viewer-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.viewer-nav {
    display: flex;
    gap: 0.5rem;
}

.viewer-header {
    margin-bottom: 1rem;
}

.viewer-header h1 {
    font-size: 1.35rem;
    margin: 0 0 0.25rem;
    word-break: break-word;
}

.viewer-content {
    margin-bottom: 1.25rem;
}

.image-viewer-wrap {
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    max-height: 75vh;
}

.image-viewer-wrap img {
    max-width: 100%;
    max-height: 75vh;
    display: block;
    object-fit: contain;
}

.audio-viewer-wrap,
.viewer-fallback {
    padding: 2rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
}

.audio-viewer-wrap audio {
    width: min(100%, 480px);
}

.pdf-viewer-wrap {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    height: 75vh;
}

.pdf-viewer-wrap iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

.viewer-actions {
    display: flex;
    gap: 0.75rem;
}

.btn.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.modal-overlay.hidden {
    display: none;
}

.modal-close {
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.25rem 0.5rem;
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.file-list.compact .file-row {
    padding: 0.4rem 0;
}

.file-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 6px;
    gap: 1rem;
}

.file-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Video player */
.watch-page {
    max-width: 1100px;
    margin: 0 auto;
}

.watch-header {
    margin-bottom: 1.5rem;
}

.watch-header h1 {
    font-size: 1.35rem;
    margin: 0.5rem 0 0.25rem;
    word-break: break-word;
}

.back-link {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.back-link:hover {
    color: var(--primary);
}

.video-player-wrap {
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    aspect-ratio: 16 / 9;
}

.video-player-wrap video {
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
}

.watch-actions {
    margin-top: 1.25rem;
    display: flex;
    gap: 0.75rem;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}

.file-meta {
    min-width: 0;
    flex: 1;
}

.file-meta .file-name {
    display: block;
}

.file-meta .file-size {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.file-status {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.35rem;
}

.file-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.filter-btn {
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
}

.filter-btn:hover,
.filter-btn.active {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(79, 140, 255, 0.1);
}

.filter-count {
    font-size: 0.85rem;
    margin-left: auto;
}

.filter-empty {
    margin-top: 0.75rem;
    text-align: center;
}

.table-compact th,
.table-compact td {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

.admin-file-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    white-space: nowrap;
}

.admin-file-actions form {
    display: inline;
}

.file-row[hidden],
.file-item[hidden] {
    display: none;
}

.file-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    color: var(--text-muted);
    font-size: 0.85rem;
    white-space: nowrap;
}

.file-details {
    margin: 1rem 0;
}

.file-details summary {
    cursor: pointer;
    color: var(--primary);
    font-size: 0.9rem;
}

/* Bundle admin */
.bundle-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.bundle-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.assign-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.assign-section h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.assign-form {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 6px;
}

.assign-form h4 {
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 240px;
    overflow-y: auto;
}

.checkbox-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.95rem;
}

.checkbox-item input {
    width: auto;
    margin-top: 0.25rem;
    flex-shrink: 0;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-width: 480px;
    width: 100%;
    box-shadow: var(--shadow);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.modal-body {
    padding: 1.5rem;
}

.modal-message {
    margin-bottom: 1.25rem;
    font-size: 1.05rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.modal-dismiss-form {
    margin-top: 0.75rem;
}

.upload-progress {
    margin: 1rem 0;
}

.progress-bar {
    height: 8px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 999px;
    transition: width 0.15s ease;
}

.progress-text {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
}

.upload-success {
    padding: 1rem;
    background: rgba(52, 211, 153, 0.15);
    border: 1px solid var(--success);
    border-radius: 6px;
    color: var(--success);
    text-align: center;
    font-weight: 500;
    margin: 1rem 0;
}

.upload-error {
    margin: 0.75rem 0;
}

#thank-you-toast {
    transition: opacity 0.4s ease;
}

/* Uploads grid */
.uploads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.upload-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.upload-preview img,
.upload-preview video {
    width: 100%;
    max-height: 240px;
    object-fit: cover;
    display: block;
    background: var(--bg);
}

.upload-placeholder {
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    background: var(--bg);
}

.upload-meta {
    padding: 1rem;
    font-size: 0.9rem;
}

.upload-actions {
    margin-top: 0.75rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.upload-missing {
    font-size: 0.95rem;
    color: var(--text-muted);
    padding: 1rem;
    text-align: center;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.steps-list {
    padding-left: 1.5rem;
    color: var(--text-muted);
}

.steps-list li {
    margin-bottom: 0.5rem;
}

/* Responsive */
@media (max-width: 640px) {
    .navbar {
        padding: 0 1rem;
        flex-wrap: wrap;
        height: auto;
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        gap: 0.5rem;
    }

    .nav-links {
        gap: 0.75rem;
        flex-wrap: wrap;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .bundle-card-header,
    .bundle-header,
    .viewer-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .viewer-toolbar-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .viewer-nav {
        justify-content: space-between;
    }

    .file-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .file-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .file-actions {
        width: 100%;
    }

    .file-actions .btn {
        flex: 1;
    }
}
