/* ============================================================
   AI Insights — Modal & Sidebar Sparkle Button Styles
   ============================================================ */

/* ── CRITICAL: prevent hidden overlay from blocking clicks ─── */
#aiInsightsModal[hidden] {
    display: none !important;
    pointer-events: none !important;
}

/* ── Override sidebar logo-details for name-left / AI-right ── */
.sidebar .logo-details {
    justify-content: space-between !important;
}

.sidebar .logo-details .logo_name {
    flex: 1;
    min-width: 0;
    margin-right: 6px;
}

/* ── Sidebar close button — outside sidebar on mobile ────── */
.sidebar-close-ext {
    display: none;
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 1050;
    background: rgba(44, 62, 80, 0.92);
    border: none;
    color: white;
    font-size: 22px;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: background 0.2s ease;
}

.sidebar-close-ext:hover {
    background: rgba(231, 76, 60, 0.85);
}

@media (max-width: 1024px) {
    body.sidebar-open .sidebar-close-ext {
        display: flex;
    }
}

/* ── Sidebar sparkle button ─────────────────────────────────── */
.ai-sparkle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 4px;
    color: inherit;
    text-decoration: none;
    line-height: 1;
    flex-shrink: 0;
}

.ai-sparkle-icon {
    font-size: 1.3rem;
    display: inline-block;
    animation: ai-sparkle-pulse 2.4s ease-in-out infinite;
    filter: drop-shadow(0 0 4px rgba(168, 85, 247, 0.6));
    color: #c084fc;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.ai-sparkle-btn:hover .ai-sparkle-icon,
.ai-sparkle-btn:focus .ai-sparkle-icon {
    transform: scale(1.25) rotate(10deg);
    filter: drop-shadow(0 0 8px rgba(168, 85, 247, 0.9));
}

@keyframes ai-sparkle-pulse {
    0%, 100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
    30% {
        transform: scale(1.18) rotate(8deg);
        opacity: 0.85;
    }
    60% {
        transform: scale(0.92) rotate(-5deg);
        opacity: 1;
    }
}

/* company name as clickable AI trigger */
.logo_name.ai-trigger {
    cursor: pointer;
    transition: color 0.2s ease;
}

.logo_name.ai-trigger:hover {
    color: #c084fc;
}

/* ── Modal overlay ──────────────────────────────────────────── */
.ai-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 4000;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.ai-modal-overlay.ai-modal--open {
    opacity: 1;
}

/* On wider screens, center it */
@media (min-width: 600px) {
    .ai-modal-overlay {
        align-items: center;
        padding: 1rem;
    }
}

/* ── Modal panel ────────────────────────────────────────────── */
.ai-modal-panel {
    background: #0f0f1a;
    border: 1px solid rgba(168, 85, 247, 0.25);
    border-radius: 1rem 1rem 0 0;
    width: 100%;
    max-width: 680px;
    height: 85dvh;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 40px rgba(168, 85, 247, 0.15);
    transform: translateY(30px);
    transition: transform 0.25s ease;
    overflow: hidden;
}

.ai-modal--open .ai-modal-panel {
    transform: translateY(0);
}

@media (min-width: 600px) {
    .ai-modal-panel {
        border-radius: 1rem;
        height: 600px;
        max-height: 80dvh;
        box-shadow: 0 8px 50px rgba(168, 85, 247, 0.2);
    }
}

/* ── Header ─────────────────────────────────────────────────── */
.ai-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid rgba(168, 85, 247, 0.15);
    background: linear-gradient(135deg, rgba(88, 28, 135, 0.4) 0%, rgba(15, 15, 26, 0) 60%);
    flex-shrink: 0;
}

.ai-modal-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-header-sparkle {
    font-size: 1.2rem;
    color: #c084fc;
    animation: ai-sparkle-pulse 2.4s ease-in-out infinite;
}

.ai-modal-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #e9d5ff;
    letter-spacing: 0.01em;
}

.ai-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    padding: 0.25rem;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
}

.ai-modal-close:hover {
    color: #e9d5ff;
    background: rgba(168, 85, 247, 0.15);
}

/* ── Chat body ──────────────────────────────────────────────── */
.ai-chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

.ai-chat-body::-webkit-scrollbar {
    width: 4px;
}
.ai-chat-body::-webkit-scrollbar-thumb {
    background: rgba(168, 85, 247, 0.3);
    border-radius: 99px;
}

/* ── Messages ───────────────────────────────────────────────── */
.ai-message {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    animation: ai-msg-in 0.2s ease;
}

@keyframes ai-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.ai-message--user {
    flex-direction: row-reverse;
}

.ai-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: #fff;
    flex-shrink: 0;
    margin-top: 2px;
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.4);
}

.ai-bubble {
    max-width: calc(100% - 40px);
    padding: 0.6rem 0.9rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.55;
    color: #e5e7eb;
}

.ai-message--bot .ai-bubble {
    background: rgba(88, 28, 135, 0.2);
    border: 1px solid rgba(168, 85, 247, 0.15);
    border-radius: 0 0.75rem 0.75rem 0.75rem;
}

