/**
 * Flash Firmware Modal Styles
 * Modal for flashing firmware to devices over USB COM port
 * 
 * @package Alledio Production Dashboard
 * @version 1.0
 */

/* Modal overlay */
.flash-firmware-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
    z-index: 6000 !important;
    isolation: isolate;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
    /* Hide scrollbar but keep functionality */
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
    overflow-y: auto;
}

.flash-firmware-modal-overlay::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    background: transparent !important;
    display: none !important;
}

.flash-firmware-modal-overlay::-webkit-scrollbar-track,
.flash-firmware-modal-overlay::-webkit-scrollbar-thumb {
    display: none !important;
}

.flash-firmware-modal-overlay.active {
    display: flex;
}

/* Prevent background scroll when modal is active */
body.flash-firmware-modal-open {
    overflow: hidden !important;
}

/* Modal container */
.flash-firmware-modal {
    background-image: url("../../images/bg_noise.webp"), linear-gradient(180deg, var(--color-bg-gradient-top, #f8f8f7), var(--color-bg-gradient-bottom, #f1f0ee));
    background-position: 0 0, 0 0;
    background-size: auto, auto;
    border: 1px solid var(--color-border, #dddfe0);
    border-radius: 1.25rem;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md, 0 2px 8px rgba(0, 0, 0, 0.08));
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Modal header */
.flash-firmware-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: none;
}

.flash-firmware-modal-title {
    font-size: 22px;
    font-weight: 600;
    color: #2c3e50;
    margin: 0;
}

.flash-firmware-modal-close {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #2c3e50;
    opacity: 0.6;
    transition: opacity 0.2s ease;
    border-radius: 6px;
}

.flash-firmware-modal-close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
}

.flash-firmware-modal-close svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
}

/* Modal body */
.flash-firmware-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    padding-top: 0.5rem;
    /* Hide scrollbar but keep functionality */
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}

.flash-firmware-modal-body::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    background: transparent !important;
    display: none !important;
}

.flash-firmware-modal-body::-webkit-scrollbar-track,
.flash-firmware-modal-body::-webkit-scrollbar-thumb {
    display: none !important;
}

/* Form sections */
.flash-form-section {
    background: #ffffff;
    border: 1px solid #e8ecef;
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 20px;
}

.flash-form-section-title {
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
    margin: 0 0 16px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.flash-form-section-title svg {
    width: 18px;
    height: 18px;
    stroke: #2d8998;
}

/* Form groups */
.flash-form-group {
    margin-bottom: 16px;
}

.flash-form-group:last-child {
    margin-bottom: 0;
}

.flash-form-group label {
    display: block;
    margin-bottom: 8px;
    color: #34495e;
    font-weight: 600;
    font-size: 12px;
}

.flash-form-group .form-hint {
    display: block;
    font-size: 11px;
    color: #777;
    font-weight: 400;
    margin-top: 4px;
}

/* Dropdown containers */
.flash-dropdown-container,
.flash-firmware-selector-container {
    width: 100%;
}

/* ESP32 specific section - hidden by default */
.flash-esp32-section {
    display: none;
}

.flash-esp32-section.active {
    display: block;
}

/* Two column layout for ESP32 settings */
.flash-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* Checkbox group */
.flash-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.flash-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #2c3e50;
    cursor: pointer;
}

