:root {
    --primary-color: #3b82f6;
    --primary-gradient: linear-gradient(135deg, #3b82f6, #60a5fa);
    --secondary-color: #f8fafc;
    --accent-color: #10b981;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --glass-bg: rgba(248, 250, 252, 0.95);
    --glass-border: rgba(255, 255, 255, 0.3);
    --shadow-light: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 8px 32px rgba(0, 0, 0, 0.12);
}

:root[data-theme="dark"] {
    --secondary-color: #1f2937;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --glass-bg: rgba(31, 41, 55, 0.95);
    --glass-border: rgba(255, 255, 255, 0.1);
}

#voice-chat-panel {
    position: fixed;
    bottom: 110px;
    right: 20px;
    width: min(450px, calc(100vw - 40px));
    height: min(650px, calc(100vh - 130px));
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.1);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
    z-index: 999998;
}

#voice-chat-panel.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    pointer-events: none;
}

.chat-input {
    display: flex;
    align-items: center;
    border-top: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    padding: 16px;
    gap: 12px;
    margin-top: auto; /* チャットメッセージの下に押し付ける */
}

.chat-input input {
    flex: 1;
    padding: 14px 16px;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    font-size: 14px;
    outline: none;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-primary);
    font-weight: 400;
}

.chat-input input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15), var(--shadow-light);
    background: rgba(255, 255, 255, 0.95);
    transform: translateY(-1px);
}

.chat-input button {
    padding: 14px 20px;
    background: var(--primary-gradient);
    color: #fff;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-light);
    backdrop-filter: blur(8px);
}

.chat-input button:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3);
    background: linear-gradient(135deg, #2563eb, #3b82f6);
}

#chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    background: transparent;
    border-radius: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(59, 130, 246, 0.3) transparent;
}

#chat-messages::-webkit-scrollbar {
    width: 4px;
}

#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(59, 130, 246, 0.3);
    border-radius: 2px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(59, 130, 246, 0.5);
}


.chat-message {
    max-width: 80%;
    padding: 16px 20px;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: fadeInUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
}

.chat-message.user {
    align-self: flex-end;
    background: var(--primary-gradient);
    color: white;
    border-bottom-right-radius: 8px;
    box-shadow: var(--shadow-light);
    font-weight: 500;
}

.chat-message.bot {
    align-self: flex-start;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.message-icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.message-icon img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.message-content {
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-primary);
    padding: 16px 20px;
    border-radius: 20px;
    border-bottom-left-radius: 8px;
    box-shadow: var(--shadow-light);
    font-weight: 400;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* チャットヘッダー */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
}

.chat-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.theme-toggle, .close-btn, .reset-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 16px;
    border: 1px solid var(--glass-border);
}

.theme-toggle:hover, .close-btn:hover, .reset-btn:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: scale(1.05);
    box-shadow: var(--shadow-light);
}

.close-btn {
    color: var(--text-secondary);
    font-size: 18px;
    font-weight: bold;
}

.close-btn:hover {
    color: #ef4444;
}

.reset-btn {
    color: var(--text-secondary);
    font-size: 14px;
}

.reset-btn:hover {
    color: #f59e0b;
}

.reset-btn.hidden {
    display: none;
}

/* ダークモードサポート */
:root[data-theme="dark"] .chat-message.bot .message-content {
    background: rgba(55, 65, 81, 0.9);
    color: var(--text-primary);
}

:root[data-theme="dark"] .chat-input input {
    background: rgba(55, 65, 81, 0.8);
    color: var(--text-primary);
}

:root[data-theme="dark"] .chat-input input:focus {
    background: rgba(55, 65, 81, 0.95);
}

:root[data-theme="dark"] .chat-header {
    background: rgba(55, 65, 81, 0.8);
}

:root[data-theme="dark"] .theme-toggle,
:root[data-theme="dark"] .close-btn,
:root[data-theme="dark"] .reset-btn {
    background: rgba(55, 65, 81, 0.6);
}

:root[data-theme="dark"] .theme-toggle:hover,
:root[data-theme="dark"] .close-btn:hover,
:root[data-theme="dark"] .reset-btn:hover {
    background: rgba(55, 65, 81, 0.9);
}

/* 初期画面（チャット開始画面） */
.chat-welcome,
.chat-reconnect {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 40px;
    text-align: center;
    gap: 24px;
}

.chat-welcome.hidden,
.chat-reconnect.hidden {
    display: none;
}

.chat-welcome h2,
.chat-reconnect h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.chat-welcome p,
.chat-reconnect p {
    font-size: 16px;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.6;
}

.chat-welcome-btn {
    padding: 16px 40px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-medium);
}

.chat-welcome-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 12px 40px rgba(59, 130, 246, 0.4);
}

.chat-welcome-btn:active {
    transform: translateY(0) scale(0.98);
}

/* 音声ボタン */
.voice-btn {
    width: 48px;
    height: 48px;
    background: var(--primary-gradient);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-light);
    color: white;
    font-size: 20px;
}

.voice-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3);
}

.voice-btn.recording {
    background: linear-gradient(135deg, #ef4444, #f87171);
    animation: pulse 1.5s infinite;
}

.voice-btn.recording:hover {
    transform: scale(1.1);
    background: linear-gradient(135deg, #ef4444, #f87171);
    box-shadow: 0 8px 25px rgba(180, 60, 0, 0.3);
}

/* 入力欄の無効化状態 */
.chat-input input:disabled,
.chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-input button:disabled:hover {
    transform: none;
    box-shadow: var(--shadow-light);
}

/* モバイル対応でアイコンとの重なりを調整 */
@media (max-width: 768px) {
    #voice-chat-panel {
        width: calc(100vw - 32px);
        height: calc(100vh - 32px);
        border-radius: 16px;
    }

    .chat-header {
        padding: 16px;
    }

    .chat-title {
        font-size: 16px;
    }

    #chat-messages {
        padding: 16px;
    }

    .chat-input {
        padding: 12px;
        gap: 8px;
    }

    .chat-welcome,
    .chat-reconnect {
        padding: 24px;
    }

    .chat-welcome h2,
    .chat-reconnect h2 {
        font-size: 24px;
    }

    .chat-welcome p,
    .chat-reconnect p {
        font-size: 14px;
    }
}