.ai-message--user .ai-bubble {
    background: linear-gradient(135deg, #5b21b6, #7c3aed);
    color: #fff;
    border-radius: 0.75rem 0 0.75rem 0.75rem;
}

.ai-message--error .ai-bubble {
    background: rgba(127, 29, 29, 0.3);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

/* Welcome message */
.ai-message--welcome .ai-bubble {
    background: rgba(49, 10, 80, 0.35);
    border: 1px dashed rgba(168, 85, 247, 0.3);
}

.ai-suggestion-label {
    margin: 0.6rem 0 0.35rem;
    font-size: 0.75rem;
    color: #9ca3af;
}

.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.ai-suggestion-chip {
    background: rgba(109, 40, 217, 0.25);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 99px;
    color: #d8b4fe;
    font-size: 0.75rem;
    padding: 0.3rem 0.7rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.ai-suggestion-chip:hover {
    background: rgba(109, 40, 217, 0.45);
    border-color: rgba(192, 132, 252, 0.6);
}

/* ── Chips bar (above input) ─────────────────────────────────── */
.ai-chips-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.5rem 1.25rem 0.35rem;
    flex-shrink: 0;
    border-top: 1px solid rgba(168, 85, 247, 0.1);
}

/* p spacing inside bubbles */
.ai-bubble p {
    margin: 0 0 0.4rem;
}
.ai-bubble p:last-child { margin-bottom: 0; }

/* ── Typing indicator ───────────────────────────────────────── */
.ai-message--typing .ai-bubble {
    padding: 0.75rem 1rem;
    display: flex;
    gap: 0.3rem;
    align-items: center;
}

.ai-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #a855f7;
    display: inline-block;
    animation: ai-dot-bounce 1.2s ease-in-out infinite;
}

.ai-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-dot-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
    40%           { transform: translateY(-6px); opacity: 1; }
}

/* ── Input area ─────────────────────────────────────────────── */
.ai-modal-footer {
    padding: 0.75rem 1.25rem 1rem;
    border-top: 1px solid rgba(168, 85, 247, 0.12);
    flex-shrink: 0;
    background: rgba(15, 15, 26, 0.8);
}

.ai-input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: rgba(88, 28, 135, 0.12);
    border: 1px solid rgba(168, 85, 247, 0.2);
    border-radius: 0.75rem;
    padding: 0.4rem 0.5rem 0.4rem 0.75rem;
    transition: border-color 0.2s;
}

.ai-input-row:focus-within {
    border-color: rgba(168, 85, 247, 0.55);
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.08);
}

.ai-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    resize: none;
    color: #e5e7eb;
    font-size: 0.875rem;
    line-height: 1.5;
    min-height: 24px;
    max-height: 120px;
    overflow-y: auto;
    font-family: inherit;
}

.ai-input::placeholder {
    color: #6b7280;
}

.ai-send-btn {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    border: none;
    border-radius: 0.5rem;
    color: #fff;
    cursor: pointer;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.15s;
}

.ai-send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.ai-send-btn:not(:disabled):hover {
    transform: scale(1.08);
}

.ai-footer-note {
    margin: 0.4rem 0 0;
    font-size: 0.68rem;
    color: #4b5563;
    text-align: center;
}

/* ── Body lock when modal open ──────────────────────────────── */
body.ai-modal-lock {
    overflow: hidden;
}

html[data-theme='dark'] .ai-modal-panel {
    background: #0f0f1a;
    border-color: rgba(168, 85, 247, 0.25);
}

html[data-theme='light'] .ai-modal-overlay {
    background: rgba(15, 23, 42, 0.35);
}

html[data-theme='light'] .ai-modal-panel {
    background: #ffffff;
    border: 1px solid #dbe3ef;
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.18);
}

html[data-theme='light'] .ai-modal-header {
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg, rgba(67, 97, 238, 0.14) 0%, rgba(255, 255, 255, 0.98) 60%);
}

html[data-theme='light'] .ai-modal-title {
    color: #1e293b;
}

html[data-theme='light'] .ai-modal-close {
    color: #475569;
}

html[data-theme='light'] .ai-modal-close:hover {
    color: #1e293b;
    background: rgba(67, 97, 238, 0.16);
}

html[data-theme='light'] .ai-bubble {
    color: #1f2937;
}

html[data-theme='light'] .ai-message--bot .ai-bubble {
    background: #eff6ff;
    border: 1px solid #c7d2fe;
}

html[data-theme='light'] .ai-message--welcome .ai-bubble {
    background: #f8fafc;
    border: 1px dashed #bfdbfe;
}

html[data-theme='light'] .ai-suggestion-label {
    color: #64748b;
}

html[data-theme='light'] .ai-suggestion-chip {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #3730a3;
}

html[data-theme='light'] .ai-suggestion-chip:hover {
    background: #e0e7ff;
    border-color: #a5b4fc;
}

html[data-theme='light'] .ai-chips-bar,
html[data-theme='light'] .ai-modal-footer {
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
}

html[data-theme='light'] .ai-input-row {
    background: #ffffff;
    border: 1px solid #cbd5e1;
}

html[data-theme='light'] .ai-input-row:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

html[data-theme='light'] .ai-input {
    color: #1f2937;
}

html[data-theme='light'] .ai-input::placeholder {
    color: #94a3b8;
}

html[data-theme='light'] .ai-footer-note {
    color: #64748b;
}
