@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Ensure popup content is scrollable */
.popup-content:has(#charCreatorPopup) {
    overflow-y: auto;
}

#charCreatorPopup {
    color: var(--SmartThemeBodyColor);
    font-family: var(--mainFontFamily);
    max-width: 1200px;
    /* Increased max-width for wider layout */
    margin: 0 auto;
    font-size: var(--mainFontSize);

    h2 {
        text-align: center;
        margin-bottom: 20px;
        font-weight: 500;
        color: var(--SmartThemeBodyColor);
    }

    h3 {
        font-weight: 500;
        margin-top: 0;
        margin-bottom: 15px;
        color: var(--SmartThemeBodyColor);
    }

    h4 {
        font-weight: 500;
        margin-top: 15px;
        margin-bottom: 10px;
        color: var(--SmartThemeBodyColor);
    }

    .container {
        display: flex;
        gap: 20px;

        @media (max-width: 992px) {
            /* Adjust breakpoint for better responsiveness */
            flex-direction: column;
        }
    }

    .column {
        width: 30%;
        /* Adjusted width */
        display: flex;
        flex-direction: column;
        gap: 15px;

        @media (max-width: 992px) {
            width: 100%;
        }
    }

    .wide-column {
        width: 70%;
        /* Adjusted width */
        display: flex;
        flex-direction: column;
        gap: 15px;

        @media (max-width: 992px) {
            width: 100%;
        }
    }

    .card {
        background-color: var(--SmartThemeBlurTintColor);
        border-radius: 10px;
        padding: 15px;
        box-shadow: 0 2px 4px var(--SmartThemeShadowColor);
        margin-bottom: 0;
        border: 1px solid var(--SmartThemeBorderColor);
    }

    /* Context Sending Options */
    .context-options {
        display: flex;
        flex-direction: column;
        gap: 5px;

        .message-options {
            margin-top: 10px;
            margin-bottom: 5px;
        }

        label[for="charCreator_includeChars"],
        label[for="charCreator_includeWorldInfo"] {
            margin-top: 15px;
        }

        /* Style for the final checkbox */
        label[for="charCreator_includeExistingFields"] {
            margin-top: 15px;
        }
    }

    /* Message inclusion options */
    .message-options {
        padding-left: 20px;
        border-left: 2px solid var(--SmartThemeBorderColor);
        margin-left: 5px;

        h4 {
            margin-top: 0;
            margin-bottom: 10px;
            font-size: 0.95em;
        }

        #charCreator_messageType {
            margin-bottom: 10px;
            width: calc(100% - 10px);
            margin-left: 5px;
        }

        #charCreator_firstX,
        #charCreator_lastX,
        #charCreator_rangeX {
            margin-top: 8px;
            padding-left: 5px;
            font-size: 0.9em;

            label {
                display: flex;
                align-items: center;
                gap: 5px;
            }
        }

        .message-input {
            width: 60px;
        }
    }

    /* Character Field Actions Styling */
    .character-field-actions {
        display: flex;
        gap: 15px;
        flex-direction: row-reverse;
        @media (max-width: 768px) {
            flex-wrap: wrap;
        }

        button {
            padding: 10px 20px;
            background-color: var(--SmartThemeBlurTintColor);
            border: 1px solid var(--SmartThemeBorderColor);
            border-radius: 6px;
            color: var(--SmartThemeBodyColor);
            font-size: 0.95em;
            cursor: pointer;
            transition: all 0.2s ease;
            display: flex;
            align-items: center;
            justify-content: center;

            &:hover {
                transform: translateY(-1px);
                box-shadow: 0 2px 4px var(--SmartThemeShadowColor);
            }

            &#charCreator_saveAsNewCharacter {
                color: white;
            }

            &#charCreator_reset {
                border-color: var(--SmartThemeBorderColor);
            }
        }
    }

    /* Output Format */
    #charCreator_outputFormat {
        margin-top: 5px;
    }

    /* Main Prompt Area */
    #charCreator_promptPreset {
        margin-bottom: 10px;
        width: 100%;
    }

    #charCreator_prompt {
        margin-bottom: 10px;
    }

    #charCreator_sendPrompt {
        width: 100%;
        background-color: var(--info);

        &:hover {
            background-color: color-mix(in srgb, var(--info) 85%, white);
        }
    }

    /* Character Field Styling */
    .character-field {
        margin-bottom: 15px;

        label {
            display: block;
            font-weight: 500;
            margin-bottom: 5px;
            color: var(--SmartThemeBodyColor);
        }

        .field-container {
            display: flex;
            align-items: flex-start;
            gap: 10px;

            textarea {
                flex-grow: 1;
                min-height: 60px;
            }

            &.large-field textarea {
                min-height: 120px;
            }
        }

        .field-prompt-container {
            margin-top: 8px;
            padding-right: 35px;

            textarea {
                width: 100%;
                min-height: 60px;
                font-size: 0.9em;
                border: 1px solid var(--SmartThemeBorderColor);
                background-color: var(--SmartThemeFormBgColor);
                color: var(--SmartThemeBodyColor);
                padding: 8px;
                border-radius: 5px;
                resize: vertical;

                &::placeholder {
                    color: var(--SmartThemeSubtleColor);
                }
            }
        }
    }

    /* Utility: Disable interaction */
    button:disabled,
    select:disabled,
    input:disabled,
    textarea:disabled {
        opacity: 0.6;
        cursor: not-allowed;
        pointer-events: none;
    }


    /* Tab Styles */
    .tab-buttons {
        display: flex;
        gap: 10px;
        margin-bottom: 15px;
        border-bottom: 1px solid var(--SmartThemeBorderColor);
        padding-bottom: 10px;
        align-items: center;
        /* Align Add button vertically */
        justify-content: flex-start;

        .right-aligned {
            margin-left: auto;
            display: flex;
            gap: 10px;
            .menu_button {
                width: auto;
            }
            flex-wrap: wrap;
        }

        .tab-button {
            background-color: transparent;
            border: none;
            border-bottom: 3px solid transparent;
            padding: 8px 15px;
            cursor: pointer;
            transition: all 0.2s ease;
            border-radius: 4px 4px 0 0;
            /* Slight rounding at top */

            &:hover {
                background-color: var(--white30a);
            }

            &.active {
                font-weight: 500;
            }
        }
    }

    .tab-content-area {
        position: relative;
        /* Optional: for potential future absolute positioning inside */
    }

    .tab-content {
        display: none;
        /* Hide tabs by default */

        &.active {
            display: block;
            /* Show active tab */
        }

        /* Remove bottom margin from card when used as tab content */
        margin-bottom: 0;
    }

    /* Utility styles */
    .subtle {
        font-size: 0.9em;
        margin-bottom: 15px;
    }
    /* Compare popup styles */
    .compare-popup {
        color: var(--SmartThemeBodyColor);
        font-family: var(--mainFontFamily);
        padding: 15px;

        h3 {
            margin-bottom: 15px;
            font-weight: 500;
            color: var(--SmartThemeBodyColor);
        }

        h4 {
            margin-bottom: 10px;
            color: var(--SmartThemeBodyColor);
        }

        .content {
            font-family: monospace;
            white-space: pre-wrap;
            padding: 15px;
            border: 1px solid var(--SmartThemeBorderColor);
            border-radius: 8px;
            background-color: var(--SmartThemeBlurTintColor);
            margin-bottom: 10px;

            span {
                &[style*="color: green"] {
                    color: var(--success) !important;
                    background-color: color-mix(in srgb, var(--success) 15%, transparent) !important;
                }

                &[style*="color: red"] {
                    color: var(--warning) !important;
                    background-color: color-mix(in srgb, var(--warning) 15%, transparent) !important;
                }

                &[style*="color: grey"] {
                    color: var(--SmartThemeBodyColor) !important;
                }
            }
        }
    }
}
