/* 主要樣式 */
body {
    font-family: 'Microsoft JhengHei', 'PingFang TC', sans-serif;
    background-color: #f8f9fa;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden; /* 防止水平滾動 */
}

.container-fluid {
    flex: 1;
}

/* 聊天容器樣式 */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 150px);
    background-color: #fff;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    margin: 20px 10px; /* 左右增加邊距 */
    overflow: hidden;
    max-width: 100%; /* 確保不會超出螢幕 */
}

/* 手機視圖下的標題調整 */
@media (max-width: 767.98px) {
    .h4-sm {
        font-size: 1.25rem; /* 手機上標題字體略小 */
    }
}

/* 手機視圖下的聊天容器調整 */
@media (max-width: 767.98px) {
    .chat-container {
        height: calc(100vh - 130px); /* 手機上高度略小 */
        margin: 10px 5px; /* 手機上邊距更小 */
        border-radius: 8px; /* 輕微調整圓角 */
    }
}

/* 聊天訊息區域樣式 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* 訊息樣式 */
.message {
    max-width: 80%;
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 10px;
    position: relative;
}

/* 手機視圖下的訊息調整 */
@media (max-width: 767.98px) {
    .message {
        max-width: 90%; /* 手機上訊息寬度略大 */
        padding: 8px 12px; /* 輕微減小內邊距 */
        margin-bottom: 10px; /* 輕微減小訊息間距 */
        font-size: 0.95rem; /* 字體略小 */
    }
}

.user-message {
    align-self: flex-end;
    background-color: #007bff;
    color: white;
    border-bottom-right-radius: 0;
}

.assistant-message {
    align-self: flex-start;
    background-color: #e9ecef;
    color: #212529;
    border-bottom-left-radius: 0;
}

.system-message {
    align-self: center;
    background-color: #f8f9fa;
    color: #6c757d;
    border: 1px solid #dee2e6;
    width: 90%;
    text-align: center;
}

/* 手機視圖下的系統訊息調整 */
@media (max-width: 767.98px) {
    .system-message {
        width: 95%; /* 手機上寬度略大 */
        font-size: 0.9rem; /* 字體略小 */
    }
}

.message-content {
    word-wrap: break-word;
}

.message-content p {
    margin-bottom: 0.5rem;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* 輸入區域樣式 */
.chat-input-container {
    padding: 15px;
    background-color: #f8f9fa;
    border-top: 1px solid #dee2e6;
    position: sticky;
    bottom: 0;
    z-index: 10; /* 確保輸入區域始終在最上層 */
}

/* 手機視圖下的輸入區域調整 */
@media (max-width: 767.98px) {
    .chat-input-container {
        padding: 10px; /* 減小內邊距 */
    }
    
    #user-input {
        font-size: 0.95rem; /* 輸入框字體略小 */
    }
    
    .chat-input-container .btn {
        padding: 0.25rem 0.5rem; /* 按鈕略小 */
    }
}

/* 打字指示器樣式 */
.typing-indicator {
    display: flex;
    padding: 10px;
    justify-content: flex-start;
    margin-top: 10px;
}

.typing-indicator span {
    height: 10px;
    width: 10px;
    margin: 0 2px;
    background-color: #9e9ea1;
    border-radius: 50%;
    display: inline-block;
    animation: bounce 1.5s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-5px);
    }
}

/* 代碼塊樣式 */
pre {
    background-color: #f8f9fa;
    border-radius: 5px;
    padding: 10px;
    overflow-x: auto;
    margin: 10px 0;
}

code {
    font-family: Consolas, Monaco, 'Andale Mono', monospace;
    font-size: 0.9em;
}

/* 響應式調整 */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 120px);
        margin: 10px 0;
    }
    
    .message {
        max-width: 90%;
    }
}

/* 回饋列 */
.feedback-bar {
    margin-top: 8px;
    padding: 6px 0;
    border-top: 1px solid rgba(0,0,0,0.08);
}

.feedback-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
}

.feedback-label {
    font-size: 0.8em;
    color: #6c757d;
    margin-right: 6px;
}

.btn-feedback {
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
    font-size: 0.85em;
    color: #6c757d;
    transition: all 0.15s;
}

.btn-feedback:hover {
    background-color: #f0f0f0;
    border-color: #dee2e6;
}

