/**
 * チャットボット CSS
 * LINE風のレスポンシブデザイン
 */

/* リセット */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    /* 高さ指定なし - ラッパーとしてのみ機能 */
}

/* チャットコンテナ - 高さはCSS変数で管理（JSで設定） */
.chat-container {
    max-width: 1000px;
    margin: 0 auto;
    height: var(--app-height, 100dvh); /* CSS変数優先、フォールバック100dvh */
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* ヘッダー */
.chat-header {
    background: #1D9E75;
    color: white;
    padding: 12px 18px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px)); /* Dynamic Island対応 */
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.bot-circle {
    width: 36px; height: 36px; border-radius: 50%;
    background: #fff;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

/* ─── クイック返信バー（ヘッダー直下・常時表示） ──────────────── */
.chips-bar {
    padding: 10px 16px;
    border-bottom: 1px solid #e0ede8;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
    background: #fff;
}

.chip {
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 20px;
    background: #F4F7FA;
    border: 0.5px solid #C8DED8;
    color: #374151;
    cursor: pointer;
    transition: all .12s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.chip:hover { background: #E1F5EE; border-color: #5DCAA5; color: #085041; }
.chip:active { background: #C8EDE0; }
.chip:disabled { opacity: 0.45; cursor: not-allowed; }

.header-info { flex: 1; margin-left: 10px; }
.header-title { font-size: 14px; font-weight: 600; }
.header-sub { font-size: 11px; opacity: 0.85; margin-top: 2px; }

.live-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #fff; opacity: 0.9; flex-shrink: 0; margin-right: 8px;
    animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot { 0%,100%{opacity:.9} 50%{opacity:.35} }

.reset-btn {
    display: inline-flex; align-items: center; gap: 5px;
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 5px 11px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 11px;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.reset-btn:hover {
    background-color: rgba(255, 255, 255, 0.35);
}

/* アバター */
.av {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 600;
    align-self: flex-end; margin-bottom: 2px;
}
.av.bot  { background: #E1F5EE; color: #0F6E56; }
.av.user { background: #EEEDFE; color: #3C3489; }

/* メッセージエリア */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: #f9f9f9;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.5) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.5) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* メッセージ */
.message {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin-bottom: 16px;
    animation: slideIn 0.3s ease-out;
}

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

/* ユーザーメッセージ: アバターを右端に */
.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content {
    background: #1D9E75;
    color: white;
    border-radius: 18px 18px 4px 18px;
    max-width: 60%;
}

/* ボットメッセージ */
.bot-message {
    flex-wrap: wrap;
}

.bot-message .message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 72%;
}

.bot-message .message-content {
    background-color: white;
    color: #333;
    border-radius: 4px 18px 18px 18px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* メッセージ内容 */
.message-content {
    padding: 12px 16px;
    word-wrap: break-word;
    line-height: 1.6;
    font-family: inherit;
}

.message-content p {
    margin: 0;
    white-space: pre-wrap;
}

/* メッセージ内のリンク */
.message-content .chat-link {
    color: #2196f3;
    text-decoration: underline;
    transition: color 0.2s;
    word-break: break-all;
}

.message-content .chat-link:hover {
    color: #1976d2;
    text-decoration: underline;
}

/* ユーザーメッセージ内のリンク（白背景用） */
.user-message .message-content .chat-link {
    color: #ffffff;
    text-decoration: underline;
}

.user-message .message-content .chat-link:hover {
    color: #e3f2fd;
}

/* メッセージ時刻 */
.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    padding: 0 5px;
}

.user-message .message-time {
    text-align: right;
}

.bot-message .message-time {
    text-align: left;
}

/* ローディング */
.loading {
    display: flex;
    justify-content: flex-start;
    padding: 0 20px;
    margin-bottom: 10px;
}

.loading-dots {
    background-color: white;
    padding: 12px 16px;
    border-radius: 18px 18px 18px 4px;
    display: flex;
    gap: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #999;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* 入力エリア */
.chat-input-container {
    background-color: white;
    border-top: 1px solid #e0e0e0;
    padding: 15px;
    padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px)); /* ホームインジケーター対応 */
    flex-shrink: 0;
}

.chat-input-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    overflow-y: hidden;
    transition: border-color 0.3s;
}

.chat-input:focus {
    outline: none;
    border-color: #1D9E75;
}

.send-btn {
    background: #1D9E75;
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    background: #0F6E56;
    box-shadow: 0 4px 8px rgba(29, 158, 117, 0.3);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* スクロールバー */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* フィードバックボタン */
.feedback-buttons {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    padding: 0 5px;
    justify-content: flex-end;
}

.feedback-btn {
    background: none;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.feedback-btn:hover {
    background-color: #f5f5f5;
    transform: scale(1.05);
}

.feedback-btn.active-like {
    background-color: #e3f2fd;
    border-color: #2196f3;
    color: #2196f3;
}

.feedback-btn.active-dislike {
    background-color: #ffebee;
    border-color: #f44336;
    color: #f44336;
}

.feedback-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* レスポンシブ対応 */
@media (max-width: 768px) {
    .chat-container {
        max-width: 100%;
        border-radius: 0;
    }

    .chat-header h1 {
        font-size: 16px;
    }

    .reset-btn {
        font-size: 11px;
        padding: 5px 10px;
    }

    .chat-messages {
        padding: 15px 10px;
    }

    .user-message .message-content {
        max-width: 75%;
    }
    .bot-message .message-wrapper {
        max-width: 80%;
    }

    .message-content {
        padding: 10px 14px;
        font-size: 14px;
    }

    .chat-input-container {
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .chat-input {
        font-size: 16px; /* iOSでズームを防ぐため */
        padding: 8px 14px;
    }

    .send-btn {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 480px) {
    .user-message .message-content,
    .bot-message .message-wrapper {
        max-width: 90%;
    }
}

/* クイック返信ボタン */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding: 0 8px;
}

/* 関連質問ボタン（回答の下・アバター分インデント） */
.related-questions {
    width: 100%;
    margin-top: 8px;
    padding-top: 8px;
    padding-left: 36px; /* アバター幅 + gap */
    border-top: 1px solid #e0e0e0;
}

.quick-reply-btn {
    background-color: #ffffff;
    border: 2px solid #1D9E75;
    color: #1D9E75;
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: normal;
    text-align: left;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* hover対応デバイス（マウス）のみhoverスタイル適用 */
@media (hover: hover) {
    .quick-reply-btn:hover {
        background-color: #1D9E75;
        color: #ffffff;
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(29, 158, 117, 0.3);
    }
}

.quick-reply-btn:active {
    background-color: #1D9E75;
    color: #ffffff;
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.quick-reply-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: #f5f5f5;
    border-color: #ccc;
    color: #999;
}

.quick-reply-btn:disabled:hover {
    transform: none;
    background-color: #f5f5f5;
    color: #999;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.quick-reply-btn .icon {
    font-size: 16px;
}

/* クイック返信ボタンの非表示アニメーション */
.quick-replies.hidden {
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: opacity 0.3s ease, max-height 0.3s ease;
    margin-top: 0;
}

/* モバイル対応 */
@media (max-width: 600px) {
    .quick-reply-btn {
        font-size: 13px;
        padding: 8px 14px;
    }
}

/* ─── 製品カード ─────────────────────────────────────────── */
.product-card {
    background: #f8f9ff;
    border: 1px solid #d0d7ff;
    border-left: 4px solid #667eea;
    border-radius: 10px;
    padding: 12px 14px;
    margin: 8px 0;
    font-size: 14px;
}

.product-card-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 8px;
}

.product-maker {
    font-size: 12px;
    color: #0F6E56;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.product-model {
    font-size: 15px;
    font-weight: 700;
    color: #333;
}

.product-card-specs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.spec-pill {
    background: #E1F5EE;
    color: #4a5568;
    border-radius: 20px;
    padding: 2px 10px;
    font-size: 12px;
    white-space: nowrap;
}

.spec-pill.spec-price {
    background: #fff3cd;
    color: #856404;
    font-weight: 600;
}

.product-card-feature {
    font-size: 13px;
    color: #555;
    margin-bottom: 8px;
    line-height: 1.5;
}

.card-detail-link {
    display: inline-block;
    font-size: 13px;
    color: #0F6E56;
    text-decoration: none;
    font-weight: 600;
    border: 0.5px solid #A7D9CC;
    border-radius: 12px;
    padding: 2px 10px;
    margin-top: 4px;
}
.card-detail-link:hover {
    background: #E1F5EE;
}

.card-detail-link:hover {
    text-decoration: underline;
}

/* ─── エスカレーション ─────────────────────────────────────── */
.escalate-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 0.5px solid #1D9E75;
    border-radius: 20px;
    padding: 8px 16px;
    margin: 8px 0;
    font-size: 13px;
    font-weight: 500;
    color: #0F6E56;
    cursor: pointer;
    transition: background .12s;
}

.escalate-btn:hover { background: #E1F5EE; }
.escalate-icon {
    font-size: 16px;
    flex-shrink: 0;
}

/* ─── 警告バナー ────────────────────────────────────────── */
.warn-banner {
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-left: 4px solid #ffc107;
    border-radius: 8px;
    padding: 8px 14px;
    margin: 8px 0;
    font-size: 13px;
    color: #5d4037;
}

/* ─── 比較テーブル ──────────────────────────────────────── */
.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin: 8px 0;
    border-radius: 8px;
    overflow: hidden;
}

.compare-table th {
    background: #1D9E75;
    color: #fff;
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
}

.compare-table td {
    padding: 7px 10px;
    border-bottom: 1px solid #e2e8f0;
    color: #444;
}

.compare-table tr:last-child td {
    border-bottom: none;
}

.compare-table tr:nth-child(even) td {
    background: #F4F7FA;
}

/* 免責表示バー */
.notice-bar {
    text-align: center;
    font-size: 11px;
    color: #9CA3AF;
    padding: 5px 14px;
    border-top: 0.5px solid #DDE3E8;
    flex-shrink: 0;
}

/* メッセージ内のリスト */
.message-content ul {
    padding-left: 20px;
    margin: 4px 0;
}

.message-content li {
    margin: 2px 0;
    line-height: 1.5;
}
