/* Quaf Chat — màu lấy từ 3 màu logo Quaf (cam / xanh ngọc / vàng) */
:root {
  --orange: #f95a1e;
  --orange-dark: #d6430c;
  --orange-soft: #ffe9df;
  --cyan: #68d0e3;
  --cyan-dark: #1d7f92;
  --cyan-soft: #e3f6fa;
  --yellow: #f5e215;
  --yellow-soft: #fdf8cf;
  --ink: #1f2328;
  --muted: #5f6770;
  --line: #e6e8eb;
  --bg: #f6f7f8;
  --white: #fff;
  --danger: #c62828;
  --radius: 12px;
  --tap: 44px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sub { color: var(--muted); font-size: 13px; }

.app { height: 100dvh; display: flex; overflow: hidden; }
.pane { min-width: 0; background: var(--white); }

/* ---------- di động: mỗi lúc một cột ---------- */
.list-pane { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
.thread-pane { display: none; flex: 1; flex-direction: column; }
.app.show-thread .list-pane { display: none; }
.app.show-thread .thread-pane { display: flex; }
.info-pane { position: fixed; inset: 0; z-index: 20; overflow-y: auto; }

.topbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; background: var(--orange-dark); color: var(--white);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.logo {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: var(--yellow); color: var(--orange-dark); font-weight: 800;
}
.icon-btn {
  min-width: var(--tap); min-height: var(--tap); padding: 0 8px;
  border: 0; background: transparent; border-radius: 10px; font-size: 20px; line-height: 1;
  display: inline-grid; place-items: center; flex: none;
}
.icon-btn:hover { background: rgb(0 0 0 / 6%); }
.topbar .icon-btn:hover { background: rgb(255 255 255 / 15%); }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 1px; }

.filters { padding: 10px 12px 6px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); background: var(--white); }
.search {
  width: 100%; min-height: var(--tap); padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding: 4px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--white); white-space: nowrap;
}
.chip b { font-weight: 700; color: var(--orange-dark); }
.chip b:empty { display: none; }
.chip.active { background: var(--orange-dark); border-color: var(--orange-dark); color: var(--white); }
.chip.active b { color: var(--yellow); }
.selects { display: flex; flex-wrap: wrap; gap: 6px; }
.selects label { flex: 1 1 128px; }
.selects select, .field select, .field input, .stack input, .inline input, .inline select, textarea {
  width: 100%; min-height: 40px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--white);
}

