:root {
    --primary-color: #4a69bd;
    --primary-color-dark: #3c56a3;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    
    --text-color: #343a40;
    --text-color-light: #6c757d;
    --bg-color: #f8f9fa;
    --card-bg-color: #ffffff;
    --border-color: #dee2e6;
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --border-radius: 8px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --transition: all 0.2s ease-in-out;
}

/* --- Global Styles & Resets --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 16px;
    line-height: 1.6;
}

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

/* --- Layout --- */
.page-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.navbar {
    background-color: var(--card-bg-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
}

.navbar-brand a {
    color: var(--text-color);
    text-decoration: none;
}

.navbar-brand i {
    color: var(--primary-color);
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-link {
    color: var(--text-color-light);
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link:hover {
    color: var(--primary-color);
    background-color: #f8f9fa;
}

.nav-link.active {
    color: var(--primary-color);
    background-color: #e3f2fd;
}

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

.logout-btn {
    color: var(--text-color-light);
    font-size: 1.25rem;
    text-decoration: none;
    transition: var(--transition);
}
.logout-btn:hover {
    color: var(--primary-color);
}

.main-content {
    flex-grow: 1;
    padding: 2.5rem 0;
}

/* --- Dashboard & Cards --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
}

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

.card {
    background-color: var(--card-bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.card-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.card-body {
    padding: 1.5rem;
}

/* --- Table Styles --- */
.table-container {
    overflow-x: auto;
}
.task-table {
    width: 100%;
    border-collapse: collapse;
}
.task-table th, .task-table td {
    padding: 1rem;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}
.task-table th:nth-child(3), .task-table td:nth-child(3) {
    width: 200px;
    min-width: 200px;
}
.task-table th {
    font-weight: 600;
    color: var(--text-color-light);
    font-size: 0.875rem;
    text-transform: uppercase;
}
.task-table tr:last-child td {
    border-bottom: none;
}
.task-table tr:hover {
    background-color: #fcfcfd;
}
.task-table code {
    background-color: #e9ecef;
    padding: 0.2em 0.4em;
    border-radius: 4px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
}

/* --- Status Badges --- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 0.875rem;
    font-weight: 500;
}
.status-badge i {
    font-size: 0.6em;
}
.status-active {
    background-color: #e6f9f1;
    color: #28a745;
}
.status-inactive {
    background-color: #fdf0f1;
    color: #dc3545;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border: 1px solid transparent;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition);
}
.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-primary { background-color: var(--primary-color); color: white; border-color: var(--primary-color); }
.btn-primary:hover { background-color: var(--primary-color-dark); border-color: var(--primary-color-dark); }
.btn-secondary { background-color: #e9ecef; color: var(--text-color); border-color: #e9ecef;}
.btn-secondary:hover { background-color: #d1d5db; border-color: #d1d5db;}

.actions { display: flex; gap: 0.5rem; align-items: center; min-height: 109px; }
.btn-icon {
    padding: 0.6rem;
    width: 38px;
    height: 38px;
    justify-content: center;
    border-radius: 50%;
    border: none;
}
.btn-success { background-color: #e6f9f1; color: #28a745; }
.btn-success:hover { background-color: #d4f5e6; }
.btn-info { background-color: #e1f5fe; color: #17a2b8; }
.btn-info:hover { background-color: #c8f0fd; }
.btn-warning { background-color: #fff8e1; color: #f57c00; }
.btn-warning:hover { background-color: #fff3cd; }
.btn-danger { background-color: #fdf0f1; color: #dc3545; }
.btn-danger:hover { background-color: #fce4e6; }

/* --- Modals --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    padding: 1rem;
}
.modal-content {
    background-color: var(--card-bg-color);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 550px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.modal-large { max-width: 800px; }

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 { font-size: 1.25rem; font-weight: 600; }
.close {
    color: var(--text-color-light);
    font-size: 1.5rem;
    font-weight: normal;
    background: none;
    border: none;
    cursor: pointer;
    transition: var(--transition);
}
.close:hover { color: var(--danger-color); }

.modal-body { padding: 1.5rem; }
.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    background-color: #f8f9fa;
    border-bottom-left-radius: var(--border-radius);
    border-bottom-right-radius: var(--border-radius);
}

/* --- Forms --- */
.form-group { margin-bottom: 1.25rem; }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.95rem;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-family: var(--font-family);
    transition: var(--transition);
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 105, 189, 0.2);
}
.form-group small {
    display: block;
    margin-top: 0.5rem;
    color: var(--text-color-light);
    font-size: 0.875rem;
}
.form-group small a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

/* --- Log Display --- */
#logContent {
    background-color: #212529;
    color: #e9ecef;
    border-radius: var(--border-radius);
    padding: 1.25rem;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.9rem;
    line-height: 1.5;
    max-height: 50vh;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-color-light);
}
.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: #ced4da;
}
.empty-state p { font-size: 1.1rem; margin: 0; }

