/*
   ═══════════════════════════════════════════════════════════════════════════════
      AJUSTES SHEET — Modal de ajustes rediseñado (Dark & Light Support)
   ═══════════════════════════════════════════════════════════════════════════════
*/

/* ═══════════════════════════════════════════════════════════════════════════════
   CSS VARIABLES — Dark Mode (Default) & Light Mode
   ═══════════════════════════════════════════════════════════════════════════════ */

:root,
html[data-theme="dark"] {
    /* Backgrounds */
    --ajustes-bg: var(--card-bg, #1a1d2e);
    --ajustes-item-bg: rgba(255, 255, 255, 0.03);
    --ajustes-item-hover-bg: rgba(255, 255, 255, 0.055);
    --ajustes-dispositivo-bg: rgba(255, 255, 255, 0.02);
    
    /* Borders */
    --ajustes-border: rgba(255, 255, 255, 0.06);
    --ajustes-border-light: rgba(255, 255, 255, 0.08);
    --ajustes-border-top: rgba(255, 255, 255, 0.07);
    --ajustes-modal-header-border: rgba(255, 255, 255, 0.06);
    
    /* Text Colors */
    --ajustes-text-primary: var(--text-primary, #f1f5f9);
    --ajustes-text-secondary: var(--text-primary, #e2e8f0);
    --ajustes-text-muted: rgba(255, 255, 255, 0.35);
    --ajustes-text-tertiary: rgba(255, 255, 255, 0.3);
    --ajustes-text-info: rgba(255, 255, 255, 0.35);
    
    /* Accent Colors */
    --ajustes-accent: #6366f1;
    --ajustes-accent-light: #a5b4fc;
    --ajustes-accent-soft: #818cf8;
    --ajustes-accent-bg: rgba(99, 102, 241, 0.12);
    --ajustes-accent-border: rgba(99, 102, 241, 0.2);
    --ajustes-accent-glow: rgba(99, 102, 241, 0.4);
    
    /* Toggle Switch */
    --ajustes-toggle-bg: rgba(255, 255, 255, 0.12);
    --ajustes-toggle-border: rgba(255, 255, 255, 0.08);
    --ajustes-toggle-active-bg: linear-gradient(135deg, #4f46e5, #6366f1);
    --ajustes-toggle-active-border: rgba(99, 102, 241, 0.3);
    --ajustes-toggle-thumb: #fff;
    
    /* Range Slider */
    --ajustes-range-bg: rgba(255, 255, 255, 0.1);
    --ajustes-range-thumb: #6366f1;
    --ajustes-range-thumb-border: #fff;
    
    /* Drag Handle */
    --ajustes-drag-handle: rgba(255, 255, 255, 0.18);
    --ajustes-drag-handle-hover: rgba(255, 255, 255, 0.35);
    
    /* Close Button */
    --ajustes-close-bg: rgba(255, 255, 255, 0.06);
    --ajustes-close-border: rgba(255, 255, 255, 0.08);
    --ajustes-close-hover: rgba(255, 255, 255, 0.12);
    --ajustes-border-hover: rgba(255,255,255,.2);
    
    /* Feedback Colors */
    --ajustes-success-bg: rgba(34, 197, 94, 0.08);
    --ajustes-success-border: rgba(34, 197, 94, 0.2);
    --ajustes-success-text: #4ade80;
    --ajustes-error-bg: rgba(239, 68, 68, 0.08);
    --ajustes-error-border: rgba(239, 68, 68, 0.2);
    --ajustes-error-text: #f87171;
    --ajustes-loading-bg: rgba(99, 102, 241, 0.08);
    --ajustes-loading-border: rgba(99, 102, 241, 0.2);
    --ajustes-loading-text: #818cf8;
    
    /* Delete Button */
    --ajustes-delete-bg: rgba(239, 68, 68, 0.1);
    --ajustes-delete-border: rgba(239, 68, 68, 0.2);
    --ajustes-delete-text: #f87171;
    --ajustes-delete-hover: rgba(239, 68, 68, 0.2);
    
    /* Info Box */
    --ajustes-info-bg: rgba(99, 102, 241, 0.05);
    --ajustes-info-border: rgba(99, 102, 241, 0.12);
    --ajustes-info-icon: #818cf8;
    
    /* Scrollbar */
    --ajustes-scrollbar: rgba(255, 255, 255, 0.1);
    
    /* Shadows */
    --ajustes-shadow: 0 -8px 40px rgba(0, 0, 0, 0.4);
}

html[data-theme="light"] {
    /* Backgrounds */
    --ajustes-bg: #ffffff;
    --ajustes-item-bg: rgba(0, 0, 0, 0.02);
    --ajustes-item-hover-bg: rgba(99, 102, 241, 0.04);
    --ajustes-dispositivo-bg: rgba(0, 0, 0, 0.02);
    
    /* Borders */
    --ajustes-border: rgba(0, 0, 0, 0.06);
    --ajustes-border-light: rgba(0, 0, 0, 0.08);
    --ajustes-border-top: rgba(0, 0, 0, 0.06);
    --ajustes-modal-header-border: rgba(0, 0, 0, 0.06);
    
    /* Text Colors */
    --ajustes-text-primary: #0f172a;
    --ajustes-text-secondary: #0f172a;
    --ajustes-text-muted: rgba(0, 0, 0, 0.4);
    --ajustes-text-tertiary: rgba(0, 0, 0, 0.35);
    --ajustes-text-info: rgba(0, 0, 0, 0.5);
    
    /* Accent Colors */
    --ajustes-accent: #4f46e5;
    --ajustes-accent-light: #4f46e5;
    --ajustes-accent-soft: #6366f1;
    --ajustes-accent-bg: rgba(99, 102, 241, 0.08);
    --ajustes-accent-border: rgba(99, 102, 241, 0.14);
    --ajustes-accent-glow: rgba(99, 102, 241, 0.3);
    
    /* Toggle Switch */
    --ajustes-toggle-bg: rgba(0, 0, 0, 0.12);
    --ajustes-toggle-border: rgba(0, 0, 0, 0.08);
    --ajustes-toggle-active-bg: linear-gradient(135deg, #4f46e5, #6366f1);
    --ajustes-toggle-active-border: rgba(99, 102, 241, 0.3);
    --ajustes-toggle-thumb: #fff;
    
    /* Range Slider */
    --ajustes-range-bg: rgba(0, 0, 0, 0.08);
    --ajustes-range-thumb: #6366f1;
    --ajustes-range-thumb-border: #fff;
    
    /* Drag Handle */
    --ajustes-drag-handle: rgba(0, 0, 0, 0.12);
    --ajustes-drag-handle-hover: rgba(0, 0, 0, 0.25);
    
    /* Close Button */
    --ajustes-close-bg: rgba(0, 0, 0, 0.04);
    --ajustes-close-border: rgba(0, 0, 0, 0.06);
    --ajustes-close-hover: rgba(0, 0, 0, 0.08);
    --ajustes-border-hover: rgba(0,0,0,.15);
    
    /* Feedback Colors */
    --ajustes-success-bg: rgba(34, 197, 94, 0.06);
    --ajustes-success-border: rgba(34, 197, 94, 0.15);
    --ajustes-success-text: #16a34a;
    --ajustes-error-bg: rgba(239, 68, 68, 0.06);
    --ajustes-error-border: rgba(239, 68, 68, 0.15);
    --ajustes-error-text: #dc2626;
    --ajustes-loading-bg: rgba(99, 102, 241, 0.06);
    --ajustes-loading-border: rgba(99, 102, 241, 0.15);
    --ajustes-loading-text: #4f46e5;
    
    /* Delete Button */
    --ajustes-delete-bg: rgba(239, 68, 68, 0.06);
    --ajustes-delete-border: rgba(239, 68, 68, 0.15);
    --ajustes-delete-text: #dc2626;
    --ajustes-delete-hover: rgba(239, 68, 68, 0.12);
    
    /* Info Box */
    --ajustes-info-bg: rgba(99, 102, 241, 0.04);
    --ajustes-info-border: rgba(99, 102, 241, 0.1);
    --ajustes-info-icon: #6366f1;
    
    /* Scrollbar */
    --ajustes-scrollbar: rgba(0, 0, 0, 0.08);
    
    /* Shadows */
    --ajustes-shadow: 0 -8px 40px rgba(0, 0, 0, 0.15);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   Override Bootstrap modal para bottom sheet
   ═══════════════════════════════════════════════════════════════════════════════ */
#ajustesModal .modal-dialog {
    margin: 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 100%;
    transform: translateY(100%) !important;
    transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1) !important;
}

#ajustesModal.show .modal-dialog {
    transform: translateY(0) !important;
}

#ajustesModal .modal-content {
    border-radius: 24px 24px 0 0;
    border: none;
    background: var(--ajustes-bg);
    border-top: 1px solid var(--ajustes-border-top);
    max-height: 88dvh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--ajustes-shadow);
}

/* Handle de arrastre (oculto, se usa el handle real) */
#ajustesModal .modal-content::before {
    display: none;
}

