/* ==========================================================================
   1. VARIABLES & RESET
   ========================================================================== */
:root {
    --bg-main: #0a0f1d;
    --bg-surface: #10192d;
    --bg-surface-elevated: #16223d;
    --bg-control: #0c1424;
    
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-glow: rgba(37, 99, 235, 0.35);
    
    --accent-blueprint: #38bdf8;
    --border-subtle: #1e293b;
    --border-hover: #334155;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-faint: #64748b;
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 0% 0%, rgba(37, 99, 235, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(56, 189, 248, 0.05) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    -webkit-font-smoothing: antialiased;
}

/* Alignement parfait des icônes Tabler */
.ti {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: -0.125em;
    font-size: 1.15em;
    line-height: 1;
}

/* ==========================================================================
   2. TYPOGRAPHIE & MISE EN PAGE GLOBALE
   ========================================================================== */
.content {
    padding: 24px 20px;
    max-width: 1400px;
    margin: auto;
}

.page-title {
    margin: 0 0 20px 0;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 13px;
}

.header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

.results-counter {
    color: var(--text-muted);
    font-size: 13px;
}

/* ==========================================================================
   3. NAVIGATION
   ========================================================================== */
.nav {
    background: rgba(13, 27, 46, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: cover;
}

.nav-title {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.3px;
    color: var(--text-main);
}

.nav-links {
    display: flex;
    gap: 16px;
    align-items: center;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 0.15s ease;
}

.nav-link:hover {
    color: var(--accent-blueprint);
}

.nav-link.logout {
    color: var(--danger);
    margin-left: 8px;
}

/* ==========================================================================
   4. FORMULAIRES & CONTRÔLES
   ========================================================================== */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="time"],
select {
    width: 100%;
    background: var(--bg-control);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="time"]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    filter: invert(1);
    opacity: 0.6;
    cursor: pointer;
}

input[type="time"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.7;
    cursor: pointer;
}

.field-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field-item label {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-main);
}

.field-item .field-key {
    font-family: monospace;
    font-size: 11px;
    color: var(--accent-blueprint);
    opacity: 0.8;
    margin-bottom: 2px;
}

.field-item .field-help {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 4px;
}

.select-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.select-wrapper {
    width: 100%;
}

.select-wrapper select {
    cursor: pointer;
}

.custom-checkbox {
    display: flex;
    align-items: center;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    color: var(--text-main);
}

.custom-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    accent-color: var(--primary);
    cursor: pointer;
}

.help-text {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    margin-left: 28px;
}

.card-control-box {
    background: var(--bg-control);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 16px;
    min-height: 54px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Ligne mixte mode + stepper */
.encode-controls-row {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

/* Stepper Workers */
.stepper-container {
    display: flex;
    flex-direction: column;
}

.worker-stepper {
    display: inline-flex;
    align-items: center;
    background: #141b2d;
    border: 1px solid #222e48;
    border-radius: 8px;
    padding: 3px 6px;
    height: 42px;
    box-sizing: border-box;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}

.stepper-btn {
    background: transparent;
    border: none;
    color: #8b9bb4;
    font-size: 18px;
    font-weight: 600;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.15s ease;
    user-select: none;
}

.stepper-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

.stepper-btn:active {
    transform: scale(0.92);
}

.stepper-value {
    min-width: 28px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    padding: 0 4px;
    user-select: none;
}

.btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 18px;
    cursor: pointer;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.15s ease, transform 0.1s ease;
}

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

.btn:active {
    transform: scale(0.98);
}

.btn.disabled {
    background: var(--bg-surface-elevated);
    color: var(--text-faint);
    pointer-events: none;
    border: 1px solid var(--border-subtle);
}

.btn-action {
    width: 100%;
    padding: 13px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-scan {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 10px var(--primary-glow);
}

.btn-scan:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-encode {
    background: #0284c7;
    color: #fff;
    box-shadow: 0 2px 10px rgba(2, 132, 199, 0.35);
}

.btn-encode:hover:not(:disabled) {
    background: #0369a1;
}

.btn-stop {
    background: var(--danger) !important;
    color: #fff !important;
}

.btn-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-subtle {
    background: var(--bg-control);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-subtle:hover {
    color: var(--text-main);
    border-color: var(--border-hover);
}

/* ==========================================================================
   5. COMPOSANTS STATISTIQUES & ACTIONS
   ========================================================================== */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stat-box {
    padding: 18px 14px;
    background: var(--bg-surface);
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
    text-align: center;
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    display: block;
}

.stat-box:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    background: var(--bg-surface-elevated);
}

.stat-box.active {
    border-color: var(--primary);
    box-shadow: 0 0 16px var(--primary-glow);
    background: var(--bg-surface-elevated);
}

.stat-box strong {
    display: block;
    font-size: 26px;
    font-weight: 700;
    margin-top: 8px;
}

.actions-dashboard {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 28px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.actions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-subtle);
}

.actions-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-control);
    border: 1px solid var(--border-subtle);
    padding: 6px 14px;
    border-radius: 9999px;
    font-size: 13px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
}

.status-dot.active {
    background: var(--accent-blueprint);
    box-shadow: 0 0 10px var(--accent-blueprint);
    animation: pulse 1.6s infinite ease-in-out;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.85); }
}

.status-text {
    color: var(--accent-blueprint);
    font-weight: 600;
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 18px;
}

.action-card {
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: border-color 0.2s ease;
}

.action-card:hover {
    border-color: var(--border-hover);
}