.btn-feedback-up:hover { color: #28a745; }
.btn-feedback-down:hover { color: #dc3545; }
.btn-feedback-detail:hover { color: #007bff; }

.feedback-detail {
    margin-top: 8px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px;
}

.feedback-type-label {
    font-size: 0.8em;
    color: #6c757d;
    margin-right: 8px;
}

.feedback-type-btn.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

.feedback-thanks {
    font-size: 0.85em;
    padding: 4px 0;
    color: #28a745;
}

/* 升級建議 */
.escalation-suggestion {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding: 10px 12px;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
}

.escalation-icon {
    color: #856404;
    font-size: 1.2em;
    flex-shrink: 0;
}

.escalation-text {
    font-size: 0.88em;
    color: #856404;
    flex: 1;
}

.escalation-btn {
    white-space: nowrap;
    flex-shrink: 0;
}

@media (max-width: 767.98px) {
    .escalation-suggestion {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
    .feedback-buttons {
        flex-wrap: wrap;
    }
}

/* ── FAQ 建議晶片 ── */
.faq-chips-container {
    padding: 8px 0 12px;
    border-bottom: 1px solid #eee;
    margin-bottom: 8px;
}

.faq-chips-label {
    font-size: 0.82em;
    color: #6c757d;
    margin-bottom: 6px;
}

.faq-chips-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.faq-chip {
    display: inline-block;
    padding: 5px 12px;
    background: #e9ecef;
    border: 1px solid #dee2e6;
    border-radius: 16px;
    font-size: 0.85em;
    color: #495057;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.faq-chip:hover {
    background: #007bff;
    color: #fff;
    border-color: #007bff;
}

.faq-chip:active {
    transform: scale(0.97);
}

.faq-chip-personal {
    background: #d1ecf1;
    border-color: #bee5eb;
    color: #0c5460;
}

.faq-chip-personal:hover {
    background: #17a2b8;
    color: #fff;
    border-color: #17a2b8;
}

/* ── 自動完成下拉選單 ── */
.autocomplete-wrapper {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    margin-bottom: 2px;
}

.autocomplete-item {
    padding: 8px 14px;
    font-size: 0.9em;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    color: #333;
    transition: background 0.1s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.active {
    background: #e9ecef;
}

.autocomplete-item mark {
    background: #fff3cd;
    padding: 0;
    border-radius: 2px;
}

/* ── 富訊息卡片 ── */
.rich-card {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 14px;
    margin: 8px 0;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.rich-card-title {
    font-weight: 600;
    font-size: 1em;
    color: #212529;
    margin-bottom: 6px;
}

.rich-card-description {
    font-size: 0.9em;
    color: #495057;
    margin-bottom: 10px;
}

.rich-card-action {
    display: inline-block;
    padding: 5px 14px;
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.15s;
}

.rich-card-action:hover {
    background: #0056b3;
}

.rich-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.rich-action-btn {
    padding: 5px 14px;
    background: #f8f9fa;
    border: 1px solid #007bff;
    color: #007bff;
    border-radius: 16px;
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.15s;
}

.rich-action-btn:hover {
    background: #007bff;
    color: #fff;
}

.rich-info-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    border-radius: 8px;
    margin: 8px 0;
    font-size: 0.9em;
    color: #0c5460;
}

.rich-info-alert i {
    margin-top: 2px;
    flex-shrink: 0;
}

/* ── 行動裝置優化 ── */
@media (max-width: 767.98px) {
    .faq-chips-container {
        padding: 6px 0 10px;
    }

    .faq-chip {
        font-size: 0.8em;
        padding: 6px 10px;
    }

    .autocomplete-dropdown {
        max-height: 160px;
    }

    .autocomplete-item {
        padding: 10px 14px;
        font-size: 0.88em;
    }

    .rich-card {
        padding: 12px;
    }

    .rich-action-btn {
        padding: 8px 14px;
        font-size: 0.82em;
    }

    #user-input {
        font-size: 16px !important; /* 防止 iOS 自動縮放 */
    }
}

/* 觸控裝置：更大的點擊目標 */
@media (pointer: coarse) {
    .faq-chip {
        padding: 8px 14px;
        min-height: 36px;
        line-height: 1.4;
    }

    .autocomplete-item {
        padding: 12px 14px;
        min-height: 44px;
    }

    .rich-action-btn {
        padding: 8px 16px;
        min-height: 36px;
    }

    .btn-feedback {
        padding: 6px 12px;
        min-height: 36px;
    }
}

/* 滾動條樣式 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
