/**
 * JavocSoft Portfolio - AI assistant widget
 *
 * Uses the theme variables from styles.css, so it follows light and dark mode.
 */

.ai-launcher {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.8rem 1.2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    border: 0;
    border-radius: 999px;
    font: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: 0 10px 25px -5px rgba(118, 75, 162, 0.55);
    cursor: pointer;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.ai-launcher span {
    max-width: 8rem;
    overflow: hidden;
    white-space: nowrap;
    transition: max-width var(--transition-base), opacity var(--transition-base);
}

/* Scrolled: just the icon, so it doesn't cover the content */
.ai-launcher.is-compact {
    gap: 0;
    padding: 0.85rem;
}

.ai-launcher.is-compact span {
    max-width: 0;
    opacity: 0;
}

.ai-launcher.is-compact:hover,
.ai-launcher.is-compact:focus-visible {
    gap: 0.55rem;
    padding: 0.8rem 1.2rem;
}

.ai-launcher.is-compact:hover span,
.ai-launcher.is-compact:focus-visible span {
    max-width: 8rem;
    opacity: 1;
}

.ai-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px -6px rgba(118, 75, 162, 0.7);
}

.ai-launcher i {
    animation: ai-sparkle 3s ease-in-out infinite;
}

.ai-launcher.is-open i {
    animation: none;
}

@keyframes ai-sparkle {
    0%, 80%, 100% { transform: rotate(0) scale(1); }
    88% { transform: rotate(-18deg) scale(1.2); }
    94% { transform: rotate(12deg) scale(1.1); }
}

/* Keep the page's own floating elements clear of the launcher */
.has-assistant .scroll-to-top {
    bottom: 5.5rem;
    right: 1.9rem;
}

.has-assistant .toast {
    bottom: 5.5rem;
}

.ai-panel {
    position: fixed;
    right: 1.5rem;
    bottom: 5.5rem;
    z-index: 901;
    width: min(400px, calc(100vw - 2rem));
    height: min(620px, calc(100vh - 8rem));
    display: flex;
    flex-direction: column;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--color-light-gray);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: ai-pop 0.22s ease-out;
}

.ai-panel[hidden] {
    display: none;
}

@keyframes ai-pop {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: none; }
}

.ai-head {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.8rem 0.9rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
}

.ai-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    image-rendering: pixelated;
}

.ai-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.ai-title span {
    font-size: 0.78rem;
    opacity: 0.85;
}

.ai-icon-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.ai-icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ai-log {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    background: var(--color-bg);
}

.ai-msg {
    max-width: 88%;
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.ai-msg p + p,
.ai-msg p + ul,
.ai-msg ul + p {
    margin-top: 0.45rem;
}

.ai-msg ul {
    padding-left: 1.2rem;
}

.ai-msg code {
    padding: 0 0.3rem;
    border-radius: 4px;
    background: rgba(100, 116, 139, 0.15);
    font-size: 0.85em;
}

.ai-bot {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--color-light-gray);
    border-bottom-left-radius: 4px;
}

.ai-bot a {
    color: var(--color-primary);
    text-decoration: underline;
}

.ai-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.ai-error {
    align-self: stretch;
    max-width: none;
    background: rgba(239, 68, 68, 0.1);
    color: #b91c1c;
    font-size: 0.85rem;
}

.ai-note {
    align-self: flex-start;
    margin-top: -0.2rem;
    padding-left: 0.4rem;
    font-size: 0.78rem;
    color: var(--color-secondary);
    font-weight: 500;
}

.ai-typing {
    display: flex;
    gap: 4px;
    padding: 0.8rem 0.9rem;
}

.ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-gray);
    animation: ai-dot 1.2s infinite ease-in-out;
}

.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-dot {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

.ai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.6rem 0.9rem 0;
    background: var(--color-bg);
}

.ai-suggestions[hidden] {
    display: none;
}

.ai-chip {
    padding: 0.35rem 0.75rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--color-light-gray);
    border-radius: 999px;
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.ai-chip:hover {
    border-color: var(--color-secondary);
    color: var(--color-secondary);
}

.ai-form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.7rem 0.9rem 0.4rem;
    background: var(--color-bg);
}

.ai-form textarea {
    flex: 1;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    color: var(--text);
    border: 2px solid var(--color-light-gray);
    border-radius: 12px;
    font: inherit;
    font-size: 0.9rem;
    line-height: 1.4;
}

.ai-form textarea:focus {
    outline: none;
    border-color: var(--color-secondary);
}

.ai-send {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    border: 0;
    border-radius: 12px;
    cursor: pointer;
}

.ai-send:disabled {
    opacity: 0.5;
    cursor: default;
}

.ai-disclaimer {
    padding: 0.2rem 0.9rem 0.7rem;
    background: var(--color-bg);
    font-size: 0.7rem;
    line-height: 1.4;
    color: var(--color-gray);
}

.ai-disclaimer a {
    color: inherit;
    text-decoration: underline;
}

.ai-launcher:focus-visible,
.ai-panel button:focus-visible {
    outline: 3px solid var(--color-primary-light);
    outline-offset: 2px;
}

@media (max-width: 640px) {
    .ai-launcher {
        right: 1rem;
        bottom: 1rem;
        padding: 0.8rem;
    }

    .ai-launcher span {
        display: none;
    }

    .has-assistant .scroll-to-top {
        right: 1.25rem;
        bottom: 4.75rem;
    }

    .ai-panel {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        height: min(85vh, 640px);
        border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
    }

    .ai-open .ai-launcher {
        display: none;
    }
}

/* Short screens (phones in landscape): the panel uses the whole height, with a
   compact header and the suggestions in one scrolling row */
@media (max-height: 500px) {
    .ai-panel {
        top: 0.5rem;
        bottom: 0.5rem;
        right: 0.75rem;
        height: auto;
        width: min(420px, calc(100vw - 1.5rem));
    }

    .ai-head {
        padding: 0.4rem 0.7rem;
    }

    .ai-avatar {
        width: 28px;
        height: 28px;
    }

    .ai-title span {
        display: none;
    }

    .ai-log {
        padding: 0.6rem 0.7rem;
    }

    .ai-suggestions {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-top: 0.4rem;
        scrollbar-width: none;
    }

    .ai-chip {
        flex-shrink: 0;
    }

    .ai-form {
        padding: 0.45rem 0.7rem 0.3rem;
    }

    .ai-disclaimer {
        padding-bottom: 0.4rem;
        font-size: 0.65rem;
    }

    .ai-open .ai-launcher {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ai-launcher i,
    .ai-typing span,
    .ai-panel {
        animation: none;
    }
}

html[data-theme="dark"] .ai-error {
    color: #fca5a5;
}

html[data-theme="dark"] .ai-note {
    color: #a78bfa;
}

html[data-theme="dark"] .ai-bot a {
    color: #93c5fd;
}
