.ai-action-button-wrapper {
    position: relative;
}

.ai-action-button {
    display: inline-block;
}

.ai-action-button__trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 14px;
    color: white;
    background-color: var(--state-info, #0e61a2);
    border: 1px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, transform 0.15s ease-in-out;
    position: relative;
}

.ai-action-button__trigger:hover {
    background-color: #0a4a7a;
    border-color: #094068;
    transform: scale(1.05);
}

.ai-action-button__trigger:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(14, 97, 162, 0.4);
}

.ai-action-button__trigger:active {
    background-color: #094068;
    transform: scale(0.95);
}

.ai-action-button__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}


/* Idle State */
.ai-action-button[data-state="idle"] .ai-action-button__trigger {
    background-color: var(--state-info, #0e61a2);
}

/* Loading State */
.ai-action-button[data-state="loading"] .ai-action-button__trigger {
    cursor: wait;
}

@keyframes ai-icon-pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.9);
    }
}

.ai-action-button[data-state="loading"] .ai-action-button__icon {
    animation: ai-icon-pulse 1s ease-in-out infinite;
}

/* Error State */
.ai-action-button[data-state="error"] .ai-action-button__trigger {
    background-color: var(--state-error, #ab3131);
}

.ai-action-button[data-state="error"] .ai-action-button__trigger:hover {
    background-color: #8a2727;
}

/* Disabled State */
.ai-action-button[data-state="disabled"] .ai-action-button__trigger {
    background-color: var(--state-default, #606060);
    opacity: 0.65;
    cursor: not-allowed;
}

.ai-action-button[data-state="disabled"] .ai-action-button__trigger:hover {
    background-color: var(--state-default, #606060);
    transform: none;
}

/* Inline variant (not absolutely positioned) */
.ai-action-button-inline {
    position: static;
    display: inline-block;
    margin-left: 8px;
}

/* AI Textarea custom editor wrapper */
.ai-textarea-wrapper {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
}

.ai-textarea-content {
    flex: 1;
    min-width: 0;
}

.ai-textarea-button-container {
    flex-shrink: 0;
    padding-top: 2px;
}

.ai-textarea-wrapper textarea {
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, height 0.2s ease;
    overflow: hidden;
    resize: vertical;
    min-height: 60px;
}

/* Apple Intelligence-like halo animation */
@keyframes ai-halo-glow {
    0% {
        box-shadow: 0 0 0 2px rgba(147, 112, 219, 0.4),
                    0 0 8px 2px rgba(147, 112, 219, 0.3),
                    0 0 16px 4px rgba(100, 149, 237, 0.2);
    }
    25% {
        box-shadow: 0 0 0 2px rgba(100, 149, 237, 0.4),
                    0 0 8px 2px rgba(100, 149, 237, 0.3),
                    0 0 16px 4px rgba(72, 209, 204, 0.2);
    }
    50% {
        box-shadow: 0 0 0 2px rgba(72, 209, 204, 0.4),
                    0 0 8px 2px rgba(72, 209, 204, 0.3),
                    0 0 16px 4px rgba(147, 112, 219, 0.2);
    }
    75% {
        box-shadow: 0 0 0 2px rgba(186, 85, 211, 0.4),
                    0 0 8px 2px rgba(186, 85, 211, 0.3),
                    0 0 16px 4px rgba(100, 149, 237, 0.2);
    }
    100% {
        box-shadow: 0 0 0 2px rgba(147, 112, 219, 0.4),
                    0 0 8px 2px rgba(147, 112, 219, 0.3),
                    0 0 16px 4px rgba(100, 149, 237, 0.2);
    }
}

.ai-textarea-wrapper textarea.ai-generating {
    animation: ai-halo-glow 2s ease-in-out infinite;
    border-color: rgba(147, 112, 219, 0.6);
}

/* AI Error Diagnosis in Modal */
h3 > .ai-error-diagnosis-container {
    float: right;
    margin-right: 10px;
}

.ai-diagnosis-result {
    margin-bottom: 15px;
    padding: 10px;
    background: var(--secondary-background);
    border-radius: var(--main-border-radius);
    border-left: 3px solid var(--state-info);
}

.ai-diagnosis-result h5 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--state-info);
}

.ai-diagnosis-result .diagnosis-content {
    white-space: pre-wrap;
    word-break: break-word;
}

/* AIIcon loading blink */
@keyframes ai-icon-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

button.is-loading i {
    animation: ai-icon-blink 0.7s ease-in-out infinite;
}

/* AI Status Panel (shared across widgets) */
.panel-widget-content:has(.ai-status-panel) {
    position: relative;
}

.ai-status-panel {
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    margin: 0;
    padding: 10px 10px 25px 10px;
    background: var(--dialog-body-background);
    border-left: 3px solid var(--state-info);
    font-size: 13px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    max-height: 100%;
    overflow-y: auto;
}

.panel-widget-content .ai-status-panel {
    position: absolute;
}

.ai-status-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--state-info);
}

.ai-status-panel__header i {
    margin-right: 4px;
}

.ai-status-panel__close {
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    color: var(--main-color);
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.6;
}

.ai-status-panel__close:hover {
    opacity: 1;
}

.ai-status-panel__body {
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--main-color);
    user-select: text;
}

.ai-status-panel--error {
    border-left-color: var(--state-error);
}

.ai-status-panel--error .ai-status-panel__header {
    color: var(--state-error);
}

/* Loading state for AI Status Panel */
@keyframes ai-border-left-glow {
    0%   { border-left-color: rgba(147, 112, 219, 0.9); }
    25%  { border-left-color: rgba(100, 149, 237, 0.9); }
    50%  { border-left-color: rgba(72, 209, 204, 0.9); }
    75%  { border-left-color: rgba(186, 85, 211, 0.9); }
    100% { border-left-color: rgba(147, 112, 219, 0.9); }
}

.ai-status-panel--loading {
    animation: ai-border-left-glow 2s ease-in-out infinite;
    padding: 8px 10px;
}

.ai-status-panel--loading .ai-status-panel__header {
    margin-bottom: 0;
}

#object_doc_container #validate_btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
