/**
 * Render Tab v2 - Table-based Job Monitoring
 * Author: Médéric (Académie des Étoiles)
 * Date: 2026-02-11
 */

/* ==================== Container ==================== */

.render-tab-v2 {
    width: 80%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ==================== Header ==================== */

.render-tab__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.render-tab__title {
    font-size: 24px;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
}

/* ==================== Flush Dropdown ==================== */

.flush-dropdown {
    position: relative;
}

.btn-flush-toggle {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-flush-toggle:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.flush-dropdown__menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    min-width: 290px;
    z-index: 100;
    padding: 6px;
    flex-direction: column;
}

.flush-dropdown__menu.is-open {
    display: flex;
}

.flush-dropdown__item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    background: none;
    border: none;
    padding: 10px 12px;
    border-radius: 7px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.flush-dropdown__item:hover {
    background: #f9fafb;
}

.flush-item-icon {
    font-size: 18px;
    line-height: 1;
    margin-top: 2px;
    flex-shrink: 0;
}

.flush-item-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.flush-item-text strong {
    font-size: 13px;
    color: #111827;
    font-weight: 600;
}

.flush-item-text small {
    font-size: 12px;
    color: #6b7280;
}

.flush-dropdown__item--danger:hover {
    background: #fef2f2;
}

.flush-dropdown__item--danger .flush-item-text strong {
    color: #dc2626;
}

.flush-dropdown__divider {
    height: 1px;
    background: #f3f4f6;
    margin: 4px 0;
}

/* ==================== Flush Confirmation Modal ==================== */

.flush-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.flush-modal {
    background: white;
    border-radius: 16px;
    padding: 32px 28px 24px;
    max-width: 420px;
    width: calc(100% - 32px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.18);
    text-align: center;
    animation: flush-modal-in 0.18s ease;
}

@keyframes flush-modal-in {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.flush-modal__icon {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
}

.flush-modal__title {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
    margin: 0 0 10px;
}

.flush-modal__message {
    font-size: 14px;
    color: #6b7280;
    line-height: 1.6;
    margin: 0 0 24px;
}

.flush-modal__actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.flush-modal__cancel {
    padding: 9px 22px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: white;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.flush-modal__cancel:hover {
    background: #f3f4f6;
}

.flush-modal__confirm {
    padding: 9px 22px;
    border: none;
    border-radius: 8px;
    background: #f59e0b;
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.flush-modal__confirm:hover {
    background: #d97706;
}

.flush-modal__confirm--danger {
    background: #ef4444;
}

.flush-modal__confirm--danger:hover {
    background: #dc2626;
}

/* ==================== Bulk Actions Bar ==================== */

.bulk-actions-bar {
    display: none;
    justify-content: space-between;
    align-items: center;
    background: #3b82f6;
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.bulk-actions-bar__info {
    font-size: 14px;
    font-weight: 500;
}

.bulk-actions-bar__buttons {
    display: flex;
    gap: 8px;
}

.bulk-actions-bar__buttons button {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s;
}

.bulk-actions-bar__buttons button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ==================== Table Container ==================== */

.jobs-table-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow-x: auto; /* Allow horizontal scrolling on narrow windows */
    overflow-y: visible;
}

/* ==================== Table ==================== */

.jobs-table {
    width: 100%;
    border-collapse: collapse;
}

.jobs-table thead {
    background: #f9fafb;
    border-bottom: 2px solid #e5e7eb;
}

.jobs-table thead th {
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Sortable columns */
.jobs-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background 0.2s;
}

.jobs-table thead th.sortable:hover {
    background: #f3f4f6;
}

.jobs-table thead th.sortable.active {
    color: #3b82f6;
}

.sort-indicator {
    margin-left: 4px;
    font-size: 10px;
}

/* Column widths - responsive with minimum sizes */
.col-checkbox { width: 40px; min-width: 40px; text-align: center; }
.col-type { width: 120px; min-width: 100px; }
.col-title { width: auto; min-width: 150px; max-width: 400px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-progress { width: 150px; min-width: 100px; }
.col-status { width: 100px; min-width: 80px; }
.col-start { width: 120px; min-width: 90px; }
.col-duration { width: 100px; min-width: 70px; }
.col-actions { width: 100px; min-width: 80px; text-align: center; }

/* ==================== Table Rows ==================== */

.jobs-table tbody tr.job-row {
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.2s;
}

.jobs-table tbody tr.job-row:hover {
    background: #f9fafb;
}

.jobs-table tbody tr.job-row td {
    padding: 14px 16px;
    font-size: 14px;
    color: #374151;
    vertical-align: middle;
}

/* Status-based row styling */
.jobs-table tbody tr.job-row.status-queued {
    background: rgba(251, 191, 36, 0.03);
}

.jobs-table tbody tr.job-row.status-processing {
    background: rgba(59, 130, 246, 0.03);
}

.jobs-table tbody tr.job-row.status-completed {
    opacity: 0.7;
}

.jobs-table tbody tr.job-row.status-failed {
    background: rgba(239, 68, 68, 0.03);
}

.jobs-table tbody tr.job-row.status-cancelled {
    opacity: 0.5;
}

/* ==================== Type Badge ==================== */

.type-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    color: white;
    white-space: nowrap;
}

/* ==================== Job Title ==================== */

.job-title {
    display: block;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

/* ==================== Progress Bar ==================== */

.progress-bar-mini {
    position: relative;
    width: 120px;
    height: 24px;
    background: #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
}

.progress-bar-mini__fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    transition: width 0.3s ease;
}

.progress-bar-mini__text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #374151;
}

.progress-complete {
    color: #9ca3af;
    font-size: 16px;
}

/* ==================== Status Badge ==================== */

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge.status-queued {
    background: #fef3c7;
    color: #92400e;
}

.status-badge.status-processing {
    background: #dbeafe;
    color: #1e40af;
}

.status-badge.status-completed {
    background: #d1fae5;
    color: #065f46;
}

.status-badge.status-failed {
    background: #fee2e2;
    color: #991b1b;
}

.status-badge.status-cancelled {
    background: #f3f4f6;
    color: #6b7280;
}

/* ==================== Action Buttons ==================== */

.job-actions {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.btn-action {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-action:hover {
    background: #f3f4f6;
}

.btn-action.btn-cancel:hover {
    background: #fee2e2;
}

/* ==================== Expanded Row ==================== */

.job-row-expanded {
    background: #f9fafb !important;
    border-bottom: 1px solid #e5e7eb;
}

.job-row-expanded td {
    padding: 0 !important;
}

.job-details {
    padding: 20px;
    border-top: 1px solid #e5e7eb;
}

.job-details__grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-item.full-width {
    grid-column: 1 / -1;
}

.detail-label {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-value {
    font-size: 14px;
    color: #374151;
    font-weight: 500;
}

.detail-value.error {
    color: #dc2626;
    background: #fee2e2;
    padding: 8px 12px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

/* ==================== Empty State ==================== */

.jobs-table-empty {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-title {
    font-size: 20px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
}

.empty-subtitle {
    font-size: 14px;
    color: #9ca3af;
}

/* ==================== Checkbox ==================== */

input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #3b82f6;
}

/* ==================== Responsive ==================== */

@media (max-width: 1200px) {
    .render-tab-v2 {
        width: 95%;
    }

    .job-details__grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .render-tab-v2 {
        width: 100%;
        padding: 16px;
    }

    .bulk-actions-bar {
        flex-direction: column;
        gap: 12px;
    }

    .bulk-actions-bar__buttons {
        width: 100%;
        justify-content: space-between;
    }

    /* Hide less important columns on mobile */
    .col-duration,
    .col-start {
        display: none;
    }
}

/* ==================== Job Widget (Header Badge) ==================== */

.job-widget {
    display: flex;
    align-items: center;
    margin-left: 1rem;
}

.job-widget__badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #111827;
    cursor: pointer;
    transition: all 0.2s ease;
}

.job-widget__badge:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.job-widget__badge:active {
    transform: translateY(0);
}

.job-widget__icon {
    font-size: 1rem;
    line-height: 1;
}

.job-widget__count {
    font-variant-numeric: tabular-nums;
    min-width: 2ch;
    text-align: center;
}

.job-widget__badge--idle {
    opacity: 0.6;
}

.job-widget__badge--active {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

.job-widget__badge--active:hover {
    background: #dbeafe;
    border-color: #60a5fa;
}

.job-widget__badge--pulse {
    animation: pulse-badge 1s ease;
}

@keyframes pulse-badge {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 8px rgba(59, 130, 246, 0);
    }
}

/* ==================== Job Widget Modal ==================== */

.job-widget-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 1rem;
}

.job-widget-modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.job-widget-modal__content {
    position: relative;
    width: 100%;
    max-width: 450px;
    max-height: calc(100vh - 2rem);
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    margin-top: 4rem;
    animation: slide-in-right 0.2s ease;
}

@keyframes slide-in-right {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.job-widget-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem;
    border-bottom: 1px solid #e5e7eb;
}

.job-widget-modal__header h3 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: #111827;
}

.job-widget-modal__close {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    font-size: 1.5rem;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s ease;
}

.job-widget-modal__close:hover {
    background: #f3f4f6;
    color: #111827;
}

.job-widget-modal__body {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    max-height: 60vh;
}

.job-widget-modal__footer {
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
}

.job-widget-modal__view-all {
    width: 100%;
    padding: 0.75rem 1rem;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.job-widget-modal__view-all:hover {
    background: #1d4ed8;
}

.job-widget-modal__empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #6b7280;
}

.job-widget-modal__empty p {
    margin: 0.5rem 0;
}

.job-widget-modal__empty-hint {
    font-size: 0.875rem;
    opacity: 0.7;
}

.job-widget-modal__job {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s ease;
}

.job-widget-modal__job:hover {
    border-color: #d1d5db;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.job-widget-modal__job:last-child {
    margin-bottom: 0;
}

.job-widget-modal__job-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.job-widget-modal__job-icon {
    font-size: 1.5rem;
    line-height: 1;
    flex-shrink: 0;
}

.job-widget-modal__job-info {
    flex: 1;
    min-width: 0;
}

.job-widget-modal__job-title {
    font-weight: 500;
    font-size: 0.875rem;
    color: #111827;
    margin-bottom: 0.25rem;
}

.job-widget-modal__job-topic {
    font-size: 0.75rem;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.job-widget-modal__job-status {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.job-widget-modal__job-status--active {
    background: #dbeafe;
    color: #1d4ed8;
}

.job-widget-modal__job-status--completed {
    background: #dcfce7;
    color: #15803d;
}

.job-widget-modal__job-status--failed {
    background: #fee2e2;
    color: #b91c1c;
}

.job-widget-modal__job-status--cancelled {
    background: #f3f4f6;
    color: #374151;
}

.job-widget-modal__job-progress {
    margin-top: 0.75rem;
}

.job-widget-modal__job-progress-bar {
    height: 0.375rem;
    background: #e5e7eb;
    border-radius: 0.25rem;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.job-widget-modal__job-progress-fill {
    height: 100%;
    background: #2563eb;
    border-radius: 0.25rem;
    transition: width 0.3s ease;
}

.job-widget-modal__job-progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #6b7280;
}

.job-widget-modal__job-meta {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: #6b7280;
}

/* Pagination Controls */
.jobs-table-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--gray-50, #f9fafb);
}

.btn-prev-page,
.btn-next-page {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 0.375rem;
    background: white;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-prev-page:hover:not(:disabled),
.btn-next-page:hover:not(:disabled) {
    background: var(--gray-100, #f3f4f6);
    border-color: var(--gray-300, #d1d5db);
}

.btn-prev-page:disabled,
.btn-next-page:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-info {
    font-size: 0.875rem;
    color: var(--gray-600, #4b5563);
    min-width: 150px;
    text-align: center;
}