/* ── Header ── */
#ajustesModal .modal-header {
    background: none !important;
    border-bottom: 1px solid var(--ajustes-modal-header-border);
    padding: .5rem 1.1rem .75rem;
    border-radius: 0;
    flex-shrink: 0;
}

.ajustes-header-inner {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex: 1;
}

.ajustes-header-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--ajustes-accent-bg);
    border: 1px solid var(--ajustes-accent-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
    color: var(--ajustes-accent-light);
    flex-shrink: 0;
}

.ajustes-header-title {
    font-size: .9rem;
    font-weight: 800;
    color: var(--ajustes-text-primary);
    line-height: 1.2;
}

.ajustes-header-sub {
    font-size: .65rem;
    color: var(--ajustes-text-muted);
    margin-top: .05rem;
}

#ajustesModal .ajustes-btn-close {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--ajustes-close-border);
    background: var(--ajustes-close-bg);
    color: var(--ajustes-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    cursor: pointer;
    transition: all .2s;
    flex-shrink: 0;
}

#ajustesModal .btn-close:hover {
    background: var(--ajustes-close-hover);
    color: var(--ajustes-text-primary);
    border-color: var(--ajustes-border-hover);
}

/* ── Body scrollable ── */
#ajustesModal .modal-body {
    overflow-y: auto;
    overflow-x: hidden;
    padding: .85rem 1rem 2rem;
    flex: 1;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

