/* ==========================================================================
   INPUTS & FORMS
   ========================================================================== */

/* --- STANDARD TEXT FIELDS --- */
.md-field, .text-field-container {
    position: relative; background-color: var(--md-sys-color-surface-container-high);
    border-radius: 4px 4px 0 0; height: 56px; display: flex; align-items: center; padding: 0 16px; margin-bottom: 16px;
    border-bottom: 1px solid var(--md-sys-color-outline); transition: all 0.2s;
}
.md-field::after {
    content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 0; background-color: var(--md-sys-color-primary); transition: all 0.2s;
}
.md-field:focus-within::after, .text-field-container:focus-within::after { height: 2px; }
.md-field input, .text-field {
    width: 100%; height: 100%; background: transparent; border: none; outline: none;
    font: var(--md-sys-typescale-body-large); color: var(--md-sys-color-on-surface); padding-top: 24px; padding-bottom: 8px;
}
.md-field label, .field-label {
    position: absolute; left: 16px; top: 18px; font: var(--md-sys-typescale-body-large);
    color: var(--md-sys-color-on-surface-variant); pointer-events: none; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.md-field input:focus ~ label, .md-field input:not(:placeholder-shown) ~ label,
.text-field:focus ~ .field-label, .text-field:not(:placeholder-shown) ~ .field-label {
    top: 8px; font-size: 12px; color: var(--md-sys-color-primary); font-weight: 500;
}

/* --- EXPRESSIVE TEXT FIELDS (Outlined) --- */
.expressive-input-group {
    position: relative;
    margin-bottom: 24px;
    width: 100%;
}

.expressive-text-field {
    width: 100%;
    height: 56px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-extra-small);
    background: transparent;
    padding: 0 16px;
    font: var(--md-sys-typescale-body-large);
    color: var(--md-sys-color-on-surface);
    outline: none;
    transition: border-color 0.2s;
}

.expressive-text-field:focus,
.expressive-text-field:focus-visible {
    border-color: var(--md-sys-color-primary);
    border-width: 2px;
    padding: 0 15px; /* Adjust for border width change */
    outline: none;
}

.expressive-input-label {
    position: absolute;
    left: 16px;
    top: 18px;
    background-color: var(--md-sys-color-surface-container);
    padding: 0 4px;
    color: var(--md-sys-color-on-surface-variant);
    font: var(--md-sys-typescale-body-large);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.expressive-text-field:focus ~ .expressive-input-label,
.expressive-text-field:not(:placeholder-shown) ~ .expressive-input-label {
    top: -10px;
    font-size: 12px;
    color: var(--md-sys-color-primary);
    font-weight: 500;
}

/* --- SWITCHES --- */
.switch { position: relative; width: 52px; height: 32px; display: inline-block; margin-right: 12px;}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track, .md-switch-track {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--md-sys-color-surface-container-highest); border: 2px solid var(--md-sys-color-outline); border-radius: 32px; transition: .4s;
}
.switch-handle, .md-switch-handle {
    position: absolute; height: 16px; width: 16px; left: 6px; bottom: 6px; background-color: var(--md-sys-color-outline); border-radius: 50%; transition: .4s;
}
.switch input:checked + .switch-track { background-color: var(--md-sys-color-primary); border-color: var(--md-sys-color-primary); }
.switch input:checked + .switch-track .switch-handle {
    transform: translateX(20px); background-color: var(--md-sys-color-on-primary); width: 24px; height: 24px; bottom: 2px; left: 2px;
}
/* --- SWITCH ICONS --- */
.switch-icon {
    position: absolute; color: var(--md-sys-color-on-primary-container);
    font-size: 16px; top: 6px; left: 6px; opacity: 0; transition: 0.3s; pointer-events: none;
}
.switch input:checked ~ .switch-icon { opacity: 1; transform: translateX(20px); color: var(--md-sys-color-primary); z-index: 2; }


/* --- OLD MATERIAL (M2) SWITCH AESTHETIC --- */
[data-style="m2"] .switch-track, .switch-m2 .switch-track {
    height: 14px; width: 36px; top: 9px; left: 8px; border: none;
    background-color: var(--md-sys-color-outline-variant); opacity: 0.5;
}
[data-style="m2"] .switch-handle, .switch-m2 .switch-handle {
    height: 20px; width: 20px; left: 0; top: -3px; 
    background-color: var(--md-sys-color-surface-container-highest);
    box-shadow: var(--md-sys-elevation-2);
    z-index: 2;
}
[data-style="m2"] .switch input:checked + .switch-track, .switch-m2 input:checked + .switch-track {
    background-color: var(--md-sys-color-primary); opacity: 0.5;
}
[data-style="m2"] .switch input:checked + .switch-track .switch-handle, .switch-m2 input:checked + .switch-track .switch-handle {
    transform: translateX(16px); background-color: var(--md-sys-color-primary);
    width: 20px; height: 20px; top: -3px; left: 0; /* Align and size for M2 */
}

