/* ============================================
   Ensemo — 文字對話 modal + 草稿確認（M1）
   獨立檔，沿用 office.css 的設計 token（--office-*），不動主樣式表。
   ============================================ */

/* 桌位「文字對話」pill（與綠色語音 pill 區隔：暖色描邊） */
.desk-chat-pill {
    margin-top: 6px; display: inline-flex; align-items: center; gap: 6px;
    font-size: 12.5px; font-weight: 700; color: var(--office-text);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(245, 185, 113, 0.45);
    border-radius: 999px; padding: 7px 15px;
    cursor: pointer; transition: filter 0.15s ease, background 0.15s ease;
    font-family: inherit;
}
.desk-chat-pill:hover { background: rgba(245, 185, 113, 0.18); filter: brightness(1.05); }

/* overlay + card */
.chat-overlay {
    position: fixed; inset: 0; z-index: 320;
    background: rgba(8, 11, 22, 0.78);
    display: flex; align-items: center; justify-content: center; padding: 20px;
    backdrop-filter: blur(4px);
}
.chat-modal-card {
    width: 100%; max-width: 440px; height: min(620px, 88vh);
    display: flex; flex-direction: column;
    background: linear-gradient(180deg, #1d2540, #161d33);
    border: 1px solid var(--office-card-border);
    border-radius: 20px; overflow: hidden;
    --agent-color: var(--office-warm);
}

.chat-head {
    display: flex; align-items: center; gap: 12px;
    padding: 15px 18px; border-bottom: 1px solid var(--office-card-border);
}
.chat-avatar {
    position: relative; width: 42px; height: 42px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 15px; color: #fff; overflow: hidden;
    border: 2px solid var(--agent-color); flex-shrink: 0;
}
.chat-avatar-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.chat-head-text { flex: 1; min-width: 0; text-align: left; }
.chat-head-text h3 { font-size: 16px; font-weight: 800; }
.chat-subtitle { font-size: 12px; color: var(--office-text-dim); margin-top: 2px; }
.chat-close {
    background: none; border: none; color: var(--office-text-dim);
    font-size: 26px; line-height: 1; cursor: pointer; padding: 0 4px; font-family: inherit;
}
.chat-close:hover { color: var(--office-text); }

.chat-log {
    flex: 1; overflow-y: auto; padding: 16px 16px 8px;
    display: flex; flex-direction: column; gap: 10px;
}
.chat-system {
    align-self: center; text-align: center; max-width: 92%;
    font-size: 12px; color: var(--office-text-dim); line-height: 1.5; padding: 2px 4px;
}
.chat-bubble {
    max-width: 82%; padding: 9px 13px; border-radius: 14px;
    font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
.chat-user {
    align-self: flex-end; color: #06281a;
    background: linear-gradient(135deg, #f7c98b, #e8985a);
    border-bottom-right-radius: 4px;
}
.chat-agent {
    align-self: flex-start; color: var(--office-text);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--office-card-border);
    border-bottom-left-radius: 4px;
    white-space: normal;   /* 渲染後的 markdown 用區塊結構排版，不靠 pre-wrap */
}

/* 員工回覆的 markdown 元素（mdToHtml 產出） */
.chat-agent > div { margin: 3px 0; }
.chat-agent ol, .chat-agent ul { margin: 4px 0 4px 1.4em; padding: 0; }
.chat-agent li { margin: 2px 0; }
.chat-agent strong { font-weight: 800; }
.chat-agent code {
    background: rgba(255, 255, 255, 0.14); padding: 1px 5px;
    border-radius: 5px; font-size: 0.92em;
}
.chat-md-h { font-weight: 800; margin: 6px 0 2px; }
.chat-typing { opacity: 0.6; letter-spacing: 2px; }

/* 員工回覆裡的連結（web_search 來源等） */
.chat-agent a { color: var(--agent-color); text-decoration: underline; word-break: break-all; }
/* 產檔下載膠囊（python_exec 產出的 pdf/xlsx/...） */
.chat-agent a.chat-file {
    display: inline-flex; align-items: center; gap: 4px;
    margin: 3px 4px 3px 0; padding: 4px 11px;
    font-size: 12.5px; font-weight: 700; text-decoration: none; word-break: normal;
    color: var(--agent-color); background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--agent-color); border-radius: 999px;
}
.chat-agent a.chat-file:hover { filter: brightness(1.12); }

/* 「員工用了哪些真工具」徽章（資訊型：web_search / python_exec）— 緊貼回覆下方 */
.chat-tools {
    align-self: flex-start; display: flex; flex-wrap: wrap; gap: 6px;
    margin: -4px 0 0 2px;
}
.chat-tool-chip {
    font-size: 11px; font-weight: 700; line-height: 1.5;
    color: var(--agent-color);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--agent-color);
    border-radius: 999px; padding: 2px 9px; opacity: 0.92;
}

/* 草稿卡（agentic 提案 → owner 確認） */
.chat-draft-card {
    align-self: stretch;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(245, 185, 113, 0.4);
    border-radius: 14px; padding: 13px 14px; margin-top: 2px;
}
.chat-draft-head {
    font-size: 13px; font-weight: 800; color: var(--office-warm);
    display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.chat-draft-tag {
    font-size: 11px; font-weight: 700; color: #3a2410;
    background: var(--office-warm); border-radius: 999px; padding: 1px 9px;
}
.chat-draft-row { display: flex; gap: 8px; font-size: 13px; margin: 3px 0; }
.chat-draft-row span { color: var(--office-text-dim); min-width: 44px; flex-shrink: 0; }
.chat-draft-row b { color: var(--office-text); word-break: break-word; }
.chat-draft-body {
    margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--office-card-border);
    font-size: 13.5px; line-height: 1.6; color: var(--office-text);
    white-space: pre-wrap; word-break: break-word;
}
.chat-draft-actions { margin-top: 12px; }
.chat-confirm-btn {
    width: 100%; padding: 10px 0; font-size: 14px; font-weight: 800;
    border: none; border-radius: 10px; cursor: pointer; font-family: inherit;
    background: linear-gradient(135deg, #4ade80, #22c55e); color: #06281a;
    transition: filter 0.15s ease;
}
.chat-confirm-btn:hover { filter: brightness(1.08); }
.chat-confirm-btn:disabled { opacity: 0.7; cursor: wait; }
.chat-draft-note { font-size: 12.5px; color: var(--office-warm); line-height: 1.5; text-align: center; }

/* 輸入列 */
.chat-input-row {
    display: flex; gap: 8px; align-items: flex-end;
    padding: 12px 14px 14px; border-top: 1px solid var(--office-card-border);
}
.chat-input {
    flex: 1; resize: none; max-height: 120px;
    padding: 10px 13px; font-size: 14px; font-family: inherit; line-height: 1.5;
    border-radius: 12px; border: 1px solid var(--office-card-border);
    background: rgba(0, 0, 0, 0.25); color: var(--office-text); outline: none;
}
.chat-input:focus { border-color: var(--agent-color); }
.chat-send-btn {
    flex-shrink: 0; padding: 10px 18px; font-size: 14px; font-weight: 700;
    border: none; border-radius: 12px; cursor: pointer; font-family: inherit;
    background: linear-gradient(135deg, #f7c98b, #e8985a); color: #3a2410;
    transition: filter 0.15s ease;
}
.chat-send-btn:hover { filter: brightness(1.08); }
.chat-send-btn:disabled { opacity: 0.6; cursor: wait; }

@media (max-width: 520px) {
    .chat-modal-card { height: 92vh; max-width: 100%; }
}
