* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    height: 100dvh; /* モバイルブラウザ対応 */
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #1976D2;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100); /* JavaScriptで設定されたビューポート高さを使用 */
    height: 100dvh; /* モバイルブラウザ対応（サポートされている場合） */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    touch-action: manipulation; /* ダブルタップズームを防止 */
}

/* メインコンテナ - 画面全体を使用 */
.ai-chat-container {
    width: 100%;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100); /* JavaScriptで設定されたビューポート高さを使用 */
    height: 100dvh; /* モバイルブラウザ対応（サポートされている場合） */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    touch-action: manipulation; /* ダブルタップズームを防止 */
}

/* ヘッダー */
.ai-chat-header {
    background: #1976D2;
    color: white;
    padding: 20px;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 10;
}

.ai-header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 900px;
    margin: 0 auto;
}

.ai-header-text {
    text-align: left;
}

.ai-chat-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 5px;
    letter-spacing: -0.5px;
}

.ai-chat-header p {
    font-size: 16px;
    opacity: 0.9;
    font-weight: 300;
}

/* チャットエリア */
.ai-chat-box {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    align-items: center;
}

@media screen and (min-width: 769px) {
    .ai-chat-header {
        padding: 14px 20px;
    }

    .ai-chat-header h1 {
        font-size: 22px;
        margin-bottom: 3px;
    }

    .ai-chat-header p {
        font-size: 13px;
    }

    .ai-chat-box {
        padding: 16px;
    }

    .ai-message {
        font-size: 14px;
        padding: 12px 16px;
        border-radius: 16px;
    }

    .ai-user {
        border-radius: 16px 16px 4px 16px;
    }

    .ai-bot {
        border-radius: 16px 16px 16px 4px;
    }

    .ai-avatar {
        width: 32px;
        height: 32px;
        font-size: 16px;
        margin: 2px 8px 0 8px;
    }

    .ai-message-container {
        margin: 8px 0;
        min-height: 40px;
    }

    .ai-chat-content {
        max-width: 520px;
    }

    .ai-faq-toggle-button {
        padding: 8px 16px;
        font-size: 12px;
    }

    .ai-faq-toggle-button i {
        font-size: 14px;
    }

    .ai-keyword-container {
        padding: 14px;
    }

    .ai-keyword-wrapper {
        max-width: 520px;
    }

    .ai-keyword-button {
        padding: 8px 16px;
        font-size: 12px;
    }

    .ai-keyword-scroll-button {
        width: 30px;
        height: 30px;
    }

    .ai-chat-input-wrapper {
        padding: 14px;
    }

    .ai-chat-input {
        max-width: 520px;
        padding: 4px;
    }

    .ai-user-input {
        padding: 10px 16px;
        font-size: 14px;
    }

    .ai-send-button {
        width: 40px;
        height: 40px;
    }

    .ai-welcome-container {
        padding: 30px;
    }

    .ai-welcome-icon {
        font-size: 64px;
        margin-bottom: 16px;
    }

    .ai-welcome-title {
        font-size: 20px;
        margin-bottom: 8px;
    }

    .ai-welcome-subtitle {
        font-size: 15px;
    }

    .ai-custom-welcome-img {
        width: 64px;
        height: 64px;
    }
}

.ai-chat-content {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
}

/* メッセージスタイル */
.ai-message-container {
    display: flex;
    align-items: flex-start; /* アイコンをメッセージの上部に配置 */
    margin: 10px 0;
    animation: fadeInUp 0.4s ease-out;
    min-height: 50px; /* レイアウトシフトを防ぐための最小高さ */
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-message {
    max-width: 70%;
    padding: 16px 20px;
    border-radius: 20px;
    display: inline-block;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    font-size: 16px;
    line-height: 1.5;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    position: relative; /* 位置を固定してレイアウトシフトを防ぐ */
}

.ai-user-container {
    justify-content: flex-end;
}

.ai-user {
    background: #1976D2;
    color: white;
    border-radius: 20px 20px 5px 20px;
    margin-left: auto;
}

.ai-bot-container {
    justify-content: flex-start;
}

.ai-bot {
    background: white;
    color: #333;
    border-radius: 20px 20px 20px 5px;
    border: 1px solid #e9ecef;
}

/* アバターアイコン */
.ai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 3px 10px 0 10px; /* 上マージンを追加してメッセージボックスとの位置を調整 */
    font-size: 20px;
    flex-shrink: 0;
}

