/* ============================================================
   AI Description Generator – Production Stylesheet
   CSP-safe. Compatible with Bootstrap 5.
   ============================================================ */

/* --- Wrapper ------------------------------------------------ */
.ai-textarea-wrapper {
    position: relative;
}

/* --- Icon Buttons (generate / voice) ------------------------ */
.ai-icon-btn {
    position: absolute;
    bottom: 6px;
    border: 0;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    color: #64748b;
    background-color: transparent;
    z-index: 10;
    transition: color 0.15s ease;
}
.ai-icon-btn:hover,
.ai-icon-btn:focus-visible {
    color: #3b82f6;
    background-color: transparent;
}
.ai-icon-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    color: #94a3b8;
}
.ai-icon-btn[aria-pressed="true"] {
    color: #ef4444;
}

/* --- Modal (overlay + centering) ----------------------------- */
.ai-generator-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10600;
    overflow-y: auto;
    align-items: center;
    justify-content: center;
}
.ai-generator-modal.ai-active {
    display: flex;
}

/* Backdrop overlay (sibling of .ai-modal-content) */
.ai-generator-modal > .ai-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10600;
    pointer-events: none;
}
.ai-generator-modal.ai-overlay-clickable > .ai-modal-overlay {
    pointer-events: auto;
}

/* Content panel (the white card) */
.ai-generator-modal > .ai-modal-content {
    position: relative;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.3);
    z-index: 10601;
    max-width: 600px;
    width: 90%;
    margin: 24px auto;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 48px);
}

/* --- Header ------------------------------------------------- */
.ai-generator-modal .ai-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}
.ai-generator-modal .ai-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #1e293b;
}
.ai-generator-modal .ai-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
    line-height: 1;
    padding: 0 4px;
}
.ai-generator-modal .ai-modal-close:hover {
    color: #1e293b;
}

/* --- Body --------------------------------------------------- */
.ai-generator-modal .ai-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1 1 auto;
}

/* --- Footer ------------------------------------------------- */
.ai-generator-modal .ai-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

/* --- Form controls ------------------------------------------ */
.ai-generator-modal .ai-form-group {
    margin-bottom: 12px;
}
.ai-generator-modal .ai-form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 0.875rem;
    color: #374151;
}
.ai-generator-modal .ai-prompt-input,
.ai-generator-modal .ai-form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.875rem;
    font-family: inherit;
    box-sizing: border-box;
    background-color: #fff;
    color: #1e293b;
    transition: border-color 0.15s;
    resize: vertical;
}
.ai-generator-modal .ai-prompt-input:focus,
.ai-generator-modal .ai-form-control:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.ai-generator-modal .ai-options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* --- Error -------------------------------------------------- */
.ai-generator-modal .ai-response-error {
    color: #dc2626;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.85rem;
    margin-bottom: 12px;
    display: none;
}

/* --- Loading ------------------------------------------------ */
.ai-generator-modal .ai-loading-indicator {
    text-align: center;
    padding: 32px 0;
    color: #64748b;
    display: none;
}
.ai-generator-modal .ai-loading-indicator p {
    margin: 12px 0 0;
    font-size: 0.9rem;
}
.ai-generator-modal .ai-spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: ai-spin 0.7s linear infinite;
}
@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

/* --- Result ------------------------------------------------- */
.ai-generator-modal .ai-result-section {
    display: none;
}
.ai-generator-modal .ai-result-content {
    max-height: 260px;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #f8fafc;
    margin-bottom: 12px;
    font-size: 0.875rem;
    line-height: 1.6;
    word-break: break-word;
    color: #1e293b;
}
.ai-generator-modal .ai-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* --- Buttons (scoped to avoid Bootstrap conflicts) ----------- */
.ai-generator-modal .btn-primary {
    background-color: #3b82f6;
    color: #fff;
    border: 1px solid #3b82f6;
    padding: 8px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    display: inline-block;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
}
.ai-generator-modal .btn-primary:hover {
    background-color: #2563eb;
    border-color: #2563eb;
    color: #fff;
}
.ai-generator-modal .btn-primary:disabled {
    background-color: #93c5fd;
    border-color: #93c5fd;
    cursor: not-allowed;
    opacity: 0.7;
}
.ai-generator-modal .btn-secondary {
    background-color: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
    padding: 8px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    display: inline-block;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
}
.ai-generator-modal .btn-secondary:hover {
    background-color: #e2e8f0;
    color: #1e293b;
}

/* --- Responsive --------------------------------------------- */
@media (max-width: 480px) {
    .ai-generator-modal > .ai-modal-content {
        width: 96%;
        margin: 12px auto;
        max-height: calc(100vh - 24px);
    }
    .ai-generator-modal .ai-options-grid {
        grid-template-columns: 1fr;
    }
}
