/* Module de gestion firmware */
.firmware-module {
    padding: 10px;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    box-sizing: border-box;
}

/* Le parent .module-content-body doit aussi propager la hauteur */
.module-content-body:has(.firmware-module) {
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.firmware-main-grid {
    display: grid;
    grid-template-columns: 55% 45%;
    gap: 20px;
    margin-top: 5px;
    flex: 1 1 auto;
    min-height: 0;
    align-items: stretch;
}

/* Portrait tablette / mobile : layout vertical scrollable */
@media (max-width: 768px), (orientation: portrait) and (max-width: 1024px) {
    /* Neutraliser le système de hauteur fixe du mode paysage */
    .module-content-body:has(.firmware-module) {
        overflow: visible;
        overflow-y: auto;
        display: block;
        height: auto;
    }

    .firmware-module {
        height: auto;
        min-height: unset;
        overflow: visible;
    }

    .firmware-main-grid {
        grid-template-columns: 1fr;
        flex: none;
        height: auto;
        min-height: unset;
    }

    .firmware-targets-section {
        min-height: 200px;
        max-height: 50vh;
    }

    .targets-list {
        flex: none;
        max-height: calc(50vh - 80px);
    }
}

/* Section des cibles */
.firmware-targets-section {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.targets-list {
    flex: 1 1 auto;
    overflow-y: auto;
    margin-top: 8px;
    min-height: 0;
}

.target-item {
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
}

.target-item:last-child {
    border-bottom: none;
}

.target-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.target-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    flex-shrink: 0;
    max-width: 200px;
    min-width: 150px;
}

.target-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.target-info {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 6px;
    flex: 1;
    overflow: hidden;
}

.target-id {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--primary-color);
    white-space: nowrap;
    flex-shrink: 0;
}

.target-name {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
    min-width: 0;
}

.target-version {
    font-size: 0.8em;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.target-status {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 60px;
    text-align: right;
    flex-shrink: 0;
}

.target-progress {
    flex: 1;
    margin: 0 10px;
}

.target-progress .progress-bar {
    width: 100%;
    height: 24px;
    background: #e9ecef;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.target-progress .progress-bar-fill {
    height: 100%;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    transition: width 0.3s;
}

.target-progress .progress-bar-fill.error {
    background: linear-gradient(135deg, #ee0979 0%, #ff6a00 100%);
}

/* Section actions (upload et déploiement) */
.firmware-actions-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.firmware-upload-section,
.firmware-list-section,
.logs-section {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.section-header h4 {
    margin: 0;
    color: var(--text-primary);
}

/* Zone d'upload */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    transition: all 0.3s ease;
    display: inline-block;
    width: auto;
}

.upload-zone.drag-over {
    border-color: var(--primary-color);
    background: var(--hover-bg);
}

.upload-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.upload-icon {
    font-size: 24px;
}

/* Liste des firmwares */
.firmware-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
}

.firmware-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.firmware-item:hover {
    background: var(--hover-bg);
}

.firmware-item.selected {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.firmware-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.firmware-name {
    font-weight: 600;
    color: var(--text-primary);
}

.firmware-size {
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* Section de déploiement */
.deployment-section {
    text-align: center;
}

.deployment-section .btn-lg {
    padding: 15px 40px;
    font-size: 1.1em;
}

/* Barres de progression */
.progress-section {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
}

#progress-bars {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.progress-item {
    margin-bottom: 15px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 2px solid var(--border-color);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 600;
}

.progress-bar-container {
    width: 100%;
    height: 24px;
    background: var(--hover-bg);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    transition: width 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.85rem;
}

.progress-bar-fill.error {
    background: linear-gradient(135deg, #ee0979 0%, #ff6a00 100%);
}

/* Old progress bar styles (kept for compatibility) */
.old-progress-bar {
    display: grid;
    grid-template-columns: 150px 1fr 60px;
    gap: 10px;
    align-items: center;
}

.progress-label {
    font-weight: 600;
    color: var(--text-primary);
}

.progress-track {
    height: 24px;
    background: var(--hover-bg);
    border-radius: 12px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
    transition: width 0.3s ease;
    border-radius: 12px;
}

.progress-value {
    text-align: right;
    font-weight: 600;
    color: var(--text-primary);
}

/* Logs */
.firmware-logs {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 15px;
    height: calc(100vh - 550px);
    min-height: 250px;
    max-height: 600px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.log-entry {
    padding: 4px 0;
    border-bottom: 1px solid var(--border-color);
}

.log-entry:last-child {
    border-bottom: none;
}

.log-info {
    color: var(--text-primary);
}

.log-success {
    color: var(--success-color);
}

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

.log-warning {
    color: var(--warning-color);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-style: italic;
}

/* Responsive: tablette paysage */
@media (min-width: 769px) and (max-width: 1200px) and (orientation: landscape) {
    .firmware-main-grid {
        grid-template-columns: 45% 55%;
        gap: 15px;
    }
    
    .firmware-module {
        padding: 8px;
    }
    
    .firmware-targets-section,
    .firmware-actions-section {
        padding: 15px;
    }
    
    .targets-list {
        max-height: 300px;
    }
    
    .logs-section .logs-container {
        height: calc(100vh - 600px);
        min-height: 200px;
        max-height: 400px;
    }
    
    .section-header h4 {
        font-size: 1em;
    }
}

/* Responsive: mobile */
@media (max-width: 768px) {
    .firmware-main-grid {
        grid-template-columns: 1fr;
    }
    
    .progress-bar {
        grid-template-columns: 100px 1fr 50px;
        gap: 8px;
    }
}

/* Dark mode */
body.dark-mode .upload-zone {
    border-color: #444;
}

body.dark-mode .upload-zone.drag-over {
    background: rgba(13, 110, 253, 0.1);
}

body.dark-mode #deploy-button {
    background-color: #66BB6A !important;
    color: #1A1A1A !important;
    border-color: #66BB6A !important;
}

body.dark-mode #deploy-button:hover:not(:disabled) {
    background-color: #7CB342 !important;
}

body.dark-mode #deploy-button:disabled {
    opacity: 0.6;
}
