/* Màn Hội thoại (đợt 8): 3 cột danh sách | thread | panel khách; modal mẫu câu, ảnh SP, hẹn, AI. Màu lấy từ biến của app.css. */

.conv-layout {
  display: grid; grid-template-columns: 320px minmax(0, 1fr) 320px; gap: 14px;
  height: calc(100vh - var(--bar-h) - 120px); min-height: 540px;
}
.conv-layout.no-active, .conv-layout.has-active:not(.has-panel) { grid-template-columns: 320px minmax(0, 1fr); }
.conv-list, .conv-thread, .conv-panel { min-height: 0; overflow: hidden; display: flex; flex-direction: column; }

/* ---------- Danh sách ---------- */
.conv-list-head { padding: 12px 12px 10px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.conv-scroll-x { overflow-x: auto; scrollbar-width: none; }
.conv-scroll-x .chips { flex-wrap: nowrap; }
.conv-scroll-x .chip, .conv-scroll-x .btn { white-space: nowrap; }
.conv-search { width: 100%; }
.conv-page-chip { display: inline-flex; align-items: center; gap: 4px; }
.conv-ai-tag { font-size: 10.5px; font-weight: 700; color: var(--violet); }
.conv-items { overflow-y: auto; flex: 1; }
.conv-item {
  display: flex; gap: 10px; width: 100%; text-align: left; padding: 10px 12px; background: none; cursor: pointer; color: inherit; font: inherit;
  border: 0; border-bottom: 1px solid var(--line); border-left: 3px solid var(--page-color, transparent);
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.is-active { background: var(--good-bg); }
.conv-item-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.conv-name { font-weight: 600; min-width: 0; }
.conv-item.is-unread .conv-name, .conv-item.is-unread .conv-snippet { font-weight: 700; color: var(--ink); }
.conv-snippet { font-size: 12.5px; color: var(--ink-2); display: block; }
.conv-tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; justify-content: flex-end; }
.conv-tag {
  display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; line-height: 1.5;
  padding: 0 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap;
}
.conv-tag.is-dashed { border-style: dashed; background: transparent; }
.conv-tag.is-red, .conv-tag.is-wait { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.conv-tag.is-amber { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.conv-tag.is-violet { background: var(--violet-bg); color: var(--violet); border-color: transparent; }

/* ---------- Thread ---------- */
.conv-thread-empty { justify-content: center; align-items: center; }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.thread-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.thread-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.thread-actions .is-on { background: var(--violet-bg); color: var(--violet); }
.conv-back, .conv-panel-btn, .conv-panel-close { display: none; }

.ai-card { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.ai-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ai-card-actions { display: flex; gap: 6px; flex-wrap: wrap; flex-shrink: 0; }
.ai-card.is-ai { background: var(--violet-bg); }
.ai-card.is-ai strong { color: var(--violet); }
.ai-card.is-danger { background: var(--danger-bg); }
.ai-card.is-danger strong { color: var(--danger); }
.ai-card.is-human { background: var(--info-bg); }
.ai-card.is-human strong { color: var(--info); }

.thread-assign { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.thread-assign .assign-select { width: auto; padding: 4px 8px; }
.thread-assign-end { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; }
.conv-reminder { color: var(--info); }

.thread-ai-log { padding: 10px 14px; border-bottom: 1px solid var(--line); max-height: 220px; overflow-y: auto; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.ai-runs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ai-run { display: flex; flex-direction: column; gap: 4px; }
.ai-run-text { font-size: 13px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 9px; }

.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column-reverse; background: var(--surface-2); }
.chat-scroll > .empty { margin: auto; }
.chat-messages { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; }
.chat-day { align-self: center; font-size: 11px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); padding: 2px 10px; border-radius: 99px; }
.bubble-row { display: flex; gap: 6px; align-items: flex-end; max-width: 78%; }
.bubble-row .avatar { width: 26px; height: 26px; font-size: 10px; flex-shrink: 0; }
.bubble-row.is-customer { align-self: flex-start; }
.bubble-row.is-ai, .bubble-row.is-staff { align-self: flex-end; }
.bubble-col { display: flex; flex-direction: column; min-width: 0; }
.is-ai .bubble-col, .is-staff .bubble-col { align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.is-customer .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.is-ai .bubble { background: var(--violet-bg); color: var(--ink); border-bottom-right-radius: 4px; }
.is-staff .bubble { background: var(--info-bg); color: var(--ink); border-bottom-right-radius: 4px; }
.bubble-meta { font-size: 11px; color: var(--muted); margin-top: 3px; padding: 0 4px; }
.msg-photos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg-photo { display: flex; flex-direction: column; gap: 1px; width: 112px; padding: 6px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); font-size: 12px; white-space: normal; }
.msg-photo-img { display: grid; place-items: center; height: 56px; border-radius: 6px; background: var(--surface-2); font-size: 22px; }

/* ---------- Khối soạn ---------- */
.composer { border-top: 1px solid var(--line); padding: 8px 12px 10px; display: flex; flex-direction: column; gap: 6px; }
.composer-tools .chips { gap: 6px; align-items: center; }
.chip-sm { padding: 3px 9px; font-size: 12px; }
.ai-suggest { color: var(--violet); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-input { position: relative; flex: 1; min-width: 0; }
.composer-input textarea { width: 100%; min-height: 44px; max-height: 140px; }
.composer-note { margin: 0; }
.conv-warn { color: var(--danger); }
.composer-photos { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.photo-chip { display: inline-flex; align-items: center; gap: 4px; max-width: 200px; padding: 2px 4px 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-size: 12px; }
.photo-chip .icon-btn { width: 22px; height: 22px; font-size: 11px; }
.slash-pop {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 5; max-height: 240px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.slash-item { display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
.slash-item.is-active, .slash-item:hover { background: var(--surface-2); }

/* ---------- Panel khách ---------- */
.conv-panel { padding: 14px; gap: 12px; overflow-y: auto; position: relative; }
.panel-who { display: flex; gap: 10px; align-items: center; }
.panel-who .badge { margin-right: 4px; }
.panel-facts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.panel-block { padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.panel-block summary { cursor: pointer; font-weight: 600; }
.panel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.panel-list li { display: flex; flex-direction: column; gap: 2px; }
.panel-list .btn { align-self: flex-start; }
.panel-order { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; color: inherit; text-decoration: none; }
.panel-order:hover strong { text-decoration: underline; }
.panel-notes { background: var(--surface); }
.panel-note-form { display: flex; flex-direction: column; gap: 6px; }
.panel-note-form .chips { gap: 4px; }
.panel-note-form .chip { padding: 3px 8px; font-size: 12px; }
.panel-note-form textarea { min-height: 54px; }

/* ---------- Modal ---------- */
.conv-settings { gap: 16px; }
.conv-check { align-items: flex-start; gap: 10px; }
.conv-check > span { display: flex; flex-direction: column; gap: 2px; }
.conv-check.is-disabled { opacity: 0.6; }
.conv-keys kbd { font-family: inherit; font-size: 12px; padding: 1px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-2); }
.tpl-list { display: flex; flex-direction: column; gap: 6px; }
.tpl-pick { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: inherit; font: inherit; cursor: pointer; }
.tpl-pick:hover { border-color: var(--ink-2); }
.tpl-rows { display: flex; flex-direction: column; gap: 10px; }
.tpl-row { display: grid; grid-template-columns: 180px minmax(0, 1fr) auto; gap: 8px; align-items: start; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; max-height: 50vh; overflow-y: auto; }
.photo-pick { display: flex; flex-direction: column; gap: 3px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; position: relative; }
.photo-pick input { position: absolute; top: 8px; right: 8px; }
.photo-pick:has(input:checked) { border-color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent-strong); }
.photo-pick-img { display: grid; place-items: center; height: 64px; border-radius: 6px; background: var(--surface-2); font-size: 24px; }
.reminder-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.reminder-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; height: auto; padding: 10px 12px; }
.lesson-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow-y: auto; }
.lesson-card { display: flex; flex-direction: column; gap: 5px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); }

/* ---------- Màn vừa: panel khách thành lớp phủ ---------- */
@media (max-width: 1200px) {
  .conv-layout, .conv-layout.has-panel { grid-template-columns: 300px minmax(0, 1fr); }
  .conv-panel-btn, .conv-panel-close { display: inline-flex; }
  .conv-panel-close { position: absolute; top: 10px; right: 10px; }
  .conv-panel { display: none; }
  .conv-panel.is-open {
    display: flex; position: fixed; top: calc(var(--bar-h) + 12px); right: 12px; bottom: 12px; width: min(360px, calc(100vw - 24px)); z-index: 40;
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.22);
  }
}

/* ---------- Điện thoại: 1 cột ---------- */
@media (max-width: 860px) {
  .conv-layout, .conv-layout.no-active, .conv-layout.has-panel { grid-template-columns: minmax(0, 1fr); height: calc(100vh - var(--bar-h) - 170px); min-height: 440px; }
  .conv-layout.has-active .conv-list { display: none; }
  .conv-layout.no-active .conv-thread { display: none; }
  .conv-back { display: inline-grid; }
  .thread-head { flex-wrap: wrap; }
  .thread-actions { width: 100%; justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; }
  .thread-actions .btn { white-space: nowrap; padding: 5px 8px; }
  .ai-card { flex-wrap: wrap; padding: 8px 12px; }
  .ai-card-text .small { display: none; }
  .bubble-row { max-width: 90%; }
  .thread-assign-end { margin-left: 0; }
  .tpl-row { grid-template-columns: minmax(0, 1fr); }
  .reminder-grid { grid-template-columns: minmax(0, 1fr); }
  .conv-panel.is-open { top: 0; right: 0; bottom: 0; width: 100%; border-radius: 0; }
}
