/**
 * AI Settings Styles - Matching existing settings design patterns
 */

.ai-settings-container {
    // Remove extra container styling as it's handled by .setting-tab-content

    .ai-settings-header {
        .title {
            gap: 5px;
            display: flex;
            color: #1E1E1E;
            font-weight: 600;
            font-size: 16px;
            line-height: 100%;
            flex-wrap: wrap;
            align-items: center;
            position: relative;
            margin-bottom: 18px;

            label {
                margin-bottom: 0;
            }
        }

        p {
            margin: 0;
            color: #666873;
            font-weight: 400;
            font-size: 13px;
            line-height: 100%;
            line-height: 1.5;
            margin-bottom: 25px;
        }
    }
}

// AI Settings Groups - Following the same pattern as performance settings
.swptls-ai-settings {
    margin-top: 25px;

    .ai-engine-selector {
        display: flex;
        gap: 10px;
        align-items: center;
    }

    p.Ai-titles {
        margin-top: -10px;
        margin-bottom: 15px;
        font-size: 13px;
    }

    &:first-child {
        margin-top: 0;
    }

    .title {
        gap: 5px;
        display: flex;
        color: #1E1E1E;
        font-weight: 600;
        font-size: 16px;
        line-height: 100%;
        flex-wrap: wrap;
        align-items: center;
        position: relative;
        margin-bottom: 18px;

        label {
            margin-bottom: 0;
            font-size: 16px;
        }
    }

    p {
        margin: 0;
        color: #666873;
        font-weight: 400;
        font-size: 16px;
        line-height: 100%;
        line-height: 1.5;
    }

    select#cache-duration {
        width: 140px;
        padding: 8px 10px;
        border: 1px solid #ccc;
        border-radius: 6px;
        background-color: #f9f9f9;
        font-size: 14px;
        color: #333;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        cursor: pointer;
        margin: 0px 0px 0px 5px;
    }

    // API Key Input Group - Custom styling for this specific input
    .api-key-input-group {
        display: flex;
        gap: 8px;
        align-items: center;
        flex-wrap: wrap;

        .api-key-input {
            flex: 1;
            min-width: 200px;
            padding: 10px 12px;
            border: 1px solid #d1d5db;
            border-radius: 6px;
            font-size: 14px;
            transition: border-color 0.2s ease;

            &:focus {
                outline: none;
                border-color: #008717;
                box-shadow: 0 0 0 3px rgba(52, 160, 250, 0.1);
            }
        }

        .test-api-btn {
            padding: 10px 16px;
            border: 1px solid #008717;
            border-radius: 6px;
            background: #008717;
            color: white;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.2s ease;
            white-space: nowrap;

            &:hover:not(:disabled) {
                background: #1589e7;
                transform: translateY(-1px);
            }

            &:disabled {
                background: #9ca3af;
                border-color: #9ca3af;
                cursor: not-allowed;
                transform: none;
            }

            &.testing {
                background: #9ca3af;
                border-color: #9ca3af;
                cursor: not-allowed;
                transform: none;
            }
        }

        @media (max-width: 768px) {
            flex-direction: column;

            .api-key-input {
                width: 100%;
                min-width: auto;
            }

            .test-api-btn {
                width: 100%;
            }
        }
    }

    // Cache Toggle - Following async loading pattern
    .ai-cache-toggle {
        display: flex;
        position: relative;
        align-items: center;
        margin-bottom: 13px;

        input[type="checkbox"] {
            position: absolute;
            left: 0;
            top: 0;
            z-index: 10;
            height: 100%;
            cursor: pointer;
            opacity: 0;
        }

        label {
            gap: 10px;
            display: flex;
            color: #1E1E1E;
            font-weight: 600;
            font-size: 16px;
            line-height: 100%;
            flex-wrap: wrap;
            align-items: center;
            position: relative;
            box-sizing: border-box;
            margin-bottom: -5px;

            &:before {
                content: '';
                min-width: 44px;
                height: 22.81px;
                background: #ccc;
                position: relative;
                display: inline-block;
                border-radius: 46px;
                box-sizing: border-box;
                transition: 0.2s ease-in;
            }

            &:after {
                content: '';
                position: absolute;
                min-width: 19px;
                height: 19px;
                border-radius: 50%;
                left: 2px;
                top: 2px;
                z-index: 2;
                background: #fff;
                box-sizing: border-box;
                transition: 0.2s ease-in;
            }
        }

        input[type="checkbox"]:checked+label:before {
            background: #008717;
        }

        input[type="checkbox"]:checked+label:after {
            left: 23px;
        }
    }

    // Range Sliders
    .range-wrapper {
        input[type="range"] {
            width: 100%;
            margin: 8px 0;
            -webkit-appearance: none;
            appearance: none;
            height: 6px;
            border-radius: 3px;
            background: #d1d5db;
            outline: none;

            &::-webkit-slider-thumb {
                -webkit-appearance: none;
                appearance: none;
                width: 18px;
                height: 18px;
                border-radius: 50%;
                background: #008717;
                cursor: pointer;
                border: 2px solid white;
                box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
            }

            &::-moz-range-thumb {
                width: 18px;
                height: 18px;
                border-radius: 50%;
                background: #008717;
                cursor: pointer;
                border: 2px solid white;
                box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
            }
        }

        .range-labels {
            display: flex;
            justify-content: space-between;
            font-size: 12px;
            color: #6b7280;
            margin-top: 4px;
        }
    }

    // Textarea
    textarea {
        width: 100%;
        padding: 10px 12px;
        border: 1px solid #d1d5db;
        border-radius: 6px;
        font-size: 14px;
        font-family: inherit;
        resize: vertical;
        min-height: 100px;
        transition: border-color 0.2s ease;

        &:focus {
            outline: none;
            border-color: #008717;
            box-shadow: 0 0 0 3px rgba(52, 160, 250, 0.1);
        }
    }

    // Performance title style for subtitles
    p.performance-title {
        color: #1E1E1E;
        font-weight: 600;
        font-size: 16px;
        line-height: 100%;
        margin-bottom: 15px;
    }
}