.ai-bot-avatar {
    background: white;
    color: #1976D2;
    border: 2px solid #e9ecef;
}

/* よくある質問トグルボタン */
.ai-faq-toggle-button {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15), 0 0 20px rgba(255, 255, 255, 0.3);
    animation: faqButtonAttention 2s ease-in-out infinite;
}

/* パルスアニメーション（注目を引く） */
@keyframes faqButtonAttention {
    0%, 100% {
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15), 0 0 0 0 rgba(255, 255, 255, 0.4);
    }
    50% {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2), 0 0 0 8px rgba(255, 255, 255, 0.0);
    }
}


.ai-faq-toggle-button:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.25);
    animation: none;
}

.ai-faq-toggle-button:active {
    transform: translateY(0) scale(0.98);
    transition: transform 0.1s ease;
}

.ai-faq-toggle-button i {
    font-size: 16px;
    animation: faqIconBounce 2s ease-in-out infinite;
}

@keyframes faqIconBounce {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.2); }
    50% { transform: scale(1); }
}

/* FAQ開いた状態のボタン */
.ai-faq-toggle-button.ai-faq-active {
    background: rgba(255, 255, 255, 0.15);
    animation: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) inset;
}

.ai-faq-toggle-button.ai-faq-active i {
    animation: none;
}



/* キーワードボタンエリア */
.ai-keyword-container {
    padding: 20px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    overflow: hidden;
}

.ai-keyword-container.ai-show {
    animation: slideDown 0.3s ease-out;
}

.ai-keyword-container.ai-hide {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideDown {
    from {
        max-height: 0;
        opacity: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
    to {
        max-height: 100px;
        opacity: 1;
        padding-top: 20px;
        padding-bottom: 20px;
    }
}

@keyframes slideUp {
    from {
        max-height: 100px;
        opacity: 1;
        padding-top: 20px;
        padding-bottom: 20px;
    }
    to {
        max-height: 0;
        opacity: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
}

.ai-keyword-wrapper {
    max-width: 600px;
    width: 100%;
    display: flex;
    align-items: center;
}

.ai-keyword-scroll-container {
    display: flex;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    flex: 1;
    gap: 15px;
    padding: 8px 15px;
}

.ai-keyword-scroll-container::-webkit-scrollbar {
    display: none;
}

.ai-keyword-button {
    background: #f8f9fa;
    color: #495057;
    border: 2px solid transparent;
    border-radius: 25px;
    padding: 10px 20px;
    margin: 2px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.ai-keyword-button:hover {
    background: #1976D2;
    color: white;
    transform: scale(1.05);
    box-shadow: 0 3px 12px rgba(25, 118, 210, 0.4);
}

.ai-keyword-button:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
}

.ai-keyword-scroll-button {
    background: #e9ecef;
    color: #6c757d;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.ai-keyword-scroll-button:hover {
    background: #dee2e6;
    color: #495057;
}

/* 入力エリア */
.ai-chat-input-wrapper {
    padding: 20px;
    background: white;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: center;
}

.ai-chat-input {
    max-width: 600px;
    width: 100%;
    display: flex;
    align-items: center;
    background: #f8f9fa;
    border-radius: 30px;
    padding: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.ai-user-input {
    flex: 1;
    padding: 15px 20px;
    border: none;
    background: transparent;
    outline: none;
    font-size: 16px;
    color: #333;
}

.ai-user-input::placeholder {
    color: #adb5bd;
}

.ai-send-button {
    background: #1976D2;
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.ai-send-button:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 20px rgba(25, 118, 210, 0.4);
}

.ai-send-button:active {
    transform: scale(0.95);
}

.ai-send-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ウェルカムメッセージ */
.ai-welcome-container {
    text-align: center;
    padding: 40px;
    animation: fadeIn 1s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.ai-welcome-icon {
    font-size: 80px;
    color: #1976D2;
    margin-bottom: 20px;
}

.ai-welcome-title {
    font-size: 24px;
    color: #333;
    margin-bottom: 10px;
    font-weight: 600;
}

.ai-welcome-subtitle {
    font-size: 18px;
    color: #6c757d;
    line-height: 1.6;
}

/* ローディング */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    background: white;
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #1976D2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* タイピングインジケーター */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    flex-direction: row;
    gap: 4px;
    padding: 0;
    margin: 0;
    height: auto;
    line-height: 1;
    vertical-align: middle;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: #6c757d;
    border-radius: 50%;
    display: block;
    flex-shrink: 0;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0s;
}

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.8) translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.0) translateY(-10px);
        opacity: 1;
    }
}

