/* ==================== */
/* CSS Variables */
/* ==================== */
:root {
    /* Primary colors - customizable via WordPress admin */
    --chat-primary: #6366f1;
    --chat-primary-dark: #4f46e5;
    --chat-header-color: #6366f1;
    --chat-title-color: #ffffff;

    /* Background colors */
    --chat-bg-main: #ffffff;
    --chat-bg-chat: #f9fafb;
    --chat-bg-input: #f3f4f6;

    /* Text colors */
    --chat-text-primary: #1f2937;
    --chat-text-secondary: #6b7280;
    --chat-text-muted: #9ca3af;

    /* Border & Shadow */
    --chat-border: #e5e7eb;
    --chat-shadow: 0 4px 24px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04);

    /* Border radius */
    --chat-radius-lg: 16px;
    --chat-radius-md: 12px;
    --chat-radius-sm: 8px;

    /* Font settings */
    --chatbot-font-family: "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
    --chatbot-font-size-message: 14px;
    --chatbot-font-size-header: 15px;
    --chatbot-font-size-input: 14px;
}

/* ==================== */
/* Base Styles */
/* ==================== */
#my-chatbot {
    z-index: 9999;
    font-family: var(--chatbot-font-family);
}

#my-chatbot * {
    box-sizing: border-box;
}

/* ==================== */
/* Chat Icon */
/* ==================== */
#my-chatbot #chat-icon {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 220px;
    height: 60px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    z-index: 9999;
}

#my-chatbot #chat-icon:hover {
    transform: scale(1.05);
}

/* ==================== */
/* Chat Container */
/* ==================== */
#my-chatbot #chat-container {
    position: fixed;
    width: 400px;
    height: 620px;
    bottom: 20px;
    right: 20px;
    border-radius: var(--chat-radius-lg);
    background: var(--chat-bg-main);
    display: none;
    flex-direction: column;
    box-shadow: var(--chat-shadow);
    overflow: hidden;
    z-index: 10000;
}

#my-chatbot #chat-container.visible {
    display: flex;
}

/* ==================== */
/* Header */
/* ==================== */
#my-chatbot #chat-header {
    background: linear-gradient(135deg, var(--chat-header-color) 0%, var(--chat-primary-dark) 100%);
    color: white;
    padding: 18px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

#my-chatbot .header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

#my-chatbot .status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.15);
    padding: 4px 10px 4px 8px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

#my-chatbot .status-dot {
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    animation: statusPulse 2s ease-in-out infinite;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

@keyframes statusPulse {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
    }
    50% {
        opacity: 0.7;
        box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.1);
    }
}

/* オフライン状態 */
#my-chatbot .status-badge.offline .status-dot {
    background: #9ca3af;
    animation: none;
    box-shadow: none;
}

#my-chatbot .status-badge.offline .status-text {
    color: rgba(255, 255, 255, 0.7);
}

#my-chatbot #chat-title {
    font-weight: 600;
    font-size: var(--chatbot-font-size-header);
    color: var(--chat-title-color);
    letter-spacing: -0.01em;
}

#my-chatbot #close-chat {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--chat-radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

#my-chatbot #close-chat:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

#my-chatbot #close-chat:active {
    transform: scale(0.95);
}

#my-chatbot #close-chat svg {
    width: 18px;
    height: 18px;
    stroke: white;
    stroke-width: 2;
    stroke-linecap: round;
}

/* ==================== */
/* Messages Area */
/* ==================== */
#my-chatbot #chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: var(--chat-bg-chat);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ==================== */
/* Message Styles */
/* ==================== */
#my-chatbot .message {
    display: flex;
    gap: 12px;
    animation: messageIn 0.35s ease-out;
}

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

#my-chatbot .message.user-message {
    flex-direction: row-reverse;
}

#my-chatbot .message.bot-message {
    flex-direction: row;
}

#my-chatbot .message-icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: var(--chat-radius-md);
    background: linear-gradient(135deg, var(--chat-header-color) 0%, var(--chat-primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#my-chatbot .message-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#my-chatbot .user-message .message-icon {
    display: none;
}

#my-chatbot .message-content {
    max-width: 72%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#my-chatbot .user-message .message-content {
    align-items: flex-end;
}

#my-chatbot .message-bubble {
    padding: 12px 16px;
    font-size: var(--chatbot-font-size-message);
    line-height: 1.6;
    letter-spacing: 0.01em;
    word-wrap: break-word;
    white-space: pre-wrap;
}