.flash-checkbox-label input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
    margin: 0;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    border: 2px solid var(--color-border, #dddfe0);
    border-radius: 4px;
    background-color: var(--color-bg, #ffffff);
    position: relative;
    transition: all 0.2s ease;
}

.flash-checkbox-label input[type="checkbox"]:hover {
    border-color: var(--color-primary, #2d8998);
    background-color: var(--color-primary-light, #e3f2fd);
}

.flash-checkbox-label input[type="checkbox"]:checked {
    background-color: var(--color-primary, #2d8998);
    border-color: var(--color-primary, #2d8998);
}

.flash-checkbox-label input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.flash-checkbox-label input[type="checkbox"]:focus {
    outline: none;
    box-shadow: var(--shadow-focus-glow);
    border-color: var(--color-primary, #2d8998);
}

/* Offset display section - hidden by default */
.flash-offset-section {
    display: none;
}

.flash-offset-section.active {
    display: block;
}

.flash-offset-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.flash-offset-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.flash-offset-item label {
    font-size: 11px;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.flash-offset-value {
    display: flex;
    align-items: center;
    gap: 8px;
}

.flash-offset-value input {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid #e8ecef;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    background: #f8f9fa;
    color: #2c3e50;
    font-weight: 600;
}

.flash-offset-value input:focus {
    outline: none;
    border-color: #2d8998;
}

.flash-offset-copy-btn {
    padding: 8px;
    background: transparent;
    border: 1px solid #e8ecef;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #2d8998;
}

.flash-offset-copy-btn:hover {
    background: #e3f2fd;
    border-color: #2d8998;
}

.flash-offset-copy-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

/* Progress section */
.flash-progress-section {
    display: none;
}

.flash-progress-section.active {
    display: block;
}

.flash-progress-bar {
    width: 100%;
    height: 8px;
    background: #e8ecef;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.flash-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #2d8998 0%, #1a5f6d 100%);
    transition: width 0.3s ease;
    width: 0%;
}

.flash-progress-status {
    font-size: 12px;
    color: #555;
    text-align: center;
}

/* Modal footer */
.flash-firmware-modal-footer {
    padding: 1rem 2rem;
    border-top: 1px solid #e8ecef;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: #ffffff;
}

.flash-btn {
    padding: 10px 24px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.flash-btn-cancel {
    background: #f8f9fa;
    color: #2c3e50;
    border: 1px solid #e8ecef;
}

.flash-btn-cancel:hover {
    background: #e9ecef;
}

.flash-btn-flash {
    background: #b8e0e8;
    color: #105c74;
    border: 1px solid #a8d5e0;
}

.flash-btn-flash:hover {
    background: #a8d5e0;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(45, 137, 152, 0.2);
}

.flash-btn-flash:active {
    transform: translateY(0);
}

.flash-btn-flash:disabled,
.flash-btn-cancel:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 768px) {
    .flash-firmware-modal {
        width: 95%;
        max-height: 95vh;
    }

    .flash-form-row {
        grid-template-columns: 1fr;
    }

    .flash-offset-grid {
        grid-template-columns: 1fr;
    }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    .flash-firmware-modal {
        background-image: none;
        background: var(--color-bg-input-disabled, #0a0b0c);
        border-color: var(--color-border, rgba(255, 255, 255, 0.12));
    }

    .flash-firmware-modal-title {
        color: var(--color-text-primary, #e5e7eb);
    }

    .flash-firmware-modal-close {
        color: var(--color-text-primary, #e5e7eb);
    }

    .flash-firmware-modal-close:hover {
        background: var(--color-bg-hover, rgba(255, 255, 255, 0.1));
    }

    .flash-form-section {
        background: var(--color-bg, #0f1113);
        border-color: var(--color-border, rgba(255, 255, 255, 0.12));
    }

    .flash-form-section-title {
        color: var(--color-text-primary, #e5e7eb);
    }

    .flash-form-group label {
        color: var(--color-text-secondary, #cbd5e1);
    }

    .flash-form-group .form-hint {
        color: var(--color-text-tertiary, #94a3b8);
    }

    .flash-checkbox-label {
        color: var(--color-text-primary, #e5e7eb);
    }

    .flash-offset-item label {
        color: var(--color-text-secondary, #cbd5e1);
    }

    .flash-offset-value input {
        background: var(--color-bg-input, #111315);
        border-color: var(--color-border, rgba(255, 255, 255, 0.12));
        color: var(--color-text-primary, #e5e7eb);
    }

    .flash-offset-copy-btn {
        border-color: var(--color-border, rgba(255, 255, 255, 0.12));
        color: var(--color-primary, #2d8998);
    }

    .flash-offset-copy-btn:hover {
        background: rgba(45, 137, 152, 0.2);
        border-color: var(--color-primary, #2d8998);
    }

    .flash-progress-bar {
        background: var(--color-bg-input, #111315);
    }

    .flash-progress-status {
        color: var(--color-text-secondary, #cbd5e1);
    }

    .flash-firmware-modal-footer {
        background: var(--color-bg, #0f1113);
        border-top-color: var(--color-border, rgba(255, 255, 255, 0.12));
    }

    .flash-btn-cancel {
        background: var(--color-bg-input, #111315);
        color: var(--color-text-primary, #e5e7eb);
        border-color: var(--color-border, rgba(255, 255, 255, 0.12));
    }

    .flash-btn-cancel:hover {
        background: var(--color-bg-hover, rgba(255, 255, 255, 0.1));
    }

    .flash-btn-flash {
        background: rgba(45, 137, 152, 0.3);
        color: #b8e0e8;
        border-color: rgba(45, 137, 152, 0.4);
    }

    .flash-btn-flash:hover {
        background: rgba(45, 137, 152, 0.4);
    }
}