.card-top {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.card-icon {
    font-size: 24px;
    padding: 10px;
    background: var(--bg-control);
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    color: var(--accent-blueprint);
}

.action-card h3 {
    margin: 0 0 4px 0;
    font-size: 15px;
    font-weight: 600;
}

.card-desc {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.card-form {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    justify-content: space-between;
}

/* ==========================================================================
   6. SECTION WORKERS & BADGES PIPELINE
   ========================================================================== */
.workers-dashboard {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 28px;
}

.workers-dashboard-title {
    margin: 0 0 14px 0;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-blueprint);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.workers-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.worker-card {
    display: flex;
    align-items: center;
    background: var(--bg-surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 12px 16px;
    gap: 14px;
    font-size: 13px;
    flex-wrap: wrap;
}

.worker-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-control);
    border: 1px solid var(--border-subtle);
    color: var(--accent-blueprint);
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 11px;
}

.worker-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-blueprint);
    border-radius: 50%;
}

.worker-filename {
    flex: 1 1 200px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.worker-badges-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.worker-step-badge {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-blueprint);
    border: 1px solid rgba(56, 189, 248, 0.25);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.worker-pipeline-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.3px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.pipeline-full-gpu {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.35);
}

.pipeline-hybrid {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-blueprint);
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.worker-progress-box {
    flex: 1 1 180px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.worker-progress-text {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
}

.worker-progress-bar-bg {
    width: 100%;
    height: 6px;
    background: var(--bg-control);
    border-radius: 999px;
    overflow: hidden;
}

.worker-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent-blueprint));
    border-radius: 999px;
}

.worker-meta {
    display: flex;
    gap: 14px;
    font-size: 12px;
    color: var(--text-muted);
}

.text-green { color: #34d399 !important; }
.text-danger { color: #ef4444 !important; }
.text-muted { color: var(--text-faint) !important; }
.text-white { color: #ffffff !important; }

/* ==========================================================================
   7. TABLEAUX, LARGEURS & TRI DE COLONNES
   ========================================================================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    background: var(--bg-surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

th, td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
    text-align: left;
}

/* La colonne Fichier prend toute la place restante sans être écrasée */
th:first-child, td:first-child {
    width: auto;
}

/* Taille (MB) compacte */
th:nth-child(2), td:nth-child(2) {
    width: 120px;
    min-width: 110px;
    white-space: nowrap;
}

/* Colonnes d'état compactes et centrées */
th:nth-child(3), td:nth-child(3),
th:nth-child(4), td:nth-child(4),
th:nth-child(5), td:nth-child(5),
th:nth-child(6), td:nth-child(6) {
    width: 95px;
    min-width: 85px;
    text-align: center;
    white-space: nowrap;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

th.sortable:hover {
    background-color: var(--border-hover);
    color: var(--text-main);
}

th.sortable.active-sort {
    color: var(--accent-blueprint);
}

.sort-icon {
    font-size: 13px;
    margin-left: 6px;
    opacity: 0.5;
    transition: opacity 0.15s ease;
}

th.sortable:hover .sort-icon,
th.sortable.active-sort .sort-icon {
    opacity: 1;
}

/* Affichage du chemin complet sans troncature (...) */
.col-filename {
    font-family: monospace;
    font-size: 12px;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
}

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    gap: 12px;
}

/* ==========================================================================
   8. PAGES SETTINGS & SCHEDULE
   ========================================================================== */
.settings-container {
    max-width: 1200px;
    margin: 0 auto;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 24px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-subtle);
}

.settings-header h1 {
    margin: 0 0 4px 0;
    font-size: 22px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    margin-bottom: 24px;
    overflow: hidden;
}

.settings-card-header {
    background: var(--bg-surface-elevated);
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.settings-card-header h2 {
    margin: 0 0 4px 0;
    font-size: 16px;
    color: var(--accent-blueprint);
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-card-header p {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 18px;
    padding: 20px;
}

.folder-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px;
    padding: 18px;
}

.folder-check-item {
    display: flex;
    align-items: center;
    background: var(--bg-control);
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    font-size: 13px;
    word-break: break-all;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.15s ease;
}

.folder-check-item:hover {
    border-color: var(--primary);
}

.form-actions-bottom {
    display: flex;
    justify-content: flex-end;
    margin-top: 15px;
    margin-bottom: 40px;
}

/* ==========================================================================
   9. AUTHENTIFICATION (LOGIN)
   ========================================================================== */
.login-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 16px;
}

.login-box {
    background: var(--bg-surface);
    padding: 36px 28px;
    border-radius: 14px;
    border: 1px solid var(--border-subtle);
    text-align: center;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.error {
    color: var(--danger);
    margin-bottom: 15px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* ==========================================================================
   10. ADAPTABILITÉ MOBILE (RESPONSIVE)
   ========================================================================== */
@media (max-width: 640px) {
    .content {
        padding: 14px;
    }

    .nav-container {
        padding: 10px 14px;
    }

    .nav-title {
        display: none;
    }

    .nav-links {
        gap: 10px;
    }

    .nav-link {
        font-size: 13px;
    }

    .settings-header button,
    .form-actions-bottom button {
        width: 100%;
    }

    .encode-controls-row {
        flex-direction: column;
        align-items: stretch;
    }

    .stepper-container {
        width: 100%;
    }

    .worker-stepper {
        justify-content: space-between;
    }

    .worker-card {
        flex-direction: column;
        align-items: flex-start;
    }

    .worker-progress-box,
    .worker-meta {
        width: 100%;
        justify-content: space-between;
    }
}