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

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    background: linear-gradient(180deg, var(--bg-primary) 0%, #fafbfc 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.03);
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: -0.02em;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.logo:hover {
    opacity: 0.8;
}

.logo-icon {
    font-size: 1.625rem;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.logo-text {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
    margin-left: 3rem;
    flex: 1;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9375rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: all 0.15s ease;
    position: relative;
}

.nav-links a:hover {
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.04);
}

.nav-links a[style*="color: #fbbf24"] {
    color: #d97706 !important;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    font-weight: 600;
}

.nav-links a[style*="color: #fbbf24"]:hover {
    background: linear-gradient(135deg, #fde68a 0%, #fcd34d 100%);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding-left: 1.5rem;
    border-left: 1px solid var(--border-color);
    margin-left: 1.5rem;
}

.user-email {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-badge {
    padding: 0.25rem 0.625rem;
    border-radius: 4px;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.superadmin-badge {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
    border: 1px solid #fcd34d;
}

.logout-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.8125rem;
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.logout-link:hover {
    color: #dc2626;
    background-color: #fef2f2;
}

/* Mobile Navigation */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-primary);
}

.nav-toggle svg {
    width: 24px;
    height: 24px;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem 0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.back-link {
    display: inline-block;
    color: var(--text-secondary);
    text-decoration: none;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--primary-color);
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.episode-summary-header {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-top: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-secondary:hover {
    background-color: var(--border-color);
}

.btn-outline {
    background-color: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.btn-outline:hover {
    background-color: var(--primary-color);
    color: white;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #059669;
}

/* Stories Grid */
.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.story-card {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

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

.story-card-header {
    margin-bottom: 1rem;
}

.story-card-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.story-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.source-badge {
    font-size: 1rem;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.source-badge:hover {
    opacity: 1;
}

.database-badge {
    filter: drop-shadow(0 1px 2px rgba(34, 197, 94, 0.3));
}

.filesystem-badge {
    filter: drop-shadow(0 1px 2px rgba(107, 114, 128, 0.3));
}

.story-counts {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.episode-count, .video-count {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
}

.video-count {
    background-color: #dbeafe;
    color: #1e40af;
}

.story-card-body {
    flex: 1;
    margin-bottom: 1rem;
}

.story-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.story-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.story-card-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Episodes List */
.episodes-section {
    margin-top: 2rem;
}

.episodes-section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.episodes-list {
    display: grid;
    gap: 1rem;
}

.episode-card {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.episode-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.episode-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.episode-badge {
    background-color: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
}

.episode-body h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.episode-summary {
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

.episode-status {
    margin-top: 0.5rem;
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
}

.status-badge.status-success {
    background-color: #d1fae5;
    color: #065f46;
}

.status-badge.status-warning {
    background-color: #fef3c7;
    color: #92400e;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.episode-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Episode Content */
.episode-content {
    margin-top: 2rem;
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.episode-content h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.episode-text {
    line-height: 1.8;
    color: var(--text-primary);
    font-size: 1rem;
}

.episode-text p {
    margin-bottom: 1.25rem;
}

/* Video Section */
.video-section {
    margin-top: 2rem;
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.video-section h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.video-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    background-color: #000;
    border-radius: var(--radius);
    overflow: hidden;
}

.video-player {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Config Editor */
.config-editor {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.config-warning {
    background-color: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
    color: #92400e;
}

.editor-container {
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
}

.editor-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.save-status {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    font-weight: 500;
}

.save-status.success {
    background-color: #d1fae5;
    color: #065f46;
}

.save-status.error {
    background-color: #fee2e2;
    color: #991b1b;
}

.save-status.info {
    background-color: #dbeafe;
    color: #1e40af;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-state h2,
.empty-state h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

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

.modal-content {
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 0;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalFadeIn 0.2s;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    transition: background-color 0.2s;
}

.modal-close:hover {
    background-color: var(--bg-tertiary);
}

.modal-body {
    padding: 1.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-group small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

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

/* Progress */
.progress-container {
    padding: 1rem 0;
}

.progress-bar {
    width: 100%;
    height: 1rem;
    background-color: var(--bg-tertiary);
    border-radius: 9999px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-fill {
    height: 100%;
    background-color: var(--primary-color);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-message {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* User Question Modal */
.user-question-text {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: var(--bg-secondary);
    border-radius: var(--radius);
    border-left: 3px solid var(--primary-color);
}

/* Error Page */
.error-page {
    text-align: center;
    padding: 4rem 2rem;
    background-color: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.error-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.error-page h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.error-message {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 1.125rem;
}

/* Footer */
.footer {
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 1.5rem 0;
    margin-top: auto;
}

.footer .container {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Episode Thumbnails */
.episode-content-wrapper {
    display: flex;
    gap: 1rem;
    width: 100%;
}

.episode-thumbnail {
    flex: 0 0 120px;
    width: 120px;
    height: 68px;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.thumbnail-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.episode-main {
    flex: 1;
    min-width: 0;
}

/* Missing Assets Indicators */
.story-needs-attention {
    border-left: 3px solid #ff9800;
}

.attention-badge {
    background: #ff9800;
    color: white;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.attention-dot {
    color: #ff3d00;
    font-size: 0.6rem;
    vertical-align: super;
    margin-left: 0.25rem;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.episode-needs-attention {
    border-left: 3px solid #ff9800;
}

.issue-count {
    background: #fff3e0;
    color: #e65100;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
}

.missing-assets {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #ffe0b2;
}

.missing-badge {
    background: #fff3e0;
    color: #e65100;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    border: 1px solid #ffcc80;
}

/* YouTube Management Styles */
.youtube-status {
    display: inline-flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.loading-youtube {
    color: #999;
    font-size: 0.85rem;
}

.status-youtube-uploaded {
    background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
    color: white;
}

.status-scored {
    background: linear-gradient(135deg, #9C27B0 0%, #7B1FA2 100%);
    color: white;
}

.status-thumbnail {
    background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
    color: white;
}

.status-shorts {
    background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
    color: white;
}

.youtube-actions {
    border-top: 1px solid #e8e8e8;
    padding-top: 0.75rem;
    margin-top: 0.75rem;
}

.youtube-actions-header {
    margin-bottom: 0.5rem;
}

.youtube-actions-header h5 {
    font-size: 0.8rem;
    color: #888;
    margin: 0;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.youtube-actions-grid {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-youtube {
    background: #f8f9fa;
    color: #495057;
    border: 1px solid #dee2e6;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    flex: 0 0 auto;
    white-space: nowrap;
}

.btn-youtube:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
}

.btn-danger {
    background: linear-gradient(135deg, #f44336 0%, #d32f2f 100%);
    color: white;
    border: none;
}

.btn-danger:hover:not(:disabled) {
    background: linear-gradient(135deg, #d32f2f 0%, #c62828 100%);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(244, 67, 54, 0.3);
}

.btn-disabled, .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #ccc !important;
    color: #666 !important;
}

.btn-disabled:hover, .btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

/* Responsive */
@media (max-width: 1024px) {
    .navbar .container {
        padding: 0 1.5rem;
    }
    
    .nav-links {
        margin-left: 2rem;
        gap: 0.125rem;
    }
    
    .nav-links a {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
    
    .user-email {
        max-width: 120px;
    }
}

@media (max-width: 768px) {
    .navbar .container {
        padding: 0 1rem;
        height: 56px;
    }
    
    .logo {
        font-size: 1rem;
    }
    
    .logo-icon {
        font-size: 1.375rem;
    }
    
    .nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        order: 3;
    }
    
    .nav-links {
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--bg-primary);
        flex-direction: column;
        padding: 1rem;
        gap: 0.25rem;
        margin-left: 0;
        border-bottom: 1px solid var(--border-color);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        transform: translateY(-100%);
        opacity: 0;
        pointer-events: none;
        transition: transform 0.25s ease, opacity 0.25s ease;
        z-index: 99;
    }
    
    .nav-links.active {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }
    
    .nav-links a {
        padding: 0.75rem 1rem;
        border-radius: 8px;
        font-size: 1rem;
    }
    
    .nav-user {
        flex: 1;
        justify-content: flex-end;
        padding-left: 0;
        border-left: none;
        margin-left: auto;
        gap: 0.5rem;
    }
    
    .user-email {
        display: none;
    }
    
    .logout-link {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    
    .page-header {
        flex-direction: column;
    }
    
    .header-actions {
        width: 100%;
    }
    
    .stories-grid {
        grid-template-columns: 1fr;
    }
    
    .episode-content-wrapper {
        flex-direction: column;
    }
    
    .episode-thumbnail {
        width: 100%;
        height: auto;
        aspect-ratio: 16/9;
        flex: none;
    }
    
    .episode-actions {
        width: 100%;
    }
    
    .episode-actions .btn {
        flex: 1;
    }
    
    .youtube-actions-grid {
        justify-content: flex-start;
    }
    
    .btn-youtube {
        font-size: 0.75rem;
        padding: 0.35rem 0.6rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 1rem;
    }
}

