/* Widget Settings CSS - Global settings modal and components */

/* === SETTINGS MODAL OVERLAY === */

.w-settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* === SETTINGS MODAL CONTAINER === */

.w-settings-modal {
    background-color: var(--color-background, white);
    color: var(--color-text, black);
    border-radius: 12px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--color-border, #ddd);
    position: relative;
    /* Prevent scroll jumps during re-renders */
    contain: layout style;
}

/* Dark theme adjustments */
[data-theme="dark"] .w-settings-modal {
    background-color: var(--color-card-bg);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* Grayscale theme adjustments */
[data-theme="grayscale"] .w-settings-modal {
    border: 3px solid var(--color-text);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

/* === SETTINGS MODAL HEADER === */

.w-settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border, #ddd);
}

.w-settings-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-text, black);
}

.w-settings-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-secondary, #666);
    padding: 0.25rem;
    border-radius: var(--border-radius, 4px);
    transition: all 0.2s ease;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.w-settings-close:hover {
    background: var(--color-annotation-bg, rgba(0, 0, 0, 0.05));
    color: var(--color-text, black);
    transform: scale(1.1);
}

/* === SETTINGS TABS NAVIGATION === */

.w-settings-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--color-border, #ddd);
    gap: 0;
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.w-settings-tabs::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.w-settings-tab {
    flex: 1;
    background: none;
    border: none;
    padding: 1rem 0.75rem;
    cursor: pointer;
    color: var(--color-text-secondary, #666);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border-bottom: 3px solid transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-height: 60px;
    position: relative;
    white-space: nowrap;
    text-align: center;
}

.w-settings-tab:hover {
    color: var(--color-primary, #0074D9);
    background: var(--color-annotation-bg, rgba(0, 0, 0, 0.02));
}

.w-settings-tab.active {
    color: var(--color-primary, #0074D9);
    border-bottom-color: var(--color-primary, #0074D9);
    background: var(--color-annotation-bg, rgba(0, 116, 217, 0.05));
}

.w-settings-tab-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.w-settings-tab-label {
    font-size: 0.85rem;
    line-height: 1.2;
}

/* Responsive tab adjustments */
@media screen and (max-width: 768px) {
    .w-settings-tab {
        padding: 0.75rem 0.5rem;
        min-height: 50px;
    }
    
    .w-settings-tab-icon {
        font-size: 1.1rem;
    }
    
    .w-settings-tab-label {
        font-size: 0.8rem;
    }
}

@media screen and (max-width: 480px) {
    .w-settings-tab {
        padding: 0.5rem 0.25rem;
        min-height: 45px;
    }
    
    .w-settings-tab-icon {
        font-size: 1rem;
    }
    
    .w-settings-tab-label {
        font-size: 0.75rem;
    }
}

/* Dark theme tab adjustments */
[data-theme="dark"] .w-settings-tab:hover {
    background: var(--color-annotation-bg, rgba(255, 255, 255, 0.05));
}

[data-theme="dark"] .w-settings-tab.active {
    background: var(--color-annotation-bg, rgba(0, 116, 217, 0.1));
}

/* High contrast theme tab adjustments */
[data-theme="grayscale"] .w-settings-tab {
    border-bottom-width: 4px;
}

[data-theme="grayscale"] .w-settings-tab:hover,
[data-theme="grayscale"] .w-settings-tab.active {
    background: var(--color-text);
    color: var(--color-background);
}

/* === SETTINGS FORM LAYOUT === */

.w-settings-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.w-setting-group {
    display: flex;
    flex-direction: column;
}

/* === SETTING INPUT COMPONENTS === */

/* Checkbox settings */
.w-setting-checkbox {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.w-setting-checkbox input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
    accent-color: var(--color-primary, #0074D9);
}

.w-setting-checkbox:hover {
    color: var(--color-primary, #0074D9);
}

/* Text input settings */
.w-setting-label {
    display: block;
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--color-text, black);
}

.w-setting-input {
    width: 100%;
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--color-border, #ddd);
    background-color: var(--color-background, white);
    color: var(--color-text, black);
    font-size: 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.w-setting-input:focus {
    outline: none;
    border-color: var(--color-primary, #0074D9);
    box-shadow: 0 0 0 3px rgba(0, 116, 217, 0.1);
}

/* === IMPROVED RANGE SLIDER STYLING === */

.w-setting-input[type="range"] {
    padding: 0;
    height: 2.5rem;
    background: transparent;
    border: none;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    margin: 0.5rem 0;
    width: 100%;
    position: relative;
    z-index: 2; /* Ensure the range input is above the track */
}

/* Range input wrapper for better styling */
.w-range-input-wrapper {
    position: relative;
    padding: 0.75rem 0;
    height: 2.5rem; /* Match the height of the range input */
    display: flex;
    align-items: center;
}

.w-range-input-wrapper::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 6px;
    background: var(--color-border, #ddd);
    border-radius: 3px;
    transform: translateY(-50%);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
    pointer-events: none;
    z-index: 0;
}

/* Filled part of the slider track */
.w-range-input-wrapper::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    height: 6px;
    background: var(--color-primary, #0074D9);
    border-radius: 3px 0 0 3px;
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 1;
    width: var(--range-progress, 50%); /* Default value, will be updated via JS */
}

.w-setting-input[type="range"]:focus {
    box-shadow: none;
    outline: none;
}

/* WebKit browsers (Chrome, Safari, Edge) */
.w-setting-input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: var(--color-border, #ddd);
    border-radius: 3px;
    border: none;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* For older WebKit browsers that might still use this */
.w-setting-input[type="range"]::-webkit-slider-track {
    width: 100%;
    height: 6px;
    background: var(--color-border, #ddd);
    border-radius: 3px;
    border: none;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.w-setting-input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    height: 24px;
    width: 24px;
    border-radius: 50%;
    background: var(--color-primary, #0074D9);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    margin-top: -9px;
    border: 2px solid white;
    transition: all 0.2s ease;
}

.w-setting-input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.w-setting-input[type="range"]::-webkit-slider-thumb:active {
    transform: scale(1.05);
}

/* Firefox */
.w-setting-input[type="range"]::-moz-range-track {
    width: 100%;
    height: 6px;
    background: var(--color-border, #ddd);
    border-radius: 3px;
    border: none;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Firefox progress bar (fills the track to the left of the thumb) */
.w-setting-input[type="range"]::-moz-range-progress {
    height: 6px;
    background: var(--color-primary, #0074D9);
    border-radius: 3px;
}

.w-setting-input[type="range"]::-moz-range-thumb {
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--color-primary, #0074D9);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    border: 2px solid white;
    transition: all 0.2s ease;
}

.w-setting-input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

/* Internet Explorer/Edge */
.w-setting-input[type="range"]::-ms-track {
    width: 100%;
    height: 6px;
    background: transparent;
    border-color: transparent;
    color: transparent;
}

.w-setting-input[type="range"]::-ms-fill-lower {
    background: var(--color-primary, #0074D9);
    border-radius: 3px;
}

.w-setting-input[type="range"]::-ms-fill-upper {
    background: var(--color-border, #ddd);
    border-radius: 3px;
}

.w-setting-input[type="range"]::-ms-thumb {
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--color-primary, #0074D9);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    border: 2px solid white;
    transition: all 0.2s ease;
}

/* Dark theme slider adjustments */
[data-theme="dark"] .w-setting-input[type="range"]::-webkit-slider-thumb,
[data-theme="dark"] .w-setting-input[type="range"]::-moz-range-thumb,
[data-theme="dark"] .w-setting-input[type="range"]::-ms-thumb {
    border-color: var(--color-card-bg, #2d2d2d);
}

[data-theme="dark"] .w-setting-input[type="range"]::-webkit-slider-track,
[data-theme="dark"] .w-setting-input[type="range"]::-moz-range-track {
    background: var(--color-input-border, #555);
}

/* Range value display container */
.w-range-value-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

.w-range-value-current {
    font-size: 1rem;
    font-weight: 500;
    color: var(--color-primary, #0074D9);
    min-width: 2.5rem;
    text-align: center;
}

.w-range-value-min,
.w-range-value-max {
    color: var(--color-text-secondary, #666);
}

/* Select dropdown settings */
.w-setting-select {
    width: 100%;
    padding: 0.75rem;
    border-radius: 6px;
    border: 1px solid var(--color-border, #ddd);
    background-color: var(--color-background, white);
    color: var(--color-text, black);
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.w-setting-select:focus {
    outline: none;
    border-color: var(--color-primary, #0074D9);
    box-shadow: 0 0 0 3px rgba(0, 116, 217, 0.1);
}

/* Setting description text */
.w-setting-description {
    margin: 0.5rem 0 0 0;
    font-size: 0.9rem;
    color: var(--color-text-secondary, #666);
    line-height: 1.4;
}

.w-setting-checkbox + .w-setting-description {
    margin-left: 2rem;
}

/* === SETTINGS ACTIONS FOOTER === */

.w-settings-actions {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border, #ddd);
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.w-settings-button {
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.w-settings-button-secondary {
    border: 1px solid var(--color-border, #ddd);
    background-color: var(--color-background, white);
    color: var(--color-text, black);
}

.w-settings-button-secondary:hover {
    background-color: var(--color-annotation-bg, rgba(0, 0, 0, 0.05));
    border-color: var(--color-primary, #0074D9);
}

.w-settings-button-primary {
    border: none;
    background-color: var(--color-primary, #0074D9);
    color: white;
}

.w-settings-button-primary:hover {
    background-color: var(--color-primary-dark, #0056b3);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* === SETTINGS TOGGLE BUTTON === */

.w-settings-toggle {
    background: var(--color-background, white);
    color: var(--color-text, black);
    border: 1px solid var(--color-border, #ddd);
    padding: var(--spacing-small, 0.5rem) var(--spacing-base, 1rem);
    font-size: 0.9rem;
    border-radius: var(--border-radius, 4px);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
}

.w-settings-toggle:hover {
    background: var(--color-annotation-bg, rgba(0, 0, 0, 0.05));
    border-color: var(--color-primary, #0074D9);
}

.w-settings-toggle:focus {
    outline: 2px solid var(--color-primary, #0074D9);
    outline-offset: 2px;
}

/* Settings icon in toggle button */
.w-settings-icon {
    font-size: 1.1rem;
}

/* === RESPONSIVE DESIGN === */

@media screen and (max-width: 768px) {
    .w-settings-modal {
        padding: 1.5rem;
        width: 95%;
        max-height: 90vh;
    }
    
    .w-settings-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .w-settings-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
    }
    
    .w-settings-actions {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .w-settings-button {
        width: 100%;
    }
}

@media screen and (max-width: 480px) {
    .w-settings-modal {
        padding: 1rem;
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .w-settings-overlay {
        padding: 0;
    }
}

/* === THEME-SPECIFIC ADJUSTMENTS === */

/* High contrast mode */
[data-theme="grayscale"] .w-settings-close:hover {
    background: var(--color-text);
    color: var(--color-background);
}

[data-theme="grayscale"] .w-setting-input:focus,
[data-theme="grayscale"] .w-setting-select:focus {
    border-color: var(--color-text);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.3);
}

[data-theme="grayscale"] .w-settings-button-secondary {
    border: 2px solid var(--color-text);
}

[data-theme="grayscale"] .w-settings-button-secondary:hover {
    background: var(--color-text);
    color: var(--color-background);
}

[data-theme="grayscale"] .w-setting-input[type="range"]::-webkit-slider-thumb,
[data-theme="grayscale"] .w-setting-input[type="range"]::-moz-range-thumb {
    border-color: var(--color-background);
    background: var(--color-text);
}

[data-theme="grayscale"] .w-setting-input[type="range"]::-webkit-slider-track,
[data-theme="grayscale"] .w-setting-input[type="range"]::-moz-range-track {
    background: var(--color-text);
}

/* Dark mode input styling */
[data-theme="dark"] .w-setting-input,
[data-theme="dark"] .w-setting-select {
    background-color: var(--color-input-bg, #333);
    border-color: var(--color-input-border, #555);
}

[data-theme="dark"] .w-setting-input:focus,
[data-theme="dark"] .w-setting-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.2);
}

/* === ACCESSIBILITY === */

/* Focus visible for keyboard navigation */
.w-settings-close:focus-visible,
.w-settings-button:focus-visible,
.w-settings-toggle:focus-visible {
    outline: 2px solid var(--color-primary, #0074D9);
    outline-offset: 2px;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .w-settings-modal,
    .w-settings-close,
    .w-settings-button,
    .w-settings-toggle,
    .w-setting-input,
    .w-setting-select {
        transition: none;
    }
    
    .w-settings-close:hover,
    .w-settings-button-primary:hover,
    .w-setting-input[type="range"]::-webkit-slider-thumb:hover,
    .w-setting-input[type="range"]::-moz-range-thumb:hover {
        transform: none;
    }
}