/* --- SLIDERS --- */
.slider-container { width: 100%; display: flex; align-items: center; padding: 24px 0; margin-bottom: 16px; }
.md-slider, input[type=range] {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 4px; border-radius: 2px;
    background: transparent; /* Track is styled via pseudo-element */
    outline: none; padding: 0; margin: 0; cursor: pointer;
}

/* --- TRACK --- */
.md-slider::-webkit-slider-runnable-track {
    height: 4px; cursor: pointer;
    background: linear-gradient(to right, var(--md-sys-color-primary) var(--slider-value, 0%), var(--md-sys-color-surface-container-highest) var(--slider-value, 0%));
    border-radius: 2px;
}
.md-slider::-moz-range-track {
    width: 100%; height: 4px; cursor: pointer;
    background: linear-gradient(to right, var(--md-sys-color-primary) var(--slider-value, 0%), var(--md-sys-color-surface-container-highest) var(--slider-value, 0%));
    border-radius: 2px;
}

/* --- THUMB (WEBKIT) --- */
.md-slider::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--md-sys-color-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    margin-top: -8px; 
    transition: transform 0.1s, box-shadow 0.2s; border: none;
}
.md-slider:active::-webkit-slider-thumb { transform: scale(1.3); }
.md-slider:hover::-webkit-slider-thumb {
    box-shadow: 0 0 0 10px rgba(var(--md-sys-color-primary-rgb), 0.1), 0 1px 3px rgba(0,0,0,0.3);
}

/* --- THUMB (MOZ) --- */
.md-slider::-moz-range-thumb {
    width: 20px; height: 20px; border: none; border-radius: 50%;
    background: var(--md-sys-color-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
}
.md-slider:hover::-moz-range-thumb {
    box-shadow: 0 0 0 10px rgba(var(--md-sys-color-primary-rgb), 0.1), 0 1px 3px rgba(0,0,0,0.3);
}

/* --- EXPRESSIVE VARIANT --- */
.slider-expressive .md-slider::-webkit-slider-runnable-track { 
    height: 16px; border-radius: 8px; 
    background: linear-gradient(to right, var(--md-sys-color-primary) var(--slider-value, 0%), var(--md-sys-color-surface-container-highest) var(--slider-value, 0%));
}
.slider-expressive .md-slider::-moz-range-track { 
    height: 16px; border-radius: 8px; 
    background: linear-gradient(to right, var(--md-sys-color-primary) var(--slider-value, 0%), var(--md-sys-color-surface-container-highest) var(--slider-value, 0%));
}

.slider-expressive .md-slider::-webkit-slider-thumb {
    height: 44px; width: 4px; border-radius: 2px; margin-top: -14px;
    background: var(--md-sys-color-on-primary-container);
    -webkit-appearance: none; appearance: none;
}
.slider-expressive .md-slider::-moz-range-thumb {
    height: 44px; width: 4px; border-radius: 2px;
    background: var(--md-sys-color-on-primary-container);
    border: none;
}

/* --- SQUIGGLY SLIDER --- */
.slider-squiggly {
    position: relative;
    padding: 18px 0;
    --wave-mask: url("data:image/svg+xml,%3Csvg width='40' height='10' viewBox='0 0 40 10' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 5 Q 10 0 20 5 T 40 5' stroke='black' stroke-width='4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

/* --- BASE TRACK --- */
.slider-squiggly::before {
    content: "";
    position: absolute;
    left: var(--slider-value, 0%); right: 0;
    top: 50%; height: 4px;
    transform: translateY(-50%);
    background: var(--md-sys-color-surface-container-highest);
    border-radius: 2px;
}

/* --- ACTIVE TRACK --- */
.slider-squiggly::after {
    content: "";
    position: absolute;
    left: 0; 
    width: var(--slider-value, 0%);
    top: 50%; height: 10px;
    transform: translateY(-50%);
    background: var(--md-sys-color-primary);
    
    mask-image: var(--wave-mask);
    -webkit-mask-image: var(--wave-mask);
    mask-size: 40px 100%; -webkit-mask-size: 40px 100%;
    
    animation: wave-slide 2s linear infinite;
    z-index: 1;
    pointer-events: none;
}

.slider-squiggly .md-slider {
    z-index: 2;
    position: relative;
    background: transparent !important;
}

.slider-squiggly .md-slider::-webkit-slider-runnable-track { background: transparent; }
.slider-squiggly .md-slider::-moz-range-track { background: transparent; }

.slider-squiggly .md-slider::-webkit-slider-thumb {
    margin-top: -8px; /* Standard 20px thumb on center of 4px track base */
}