.conv-list { list-style: none; margin: 0; padding: 0; }
.conv {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 4px 10px; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.conv:hover { background: var(--bg); }
.conv.active { background: var(--cyan-soft); }
.conv .avatar { grid-row: span 2; }
.conv .top, .conv .bottom { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.conv.unread .name, .conv.unread .text { font-weight: 700; color: var(--ink); }
.conv .text { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.conv .time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.conv .meta { grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.badge {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--orange); color: var(--white); font-size: 12px; font-weight: 700; display: inline-grid; place-items: center;
}
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; background: var(--bg); color: var(--muted); white-space: nowrap;
}
.pill.page { background: var(--cyan-soft); color: var(--cyan-dark); }
.pill.wait { background: var(--orange-soft); color: var(--orange-dark); font-weight: 600; }
.tag-orange { background: var(--orange-soft); color: var(--orange-dark); }
.tag-cyan { background: var(--cyan-soft); color: var(--cyan-dark); }
.tag-yellow { background: var(--yellow-soft); color: #6b5f00; }
.tag-gray { background: #eceef0; color: #4a525a; }

.window { font-size: 12px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; background: var(--cyan-soft); color: var(--cyan-dark); }
.window.warn { background: var(--yellow-soft); color: #6b5f00; }
.window.urgent { background: var(--orange-soft); color: var(--orange-dark); font-weight: 600; }
.window.closed { background: #eceef0; color: #4a525a; }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; overflow: hidden; flex: none;
  display: grid; place-items: center; font-weight: 700; color: var(--white); background: var(--cyan-dark);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.c1 { background: var(--orange-dark); }
.avatar.c2 { background: var(--cyan-dark); }
.avatar.c3 { background: #8a7a00; }
.avatar.c0 { background: #5f6770; }

.more { margin: 12px; min-height: var(--tap); border: 1px dashed var(--line); background: var(--white); border-radius: var(--radius); }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* ---------- khung chat ---------- */
.thread-empty { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
.thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.thread-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--white);
}
.thread-head .avatar { width: 38px; height: 38px; }
.thread-head .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.thread-head .who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-head .who .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-head .who .window { align-self: flex-start; margin-top: 2px; }
.back { font-size: 30px; }
.messages { flex: 1; overflow-y: auto; padding: 12px; background: var(--bg); display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--white); padding: 2px 10px; border-radius: 999px; margin: 6px 0; }
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 2px; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble {
  padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--white); border: 1px solid var(--line);
}
.msg.out .bubble { background: var(--orange-soft); border-color: #ffd3c0; }
.msg.out.page .bubble { background: var(--cyan-soft); border-color: #c4ebf3; }
.msg.failed .bubble { border-color: var(--danger); }
.bubble img { display: block; max-width: min(240px, 100%); max-height: 320px; border-radius: 10px; }
.bubble a { color: var(--cyan-dark); }
.msg .info { font-size: 11px; color: var(--muted); }
.msg .err { font-size: 12px; color: var(--danger); }
.expired { font-size: 13px; color: var(--muted); font-style: italic; }

.quick-panel {
  max-height: 40vh; overflow-y: auto; border-top: 1px solid var(--line); background: var(--white);
  display: flex; flex-direction: column; gap: 6px; padding: 8px;
}
.quick-panel button {
  text-align: left; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); min-height: var(--tap);
  flex: none;
}
.quick-panel button strong { display: block; color: var(--orange-dark); }
.quick-panel button span { color: var(--muted); font-size: 13px; }

.composer { border-top: 1px solid var(--line); background: var(--white); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
.compose-row { display: flex; align-items: flex-end; gap: 4px; }
.compose-row textarea { flex: 1; min-width: 0; resize: none; max-height: 160px; border-radius: 20px; padding: 10px 14px; }
.file-btn { cursor: pointer; }
.send {
  min-height: var(--tap); padding: 0 16px; border: 0; border-radius: 22px; flex: none;
  background: var(--orange-dark); color: var(--white); font-weight: 700; white-space: nowrap;
}
.send:disabled { background: #b9bec4; cursor: not-allowed; }
.closed-note { font-size: 13px; padding: 6px 8px; margin-bottom: 6px; border-radius: 8px; background: #eceef0; color: #4a525a; }
.attach-preview { display: flex; align-items: center; gap: 10px; padding: 4px 4px 8px; }
.attach-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.text-btn { border: 0; background: none; color: var(--danger); min-height: var(--tap); padding: 0 8px; }

/* ---------- thông tin khách ---------- */
.info-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 16px; border-bottom: 1px solid var(--line); background: var(--white); }
.info-body { padding: 12px 16px 24px; display: grid; gap: 16px; }
.field { display: grid; gap: 6px; font-weight: 600; }
.field .sub { font-weight: 400; }
.tag-toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-toggles button {
  min-height: 36px; padding: 4px 12px; border-radius: 999px; border: 2px solid transparent; font-weight: 600; white-space: nowrap;
}
.tag-toggles button[aria-pressed="false"] { opacity: .55; border-color: var(--line); background: var(--white); color: var(--muted); }
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-weight: 400; }
.notes li { background: var(--yellow-soft); border-radius: 8px; padding: 6px 10px; white-space: pre-wrap; }
.notes .sub { display: block; }
.btn {
  min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid var(--orange-dark);
  background: var(--white); color: var(--orange-dark); font-weight: 600; white-space: nowrap; justify-self: start;
}
.btn.primary { background: var(--orange-dark); color: var(--white); }
.link { color: var(--cyan-dark); font-weight: 600; min-height: var(--tap); display: inline-flex; align-items: center; }

/* ---------- cài đặt ---------- */
.sheet {
  width: min(560px, 100vw); max-width: 100vw; max-height: 100dvh; padding: 0; border: 0; border-radius: var(--radius);
}
.sheet::backdrop { background: rgb(0 0 0 / 40%); }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 16px; border-bottom: 1px solid var(--line); background: var(--white); margin: 0; }
.sheet-body { padding: 8px 16px 24px; }
.sheet-body h3 { margin: 20px 0 8px; font-size: 15px; color: var(--orange-dark); }
.rows { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.rows li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; flex-wrap: wrap; }
.rows li .grow { flex: 1 1 160px; min-width: 0; overflow-wrap: anywhere; }
.rows li .ok { color: var(--cyan-dark); }
.rows li .bad { color: var(--danger); }
.stack { display: grid; gap: 6px; }
.inline { display: flex; flex-wrap: wrap; gap: 6px; }
.inline input { flex: 1 1 140px; width: auto; }
.inline select { flex: 0 1 110px; width: auto; }
.switch { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); white-space: nowrap; }
.switch input { width: 20px; height: 20px; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--white); padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 24px);
}
.toast.bad { background: var(--danger); }

/* ---------- máy tính: 2 cột, rộng hơn thì 3 cột ---------- */
@media (min-width: 900px) {
  .list-pane { flex: 0 0 380px; display: flex !important; border-right: 1px solid var(--line); }
  .thread-pane { display: flex !important; }
  .back { display: none; }
}
@media (min-width: 1280px) {
  .info-pane { position: static; flex: 0 0 320px; border-left: 1px solid var(--line); }
  #btn-info-close { display: none; }
}
@media (min-width: 600px) {
  .sheet { margin-top: 5vh; max-height: 90dvh; }
}
@media (max-width: 599px) {
  .sheet { margin: 0; width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
}