#ajustesModal .modal-body::-webkit-scrollbar { width: 3px; }
#ajustesModal .modal-body::-webkit-scrollbar-track { background: transparent; }
#ajustesModal .modal-body::-webkit-scrollbar-thumb {
    background: var(--ajustes-scrollbar);
    border-radius: 50px;
}

/* ── Desktop: centrado ── */
@media (min-width: 768px) {
    #ajustesModal .modal-dialog {
        left: 50%;
        right: auto;
        width: 480px;
        transform: translateX(-50%) translateY(100%) !important;
        bottom: 1rem;
        border-radius: 24px;
    }

    #ajustesModal.show .modal-dialog {
        transform: translateX(-50%) translateY(0) !important;
    }

    #ajustesModal .modal-content {
        border-radius: 24px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SECCIÓN LABEL
   ═══════════════════════════════════════════════════════════════════════════════ */
.ajustes-section-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .6rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ajustes-text-tertiary);
    margin: .85rem 0 .4rem;
    padding: 0 .1rem;
}

.ajustes-section-label:first-child { margin-top: 0; }

.ajustes-section-label i {
    font-size: .6rem;
    color: var(--ajustes-accent-soft);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   ITEM
   ═══════════════════════════════════════════════════════════════════════════════ */
.ajustes-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .65rem .85rem;
    background: var(--ajustes-item-bg);
    border: 1px solid var(--ajustes-border);
    border-radius: 14px;
    margin-bottom: .4rem;
    transition: background .2s;
    gap: .75rem;
}

.ajustes-item:hover {
    background: var(--ajustes-item-hover-bg);
}

.ajustes-item-info {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex: 1;
    min-width: 0;
}

/* Ícono compacto */
.ajustes-item-icon {
    font-size: 1rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ajustes-accent-bg);
    border-radius: 9px;
    flex-shrink: 0;
    line-height: 1;
}