#my-chatbot .bot-message .message-bubble {
    background: var(--chat-bg-main);
    color: var(--chat-text-primary);
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

#my-chatbot .user-message .message-bubble {
    background: var(--chat-header-color);
    color: white;
    border-radius: 18px 18px 4px 18px;
}

/* Message links */
#my-chatbot .message-bubble a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

#my-chatbot .bot-message .message-bubble a {
    color: var(--chat-header-color);
}

#my-chatbot .message-bubble a:hover {
    opacity: 0.8;
}

/* ==================== */
/* Typing Indicator */
/* ==================== */
#my-chatbot .message.bot-message.is-typing {
    display: flex !important;
}

#my-chatbot .typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
    background: var(--chat-bg-main);
    border-radius: 18px 18px 18px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

#my-chatbot .typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

#my-chatbot .typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

#my-chatbot .typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* ==================== */
/* Input Area - Floating Style */
/* ==================== */
#my-chatbot #chat-input-container {
    padding: 16px;
    background: var(--chat-bg-main);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

#my-chatbot .input-wrapper {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 10px;
    background: var(--chat-bg-input);
    border-radius: var(--chat-radius-md);
    padding: 8px;
    transition: all 0.2s ease;
}

#my-chatbot .input-wrapper:focus-within {
    background: #eef2ff;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

#my-chatbot #user-input {
    flex: 1;
    border: none;
    background: var(--chat-bg-main);
    border-radius: var(--chat-radius-sm);
    padding: 12px 16px;
    font-size: var(--chatbot-font-size-input);
    font-family: var(--chatbot-font-family);
    outline: none;
    color: var(--chat-text-primary);
}

#my-chatbot #user-input::placeholder {
    color: var(--chat-text-muted);
}

#my-chatbot #send-button {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--chat-header-color);
    color: white;
    border: none;
    border-radius: var(--chat-radius-sm);
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--chatbot-font-family);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

#my-chatbot #send-button:hover {
    background: var(--chat-primary-dark);
    transform: translateY(-1px);
}

#my-chatbot #send-button:active {
    transform: translateY(0) scale(0.98);
}

#my-chatbot #send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#my-chatbot #send-button svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ==================== */
/* Footer */
/* ==================== */
#my-chatbot #chat-footer {
    padding: 12px 16px;
    text-align: center;
    font-size: 11px;
    color: var(--chat-text-muted);
    border-top: 1px solid var(--chat-border);
    background: var(--chat-bg-main);
    flex-shrink: 0;
}

#my-chatbot #chat-footer a {
    color: var(--chat-text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

#my-chatbot #chat-footer a:hover {
    color: var(--chat-header-color);
}

#my-chatbot #chat-footer .separator {
    margin: 0 8px;
    color: var(--chat-border);
}

/* ==================== */
/* Mobile Styles */
/* ==================== */
@media screen and (max-width: 768px) {
    #my-chatbot #chat-icon {
        bottom: 20px;
        right: 5vw;
        width: 50vw;
        max-width: 200px;
        height: auto;
        padding-bottom: 25vw;
    }

    #my-chatbot #chat-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    #my-chatbot #chat-header {
        padding: 20px;
        padding-top: max(20px, env(safe-area-inset-top));
    }

    #my-chatbot #close-chat {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        background: rgba(255, 255, 255, 0.2);
        z-index: 10001;
    }

    #my-chatbot #close-chat svg {
        width: 24px;
        height: 24px;
    }

    #my-chatbot #chat-messages {
        padding: 16px;
    }

    #my-chatbot .message-content {
        max-width: 80%;
    }

    #my-chatbot #user-input {
        font-size: 16px; /* iOS zoom prevention */
    }

    #my-chatbot #chat-input-container {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

/* ==================== */
/* Body Styles */
/* ==================== */
body.chat-open {
    overflow: hidden;
}

/* ==================== */
/* Chatbot Links (dynamically added) */
/* ==================== */
#my-chatbot .chatbot-links {
    padding: 10px;
    text-align: center;
    font-size: 12px;
}

#my-chatbot .chatbot-links a {
    color: var(--chat-text-secondary);
    text-decoration: none;
}

#my-chatbot .chatbot-links a:hover {
    color: var(--chat-header-color);
    text-decoration: underline;
}
