/* ============================================
   AI Chat Widget — 共通 CSS
   CSS 変数でプロジェクトごとにテーマ切替可能

   使い方:
     :root {
       --ai-primary: #10b981;
       --ai-bg: #0f1715;
       --ai-text: #e2e8f0;
     }
   ============================================ */

#ai-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 500;
}

/* --- FAB Toggle Button --- */
.ai-toggle-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--ai-gradient, linear-gradient(135deg,
        var(--ai-primary, var(--accent-primary, #3b82f6)),
        var(--ai-secondary, var(--accent-secondary, #8b5cf6))));
    border: none;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--ai-shadow, rgba(59, 130, 246, 0.4));
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.ai-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px var(--ai-shadow, rgba(59, 130, 246, 0.5));
}

.ai-toggle-btn.active {
    background: linear-gradient(135deg,
        var(--ai-secondary, #8b5cf6),
        var(--ai-primary, var(--accent-primary, #3b82f6)));
    box-shadow: 0 0 20px var(--ai-shadow-active, rgba(139, 92, 246, 0.5));
}

/* --- Chat Panel --- */
.ai-panel {
    position: absolute;
    bottom: 64px;
    right: 0;
    width: 380px;
    max-height: 520px;
    background: var(--ai-bg, var(--bg-secondary, #111827));
    border-radius: 16px;
    border: 1px solid var(--ai-border, rgba(59, 130, 246, 0.2));
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiSlideUp 0.3s ease;
}

.ai-panel.hidden {
    display: none;
}

@keyframes aiSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Header --- */
.ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--ai-primary, #3b82f6) 15%, transparent),
        color-mix(in srgb, var(--ai-secondary, #8b5cf6) 10%, transparent));
    border-bottom: 1px solid var(--ai-border, rgba(59, 130, 246, 0.2));
    color: var(--ai-text, var(--text-primary, #e2e8f0));
    font-weight: 600;
    font-size: 14px;
}

.ai-close-btn {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 6px;
    color: var(--ai-text-dim, var(--text-secondary, #94a3b8));
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* --- Messages --- */
.ai-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    max-height: 350px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--ai-bg-deep, var(--bg-primary, #0a0e17));
}

.ai-messages::-webkit-scrollbar {
    width: 4px;
}

.ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-messages::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--ai-primary, #3b82f6) 30%, transparent);
    border-radius: 2px;
}

.ai-message {
    padding: 10px 14px;
    border-radius: 12px;
    max-width: 85%;
    line-height: 1.6;
    font-size: 13px;
    word-break: break-word;
}

.ai-message-user {
    background: linear-gradient(135deg,
        var(--ai-primary, var(--accent-primary, #3b82f6)),
        color-mix(in srgb, var(--ai-primary, #3b82f6) 80%, #000));
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.ai-message-assistant {
    background: var(--ai-bg, var(--bg-secondary, #111827));
    color: var(--ai-text, var(--text-primary, #e2e8f0));
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--ai-border-subtle, rgba(59, 130, 246, 0.1));
}

.ai-message code {
    background: color-mix(in srgb, var(--ai-primary, #3b82f6) 15%, transparent);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
}

.ai-message strong {
    color: var(--ai-accent, var(--accent-primary, #60a5fa));
}

/* --- Hint Chips --- */
.ai-hints {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 0;
}

.ai-hint-chip {
    background: color-mix(in srgb, var(--ai-primary, #3b82f6) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--ai-primary, #3b82f6) 20%, transparent);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--ai-primary, var(--accent-primary, #3b82f6));
    cursor: pointer;
    transition: background 0.2s;
    text-align: left;
}

.ai-hint-chip:hover {
    background: color-mix(in srgb, var(--ai-primary, #3b82f6) 20%, transparent);
}

/* --- Loading Dots --- */
.ai-loading {
    display: flex;
    gap: 5px;
    padding: 14px;
}

.ai-loading .dot {
    width: 8px;
    height: 8px;
    background: var(--ai-primary, var(--accent-primary, #3b82f6));
    border-radius: 50%;
    animation: aiBounce 1.4s infinite ease-in-out;
}

.ai-loading .dot:nth-child(1) { animation-delay: -0.32s; }
.ai-loading .dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes aiBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40%           { transform: scale(1); opacity: 1; }
}

/* --- Input Area --- */
.ai-input-area {
    display: flex;
    gap: 8px;
    padding: 14px;
    background: var(--ai-bg, var(--bg-secondary, #111827));
    border-top: 1px solid var(--ai-border-subtle, rgba(59, 130, 246, 0.15));
}

#ai-chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--ai-border, rgba(59, 130, 246, 0.2));
    border-radius: 24px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: var(--ai-bg-deep, var(--bg-primary, #0a0e17));
    color: var(--ai-text, var(--text-primary, #e2e8f0));
}

#ai-chat-input:focus {
    border-color: var(--ai-primary, var(--accent-primary, #3b82f6));
    box-shadow: 0 0 8px color-mix(in srgb, var(--ai-primary, #3b82f6) 15%, transparent);
}

#ai-chat-input::placeholder {
    color: var(--ai-text-dim, var(--text-secondary, #94a3b8));
}

.ai-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--ai-gradient, linear-gradient(135deg,
        var(--ai-primary, #3b82f6),
        var(--ai-secondary, #8b5cf6)));
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.ai-send-btn svg {
    width: 18px;
    height: 18px;
}

.ai-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 12px var(--ai-shadow, rgba(59, 130, 246, 0.3));
}

/* --- Mobile --- */
@media (max-width: 480px) {
    .ai-panel {
        width: calc(100vw - 48px);
        max-height: 60vh;
    }

    #ai-chat-widget {
        bottom: 16px;
        right: 16px;
    }
}

/* --- Print: hide --- */
@media print {
    #ai-chat-widget {
        display: none !important;
    }
}
