:root {
  --blue: #0068ff; --blue-d: #0055d4; --blue-soft: #e5efff; --rail: #0068ff;
  --bg: #f4f5f7; --panel: #ffffff; --line: #e1e4ea; --text: #081c36; --muted: #7589a3;
  --chat-bg: #e9edf2; --out: #e5efff; --in: #ffffff; --phone: #f2f4f7; --bot: #e8f7ef;
  --hover: #f3f5f6; --active: #e5efff;
  --f0: #20b26b; --f1: #8cc63f; --f2: #e8b81e; --f3: #f39a1e; --f4: #ea5b2a; --f5: #d7263d;
  --radius: 10px; --shadow: 0 1px 2px rgba(8,28,54,.06), 0 4px 16px rgba(8,28,54,.07);
  font-family: Roboto, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text); font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101722; --panel: #19222f; --line: #2a3546; --text: #e6ebf2; --muted: #8b9bb2;
    --chat-bg: #0f151e; --out: #1c3a6b; --in: #222c3a; --phone: #273242; --bot: #163628;
    --hover: #212b39; --active: #1c3256; --blue-soft: #1c3256; --rail: #0a4fc4;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .sm { font-size: 12px; }
svg { width: 22px; height: 22px; flex-shrink: 0; }

/* ---------- nút ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 7px 14px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; font-weight: 500; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: var(--blue-d); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--f5); border-color: var(--f5); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon { border: 0; background: transparent; cursor: pointer; width: 36px; height: 36px; border-radius: 6px; display: inline-grid; place-items: center; color: var(--text); font-size: 20px; line-height: 1; flex-shrink: 0; }
.icon:hover { background: var(--hover); }
.icon.sm { width: 26px; height: 26px; font-size: 18px; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.logo.big { width: 72px; height: 72px; font-size: 36px; border-radius: 20px; margin: 0 auto 12px; }

/* ---------- đăng nhập ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #e8f3ff, var(--bg)); }
.login-card { width: min(380px, 100%); background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.brand b { font-size: 20px; display: block; } .brand small { color: var(--muted); }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 8px 10px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); }
.err { color: var(--f5); min-height: 1em; margin: 0; font-size: 13px; }
.fine { font-size: 12px; color: var(--muted); margin: 0; }

/* ---------- khung app ---------- */
.app { display: flex; height: 100dvh; }
/* App iPhone (Capacitor): chừa tai thỏ / thanh trạng thái */
.native .app { padding-top: env(safe-area-inset-top); }
.native .login { padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.rail { width: 64px; background: var(--rail); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 24px 0 12px; flex-shrink: 0; }
.me-avatar { width: 48px; height: 48px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); background: #fff; color: var(--blue); font-weight: 700; font-size: 16px; cursor: pointer; margin-bottom: 18px; }
.rail-btn { position: relative; width: 64px; height: 56px; border: 0; background: transparent; cursor: pointer; color: #fff; display: grid; place-items: center; }
.rail-btn svg { width: 26px; height: 26px; }
.rail-btn.active, .rail-btn:hover { background: rgba(0,0,0,.18); }
.rail-spacer { flex: 1; }
.badge { position: absolute; top: 8px; right: 10px; background: var(--f5); color: #fff; font-style: normal; font-size: 10px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; border: 2px solid var(--rail); }
.view { flex: 1; min-width: 0; }

/* ---------- cột danh sách ---------- */
.chat-view { display: flex; height: 100%; }
.threads { width: 344px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; flex-shrink: 0; }
.threads-head { padding: 16px 16px 0; display: grid; gap: 10px; }
.searchbox { display: flex; align-items: center; gap: 6px; background: var(--hover); border-radius: 6px; padding: 0 10px; color: var(--muted); }
.searchbox svg { width: 18px; height: 18px; }
.searchbox input { border: 0; background: transparent; flex: 1; padding: 8px 0; color: var(--text); }
.tabs-row { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 16px; }
.tab { border: 0; background: transparent; padding: 8px 0; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }
.classify { position: relative; }
.classify-btn { border: 0; background: transparent; display: flex; align-items: center; gap: 4px; cursor: pointer; color: var(--muted); font-size: 13px; padding: 6px 4px; border-radius: 6px; }
.classify-btn:hover { background: var(--hover); } .classify-btn svg { width: 16px; height: 16px; }
.classify-btn.on { color: var(--blue); font-weight: 600; }
.menu { position: absolute; right: 0; top: 34px; background: var(--panel); border-radius: 8px; box-shadow: var(--shadow); border: 1px solid var(--line); z-index: 30; min-width: 210px; padding: 6px 0; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 14px; cursor: pointer; }
.menu button:hover { background: var(--hover); }
.dotc { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding-bottom: 8px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--f3); }
.conn.ok .dot { background: var(--f0); } .conn.bad .dot { background: var(--f5); }
.thread-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.thread { display: flex; gap: 12px; padding: 12px 16px; cursor: pointer; align-items: center; position: relative; }
.thread:hover { background: var(--hover); }
.thread.active { background: var(--active); }
.thread.hot::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--f5); }
.avatar { width: 48px; height: 48px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; background-size: cover; background-position: center; font-size: 17px; position: relative; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.avatar.xl { width: 64px; height: 64px; font-size: 22px; }
.t-body { flex: 1; min-width: 0; }
.t-top { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.t-name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.t-bottom { display: flex; gap: 6px; align-items: center; margin-top: 3px; }
.t-prev { flex: 1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread.unread .t-name { font-weight: 700; } .thread.unread .t-prev { color: var(--text); font-weight: 600; } .thread.unread .t-time { color: var(--text); font-weight: 600; }
.t-meta { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.fpill { font-size: 10px; font-weight: 700; color: #fff; border-radius: 4px; padding: 1px 5px; line-height: 15px; }
.tag { font-size: 11px; background: var(--hover); color: var(--muted); border-radius: 4px; padding: 0 6px; line-height: 18px; white-space: nowrap; }
.unread-n { background: var(--f5); color: #fff; font-size: 11px; border-radius: 9px; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 5px; font-weight: 700; flex-shrink: 0; }

/* ---------- khung chat ---------- */
.conversation { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--chat-bg); }
.empty-state { margin: auto; text-align: center; color: var(--muted); padding: 24px; } .empty-state h3 { color: var(--text); margin: 0 0 8px; font-weight: 500; font-size: 20px; } .empty-state p { line-height: 1.6; }
.conv-head { display: flex; align-items: center; gap: 12px; padding: 0 12px 0 16px; height: 68px; background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0; }
.conv-title { flex: 1; min-width: 0; } .conv-title b { display: block; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-title small { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
#doneBtn.is-done { color: var(--f0); }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px 16px 8px; display: flex; flex-direction: column; }
.day-sep { align-self: center; font-size: 12px; color: #fff; background: rgba(8,28,54,.32); padding: 3px 12px; border-radius: 12px; margin: 14px 0 10px; }
.row { display: flex; gap: 8px; align-items: flex-end; margin-top: 2px; }
.row.out { justify-content: flex-end; }
.row.first { margin-top: 10px; }
.row .av-slot { width: 32px; flex-shrink: 0; align-self: flex-start; }
.msg { max-width: min(560px, 72%); padding: 9px 12px 7px; border-radius: 8px; background: var(--in); box-shadow: 0 1px 1px rgba(8,28,54,.08); word-wrap: break-word; position: relative; font-size: 15px; line-height: 1.4; border: 1px solid transparent; }
.row.out .msg { background: var(--out); border-color: #c7e0ff; }
@media (prefers-color-scheme: dark) { .row.out .msg { border-color: #27508f; } }
.row.out.phone .msg { background: var(--phone); border-color: var(--line); } .row.out.bot .msg { background: var(--bot); border-color: transparent; }
.msg .txt { white-space: pre-wrap; }
.msg .sender { font-size: 12px; color: var(--muted); margin-bottom: 2px; font-weight: 500; }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; align-items: center; }
.tone { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 8px; color: #fff; margin-right: 4px; }
.tone.t1 { background: var(--f2); } .tone.t2 { background: var(--f4); } .tone.t3 { background: var(--f5); }
.eff { font-weight: 700; } .eff.up { color: var(--f0); } .eff.down { color: var(--f5); }
.row.in.f3 .msg { border-left: 3px solid var(--f3); } .row.in.f4 .msg { border-left: 3px solid var(--f4); } .row.in.f5 .msg { border-left: 3px solid var(--f5); }
.msg.media { padding: 4px; } .msg.media .txt { padding: 4px 8px 0; } .msg.media .msg-meta, .msg.media .sender { padding: 0 8px 4px; }
.msg img.att { display: block; max-width: 260px; max-height: 320px; border-radius: 6px; cursor: zoom-in; background: var(--hover); }
.msg a.file { display: flex; gap: 8px; align-items: center; color: var(--blue); text-decoration: none; padding: 4px 0; }
.msg audio { max-width: 240px; }
.seen { align-self: flex-end; font-size: 11px; color: var(--muted); margin: 3px 2px 0; }

.suggest { margin: 0 16px 8px; background: var(--panel); border: 1px solid var(--blue); border-radius: 8px; padding: 10px 12px; box-shadow: var(--shadow); }
.suggest-head { display: flex; justify-content: space-between; align-items: center; color: var(--blue); font-weight: 600; font-size: 13px; }
.suggest-head span { display: flex; align-items: center; gap: 4px; } .suggest-head svg { width: 16px; height: 16px; } .suggest-head em { font-style: normal; }
.suggest p { margin: 6px 0 10px; white-space: pre-wrap; font-size: 14px; }
.suggest-actions { display: flex; gap: 8px; justify-content: flex-end; }

.composer { background: var(--panel); border-top: 1px solid var(--line); position: relative; flex-shrink: 0; }
.toolbar { display: flex; gap: 2px; padding: 4px 8px; border-bottom: 1px solid var(--line); }
.tool { border: 0; background: transparent; display: flex; align-items: center; gap: 5px; padding: 6px 8px; border-radius: 4px; cursor: pointer; color: var(--text); font-size: 13px; }
.tool:hover { background: var(--hover); } .tool svg { width: 20px; height: 20px; }
.input-row { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px 10px 16px; }
.input-row textarea { flex: 1; resize: none; max-height: 160px; border: 0; padding: 8px 0; font-size: 15px; background: transparent; line-height: 1.4; }
.send { width: 40px; height: 40px; border: 0; border-radius: 6px; background: transparent; color: var(--blue); cursor: pointer; display: grid; place-items: center; }
.send:hover { background: var(--blue-soft); } .send:disabled { color: var(--muted); }
.tpl-menu { position: absolute; bottom: calc(100% + 6px); left: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); width: min(460px, calc(100% - 24px)); max-height: 320px; overflow-y: auto; z-index: 20; }
.tpl-menu .tpl-head { padding: 10px 12px; font-weight: 600; border-bottom: 1px solid var(--line); font-size: 13px; }
.tpl-menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; cursor: pointer; font-size: 13px; }
.tpl-menu button:hover, .tpl-menu button.sel { background: var(--blue-soft); }
.tpl-menu b { color: var(--blue); margin-right: 6px; } .tpl-menu small { display: block; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- panel thông tin hội thoại ---------- */
.insight { width: 344px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; flex-shrink: 0; }
.insight-head { display: flex; justify-content: center; align-items: center; height: 68px; border-bottom: 1px solid var(--line); position: relative; font-size: 16px; }
.insight-head .icon { position: absolute; right: 8px; display: none; }
.profile { display: grid; justify-items: center; gap: 6px; padding: 18px 16px; border-bottom: 8px solid var(--bg); text-align: center; }
.profile b { font-size: 16px; }
.sec { border-bottom: 8px solid var(--bg); padding: 0 16px; }
.sec summary { list-style: none; cursor: pointer; padding: 14px 0; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sec summary::-webkit-details-marker { display: none; }
.sec summary::after { content: "▾"; color: var(--muted); font-size: 12px; }
.sec:not([open]) summary::after { content: "▸"; }
.sec summary .btn { margin-left: auto; }
.sec > :last-child { padding-bottom: 14px; }
.meter { height: 8px; border-radius: 4px; background: var(--hover); overflow: hidden; }
.meter-fill { height: 100%; width: 0; border-radius: 4px; transition: width .4s, background .4s; }
.meter-label { margin-top: 6px; font-size: 13px; } .meter-label #scoreNum { font-size: 22px; font-weight: 700; }
.spark { width: 100%; height: 40px; margin-top: 4px; }
.facts { margin: 10px 0 0; display: grid; gap: 2px; } .facts dt { font-size: 12px; color: var(--muted); margin-top: 8px; } .facts dd { margin: 0; }
.cust-form { display: grid; gap: 8px; }
.saved { color: var(--f0); font-size: 12px; }
.case { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; display: grid; gap: 6px; font-size: 13px; }
.case.closed { opacity: .6; }
.case-top { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.case select, .case input { padding: 5px 8px; font-size: 13px; width: 100%; }
.case .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.src { font-size: 10px; border-radius: 4px; padding: 1px 6px; background: var(--blue-soft); color: var(--blue); font-weight: 600; }

/* ---------- trang ---------- */
.page { overflow-y: auto; padding: 20px; height: 100%; }
.page h2 { margin: 0 0 6px; } .page-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; } .page-head h2 { flex: 1; margin: 0; }
.card { background: var(--panel); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; min-width: 0; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; } .grid2 .card { margin-bottom: 0; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.kpis6 { grid-template-columns: repeat(6, 1fr); }
.kpi { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi small { color: var(--muted); display: block; font-size: 12px; } .kpi b { font-size: 26px; }
.kpi.accent { background: var(--blue); color: #fff; } .kpi.accent small { color: rgba(255,255,255,.8); }
.kpi.danger b { color: var(--f5); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); } .tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; height: 100%; justify-content: flex-end; }
.bar { width: 100%; max-width: 34px; background: var(--blue); border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.bar .hotpart { position: absolute; bottom: 0; left: 0; right: 0; background: var(--f5); }
.bar-col small { font-size: 10px; color: var(--muted); } .bar-col .v { font-size: 10px; }
.card-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.card-list li { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; cursor: pointer; display: flex; gap: 12px; align-items: flex-start; }
.card-list li:hover { border-color: var(--blue); }
.card-list .big-score { font-size: 20px; font-weight: 800; width: 40px; height: 40px; border-radius: 8px; color: #fff; display: grid; place-items: center; flex-shrink: 0; }
.card-list p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.quote-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.quote-list li { border-left: 3px solid var(--line); padding: 4px 10px; } .quote-list small { color: var(--muted); display: block; margin-top: 2px; }
#bestList li, #dBest li { border-color: var(--f0); } #worstList li, #dWorst li { border-color: var(--f5); }
.warn { background: #fff4e0; color: #7a4b00; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
@media (prefers-color-scheme: dark) { .warn { background: #3a2b10; color: #f5d59a; } }
.modes { display: grid; gap: 10px; } .modes label { display: flex; gap: 8px; align-items: flex-start; color: var(--text); font-size: 14px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; } .inline-form input { flex: 1; min-width: 140px; }
.zalo-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.qr-box { display: grid; place-items: center; min-height: 230px; text-align: center; }
.qr-box img { width: 230px; height: 230px; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
.qr-steps { margin: 0; padding-left: 18px; font-size: 14px; display: grid; gap: 4px; }
.acc-pending td { background: color-mix(in srgb, var(--f2) 14%, transparent); }
.zalo-box img { width: 220px; height: 220px; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
.progress { height: 8px; background: var(--hover); border-radius: 4px; overflow: hidden; margin: 10px 0 6px; }
.progress > div { height: 100%; background: var(--blue); border-radius: 4px; transition: width .3s; }
.progress.indet > div { width: 30% !important; animation: indet 1.2s infinite ease-in-out; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.ai-card { border-top: 3px solid var(--blue); } .urgent-card { border-top: 3px solid var(--f5); }
.md h4 { margin: 14px 0 6px; font-size: 14px; color: var(--blue); } .md h4:first-child { margin-top: 0; }
.md ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; } .md p { margin: 6px 0; }
.wstats { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 12px; }
.wstats div small { display: block; color: var(--muted); font-size: 12px; } .wstats b { font-size: 22px; }
.grid2.inner { margin-bottom: 12px; } .grid2.inner h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.hbar { display: grid; grid-template-columns: 120px 1fr 28px; gap: 8px; align-items: center; font-size: 13px; margin-bottom: 6px; }
.hbar .track { background: var(--hover); border-radius: 4px; height: 10px; overflow: hidden; } .hbar .fill { background: var(--blue); height: 100%; border-radius: 4px; }
.hbar .n { text-align: right; font-variant-numeric: tabular-nums; }
.st { font-size: 11px; border-radius: 4px; padding: 2px 7px; font-weight: 600; white-space: nowrap; }

dialog { border: 0; border-radius: 12px; padding: 0; box-shadow: var(--shadow); background: var(--panel); color: var(--text); width: min(360px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(8,28,54,.45); }
.dlg { padding: 20px; display: grid; gap: 12px; } .dlg h3 { margin: 0; } .dlg-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.img-dlg { width: auto; max-width: 92vw; background: transparent; box-shadow: none; }
.img-dlg img { max-width: 92vw; max-height: 88vh; display: block; border-radius: 8px; }
.close-img { position: fixed; top: 12px; right: 12px; background: rgba(0,0,0,.5); color: #fff; }

.toasts { position: fixed; right: 16px; top: 16px; display: grid; gap: 8px; z-index: 100; width: min(360px, calc(100% - 32px)); }
.toast { background: var(--panel); border-left: 4px solid var(--f5); border-radius: 8px; padding: 12px 14px; box-shadow: var(--shadow); cursor: pointer; animation: pop .25s ease-out; }
.toast b { display: block; } .toast p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.toast.info { border-color: var(--blue); }
@keyframes pop { from { transform: translateY(-8px); opacity: 0; } }

/* ---------- màn hình vừa ---------- */
@media (max-width: 1180px) {
  .insight { position: absolute; right: 0; top: 0; bottom: 0; z-index: 25; box-shadow: var(--shadow); }
  .insight-head .icon { display: inline-grid; }
  .chat-view { position: relative; }
  .kpis6 { grid-template-columns: repeat(3, 1fr); }
}
/* ---------- điện thoại ---------- */
@media (max-width: 760px) {
  /* iPhone tự phóng to trang khi bấm vào ô nhập có chữ < 16px */
  input, select, textarea { font-size: 16px !important; }
  .app { flex-direction: column-reverse; }
  .rail { width: 100%; height: calc(56px + env(safe-area-inset-bottom)); flex-direction: row; justify-content: space-around; padding: 0 4px; padding-bottom: env(safe-area-inset-bottom); }
  .rail-spacer { display: none; }
  .me-avatar { width: 32px; height: 32px; margin: 0; font-size: 12px; order: 9; }
  .rail-btn { width: 52px; height: 56px; } .badge { top: 6px; right: 6px; }
  .view { height: calc(100dvh - 56px); }
  .threads { width: 100%; border-right: 0; }
  .chat-view.open .threads { display: none; }
  .chat-view:not(.open) .conversation { display: none; }
  .back { display: inline-grid; }
  .conv-head { padding-left: 4px; gap: 8px; } .conv-head .avatar { width: 40px; height: 40px; }
  .insight { width: 100%; }
  .msg { max-width: 82%; } .msg img.att { max-width: 200px; }
  .row .av-slot { width: 28px; } .avatar.sm { width: 28px; height: 28px; }
  .messages { padding: 10px 8px 6px; }
  .tool span { display: none; }
  .kpis, .kpis6 { grid-template-columns: repeat(2, 1fr); } .grid2 { grid-template-columns: 1fr; }
  .page { padding: 14px; }
  .page-head h2 { flex-basis: 100%; font-size: 20px; } .page-head input[type=date] { flex: 1; }
  .tbl { font-size: 12px; } .tbl th, .tbl td { padding: 6px 4px; }
  .hbar { grid-template-columns: 96px 1fr 24px; }
}
@media print {
  .rail, .page-head button, .page-head input, .toasts { display: none !important; }
  .app { height: auto; display: block; } .view { height: auto !important; overflow: visible !important; }
  .card, .kpi { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  body, .page { background: #fff; }
}