// Link Support Pattern - Matching the existing radio button styles exactly
.swptls-link-support {
    // margin-top: 25px;

    &:first-child {
        margin-top: 0;
    }

    .title {
        gap: 5px;
        display: flex;
        color: #1E1E1E;
        font-weight: 600;
        font-size: 16px;
        line-height: 100%;
        flex-wrap: wrap;
        align-items: center;
        position: relative;
        margin-bottom: 18px;

        label {
            margin-bottom: 0;
        }

        button.btn-pro.btn-new {
            margin-top: 0;
        }
    }

    .link-modes {
        gap: 2px;
        display: flex;
        margin-top: 8px;
        flex-wrap: wrap;
        text-align: center;
        justify-content: left;
        align-items: center;
        position: relative;

        label {
            display: flex;
            font-size: 15px;
            line-height: 100%;
            align-items: center;
            position: relative;
            box-sizing: border-box;
            margin-bottom: 6px;
        }

        button.btn-pro.recommended-pro {
            border: 1px solid;
            outline: 0;
            cursor: pointer;
            box-shadow: none;
            color: #008717;
            font-weight: 600;
            font-size: 11px;
            line-height: 100%;
            margin-left: 8px;
            padding: 4px 10px;
            border-radius: 11.5px;
            background-color: rgba(43, 240, 87, 0.1);
            border-color: #88dcbe;
        }

        input[type="radio"] {
            width: 16px;
            height: 16px;
            outline: none;
            box-shadow: none;
            margin-right: 7px;
            position: relative;
            border-radius: 11px;
            box-sizing: border-box;
            border: 2px solid #ccd5dc;

            &::before {
                margin: 0.1875rem;
            }
        }

        input[type="radio"]:checked::before {
            content: "";
            border-radius: 50%;
            background-color: #fdfeff;
            line-height: 1.14285714;
            border: 4px solid #008717;
            position: absolute;
            left: 3px;
            top: 20%;
            width: 16px;
            height: 16px;
            transform: translate(-50%, -50%);
            border: 4px solid #008717;
            border-radius: 8px;
            box-sizing: border-box;
            box-shadow: none;
            outline: none;
        }
    }

    button.btn-pro.btn-new {
        color: white;
        background: #008717;
        font-weight: bold;
        border-radius: 15px;
        height: 21px;
        font-size: 11px;
    }
}

