/**
 * SETTINGS - VERSION ADMIN MODERNE COMPLÈTE
 * Utilise les variables de theme.css
 * Toutes les fonctionnalités conservées + CORRECTIONS SESSIONS
 */

/* ========================================
   MAIN CONTAINER
   ======================================== */

.settings-main {
    padding: 40px 20px;
    max-width: 680px;
    margin: 0 auto;
}

.settings-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* ========================================
   HEADER
   ======================================== */

.settings-header {
    text-align: center;
    margin-bottom: 20px;
}

.settings-header h1 {
    font-size: 36px;
    font-weight: 700;
    margin: 0 0 10px 0;
    color: var(--text-primary);
}

.settings-subtitle {
    color: var(--text-muted);
    font-size: 16px;
    margin: 0;
}

/* ========================================
   MESSAGES
   ======================================== */

.message-box {
    padding: 16px 20px;
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideDown 0.3s ease-out;
}

.message-box.success-message {
    background: rgba(var(--success-rgb), 0.1);
    border: 1px solid rgba(var(--success-rgb), 0.3);
}

.message-box.error-message {
    background: rgba(var(--danger-rgb), 0.1);
    border: 1px solid rgba(var(--danger-rgb), 0.3);
}

.message-icon {
    font-size: 24px;
}

.message-content p {
    margin: 0;
    color: var(--text-primary);
    font-size: 14px;
}


/* ========================================
   SETTINGS SECTIONS
   ======================================== */

.settings-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 30px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.settings-section:hover {
    border-color: var(--border-color-hover);
    box-shadow: var(--shadow-md);
}

/* ========================================
   SECTION HEADER
   ======================================== */

.section-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.section-icon {
    font-size: 32px;
    line-height: 1;
    color: var(--primary);
}

.section-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 6px 0;
    color: var(--text-primary);
}

.section-description {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0;
}

/* ========================================
   FORMS
   ======================================== */

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.label-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.label-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
}

.form-control:hover {
    background: var(--bg-hover);
}

.form-control:focus {
    outline: none;
    border-color: var(--border-color-focus);
    background: var(--bg-input-focus);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
}

/* Correction des options du select */
.form-control option {
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 10px;
}

/* ========================================
   CUSTOM SELECT (DESKTOP/TESLA)
   ======================================== */

.custom-select-wrapper {
    position: relative;
    width: 100%;
}

.custom-select {
    position: relative;
    width: 100%;
    cursor: pointer;
    user-select: none;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 14px;
    transition: var(--transition);
    color: var(--text-primary);
}

.custom-select-trigger:hover {
    background: var(--bg-hover);
}

.custom-select.open .custom-select-trigger {
    background: var(--bg-input-focus);
    border-color: var(--border-color-focus);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.arrow {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid var(--text-primary);
    transition: transform 0.2s ease;
    margin-left: 10px;
}

.custom-select.open .arrow {
    transform: rotate(180deg);
}

.custom-options {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color-focus);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: var(--shadow-lg);
}

/* Force opacité complète en mode sombre */
[data-theme="dark"] .custom-options {
    background: #1f2429;
}

.custom-select.open .custom-options {
    display: block;
}

.custom-option {
    padding: 12px 16px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    color: var(--text-secondary);
}

.custom-option:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.custom-option.selected {
    background: rgba(var(--primary-rgb), 0.1);
    color: var(--primary);
    font-weight: 600;
}

/* Scrollbar pour les options */
.custom-options::-webkit-scrollbar {
    width: 8px;
}

.custom-options::-webkit-scrollbar-track {
    background: var(--gray-100);
}

[data-theme="dark"] .custom-options::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.custom-options::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: var(--radius-sm);
}

[data-theme="dark"] .custom-options::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

.custom-options::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

[data-theme="dark"] .custom-options::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========================================
   CHECKBOX GROUPS
   ======================================== */

.form-group-checkbox {
    padding: 16px;
    background: var(--gray-50);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

[data-theme="dark"] .form-group-checkbox {
    background: rgba(255, 255, 255, 0.02);
}

.form-group-checkbox:hover {
    background: var(--bg-hover);
    border-color: var(--border-color-hover);
}

.checkbox-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.checkbox-wrapper input[type="checkbox"] {
    margin-top: 4px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--primary);
}

.checkbox-wrapper label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
}

.checkbox-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.checkbox-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* ========================================
   FORM ACTIONS
   ======================================== */

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 10px;
}

/* ========================================
   BUTTONS
   ======================================== */

.btn-primary {
    padding: 12px 24px;
    background: linear-gradient(90deg, var(--primary), var(--primary-hover));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    padding: 12px 24px;
    background: var(--gray-100);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: var(--transition);
}

[data-theme="dark"] .btn-secondary {
    background: rgba(255, 255, 255, 0.05);
}

.btn-secondary:hover {
    background: var(--gray-200);
    transform: translateY(-2px);
}

[data-theme="dark"] .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
    padding: 12px 24px;
    background: linear-gradient(90deg, var(--danger), var(--danger-hover));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-danger strong {
    font-weight: 700;
}

