/* ==========================================================================
   AI for Bricks - Builder Integration Styles
   ========================================================================== */

/* ==========================================================================
   1. AI Button Styles
   ========================================================================== */

.bai-ai-button {
    /* Base button styles */
    position: absolute !important;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    
    /* Visual styling */
    background-color: var(--builder-bg-3);
    color: #555;
    border-radius: var(--builder-border-radius) 0 0 var(--builder-border-radius);
    
    /* Size and positioning for text fields */
    width: 24px;
    height: 32px;
    top: 0 !important;
    right: 24px !important;
    
    /* Z-index hierarchy - just above sidebar */
    z-index: 2100;
    
    /* Ensure clickability */
    pointer-events: auto;
}

.bai-ai-button:hover {
    background-color: var(--builder-bg-accent) !important;
    color: var(--builder-color-accent) !important;
}

.bai-ai-button:focus {
    outline: 2px solid var(--builder-color-accent);
    outline-offset: 2px;
}

.bai-ai-button:active {
    transform: scale(0.95);
}

.bai-ai-button svg {
    width: 12px;
    height: 12px;
    pointer-events: none;
}

/* Textarea-specific button styling */
[data-control="textarea"] .bai-ai-button {
    width: 20px !important;
    height: 20px !important;
    border-radius: var(--builder-border-radius) !important;
    margin: var(--builder-border-radius) !important;
}

/* Loading state */
.bai-ai-button.loading {
    pointer-events: none;
    opacity: 0.7;
}

.bai-ai-button.loading::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 2px solid currentColor;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: bai-spin 1s linear infinite;
    z-index: 1;
}

.bai-ai-button:not(.loading) {
    pointer-events: auto !important;
    opacity: 1 !important;
    cursor: pointer !important;
}

.bai-ai-button * {
    pointer-events: none;
}

/* ==========================================================================
   2. Control Container Styles
   ========================================================================== */

.control {
    position: relative !important;
    margin-top: 5px;
}

[data-control="text"],
[data-control="textarea"] {
    position: relative;
}

[data-control="text"] input,
[data-control="textarea"] textarea {
    padding-right: 56px; /* Space for AI button and dynamic data picker */
}

/* ==========================================================================
   3. Feedback & Notification Styles
   ========================================================================== */

.bai-feedback {
    margin-bottom: 5px;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    color: #fff;
    animation: bai-fade-in 0.3s ease-in;
    z-index: 2100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border: 1px solid;
    max-width: 300px;
    word-wrap: break-word;
}

.bai-feedback.success {
    background-color: #28a745;
    border-color: #1e7e34;
}

.bai-feedback.error {
    background-color: #dc3545;
    border-color: #bd2130;
}

/* ==========================================================================
   4. Animation Keyframes
   ========================================================================== */

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