.ajustes-item-info strong {
    display: block;
    color: var(--ajustes-text-secondary);
    font-size: .8rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ajustes-item-info small {
    display: block;
    color: var(--ajustes-text-muted);
    font-size: .65rem;
    line-height: 1.3;
    margin-top: .05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   TOGGLE SWITCH
   ═══════════════════════════════════════════════════════════════════════════════ */
.ajustes-toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    cursor: pointer;
    flex-shrink: 0;
    margin: 0;
}

.ajustes-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.ajustes-slider {
    position: absolute;
    inset: 0;
    background: var(--ajustes-toggle-bg);
    border-radius: 999px;
    transition: background .25s;
    border: 1px solid var(--ajustes-toggle-border);
}

.ajustes-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    top: 2px;
    background: var(--ajustes-toggle-thumb);
    border-radius: 50%;
    transition: transform .25s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.ajustes-toggle input:checked + .ajustes-slider {
    background: var(--ajustes-toggle-active-bg);
    border-color: var(--ajustes-toggle-active-border);
}

.ajustes-toggle input:checked + .ajustes-slider::before {
    transform: translateX(20px);
}

.ajustes-toggle input:disabled + .ajustes-slider {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   VOLUMEN
   ═══════════════════════════════════════════════════════════════════════════════ */
.ajustes-item-volume {
    display: block;
    padding: .75rem .85rem;
}

.ajustes-item-volume .ajustes-item-info {
    margin-bottom: .6rem;
}

.ajustes-volume-badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .22rem .6rem;
    padding-top: .32rem;
    border-radius: 50px;
    background: var(--ajustes-accent-bg);
    border: 1px solid var(--ajustes-accent-border);
    color: var(--ajustes-accent-light);
    font-size: .68rem;
    font-weight: 800;
    min-width: 58px;
    justify-content: center;
    font-variant-numeric: tabular-nums;
}

/* ── Range Slider - Webkit (Chrome, Safari, Edge) ── */
.ajustes-range {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 50px;
    background: var(--ajustes-range-bg);
    outline: none;
    cursor: pointer;
    transition: background .2s;
}

.ajustes-range::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 50px;
    background: var(--ajustes-range-bg);
}

.ajustes-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--ajustes-range-thumb);
    border: 3px solid var(--ajustes-range-thumb-border);
    box-shadow: 0 2px 8px var(--ajustes-accent-glow);
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
    margin-top: -7px;
}

.ajustes-range::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 3px 12px var(--ajustes-accent-glow);
}

/* ── Range Slider - Firefox ── */
.ajustes-range::-moz-range-track {
    height: 6px;
    border-radius: 50px;
    background: var(--ajustes-range-bg);
}

.ajustes-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--ajustes-range-thumb);
    border: 3px solid var(--ajustes-range-thumb-border);
    box-shadow: 0 2px 8px var(--ajustes-accent-glow);
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
}

.ajustes-range::-moz-range-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 3px 12px var(--ajustes-accent-glow);
}

/* ── Range Slider - Focus state ── */
.ajustes-range:focus {
    outline: none;
}

.ajustes-range:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px var(--ajustes-accent-bg), 0 2px 8px var(--ajustes-accent-glow);
}

.ajustes-range:focus::-moz-range-thumb {
    box-shadow: 0 0 0 4px var(--ajustes-accent-bg), 0 2px 8px var(--ajustes-accent-glow);
}

/* ── Range Slider - Disabled ── */
.ajustes-range:disabled {
    opacity: .35;
    cursor: not-allowed;
}

.ajustes-range:disabled::-webkit-slider-thumb {
    cursor: not-allowed;
}

.ajustes-range:disabled::-moz-range-thumb {
    cursor: not-allowed;
}

/* ── Light Theme Range - Track más visible ── */
html[data-theme="light"] .ajustes-range {
    background: rgba(0, 0, 0, 0.1);
}

html[data-theme="light"] .ajustes-range::-webkit-slider-runnable-track {
    background: rgba(0, 0, 0, 0.1);
}