/* タイピングインジケーター用のメッセージボックス */
.ai-typing-indicator-message {
    width: 60px !important;
    min-width: 60px !important;
    max-width: 60px !important;
    overflow: hidden;
}

/* タイピングインジケーターコンテナ */
#typingIndicator {
    transition: opacity 0.2s ease-out, height 0.2s ease-out, margin 0.2s ease-out, padding 0.2s ease-out;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* カスタムアイコン画像スタイル */
.ai-custom-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.ai-custom-welcome-img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
}

/* レスポンシブ対応 */
@media screen and (max-width: 768px) {
    .ai-chat-header {
        padding: 12px 15px;
    }

    .ai-header-content {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .ai-header-text {
        text-align: center;
    }

    .ai-chat-header h1 {
        font-size: 20px;
        margin-bottom: 3px;
    }

    .ai-chat-header p {
        font-size: 12px;
    }

    .ai-faq-toggle-button {
        padding: 12px 22px;
        font-size: 15px;
        gap: 8px;
    }

    .ai-faq-toggle-button i {
        font-size: 18px;
    }

    .ai-chat-box {
        padding: 20px 15px;
    }

    .ai-message {
        max-width: 85%;
        font-size: 15px;
    }

    .ai-keyword-container {
        padding: 15px 10px;
    }

    .ai-keyword-button {
        padding: 8px 16px;
        font-size: 13px;
    }

    .ai-welcome-title {
        font-size: 20px;
    }

    .ai-welcome-subtitle {
        font-size: 16px;
    }

    .ai-avatar {
        width: 35px;
        height: 35px;
        font-size: 18px;
    }

    .ai-chat-input-wrapper {
        padding: 15px;
    }

    .ai-user-input {
        font-size: 16px; /* iOS Safari zoom防止 */
    }
}

@media screen and (max-width: 480px) {
    .ai-chat-header {
        padding: 10px 12px;
    }

    .ai-chat-header h1 {
        font-size: 18px;
        margin-bottom: 2px;
    }

    .ai-chat-header p {
        font-size: 11px;
    }

    .ai-faq-toggle-button {
        padding: 11px 20px;
        font-size: 14px;
        gap: 7px;
    }

    .ai-faq-toggle-button i {
        font-size: 16px;
    }

    .ai-chat-box {
        padding: 15px 10px;
    }

    .ai-welcome-container {
        padding: 30px 20px;
    }

    .ai-welcome-icon {
        font-size: 60px;
    }

    .ai-welcome-title {
        font-size: 18px;
    }

    .ai-welcome-subtitle {
        font-size: 14px;
    }
}