/**
 * チャットボット ウィジェット CSS
 * .chatbot- プレフィックスで既存CSSとの衝突を回避
 * variables.css のCSS変数を継承
 */

/* ===== バブルボタン（縦長縦書きタブ） ===== */
.chatbot-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: auto;
    min-width: 56px;
    height: auto;
    border-radius: 16px;
    background: linear-gradient(135deg, #818cf8, #a78bfa);
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: var(--shadow-lg);
    z-index: var(--z-index-fixed);
    transition: transform var(--transition-fast) ease, box-shadow var(--transition-fast) ease,
                width var(--transition-fast) ease, height var(--transition-fast) ease,
                border-radius var(--transition-fast) ease, right var(--transition-fast) ease;
    padding: 12px 10px;
}

.chatbot-bubble:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-xl);
}

.chatbot-bubble:active {
    transform: scale(0.98);
}

.chatbot-bubble-logo {
    width: 28px;
    height: 28px;
    border-radius: var(--border-radius-full);
    object-fit: contain;
    pointer-events: none;
    flex-shrink: 0;
}

.chatbot-bubble-label {
    writing-mode: vertical-rl;
    color: var(--white);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    pointer-events: none;
}

/* 英数字（AI等）を縦書き中で横組み */
.chatbot-bubble-label .tcy {
    text-combine-upright: all;
}

.chatbot-bubble-close {
    width: 24px;
    height: 24px;
    display: none;
}

/* 開いた状態: 丸い閉じるボタンに変化 */
.chatbot-bubble.is-open {
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: var(--border-radius-full);
    padding: 0;
}

.chatbot-bubble.is-open .chatbot-bubble-logo {
    display: none;
}

.chatbot-bubble.is-open .chatbot-bubble-label {
    display: none;
}

.chatbot-bubble.is-open .chatbot-bubble-close {
    display: block;
}

/* ===== ウィンドウ ===== */
.chatbot-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    border-radius: var(--border-radius-md);
    background: var(--white);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-index-fixed);
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    transition: opacity var(--transition-fast) ease, transform var(--transition-fast) ease;
}

.chatbot-window.is-visible {
    display: flex;
}

.chatbot-window.is-open {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ===== ヘッダー ===== */
.chatbot-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: linear-gradient(135deg, #818cf8, #a78bfa);
    color: var(--white);
    flex-shrink: 0;
}

.chatbot-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-full);
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-header-avatar img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.chatbot-header-info {
    flex: 1;
    min-width: 0;
}

.chatbot-header-title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    line-height: var(--line-height-tight);
}

.chatbot-header-subtitle {
    font-size: var(--font-size-xs);
    opacity: 0.8;
    line-height: var(--line-height-tight);
}

.chatbot-header-close {
    width: 32px;
    height: 32px;
    border-radius: var(--border-radius-full);
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--white);
    transition: background var(--transition-fast) ease;
}

.chatbot-header-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chatbot-header-close svg {
    width: 18px;
    height: 18px;
}

/* ===== メッセージエリア ===== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--gray-50);
}

.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 2px;
}

/* ===== メッセージ行（アバター + バブル） ===== */
.chatbot-msg-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.chatbot-msg-row-user {
    flex-direction: row-reverse;
}

/* ===== メッセージアバター ===== */
.chatbot-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chatbot-msg-avatar-bot {
    background: #f1f5f9;
    color: #64748b;
}

.chatbot-msg-avatar-user {
    background: #818cf8;
    color: white;
}

.chatbot-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

/* ===== メッセージバブル ===== */
.chatbot-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: var(--font-size-xs);
    line-height: var(--line-height-relaxed);
    word-break: break-word;
    white-space: pre-wrap;
}

.chatbot-msg-bot {
    background: var(--white);
    color: var(--text-dark);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.chatbot-msg-user {
    background: var(--primary-color);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

/* ===== タイピングインジケーター ===== */
.chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--white);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.chatbot-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: var(--border-radius-full);
    background: var(--gray-400);
    animation: chatbot-bounce 1.2s infinite ease-in-out;
}

.chatbot-typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.chatbot-typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chatbot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* ===== 入力エリア ===== */
.chatbot-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-light);
    background: var(--white);
    flex-shrink: 0;
}

.chatbot-textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-light);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: var(--font-size-xs);
    font-family: inherit;
    line-height: var(--line-height-normal);
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    transition: border-color var(--transition-fast) ease;
}

.chatbot-textarea:focus {
    border-color: var(--primary-color);
}

.chatbot-textarea::placeholder {
    color: var(--gray-400);
}

.chatbot-send-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-full);
    background: var(--primary-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition-fast) ease, opacity var(--transition-fast) ease;
}

.chatbot-send-btn:hover {
    background: var(--secondary-color);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-send-btn svg {
    width: 18px;
    height: 18px;
    fill: var(--white);
}

/* ===== エラーメッセージ ===== */
.chatbot-msg-error {
    align-self: center;
    background: #fef2f2;
    color: #dc2626;
    border-radius: var(--border-radius-sm);
    font-size: 0.75rem;
    padding: 6px 12px;
}

/* ===== レスポンシブ: タブレット ===== */
@media (max-width: 768px) {
    .chatbot-window {
        width: calc(100vw - 32px);
        right: 16px;
        bottom: 88px;
        height: calc(100vh - 112px);
        max-height: none;
    }

    .chatbot-bubble {
        bottom: 20px;
        right: 16px;
    }

    .chatbot-bubble.is-open {
        right: 16px;
    }
}

/* ===== レスポンシブ: スマホ ===== */
@media (max-width: 480px) {
    .chatbot-window {
        width: 100%;
        height: 100%;
        right: 0;
        bottom: 0;
        border-radius: 0;
        max-height: none;
    }

    .chatbot-bubble {
        bottom: 16px;
        right: 12px;
        min-width: 48px;
        padding: 10px 8px;
    }

    .chatbot-bubble-logo {
        width: 24px;
        height: 24px;
    }

    .chatbot-bubble-label {
        font-size: 10px;
    }

    .chatbot-bubble.is-open {
        right: 16px;
        width: 48px;
        height: 48px;
    }
}

/* ===== アクセシビリティ: reduced-motion ===== */
@media (prefers-reduced-motion: reduce) {
    .chatbot-bubble,
    .chatbot-window,
    .chatbot-textarea,
    .chatbot-send-btn {
        transition: none;
    }

    .chatbot-typing-dot {
        animation: none;
    }

    .chatbot-window {
        transform: none;
    }
}
