.nav-badge {
    display: inline-block;
    min-width: 18px;
    padding: 1px 6px;
    margin-left: 6px;
    border-radius: 999px;
    background: #ef4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

.messages-page {
    display: flex;
    height: calc(100vh - 140px);
    min-height: 420px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .05);
    overflow: hidden;
}

.messages-list-pane {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #eee;
}

.messages-list-header {
    padding: 16px;
    border-bottom: 1px solid #eee;
}

.messages-list-header h1 {
    margin: 0 0 10px;
    font-size: 20px;
}

.messages-search {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
}

.messages-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.messages-filter {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    font-size: 12px;
    color: #6b7280;
}

.messages-filter select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 13px;
    background: white;
    box-sizing: border-box;
}

#clearFilters {
    margin-top: 8px;
    padding: 0;
    font-size: 13px;
}

.messages-item-top strong {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.messages-list {
    flex: 1;
    overflow-y: auto;
}

.messages-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-bottom: 1px solid #f3f4f6;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.messages-item:hover { background: #f9fafb; }
.messages-item.active { background: #eff6ff; }

.messages-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.messages-avatar-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e5e7eb;
    color: #4b5563;
    font-weight: 700;
}

.messages-item-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.messages-item-top,
.messages-item-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.messages-item-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.messages-item-time {
    color: #9ca3af;
    font-size: 12px;
    flex-shrink: 0;
}

.messages-item-preview {
    color: #6b7280;
    font-size: 13px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.messages-unread {
    flex-shrink: 0;
    min-width: 18px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #ef4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}

.messages-thread {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.messages-thread-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid #eee;
}

.messages-thread-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.messages-thread-title .muted { color: #6b7280; font-size: 13px; }

.messages-bubbles {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f9fafb;
}

.message-row {
    display: flex;
    flex-direction: column;
    max-width: 70%;
}

.message-row.in { align-self: flex-start; align-items: flex-start; }
.message-row.out { align-self: flex-end; align-items: flex-end; }

.message-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    background: white;
    border: 1px solid #e5e7eb;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-row.out .message-bubble {
    background: var(--primary-color, #2563eb);
    border-color: transparent;
    color: white;
}

.message-time {
    margin-top: 3px;
    color: #9ca3af;
    font-size: 11px;
}

.messages-composer {
    padding: 12px 20px;
    border-top: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.messages-composer-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.messages-composer textarea {
    flex: 1;
    min-height: 40px;
    max-height: 140px;
    resize: vertical;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font: inherit;
}

.messages-composer-hint {
    color: #6b7280;
    font-size: 12px;
}

.messages-composer-warn {
    color: #92400e;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
}

.messages-composer-error {
    color: #b91c1c;
    font-size: 13px;
}

/* A reply on its way to the customer */
.message-row.pending .message-bubble { opacity: .6; }

.message-row.pending .message-time { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }

.send-spinner {
    display: inline-block;
    width: 11px;
    height: 11px;
    margin-right: 5px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -1px;
    animation: send-spin .7s linear infinite;
}

@keyframes send-spin { to { transform: rotate(360deg); } }

.messages-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px 20px;
    color: #6b7280;
    text-align: center;
    line-height: 1.6;
}

.messages-thread > .messages-empty { flex: 1; }

.channel-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
    vertical-align: middle;
    color: white;
}

.stage-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #4b5563;
    font-size: 10px;
    font-weight: 600;
    vertical-align: middle;
}

.stage-badge i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.channel-badge-line { background: #06c755; }
.channel-badge-messenger { background: #0084ff; }
.channel-badge-instagram { background: #d6249f; }

/* 手機版才會用到的按鈕：電腦版不顯示（樣式在 css/mobile.css） */
.messages-back-btn,
.messages-filters-toggle {
    display: none;
}

/* =========================================================
   四欄版面：分類 ｜ 對話列表 ｜ 聊天 ｜ 客戶資料
   （最左邊的功能選單是整個系統共用的側邊欄）
========================================================= */

.messages-category-pane {
    width: 200px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 10px;
    border-right: 1px solid #eee;
    background: #fafafa;
    overflow-y: auto;
}

.messages-category-pane h1 {
    margin: 0 0 10px 6px;
    font-size: 20px;
}

.messages-category-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 12px;
}

.messages-category-title {
    margin: 4px 0 2px 10px;
    color: #9ca3af;
    font-size: 12px;
    font-weight: 600;
}

.messages-category {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #374151;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.messages-category:hover { background: #f3f4f6; }

.messages-category.active {
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 600;
}

.messages-category-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.messages-category-count {
    flex-shrink: 0;
    color: #9ca3af;
    font-size: 12px;
    font-weight: 400;
}

/* 管道小圖示 */
.channel-icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.channel-icon svg {
    width: 100%;
    height: 100%;
}

.channel-icon-inline {
    width: 16px;
    height: 16px;
    margin-left: 6px;
    vertical-align: middle;
}

/* 列表裡的頭像：右下角疊上管道圖示 */
.messages-avatar-wrap {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

.avatar-channel-icon {
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px white;
}

.messages-item.active .avatar-channel-icon { box-shadow: 0 0 0 2px #eff6ff; }

/* 灰色的帳號標籤 */
.account-tag {
    display: inline-block;
    max-width: 150px;
    margin-left: 6px;
    padding: 1px 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 11px;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.messages-item-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.messages-item-meta .account-tag,
.messages-item-meta .stage-badge {
    margin-left: 0;
}

/* 指派與狀態：列表上的「負責：小美」、「已結束」小標籤 */
.assignee-tag,
.status-tag {
    display: inline-block;
    max-width: 150px;
    padding: 1px 8px;
    overflow: hidden;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.assignee-tag { background: #eff6ff; color: #1d4ed8; }

.status-tag { background: #e5e7eb; color: #4b5563; }

/* 聊天標題列下方：負責人下拉選單、結束／重新開啟對話 */
.messages-thread-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 8px 20px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
    font-size: 13px;
}

.messages-assign {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    color: #6b7280;
}

.messages-assign select {
    width: auto;
    min-width: 140px;
    max-width: 220px;
    margin: 0;
    padding: 4px 8px;
}

.messages-thread-toolbar button {
    margin: 0;
    padding: 4px 12px;
}

.messages-thread-toolbar .messages-composer-error { margin: 0; }

/* 處理時間（「共處理 8 天」「已處理 3 小時」） */
.handling-time {
    color: #6b7280;
    font-size: 12px;
    white-space: nowrap;
}

/* 「歷史」視窗：誰在什麼時間做了什麼，新的在上面 */
.modal-content:has(.history-modal) {
    width: min(520px, 94vw);
}

.history-modal h2 { margin: 0 0 4px; }

.history-summary {
    margin: 0 0 12px;
    color: #6b7280;
    font-size: 13px;
}

.history-list {
    max-height: 55vh;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
}

.history-list li {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 14px;
}

.history-list time {
    flex: 0 0 96px;
    color: #6b7280;
    font-size: 12px;
    line-height: 1.7;
}

.history-list span { min-width: 0; overflow-wrap: anywhere; }

.history-modal .modal-footer { margin-top: 16px; }

/* 右邊的客戶資料面板：寬螢幕預設打開，其餘由聊天標題列的「客戶資料」按鈕切換 */
.messages-customer-pane {
    display: none;
    width: 280px;
    flex-shrink: 0;
    overflow-y: auto;
    border-left: 1px solid #eee;
    background: #fff;
}

.messages-page.panel-open .messages-customer-pane { display: block; }

.messages-panel-toggle[aria-expanded="true"] {
    background: #eff6ff;
    color: #1d4ed8;
}

.customer-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px 16px 14px;
    border-bottom: 1px solid #f3f4f6;
    text-align: center;
}

.customer-card .messages-avatar {
    width: 64px;
    height: 64px;
    font-size: 24px;
}

.customer-card-channel {
    display: inline-flex;
    align-items: center;
    color: #6b7280;
    font-size: 13px;
}

.customer-card-channel .channel-icon-inline { margin: 0 6px 0 0; }

.customer-section {
    padding: 14px 16px;
    border-bottom: 1px solid #f3f4f6;
}

.customer-section h3 {
    margin: 0 0 8px;
    color: #6b7280;
    font-size: 12px;
    font-weight: 600;
}

.customer-info-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
    font-size: 13px;
}

.customer-info-row span { flex-shrink: 0; color: #9ca3af; }

.customer-info-row strong {
    min-width: 0;
    font-weight: 500;
    text-align: right;
    word-break: break-all;
}

.customer-info-row .stage-badge { margin-left: 0; }

.customer-note {
    margin: 0;
    color: #9ca3af;
    font-size: 13px;
    line-height: 1.6;
}

.customer-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.customer-channel {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
}

.customer-channel-name {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.customer-channel-name small {
    overflow: hidden;
    color: #9ca3af;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.customer-channel-warn {
    flex-shrink: 0;
    color: #92400e;
    font-size: 11px;
}

@media (max-width: 1100px) {
    .messages-category-pane { width: 160px; }
    .messages-list-pane { width: 280px; }
}

/* 回覆框上方的「快速回覆」按鈕與挑選清單 */
.messages-composer-tools {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
}

.messages-composer-tools button {
    margin: 0;
    padding: 4px 12px;
    font-size: 13px;
}

.quick-reply-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .08);
}

.quick-reply-panel.hidden { display: none; }

.quick-reply-search {
    width: 100%;
    margin: 0;
    padding: 7px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font: inherit;
    box-sizing: border-box;
}

.quick-reply-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
}

.quick-reply-option {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: #f9fafb;
    color: #111827;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.quick-reply-option:hover,
.quick-reply-option:focus-visible {
    border-color: #bfdbfe;
    background: #eff6ff;
}

.quick-reply-option span {
    color: #6b7280;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.quick-reply-empty {
    padding: 10px 4px;
    color: #6b7280;
    font-size: 13px;
    line-height: 1.6;
}

/* 設定 → 客戶 CRM → 快速回覆 */
.quick-replies-config h3 { margin: 18px 0 8px; font-size: 15px; }

.quick-reply-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 640px;
}

.quick-reply-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    font-size: 13px;
    color: #374151;
}

.quick-reply-field input,
.quick-reply-field textarea {
    width: 100%;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font: inherit;
    box-sizing: border-box;
}

.quick-reply-field textarea { resize: vertical; }

.quick-reply-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-reply-actions button { margin: 0; }

.quick-reply-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 640px;
}

.quick-reply-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
}

.quick-reply-item.editing { display: block; }

.quick-reply-text { min-width: 0; flex: 1; }

.quick-reply-text p {
    margin: 4px 0 0;
    color: #4b5563;
    font-size: 13px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.quick-reply-error { color: #b91c1c; }

/* 客戶資料面板：備註與自訂屬性可以直接編輯 */
.customer-edit-title {
    display: block;
    margin: 0 0 8px;
    color: #6b7280;
    font-size: 12px;
    font-weight: 600;
}

.customer-edit-input,
.customer-edit-field input,
.customer-edit-field select {
    width: 100%;
    margin: 0;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font: inherit;
    font-size: 13px;
    box-sizing: border-box;
}

.customer-edit-input { resize: vertical; }

.customer-edit-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin: 0 0 10px;
}

.customer-edit-label {
    color: #6b7280;
    font-size: 12px;
}

.customer-edit-label small {
    margin-left: 6px;
    color: #9ca3af;
}

.customer-edit-image {
    max-width: 100%;
    max-height: 120px;
    border-radius: 6px;
    object-fit: contain;
    align-self: flex-start;
}

.customer-edit-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.customer-edit-actions button {
    margin: 0;
    padding: 4px 12px;
    font-size: 13px;
}

.customer-edit-status {
    color: #6b7280;
    font-size: 12px;
}

.customer-edit-status.error { color: #b91c1c; }

/* 批次處理：勾選多個對話，一次指派、結束或重新開啟 */
.messages-bulk-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
    font-size: 13px;
}

.messages-bulk-bar.hidden { display: none; }

.messages-bulk-toggle {
    margin: 10px 0 0;
    padding: 4px 12px;
    font-size: 13px;
}

.bulk-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.bulk-all,
.bulk-assignee {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    color: #374151;
}

.bulk-assignee { flex: 1; min-width: 160px; }

.bulk-assignee select {
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 4px 8px;
}

.bulk-all input,
.bulk-count { margin: 0; }

.bulk-count { color: #6b7280; }

.messages-bulk-bar button {
    margin: 0;
    padding: 4px 12px;
    font-size: 13px;
}

.messages-bulk-bar .field-hint { margin: 0; font-size: 12px; }

.bulk-status {
    min-height: 1.2em;
    color: #374151;
    font-size: 12px;
    line-height: 1.5;
}

.bulk-status.error { color: #b91c1c; }

.messages-item-row {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #f3f4f6;
}

.messages-item-row.checked { background: #eff6ff; }

.messages-item-row .messages-item {
    flex: 1;
    min-width: 0;
    border-bottom: none;
}

.messages-select {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin: 0 0 0 14px;
}

/* 釘選的對話：名字旁的圖釘 */
.pin-mark {
    margin-left: 2px;
    font-size: 12px;
    vertical-align: baseline;
}

/* 客戶資料面板：「不接收群發」開關 */
.customer-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 6px;
    font-size: 13px;
    color: #374151;
}

.customer-check input {
    width: 18px;
    height: 18px;
    margin: 0;
    flex-shrink: 0;
}

/* 協作多人服務：列表上的「協助：小美」小標籤、工具列的「協助同事」 */
.collab-tag {
    display: inline-block;
    max-width: 150px;
    padding: 1px 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #f0fdf4;
    color: #15803d;
    font-size: 11px;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.messages-collab {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    color: #6b7280;
}

.collab-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px 2px 10px;
    border-radius: 999px;
    background: #f0fdf4;
    color: #15803d;
    font-size: 12px;
}

.messages-thread-toolbar .collab-remove {
    min-width: 0;
    padding: 0 6px;
    border: 0;
    background: transparent;
    color: #15803d;
    font-size: 12px;
    line-height: 20px;
    cursor: pointer;
}

.messages-collab select {
    width: auto;
    max-width: 180px;
    margin: 0;
    padding: 3px 8px;
}

/* 設定 → 客戶 CRM → 自動指派 */
.auto-assign-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 640px;
}

.auto-assign-switch,
.auto-assign-person {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 14px;
    color: #374151;
}

.auto-assign-switch input,
.auto-assign-person input { width: auto; margin: 0; }

.auto-assign-form select {
    width: 100%;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font: inherit;
    box-sizing: border-box;
}

.auto-assign-people {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.auto-assign-people legend { padding: 0 6px; font-size: 13px; color: #6b7280; }

/* 設定 → 客戶 CRM → 自動回覆 */
.auto-reply-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 640px;
}

.auto-reply-form select,
.auto-reply-form textarea {
    width: 100%;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font: inherit;
    box-sizing: border-box;
}

.auto-reply-form textarea { resize: vertical; }

.auto-reply-day {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
}

.auto-reply-day .auto-assign-person { min-width: 120px; }

.auto-reply-time {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 13px;
    color: #374151;
}

.auto-reply-time input {
    width: auto;
    margin: 0;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font: inherit;
}

/* 對話內部備註：送出區的切換、對話裡的備註卡片 */
.composer-modes {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.composer-mode {
    margin: 0;
    padding: 4px 12px;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    background: #fff;
    color: #374151;
    font-size: 13px;
    cursor: pointer;
}

.composer-mode[aria-pressed="true"] {
    border-color: #d97706;
    background: #fef3c7;
    color: #92400e;
    font-weight: 600;
}

.composer-modes .composer-mode:first-child[aria-pressed="true"] {
    border-color: #2563eb;
    background: #eff6ff;
    color: #1d4ed8;
}

.messages-composer.note-mode #replyText {
    background: #fffbeb;
    border-color: #fcd34d;
}

.note-row {
    display: flex;
    justify-content: center;
    margin: 8px 0;
}

.note-card {
    width: 92%;
    max-width: 560px;
    box-sizing: border-box;
    padding: 8px 12px;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    background: #fffbeb;
    color: #78350f;
    font-size: 13px;
}

.note-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-bottom: 4px;
    font-size: 12px;
}

.note-label {
    padding: 1px 8px;
    border-radius: 999px;
    background: #fde68a;
    color: #92400e;
    font-weight: 600;
}

.note-meta { color: #92400e; }

.note-delete {
    margin: 0 0 0 auto;
    padding: 2px 8px;
    font-size: 12px;
}

.note-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.5;
}

/* 設定 → 客戶 CRM → 關鍵字回覆 */
.keyword-replies-config select {
    width: 100%;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font: inherit;
    box-sizing: border-box;
}

.keyword-order { color: #6b7280; font-weight: 400; }

.keyword-match-tag,
.keyword-off-tag {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 8px;
    border-radius: 999px;
    background: #e0e7ff;
    color: #3730a3;
    font-size: 12px;
}

.keyword-off-tag { background: #f3f4f6; color: #6b7280; }

.keyword-rule.inactive { opacity: 0.7; }

.keyword-active {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0;
    font-size: 13px;
}

.keyword-active input { width: auto; margin: 0; }

/* 設定 → 客戶 CRM → 資料收集 */
.intake-forms-config select {
    width: 100%;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font: inherit;
    box-sizing: border-box;
}

.intake-notice {
    margin: 0 0 12px;
    padding: 8px 12px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #eff6ff;
    color: #1e3a8a;
}

.intake-questions {
    margin: 0;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.intake-questions legend { padding: 0 6px; font-size: 13px; color: #6b7280; }

.intake-field-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0 0 10px;
    padding: 0;
    list-style: none;
}

.intake-field-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
}

.intake-field-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 12px;
}

.intake-field-tools { display: inline-flex; gap: 6px; }

.intake-field-tools button { margin: 0; padding: 2px 10px; }

.intake-add {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
}

.intake-add .quick-reply-field { flex: 1; min-width: 200px; }

.intake-add button { margin: 0; }

.intake-empty { margin: 0 0 10px; color: #6b7280; font-size: 13px; }

.intake-form-item.inactive { opacity: 0.7; }

.intake-keywords { margin: 6px 0 0; }

.intake-keyword {
    display: inline-block;
    margin: 0 4px 0 0;
    padding: 1px 8px;
    border-radius: 999px;
    background: #ecfdf5;
    color: #065f46;
    font-size: 12px;
}

.intake-summary {
    margin: 6px 0 0;
    padding-left: 20px;
    color: #4b5563;
    font-size: 13px;
}

.intake-field-tag {
    display: inline-block;
    margin-left: 4px;
    padding: 0 6px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 11px;
}

.intake-field-tag.required { background: #fee2e2; color: #b91c1c; }

/* 內部備註：編輯、已編輯標記、@提及 */
.note-actions {
    display: inline-flex;
    gap: 4px;
    margin-left: auto;
}

.note-actions .note-delete { margin: 0; }

.note-edit-start {
    margin: 0;
    padding: 2px 8px;
    font-size: 12px;
}

.note-edited {
    color: #a16207;
    font-size: 12px;
    cursor: help;
}

.note-mention-me {
    padding: 1px 8px;
    border-radius: 999px;
    background: #fecaca;
    color: #991b1b;
    font-size: 12px;
    font-weight: 600;
}

.note-card.mentions-me {
    border-color: #f87171;
    box-shadow: 0 0 0 2px #fee2e2;
}

.note-mentions {
    margin-bottom: 4px;
    color: #92400e;
    font-size: 12px;
}

.note-edit-text {
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 6px 8px;
    border: 1px solid #fcd34d;
    border-radius: 6px;
    background: #fff;
    font: inherit;
    resize: vertical;
}

.note-edit-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.note-edit-actions button {
    margin: 0;
    padding: 3px 12px;
    font-size: 13px;
}

.composer-mention { margin-bottom: 4px; }

.mention-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 6px;
    padding: 8px;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    background: #fffbeb;
}

.mention-option {
    margin: 0;
    padding: 3px 12px;
    border: 1px solid #fcd34d;
    border-radius: 999px;
    background: #fff;
    color: #92400e;
    font-size: 13px;
    cursor: pointer;
}

.mention-empty { color: #92400e; font-size: 13px; }

.mention-tag {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    background: #fee2e2;
    color: #991b1b;
    font-size: 12px;
    font-weight: 600;
}


/* 訊息裡的圖片與檔案（客戶傳來的、同事傳出的） */
.message-image-link { display: block; line-height: 0; }

.message-image {
    display: block;
    max-width: 240px;
    max-height: 320px;
    min-width: 80px;
    min-height: 60px;
    border-radius: 8px;
    background: #e5e7eb;
    object-fit: contain;
    cursor: zoom-in;
}

/* 貼圖：比照片小；貼圖本來就是透明背景，不加灰底，只有貼圖的訊息泡泡也不留白框 */
.message-image.message-sticker {
    max-width: 150px;
    max-height: 150px;
    min-width: 0;
    min-height: 0;
    background: transparent;
}

.message-bubble:has(.message-sticker) {
    padding: 0;
    background: transparent;
    border-color: transparent;
}

.message-caption { margin-top: 6px; }

.message-file {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
    word-break: break-all;
}

.message-file small { font-weight: 400; opacity: .75; }

/* 回覆框：要傳的圖片預覽 */
.composer-image-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
}

.composer-image-preview img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.composer-image-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    font-size: 13px;
    overflow-wrap: anywhere;
}

.composer-image-info small { color: #6b7280; font-size: 12px; }

.composer-image-preview button { margin: 0; padding: 4px 12px; font-size: 13px; flex-shrink: 0; }