/* --- Login Page --- */
.login-page {
    background-color: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-form {
    background-color: var(--card-bg-color);
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}
.login-form h2 {
    text-align: center;
    margin-bottom: 2rem;
    font-weight: 600;
}
.btn-full {
    width: 100%;
    padding: 0.8rem;
}

/* --- Alerts --- */
.alert {
    padding: 1rem;
    margin-bottom: 1.5rem;
    border-radius: var(--border-radius);
    text-align: center;
}
.alert-error {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
    .form-row {
        flex-direction: column;
    }
    .navbar {
        padding: 1rem;
    }
    .main-content {
        padding: 1.5rem 0;
    }
}

/* --- Database Dashboard Styles --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background-color: var(--card-bg-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 0.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.stat-card:nth-child(1) .stat-icon {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-card:nth-child(2) .stat-icon {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-card:nth-child(3) .stat-icon {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.stat-card:nth-child(4) .stat-icon {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.stat-content h3 {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-color);
}

.stat-content p {
    margin: 0;
    color: var(--text-color-light);
    font-size: 0.9rem;
}

.filters-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.card-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th, .data-table td {
    padding: 1rem;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    font-weight: 600;
    color: var(--text-color-light);
    font-size: 0.875rem;
    text-transform: uppercase;
    background-color: #f8f9fa;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover {
    background-color: #fcfcfd;
}

.upload-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 300px;
}

.thumbnail {
    width: 40px;
    height: 30px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

.badge-shorts {
    background-color: #fff3cd;
    color: #856404;
}

.badge-video {
    background-color: #d1ecf1;
    color: #0c5460;
}

.badge-good {
    background-color: #d4edda;
    color: #155724;
}

.badge-bad {
    background-color: #f8d7da;
    color: #721c24;
}

.badge-null {
    background-color: #e2e3e5;
    color: #383d41;
}

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.pagination-info {
    color: var(--text-color-light);
    font-size: 0.9rem;
}

.pagination-controls {
    display: flex;
    gap: 0.5rem;
}

.loading, .error, .empty {
    text-align: center;
    padding: 2rem;
    color: var(--text-color-light);
}

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

.empty {
    font-style: italic;
}

.upload-details {
    line-height: 1.8;
}

.upload-details p {
    margin-bottom: 0.5rem;
}

.upload-details strong {
    color: var(--text-color);
}

/* Responsive adjustments for database dashboard */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .filters-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .filters-row {
        grid-template-columns: 1fr;
    }
    
    .card-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    
    .pagination {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .upload-title {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .thumbnail {
        width: 60px;
        height: 45px;
    }
}

/* Selected stat card */
.stat-card.selected {
    border-color: var(--primary-color);
    background-color: #f8f9ff;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(74, 105, 189, 0.15);
}

/* Task status monitoring styles */
.btn-running {
    background-color: #fff8e1 !important;
    color: #f57c00 !important;
    animation: pulse 2s infinite;
}

.btn-completed {
    background-color: #e6f9f1 !important;
    color: #28a745 !important;
}

.btn-failed {
    background-color: #fdf0f1 !important;
    color: #dc3545 !important;
}

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

/* --- Task Statistics Styles --- */
.statistics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.stat-card {
    background: var(--card-bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.stat-card h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f0f0f0;
}

.stat-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.stat-label {
    color: var(--text-color-light);
    font-weight: 500;
    font-size: 0.9rem;
}

.stat-value {
    color: var(--text-color);
    font-weight: 600;
    font-size: 1rem;
}

/* --- Task History Styles --- */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-actions select {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--card-bg-color);
    color: var(--text-color);
    font-size: 0.875rem;
    min-width: 150px;
}

.header-actions select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 105, 189, 0.2);
}

/* --- Loading and Error States --- */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-color-light);
    font-style: italic;
}

.error {
    background-color: #fdf0f1;
    color: var(--danger-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    border: 1px solid #f5c6cb;
    text-align: center;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    .statistics-grid {
        grid-template-columns: 1fr;
    }
    
    .header-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    
    .header-actions select {
        min-width: auto;
    }
    
    .stat-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }
    
    .stat-value {
        font-size: 1.1rem;
        color: var(--primary-color);
    }
}

/* --- Task Execution Details --- */
.execution-details {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.task-execution-section {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    background-color: var(--card-bg-color);
}

.task-execution-section h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
    font-size: 1.1rem;
    font-weight: 600;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 0.5rem;
}

.execution-timeline {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.execution-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--border-radius);
    background-color: #f8f9fa;
    border: 1px solid var(--border-color);
    min-width: 140px;
    transition: var(--transition);
}

.execution-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.execution-item.status-completed {
    border-left: 4px solid var(--success-color);
    background-color: #f8fff9;
}

.execution-item.status-failed {
    border-left: 4px solid var(--danger-color);
    background-color: #fff8f8;
}

.execution-item.status-timeout {
    border-left: 4px solid var(--warning-color);
    background-color: #fffdf8;
}

.execution-item.status-running {
    border-left: 4px solid var(--info-color);
    background-color: #f8fcff;
}

.execution-status {
    display: flex;
    align-items: center;
    justify-content: center;
}

.status-icon {
    font-size: 1.2rem;
}

.execution-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
}

.execution-time {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
}

.execution-duration {
    color: var(--text-color-light);
    font-size: 0.85rem;
    font-weight: 500;
}

.execution-error {
    color: var(--danger-color);
    font-size: 0.8rem;
    font-style: italic;
    background-color: #fdf0f1;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    margin-top: 0.25rem;
}

@media (max-width: 768px) {
    .execution-timeline {
        flex-direction: column;
    }
    
    .execution-item {
        min-width: auto;
        width: 100%;
    }
    
    .task-execution-section {
        padding: 1rem;
    }
}

#logModalContent {
    max-width: 100%;
}