.btn-danger-small {
    padding: 8px 16px;
    background: linear-gradient(90deg, var(--danger), var(--danger-hover));
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-danger-small:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

/* ========================================
   EXPORT INFO
   ======================================== */

.export-info {
    padding: 16px 20px;
    background: rgba(var(--success-rgb), 0.05);
    border: 1px solid rgba(var(--success-rgb), 0.2);
    border-radius: var(--radius-md);
    margin-bottom: 20px;
}

.export-info p {
    margin: 8px 0;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
}

/* ========================================
   SUBSECTIONS
   ======================================== */

.subsection {
    margin-top: 30px;
    padding-top: 30px;
    border-top: 1px solid var(--border-color);
}

.subsection h3 {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 8px 0;
    color: var(--text-primary);
}

.subsection-description {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 20px 0;
}

/* ========================================
   SESSIONS LIST
   ======================================== */

.sessions-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.session-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.session-item:hover {
    background: var(--bg-hover);
    border-color: var(--border-color-hover);
}

.session-info {
    flex: 1;
}

.session-device {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.session-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.session-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Session actuelle dans métadonnées */
.session-current {
    display: inline-block;
    padding: 4px 8px;
    background: rgba(var(--success-rgb), 0.1);
    color: var(--success);
    border: 1px solid rgba(var(--success-rgb), 0.3);
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
}

[data-theme="dark"] .session-current {
    background: rgba(var(--success-rgb), 0.15);
    border-color: rgba(var(--success-rgb), 0.4);
}

.current-session-badge {
    padding: 6px 12px;
    background: rgba(var(--success-rgb), 0.1);
    color: var(--success);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
}

/* ========================================
   HISTORY LIST
   ======================================== */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.history-status {
    font-size: 20px;
}

.history-status.success {
    color: var(--success);
}

.history-status.failed {
    color: var(--danger);
}

.history-status.blocked {
    color: var(--warning);
}

.history-info {
    flex: 1;
}

.history-time {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.history-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
}

.history-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Statut dans historique */
.history-status-text {
    font-weight: 600;
    font-size: 12px;
}

.history-item:has(.history-status.success) .history-status-text {
    color: var(--success);
}

.history-item:has(.history-status.failed) .history-status-text {
    color: var(--danger);
}

.history-item:has(.history-status.blocked) .history-status-text {
    color: var(--warning);
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    padding: 20px;
}

/* ========================================
   RESPONSIVE
   ======================================== */

/* Tablettes */
@media (max-width: 768px) {
    .settings-main {
        padding: 30px 15px;
    }

    .settings-header h1 {
        font-size: 28px;
    }

    .settings-subtitle {
        font-size: 14px;
    }

    .settings-section {
        padding: 24px 20px;
    }

    .section-header {
        flex-direction: column;
        gap: 12px;
    }

    .section-icon {
        font-size: 28px;
    }

    .section-header h2 {
        font-size: 20px;
    }

    .session-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .btn-danger-small {
        width: 100%;
    }
    
    .session-current {
        display: block;
        margin: 8px 0 0 0;
        text-align: center;
    }
    
    .session-meta {
        flex-direction: column;
        gap: 4px;
    }
}

/* Smartphones */
@media (max-width: 480px) {
    .settings-main {
        padding: 20px 10px;
    }

    .settings-header h1 {
        font-size: 24px;
    }

    .settings-section {
        padding: 20px 16px;
    }

    .section-header h2 {
        font-size: 18px;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions button,
    .form-actions a {
        width: 100%;
        text-align: center;
    }

    .session-meta {
        font-size: 11px;
    }

    .history-meta {
        font-size: 11px;
    }

    .subsection h3 {
        font-size: 16px;
    }
    
    .session-current {
        font-size: 10px;
        padding: 3px 6px;
    }
    
    .history-status-text {
        font-size: 11px;
    }
}
/* ========================================
   FIX iOS - Correction des flèches multiples sur iPhone/iPad
   ======================================== */

/* Enlever COMPLÈTEMENT l'apparence native d'iOS */
select,
select.form-control,
.form-control select {
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-image: none !important;
}

/* Ajouter UNE SEULE flèche personnalisée (mode light) */
select.form-control,
select {
    background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%23666' d='M4.427 6.427l3.396 3.396a.25.25 0 00.354 0l3.396-3.396A.25.25 0 0011.396 6H4.604a.25.25 0 00-.177.427z'/%3E%3C/svg%3E") no-repeat !important;
    background-position: right 12px center !important;
    background-size: 16px 16px !important;
    padding-right: 40px !important;
}

/* Flèche personnalisée en mode dark */
[data-theme="dark"] select.form-control,
[data-theme="dark"] select {
    background: var(--bg-input) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%23bbb' d='M4.427 6.427l3.396 3.396a.25.25 0 00.354 0l3.396-3.396A.25.25 0 0011.396 6H4.604a.25.25 0 00-.177.427z'/%3E%3C/svg%3E") no-repeat !important;
    background-position: right 12px center !important;
    background-size: 16px 16px !important;
}

/* Fix spécifique pour Safari iOS */
@supports (-webkit-touch-callout: none) {
    select,
    select.form-control {
        -webkit-appearance: none !important;
        text-indent: 0.01px !important;
        text-overflow: '' !important;
        border-radius: var(--radius-md) !important;
    }
}

/* Enlever les spinners sur les inputs number (iOS et tous navigateurs) */
input[type="number"] {
    -webkit-appearance: none !important;
    -moz-appearance: textfield !important;
    appearance: none !important;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
    display: none !important;
}

/* S'assurer qu'aucun pseudo-élément n'ajoute de flèches */
select::before,
select::after,
select.form-control::before,
select.form-control::after {
    display: none !important;
    content: none !important;
}