/**
 * ai-button.css — Styles for the reusable AI button component.
 *
 * Provides base styles for:
 * - .ai-button (the main button)
 * - .ai-button-popover (action list)
 * - .ai-loading-modal (spinner)
 * - .ai-result-modal (result display)
 */

/* ===== AI Button — prominent, vibrant, deliberately stands out ===== */
.ai-button {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.65rem 1.25rem;
    background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 50%, #f59e0b 100%);
    background-size: 200% 200%;
    color: #fff;
    border: none;
    border-radius: 999px; /* full pill */
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-position 0.5s ease;
    box-shadow:
        0 4px 14px rgba(139, 92, 246, 0.45),
        0 0 0 1px rgba(255, 255, 255, 0.15) inset;
    animation: aiButtonPulse 3s ease-in-out infinite;
    z-index: 1;
}
.ai-button::before {
    /* soft glow halo on idle */
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 999px;
    background: linear-gradient(135deg, #8b5cf6, #ec4899, #f59e0b);
    filter: blur(10px);
    opacity: 0.35;
    z-index: -1;
    transition: opacity 0.25s ease;
}
.ai-button:hover {
    transform: translateY(-2px) scale(1.03);
    background-position: 100% 100%;
    box-shadow:
        0 8px 22px rgba(236, 72, 153, 0.55),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}
.ai-button:hover::before {
    opacity: 0.6;
}
.ai-button:active {
    transform: translateY(0) scale(0.99);
}
.ai-button:focus-visible {
    outline: 2px solid #fbbf24;
    outline-offset: 3px;
}

/* Sparkle pulse on idle so the button calls attention to itself without
   becoming annoying. Subtle scale + shadow breathing. */
@keyframes aiButtonPulse {
    0%, 100% {
        box-shadow: 0 4px 14px rgba(139, 92, 246, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.15) inset;
    }
    50% {
        box-shadow: 0 6px 20px rgba(236, 72, 153, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.2) inset;
    }
}

/* Variant: floating action button (FAB) for placing on student dashboards
   and similar pages where AI is the primary CTA. Use class="ai-button ai-button-fab".
   Sits bottom-right, large, persistent. */
.ai-button-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 0.85rem 1.5rem;
    font-size: 1.05rem;
    box-shadow:
        0 8px 24px rgba(139, 92, 246, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset;
    z-index: 9999;
}

/* Variant: small. For tight toolbars where we still want AI to read clearly
   but not dominate. Use class="ai-button ai-button-sm". */
.ai-button-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.85rem;
    gap: 0.4rem;
}

/* Reduce-motion users get the colors without the pulse. */
@media (prefers-reduced-motion: reduce) {
    .ai-button {
        animation: none;
    }
}

/* ===== Popover ===== */
.ai-button-popover {
    /* Hard-coded dark palette so the popover stays readable wherever it
       lands — earlier we relied on --text-color/--bg-light, but the editor
       overrides --text-color to white, which made labels invisible against
       the popover's white background. */
    background: rgba(15, 15, 28, 0.97);
    color: #fff;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
    z-index: 10000;
    min-width: 240px;
    overflow: hidden;
    animation: aiPopoverSlideIn 0.15s ease-out;
}

@keyframes aiPopoverSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-popover-header {
    padding: 0.75rem 1rem;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.4px;
    color: rgba(255, 255, 255, 0.55);
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.03);
}

.ai-popover-actions {
    display: flex;
    flex-direction: column;
    padding: 4px;
}

.ai-popover-action {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    background: none;
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    text-align: left;
    font-size: 0.9rem;
    font-family: inherit;
    transition: background-color 0.15s ease;
}

.ai-popover-action:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.ai-popover-action:focus {
    outline: 2px solid var(--accent, #e94560);
    outline-offset: -2px;
}

.ai-action-icon {
    font-size: 1.1rem;
    min-width: 1.5rem;
    line-height: 1;
}

.ai-action-label {
    font-weight: 500;
    color: #fff;
    flex: 1; /* push the cost chip to the right edge */
}

/* Estimated-cost chip on the right of each AI action row.
   "<1¢" / "~1¢" / "1¢" / "5¢" — derived from pricing × max_tokens in api/ai.php. */
.ai-action-cost {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.3px;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.55);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    flex-shrink: 0;
}

/* Popover footer — holds the History button. Earlier this rendered as a
   white-on-purple block (button defaults), inverted from everything else. */
.ai-popover-footer {
    padding: 6px 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.02);
    display: flex;
}

.ai-popover-history {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: none;
    border: none;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.ai-popover-history:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: #fff;
}

/* ===== Loading Modal ===== */
.ai-loading-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    backdrop-filter: blur(2px);
}

.ai-loading-spinner {
    background: white;
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
}

.ai-spinner {
    width: 40px;
    height: 40px;
    margin: 0 auto 1rem;
    border: 3px solid var(--border-color, #e5e7eb);
    border-top-color: var(--primary-color, #6366f1);
    border-radius: 50%;
    animation: aiSpinRotate 0.8s linear infinite;
}

@keyframes aiSpinRotate {
    to { transform: rotate(360deg); }
}

.ai-loading-spinner p {
    margin: 0;
    color: var(--text-color, #1f2937);
    font-weight: 500;
}

/* ===== Result Modal ===== */
.ai-result-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    backdrop-filter: blur(2px);
    padding: 1rem;
}

.ai-result-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: aiModalFadeIn 0.2s ease-out;
}

@keyframes aiModalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.ai-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.ai-result-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-color, #1f2937);
}

.ai-result-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-color, #1f2937);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.15s ease;
}

.ai-result-close:hover {
    background-color: var(--hover-bg, #f3f4f6);
}

.ai-result-body {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

.ai-result-text {
    margin: 0;
    padding: 1rem;
    background: var(--bg-light, #f9fafb);
    border-radius: 6px;
    border: 1px solid var(--border-color, #e5e7eb);
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-color, #1f2937);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
}

.ai-result-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--bg-light, #f9fafb);
    justify-content: flex-end;
}

.ai-result-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    color: var(--text-color, #1f2937);
}

.ai-result-btn:hover {
    background-color: var(--hover-bg, #f3f4f6);
}

.ai-result-btn.apply {
    background: var(--primary-color, #6366f1);
    color: white;
    border-color: var(--primary-color, #6366f1);
}

.ai-result-btn.apply:hover {
    background: var(--primary-dark, #4f46e5);
    border-color: var(--primary-dark, #4f46e5);
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .ai-button-popover {
        min-width: 200px;
    }

    .ai-result-modal {
        padding: 0.5rem;
    }

    .ai-result-content {
        max-width: calc(100vw - 1rem);
        max-height: 90vh;
    }

    .ai-result-text {
        font-size: 0.8rem;
        max-height: 300px;
    }

    .ai-result-footer {
        flex-wrap: wrap;
    }
}