html[data-theme="light"] .ajustes-range::-moz-range-track {
    background: rgba(0, 0, 0, 0.1);
}

/* Progress fill para webkit - simulado con gradiente */
html[data-theme="light"] .ajustes-range::-webkit-slider-thumb {
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

html[data-theme="dark"] .ajustes-range {
    background: rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] .ajustes-range::-webkit-slider-runnable-track {
    background: rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] .ajustes-range::-moz-range-track {
    background: rgba(255, 255, 255, 0.1);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   DISPOSITIVOS
   ═══════════════════════════════════════════════════════════════════════════════ */
.dispositivo-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .55rem .75rem;
    background: var(--ajustes-dispositivo-bg);
    border: 1px solid var(--ajustes-border);
    border-radius: 10px;
    margin-bottom: .35rem;
    gap: .5rem;
}

.dispositivo-info {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.dispositivo-info strong {
    display: block;
    color: var(--ajustes-text-secondary);
    font-size: .75rem;
    font-weight: 700;
}

.dispositivo-info small {
    color: var(--ajustes-text-muted);
    font-size: .62rem;
}

.btn-eliminar-dispositivo {
    background: var(--ajustes-delete-bg);
    border: 1px solid var(--ajustes-delete-border);
    color: var(--ajustes-delete-text);
    border-radius: 8px;
    padding: .25rem .6rem;
    font-size: .65rem;
    font-weight: 700;
    cursor: pointer;
    transition: background .2s;
    white-space: nowrap;
}

.btn-eliminar-dispositivo:hover {
    background: var(--ajustes-delete-hover);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   FEEDBACK
   ═══════════════════════════════════════════════════════════════════════════════ */
.ajustes-feedback {
    padding: .6rem .85rem;
    border-radius: 10px;
    font-size: .75rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: .5rem;
}

.ajustes-feedback.success {
    background: var(--ajustes-success-bg);
    border: 1px solid var(--ajustes-success-border);
    color: var(--ajustes-success-text);
}

.ajustes-feedback.error {
    background: var(--ajustes-error-bg);
    border: 1px solid var(--ajustes-error-border);
    color: var(--ajustes-error-text);
}

.ajustes-feedback.loading {
    background: var(--ajustes-loading-bg);
    border: 1px solid var(--ajustes-loading-border);
    color: var(--ajustes-loading-text);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   INFO BOX
   ═══════════════════════════════════════════════════════════════════════════════ */
.ajustes-info-box {
    background: var(--ajustes-info-bg);
    border: 1px solid var(--ajustes-info-border);
    border-radius: 10px;
    padding: .6rem .85rem;
    font-size: .68rem;
    color: var(--ajustes-text-info);
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    line-height: 1.55;
    margin-top: .5rem;
}

.ajustes-info-box i {
    color: var(--ajustes-info-icon);
    font-size: .65rem;
    flex-shrink: 0;
    margin-top: .1rem;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   DRAG HANDLE
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Handle real clickeable */
.ajustes-drag-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: .75rem 0 .2rem;
    cursor: grab;
    user-select: none;
    flex-shrink: 0;
    touch-action: none;
    /* Área de toque más grande */
    min-height: 36px;
}

.ajustes-drag-handle:active {
    cursor: grabbing;
}

.ajustes-drag-bar {
    width: 40px;
    height: 4px;
    border-radius: 50px;
    background: var(--ajustes-drag-handle);
    transition: background .2s, width .2s;
    pointer-events: none;
}

.ajustes-drag-handle:hover .ajustes-drag-bar,
.ajustes-drag-handle:active .ajustes-drag-bar {
    background: var(--ajustes-drag-handle-hover);
    width: 52px;
}

/* ── Transición del modal-dialog durante el drag ── */
#ajustesModal .modal-dialog {
    will-change: transform;
}

/* Cuando está siendo arrastrado, desactivar la transición
   de Bootstrap para que el movimiento sea inmediato */
#ajustesModal .modal-dialog.is-dragging {
    transition: none !important;
}

/* ── Overlay se oscurece/aclara con el drag ── */
#ajustesModal.modal.dragging-active .modal-backdrop {
    transition: opacity .05s linear !important;
}
