/**
 * Enhanced Switch Styles for Alluagro
 * Supports the stateless switch system without DOM state tracking
 */

/* Base switch styles */
.form-check.form-switch.switch-enhanced {
    padding-left: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px; /* Minimum touch target */
    margin-bottom: 1rem;
    position: relative;
}

.form-check.form-switch.switch-enhanced .form-check-input {
    width: 50px;
    height: 26px;
    margin-left: auto;
    margin-right: 0;
    background-color: #ccc;
    border: none;
    border-radius: 13px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.form-check.form-switch.switch-enhanced .form-check-input:checked {
    background-color: #00522d;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 8px rgba(0, 82, 45, 0.3);
}

.form-check.form-switch.switch-enhanced .form-check-input::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    top: 2px;
    left: 2px;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.form-check.form-switch.switch-enhanced .form-check-input:checked::before {
    transform: translateX(24px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.form-check.form-switch.switch-enhanced .form-check-label {
    flex: 1;
    margin-bottom: 0;
    cursor: pointer;
    user-select: none;
    font-weight: 500;
    line-height: 1.4;
}

/* Size variations */
.form-check.form-switch.switch-small .form-check-input {
    width: 40px;
    height: 22px;
    border-radius: 11px;
}

.form-check.form-switch.switch-small .form-check-input::before {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    top: 2px;
    left: 2px;
}

.form-check.form-switch.switch-small .form-check-input:checked::before {
    transform: translateX(18px);
}

.form-check.form-switch.switch-large {
    min-height: 50px;
}

.form-check.form-switch.switch-large .form-check-input {
    width: 60px;
    height: 32px;
    border-radius: 16px;
}

.form-check.form-switch.switch-large .form-check-input::before {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    top: 2px;
    left: 2px;
}

.form-check.form-switch.switch-large .form-check-input:checked::before {
    transform: translateX(28px);
}

.form-check.form-switch.switch-large .form-check-label {
    font-size: 1.1rem;
    font-weight: 600;
}

/* State indicators */
.form-check.form-switch.switch-enhanced.state-changing {
    transform: scale(0.98);
    transition: transform 0.2s ease;
}

.form-check.form-switch.switch-enhanced.state-changing .form-check-input {
    box-shadow: 0 0 12px rgba(0, 82, 45, 0.5);
}

/* Loading state */
.form-check.form-switch.switch-loading .form-check-input {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.form-check.form-switch.switch-loading .form-check-input::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    border: 2px solid transparent;
    border-top: 2px solid #fff;
    border-radius: 50%;
    animation: switch-loading-spin 1s linear infinite;
}

@keyframes switch-loading-spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Focus states for accessibility */
.form-check.form-switch.switch-enhanced .form-check-input:focus {
    box-shadow: 0 0 0 3px rgba(0, 82, 45, 0.25);
    outline: none;
}

.form-check.form-switch.switch-enhanced .form-check-input:focus-visible {
    box-shadow: 0 0 0 3px rgba(0, 82, 45, 0.4);
}

/* Hover effects for non-touch devices */
@media (hover: hover) and (pointer: fine) {
    .form-check.form-switch.switch-enhanced:hover .form-check-input {
        box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 8px rgba(0, 82, 45, 0.2);
    }
    
    .form-check.form-switch.switch-enhanced:hover .form-check-input:checked {
        box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 12px rgba(0, 82, 45, 0.4);
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .form-check.form-switch.switch-enhanced {
        min-height: 48px; /* Larger touch target for mobile */
        padding: 6px 0;
    }
    
    .form-check.form-switch.switch-enhanced .form-check-input {
        width: 52px;
        height: 28px;
    }
    
    .form-check.form-switch.switch-enhanced .form-check-input::before {
        width: 24px;
        height: 24px;
    }
    
    .form-check.form-switch.switch-enhanced .form-check-input:checked::before {
        transform: translateX(24px);
    }
}

/* Disabled state */
.form-check.form-switch.switch-enhanced .form-check-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.form-check.form-switch.switch-enhanced .form-check-input:disabled + .form-check-label {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Animation classes for view changes */
.switch-content-change {
    opacity: 0.8;
    transform: scale(0.98);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.switch-fade-in {
    animation: switchFadeIn 0.5s ease-out;
}

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

/* View toggle specific styling */
.view-switch-section {
    margin: 20px 0;
    padding: 15px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: 12px;
    border: 1px solid #dee2e6;
}

.switch-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.switch-container h4 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: #00522d;
    flex: 1;
}

.switch-container .form-check {
    margin: 0;
    flex-shrink: 0;
}

/* Configuration section styling */
.config-section {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid #e9ecef;
}

.config-section h5 {
    color: #00522d;
    font-weight: 600;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid #00522d;
}

.form-group-switch {
    margin-bottom: 15px;
}

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

/* Config actions */
.config-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e9ecef;
}

.config-actions .btn {
    min-width: 150px;
    padding: 10px 20px;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.config-actions .btn-primary {
    background: linear-gradient(135deg, #00522d, #28a745);
    border: none;
    box-shadow: 0 2px 8px rgba(0, 82, 45, 0.3);
}

.config-actions .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 82, 45, 0.4);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .switch-container {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .switch-container h4 {
        text-align: center;
        margin-bottom: 10px;
    }
    
    .config-actions {
        flex-direction: column;
        align-items: center;
    }
    
    .config-actions .btn {
        width: 100%;
        max-width: 300px;
    }
}

@media (max-width: 480px) {
    .config-section {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .view-switch-section {
        padding: 10px;
    }
    
    .switch-container h4 {
        font-size: 1.1rem;
    }
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .form-check.form-switch.switch-enhanced .form-check-input {
        background-color: #495057;
    }
    
    .form-check.form-switch.switch-enhanced .form-check-input:checked {
        background-color: #4ade80;
    }
    
    .config-section {
        background: #2d3748;
        border-color: #4a5568;
    }
    
    .config-section h5 {
        color: #4ade80;
        border-bottom-color: #4ade80;
    }
    
    .view-switch-section {
        background: linear-gradient(135deg, #2d3748, #4a5568);
        border-color: #4a5568;
    }
    
    .switch-container h4 {
        color: #4ade80;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .form-check.form-switch.switch-enhanced .form-check-input {
        border: 2px solid #000;
    }
    
    .form-check.form-switch.switch-enhanced .form-check-input:checked {
        background-color: #000;
    }
    
    .form-check.form-switch.switch-enhanced .form-check-input::before {
        border: 1px solid #000;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .form-check.form-switch.switch-enhanced .form-check-input,
    .form-check.form-switch.switch-enhanced .form-check-input::before,
    .switch-content-change,
    .switch-fade-in {
        transition: none !important;
        animation: none !important;
    }
}