@keyframes bai-fade-in {
    from { 
        opacity: 0; 
        transform: translateY(-10px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

@keyframes bai-fade-out {
    from { 
        opacity: 1; 
        transform: translateY(0); 
    }
    to { 
        opacity: 0; 
        transform: translateY(-10px); 
    }
}

/* ==========================================================================
   5. AI Modal Styles
   ========================================================================== */

.bai-ai-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(20, 22, 25, 0.65);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.bai-ai-modal-content {
    background: #23272b;
    color: #f3f3f3;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    min-width: 450px;
    max-width: 600px;
    width: 100%;
    padding: 0;
    display: flex;
    flex-direction: column;
    font-family: inherit;
}

/* Modal Header */
.bai-ai-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px 12px 24px;
    border-bottom: 1px solid #31363b;
    font-size: 1.1em;
    font-weight: 600;
    background: #23272b;
    border-radius: 12px 12px 0 0;
}

.bai-ai-modal-close {
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.3em;
    cursor: pointer;
    padding: 0 0 0 12px;
    transition: color 0.15s;
}

.bai-ai-modal-close:hover {
    color: #fff;
}

/* Modal Info */
.bai-ai-modal-info {
    font-size: 0.95em;
    color: #b0b3b8;
    margin: 10px 24px;
    padding: 0;
}

/* Modal Sections */
.bai-original-section,
.bai-generated-section {
    padding: 0 24px;
}

.bai-generated-section {
    padding-top: 20px;
}

.bai-original-section label,
.bai-generated-section label {
    display: block;
    margin-bottom: 8px;
    color: #b0b3b8;
    font-size: 0.95em;
    font-weight: 500;
}

.bai-original-textarea,
.bai-generated-textarea {
    width: 100%;
    min-height: 100px;
    background: #181a1b;
    color: #f3f3f3;
    border: 1px solid #31363b;
    border-radius: 6px;
    padding: 10px;
    font-size: 1em;
    resize: vertical;
}

.bai-original-textarea {
    opacity: 0.8; /* Slightly dimmed for read-only */
}

/* Preview Comparison */
.bai-preview-comparison {
    background: #1a1d20;
    border: 1px solid #31363b;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 10px;
    font-size: 0.95em;
    line-height: 1.5;
    display: none;
}

.bai-preview-content {
    color: #f3f3f3;
}

.bai-preview-content .bai-unchanged {
    color: #f3f3f3;
}

.bai-preview-content .bai-added {
    color: #4ade80;
    font-weight: 500;
}

.bai-preview-content .bai-removed {
    color: #6b7280;
    text-decoration: line-through;
    opacity: 0.7;
}

/* ==========================================================================
   6. Toolbar Styles
   ========================================================================== */

.bai-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 8px;
    padding: 12px 24px;
    background: #1c2024;
    border-top: 1px solid #31363b;
    border-bottom: 1px solid #31363b;
    overflow-x: auto;
    white-space: nowrap;
    flex-direction: column;
}

.bai-toolbar-options {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    flex-wrap: nowrap;
}

.bai-toolbar-options.hidden {
    display: none;
}

/* Toolbar Buttons and Select */
.bai-toolbar button,
.bai-toolbar select {
    background: #31363b;
    color: #f3f3f3;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.95em;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.bai-toolbar button:hover {
    background: #3a3f44;
    transform: translateY(-1px);
}

.bai-toolbar select:hover {
    background-color: #3a3f44;
    transform: translateY(-1px);
}

.bai-toolbar button:active,
.bai-toolbar select:active {
    transform: translateY(0);
}

.bai-toolbar button:focus,
.bai-toolbar select:focus {
    outline: none;
    box-shadow: none;
}

/* Default action button */
.bai-toolbar .bai-default-action {
    background: #31363b;
    color: #f3f3f3;
}

.bai-toolbar .bai-default-action:hover {
    background: #3a3f44;
}

/* Select dropdown styling */
.bai-toolbar select {
    appearance: none;
    padding-right: 28px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" fill="%23f3f3f3"><path d="M0 0l5 5 5-5H0z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    line-height: 1;
    width: auto;
}

.bai-toolbar select option {
    background: #23272b;
    color: #f3f3f3;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 2px;
}

/* ==========================================================================
   7. Custom Prompt Section
   ========================================================================== */

.bai-custom-prompt-section {
    display: none;
    width: 100%;
}

.bai-custom-prompt-section.active {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

.bai-custom-prompt-section textarea {
    width: 100%;
    min-height: 60px;
    background: #181a1b;
    color: #f3f3f3;
    border: 1px solid #31363b;
    border-radius: 6px;
    padding: 10px;
    font-size: 0.98em;
    resize: vertical;
}

.bai-custom-prompt-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.bai-custom-prompt-actions button {
    background: #31363b;
    color: #f3f3f3;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.95em;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.bai-custom-prompt-actions button:hover {
    background: #3a3f44;
    transform: translateY(-1px);
}

.bai-generate-btn {
    background: #4a90e2 !important;
    color: #ffffff !important;
}

.bai-generate-btn:hover {
    background: #357abd !important;
}

/* ==========================================================================
   8. Modal Footer
   ========================================================================== */

.bai-ai-modal-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 24px;
    border-top: 1px solid #31363b;
    background: linear-gradient(180deg, #1c2024 0%, #23272b 100%);
    border-radius: 0 0 12px 12px;
    margin-top: 0;
    position: relative;
}

.bai-ai-modal-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, #4a90e2 50%, transparent 100%);
    opacity: 0.3;
}

.bai-ai-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    width: 100%;
}

.bai-ai-modal-use-text {
    background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%) !important;
    color: #ffffff !important;
    padding: 10px 24px !important;
    font-size: 1em !important;
    font-weight: 600 !important;
    border-radius: 25px !important;
    border: none !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    min-width: 120px !important;
}

.bai-ai-modal-use-text:hover {
    background: linear-gradient(135deg, #357abd 0%, #2d6da3 100%) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 20px rgba(74, 144, 226, 0.4) !important;
}

.bai-ai-modal-use-text:active {
    transform: translateY(0) !important;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3) !important;
}