// Info Section - Following the existing info patterns
.ai-settings-info {
    margin-top: 40px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e5e7eb;

    h4 {
        margin: 0 0 16px 0;
        color: #1E1E1E;
        font-size: 16px;
        font-weight: 600;
        line-height: 100%;
    }

    ul {
        margin: 0;
        padding-left: 20px;

        li {
            margin-bottom: 8px;
            color: #666873;
            line-height: 1.5;
            font-size: 14px;

            a {
                color: #008717;
                text-decoration: none;

                &:hover {
                    text-decoration: underline;
                    color: #1589e7;
                }
            }
        }
    }
}

// Responsive adjustments
@media screen and (max-width: 991px) {
    .swptls-ai-settings {
        .api-key-input-group {
            gap: 12px;
        }
    }
}

@media screen and (max-width: 575px) {
    .swptls-ai-settings {
        margin-top: 20px;

        .title {
            margin-bottom: 12px;
        }

        .ai-modes {
            margin-top: 6px;
        }
    }

    .ai-settings-info {
        margin-top: 30px;
        padding: 16px;
    }
}

// Advanced Settings Styles
.swptls-ai-settings {

    // Advanced Settings Toggle Button
    .advanced-settings-toggle {
        margin-bottom: 20px;

        .advanced-toggle-btn {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 12px 16px;
            border: 1px solid #d1d5db;
            border-radius: 8px;
            background: #f9fafb;
            color: #374151;
            font-size: 15px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s ease;
            width: 100%;
            justify-content: flex-start;

            &:hover {
                background: #f3f4f6;
                border-color: #9ca3af;
                transform: translateY(-1px);
            }

            &:focus {
                outline: none;
                border-color: #008717;
                box-shadow: 0 0 0 3px rgba(52, 160, 250, 0.1);
            }

            .toggle-icon {
                display: flex;
                align-items: center;
                justify-content: center;
                width: 12px;
                height: 12px;
                transition: transform 0.2s ease;

                svg {
                    width: 100%;
                    height: 100%;
                }
            }
        }

        p {
            margin: 8px 0 0 0;
            color: #6b7280;
            font-size: 14px;
            line-height: 1.4;
        }
    }
}

// Advanced Settings Content - Collapsible Container
.advanced-settings-content {
    overflow: hidden;
    transition: all 0.3s ease;
    // border-left: 3px solid #e5e7eb;
    padding-left: 20px;
    margin-left: 10px;

    &.hide {
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
        margin-top: 0;
        margin-bottom: 0;
        opacity: 0;
        visibility: hidden;
    }

    &.show {
        max-height: 2000px; // Large enough to accommodate all content
        padding-top: 15px;
        padding-bottom: 15px;
        margin-top: 15px;
        margin-bottom: 20px;
        opacity: 1;
        visibility: visible;
        // border-left-color: #008717;
    }

    // Override margins for nested settings within advanced section
    .swptls-ai-settings,
    .swptls-link-support {
        margin-top: 20px;

        &:first-child {
            margin-top: 0;
        }
    }
}

// Additional responsive adjustments for link support pattern
@media screen and (max-width: 575px) {
    .swptls-link-support {
        margin-top: 20px;

        .title {
            margin-bottom: 12px;
        }

        .link-modes {
            margin-top: 6px;
        }
    }
}