/* Fusin CRM — giao diện nhân viên */
:root {
  /* Bảng màu lấy từ mặt tiền Fusin Việt Nam: tường trắng, chữ vàng đồng hắt sáng, ánh đèn ấm, khung cửa đồng, bồn cây xanh */
  --nen: #f3f6fc; --mat: #ffffff; --vien: #dde5f2; --chu: #1b2540; --mo: #6b7791; --nhat: #f8faff;
  --chinh: #1e56c8; --chinh-dam: #153f9a; --chinh-nhat: #eaf1ff; --vang: #e056a8;
  --xanh: #3f6b3a; --cam: #a8691a; --do: #b93a2e; --lam: #2563eb;
  --bong: 0 1px 2px rgba(20, 45, 100, .05), 0 6px 20px rgba(20, 45, 100, .06);
  --r: 10px;
  --chu-bien: "Be Vietnam Pro", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--chu); background: var(--nen); }
a { color: var(--chinh); text-decoration: none; }
h1 { font-family: var(--chu-bien); font-size: 27px; font-weight: 600; margin: 0; letter-spacing: .01em; line-height: 1.2; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 12px; margin: 16px 0 6px; color: var(--mo); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--vien); border-radius: 8px; background: var(--mat); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--chinh); box-shadow: 0 0 0 3px var(--chinh-nhat); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 12px; color: var(--mo); margin: 10px 0 4px; }
.nut { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--vien); background: var(--mat); cursor: pointer; white-space: nowrap; font-weight: 500; }
.nut:hover { border-color: #c3cde0; background: var(--nhat); }
.nut.chinh { background: var(--chinh); border-color: var(--chinh); color: #fff; }
.nut.chinh:hover { background: var(--chinh-dam); }
.nut.nho { padding: 4px 10px; font-size: 13px; }
.nut.do { color: var(--do); }
.nut:disabled { opacity: .5; cursor: default; }

/* Khung 5 vùng: thanh biểu tượng · cột danh sách · tabs + nội dung · cột phải · thanh đáy */
.app { display: grid; grid-template-columns: 64px 280px minmax(0, 1fr) 320px; grid-template-rows: minmax(0, 1fr) 30px; height: 100vh; background: var(--nen); }
.app.khong-rb { grid-template-columns: 64px 280px minmax(0, 1fr); }
.app.khong-rb .rb { display: none; }
.rail { grid-row: 1; background: var(--mat); border-right: 1px solid var(--vien); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 4px; overflow-y: auto; }
.rail .logo { font-family: var(--chu-bien); font-weight: 600; font-size: 22px; letter-spacing: .04em; color: var(--chinh); text-shadow: 0 0 12px rgba(224, 86, 168, .6); width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--vang); border-radius: 50%; margin-bottom: 10px; flex: none; }
.rail a { position: relative; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; color: #5b6781; flex: none; }
.rail a em { display: none; font-style: normal; }
.rail a:hover { background: var(--nhat); color: var(--chinh); }
.rail a.on { background: var(--chinh-nhat); color: var(--chinh-dam); box-shadow: inset 3px 0 0 var(--vang); }
.rail a .so { position: absolute; top: 2px; right: 0; background: var(--chinh); color: #fff; border-radius: 99px; font-size: 10px; font-weight: 700; padding: 0 5px; min-width: 16px; text-align: center; line-height: 16px; }
.rail .nguoi { margin-top: auto; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--vang); background: var(--chinh-nhat); color: var(--chinh-dam); font-weight: 700; cursor: pointer; flex: none; }
.rail .nguoi:hover { background: var(--vang); color: #fff; }
.sb { background: var(--mat); border-right: 1px solid var(--vien); display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow-y: auto; }
.sb-dau { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 14px 8px; }
.sb-dau h2 { font-family: var(--chu-bien); font-size: 22px; font-weight: 600; margin: 0; }
.sb-loc { padding: 4px 12px 10px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.sb-loc .o2 { grid-template-columns: minmax(0, 1fr); gap: 8px; }
.sb-loc input, .sb-loc select { min-width: 0; }
.sb-nhom { font-size: 11px; color: var(--mo); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; padding: 10px 14px 4px; }
.sb-ghi { font-size: 12px; color: var(--mo); padding: 12px 14px; }
.muc-sb { display: flex; align-items: center; gap: 9px; padding: 8px 14px; color: var(--chu); cursor: pointer; border-left: 3px solid transparent; }
.muc-sb:hover { background: var(--nhat); }
.muc-sb.on { background: var(--chinh-nhat); color: var(--chinh-dam); font-weight: 600; border-left-color: var(--vang); }
.muc-sb i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.muc-sb span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muc-sb b { font-weight: 600; color: var(--mo); font-size: 12px; font-variant-numeric: tabular-nums; }
.nut-loc { display: flex; gap: 4px; }
.nut-loc button { flex: 1; padding: 5px 2px; border: 1px solid var(--vien); background: var(--mat); border-radius: 7px; cursor: pointer; font-size: 12px; white-space: nowrap; }
.nut-loc button.on { background: var(--chinh); color: #fff; border-color: var(--chinh); }
.giua { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs-tren { display: flex; background: var(--mat); border-bottom: 1px solid var(--vien); min-height: 46px; overflow-x: auto; flex: none; }
.tabs-tren button { flex: 1 1 0; max-width: 240px; min-width: max-content; padding: 0 16px; border: 0; border-right: 1px solid var(--vien); border-bottom: 2px solid transparent; background: none; cursor: pointer; color: var(--mo); white-space: nowrap; }
.tabs-tren button:hover { background: var(--nhat); color: var(--chu); }
.tabs-tren button.on { background: var(--chinh-nhat); color: var(--chinh-dam); font-weight: 600; border-bottom-color: var(--vang); }
main { flex: 1; overflow-y: auto; min-width: 0; min-height: 0; }
main.day { display: flex; flex-direction: column; overflow: hidden; }
.rb { background: var(--mat); border-left: 1px solid var(--vien); overflow-y: auto; min-height: 0; min-width: 0; padding: 14px; }
.rb-khoi { margin-bottom: 18px; }
.rb-khoi h3 { margin-top: 0; }
.rb .ten-lon { font-family: var(--chu-bien); font-size: 22px; font-weight: 600; line-height: 1.2; }
.bb { grid-column: 1 / -1; background: var(--mat); border-top: 1px solid var(--vien); display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 14px; font-size: 12px; color: var(--mo); white-space: nowrap; overflow: hidden; }
.bb b { color: var(--chinh); letter-spacing: .16em; font-family: var(--chu-bien); font-size: 14px; }
.bb #bb-phai { display: flex; gap: 16px; }
.bb a { color: var(--mo); } .bb a:hover { color: var(--chinh); }
.chi-dt { display: none; }
.trang { padding: 18px 20px 40px; }
.dau { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.dau .gian { flex: 1; }
.loc { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.loc > * { width: auto; }
.loc input[type=search] { min-width: 220px; }
.the { background: var(--mat); border: 1px solid var(--vien); border-radius: var(--r); padding: 16px; box-shadow: var(--bong); }
.luoi { display: grid; gap: 14px; }
.hai { grid-template-columns: 1fr 1fr; }
.o2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.o3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.mo { color: var(--mo); }
.nho-chu { font-size: 12px; }
.phai { text-align: right; }
.trong { padding: 40px 16px; text-align: center; color: var(--mo); }

/* Bảng */
.bang-cuon { overflow-x: auto; background: var(--mat); border: 1px solid var(--vien); border-radius: var(--r); box-shadow: var(--bong); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--mo); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--vien); background: var(--nhat); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid #edf1f7; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.bam { cursor: pointer; }
tr.bam:hover td { background: var(--nhat); }
td.so, th.so { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Nhãn */
.nhan { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 500; background: #e9eef7; color: #4a556b; white-space: nowrap; }
.nhan.xanh { background: #e6efe2; color: #33592f; } .nhan.vang { background: #fbefd6; color: #8a5a10; } .nhan.do { background: #fbe6e2; color: #96291f; }
.nhan.lam { background: #e5edff; color: #1e46b5; } .nhan.tim { background: #f0e8fd; color: #5b2bb0; } .nhan.hong { background: var(--chinh-nhat); color: var(--chinh-dam); }
.kenh { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 6px; font-size: 10px; font-weight: 700; color: #fff; flex: none; }
.kenh.fb { background: #1877f2; } .kenh.zalo_oa { background: #0068ff; } .kenh.zalo_cn { background: #00a2ff; } .kenh.web { background: #0f8a5f; } .kenh.form { background: #b7791f; }

/* Hộp chat */
.c-list { overflow-y: auto; flex: 1; }
.c-dong { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid #edf1f7; cursor: pointer; }
.c-dong:hover { background: var(--nhat); }
.c-dong.on { background: var(--chinh-nhat); }
.c-dong .giua-dong { flex: 1; min-width: 0; }
.c-dong .ten { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.c-dong .ten span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-dong .tin { color: var(--mo); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-dong.moi .tin { color: var(--chu); font-weight: 600; }
.c-dong .phai { font-size: 11px; color: var(--mo); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.cham { background: var(--chinh); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 0 6px; }
.c-giua { background: var(--nen); flex: 1; min-height: 0; display: flex; flex-direction: column; }
.c-dau { padding: 10px 16px; background: var(--mat); border-bottom: 1px solid var(--vien); display: flex; align-items: center; gap: 10px; }
.c-dau .ten { font-weight: 600; }
.c-than { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.bong { max-width: 72%; padding: 8px 12px; border-radius: 14px; background: var(--mat); border: 1px solid var(--vien); white-space: pre-wrap; word-break: break-word; align-self: flex-start; }
.bong.me { align-self: flex-end; background: var(--chinh); color: #fff; border-color: var(--chinh); }
.bong.sys { align-self: center; background: #fdf3dc; border-color: #f1dfb2; color: #5c4310; font-size: 13px; max-width: 86%; }
.bong .gio { display: block; font-size: 10px; opacity: .65; margin-top: 3px; }
.bong .loi { display: block; font-size: 11px; background: #fff; color: var(--do); border-radius: 6px; padding: 2px 6px; margin-top: 4px; }
.bong img { max-width: 240px; border-radius: 8px; display: block; margin-top: 4px; }
.bong a { color: inherit; text-decoration: underline; }
.c-nhap { padding: 10px 12px; background: var(--mat); border-top: 1px solid var(--vien); display: flex; gap: 8px; align-items: flex-end; }
.c-nhap textarea { min-height: 42px; max-height: 140px; resize: none; }
.c-nhap-khung { position: relative; }
.c-nhap .c-cong-cu { padding: 8px 10px; font-size: 16px; line-height: 1; }
.tn-hop { position: absolute; left: 12px; right: 12px; bottom: 100%; max-height: 260px; overflow-y: auto; background: var(--mat); border: 1px solid var(--vien); border-radius: 10px; box-shadow: var(--bong); z-index: 5; }
.tn-dong { display: flex; gap: 10px; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--vien); font-size: 13px; }
.tn-dong:last-child { border-bottom: 0; }
.tn-dong b { color: var(--chinh); white-space: nowrap; }
.tn-dong span { color: var(--mo); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tn-dong.on, .tn-dong:hover { background: var(--chinh-nhat); }
.tep-chip { display: inline-flex; align-items: center; gap: 8px; margin: 8px 12px 0; padding: 4px 8px; border: 1px solid var(--vien); border-radius: 8px; background: var(--nhat); font-size: 13px; max-width: calc(100% - 24px); }
.tep-chip img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }
.tep-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tep-chip button { border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--mo); }
.bong .tep-the { display: inline-block; margin-top: 4px; }
.bong .thu-hoi { margin-left: 8px; border: 0; background: rgba(255,255,255,.2); color: inherit; font-size: 10px; border-radius: 6px; padding: 1px 6px; cursor: pointer; }
.bong.da-thu-hoi { opacity: .6; background: var(--nhat); color: var(--mo); border-style: dashed; }
.bong.danh-thiep { border-left: 4px solid var(--vang); }
.bong.goi-y { align-self: flex-end; background: var(--chinh-nhat); color: var(--chu); border: 1px dashed var(--chinh); max-width: 78%; }
.bong .nhan-goi-y { font-size: 11px; font-weight: 600; color: var(--chinh); margin-bottom: 4px; }
.bong .nut-goi-y { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }
.c-ghi-chu { font-size: 12px; color: var(--cam); padding: 4px 14px; background: #fffaf0; border-top: 1px solid #f1dfb2; }
.dong-kv { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; font-size: 13px; }
.dong-kv span:first-child { color: var(--mo); flex: none; }
.muc { border: 1px solid var(--vien); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 13px; }

/* Pipeline */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.cot { flex: 0 0 250px; background: #e9eef7; border-radius: var(--r); padding: 8px; }
.cot.tha { outline: 2px dashed var(--chinh); }
.cot .dau-cot { display: flex; align-items: center; gap: 6px; padding: 4px 6px 8px; font-weight: 600; font-size: 13px; }
.cot .dau-cot i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.cot .dau-cot .so { margin-left: auto; color: var(--mo); font-weight: 500; }
.cot .ds { display: grid; gap: 6px; max-height: calc(100vh - 210px); overflow-y: auto; min-height: 40px; }
.the-kh { background: var(--mat); border: 1px solid var(--vien); border-radius: 8px; padding: 9px 10px; cursor: grab; font-size: 13px; }
.the-kh:hover { border-color: #c3cde0; }
.the-kh b { display: block; }

/* Số liệu */
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi .the { border-top: 2px solid var(--vang); }
.kpi .the b { display: block; font-size: 22px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .the span { color: var(--mo); font-size: 12px; }
.thanh { height: 8px; background: #e9eef7; border-radius: 99px; overflow: hidden; }
.thanh i { display: block; height: 100%; background: var(--chinh); border-radius: 99px; }

/* Hồ sơ 360 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--vien); margin-bottom: 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--mo); white-space: nowrap; }
.tabs button.on { color: var(--chinh); border-color: var(--chinh); font-weight: 600; }
.dong-tg { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid #edf1f7; font-size: 13px; }
.dong-tg .luc { flex: 0 0 96px; color: var(--mo); font-size: 12px; }
.canh-bao { background: #fffaf0; border: 1px solid #f1dfb2; color: #5c4310; border-radius: 8px; padding: 8px 12px; font-size: 13px; }

/* Hộp thoại */
.phu { position: fixed; inset: 0; background: rgba(20, 30, 60, .5); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.hop { background: var(--mat); border-radius: 14px; width: 100%; max-width: 620px; padding: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.hop .chan { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.hang-dv { display: grid; grid-template-columns: 1fr 60px 120px 30px; gap: 6px; margin-bottom: 6px; }
.hang-dv button { border: 0; background: none; cursor: pointer; color: var(--mo); font-size: 16px; }
.bao { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1b2540; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 99; box-shadow: var(--bong); max-width: 90vw; }
.bao.loi { background: var(--do); }
code, .ma { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #eef2f8; border-radius: 6px; padding: 2px 6px; word-break: break-all; }
pre.ma { padding: 10px; white-space: pre-wrap; margin: 6px 0; }

@media (max-width: 1180px) {
  /* Màn vừa: cột phải xuống dưới nội dung chính */
  .app { grid-template-columns: 64px 250px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto 30px; }
  .rail, .sb { grid-row: 1 / 3; }
  .rb { grid-column: 3; border-left: 0; border-top: 1px solid var(--vien); max-height: 38vh; }
  .hai { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  /* Điện thoại: menu xuống đáy, các vùng xếp chồng; hộp chat hiện danh sách HOẶC khung tin */
  .app, .app.khong-rb { display: flex; flex-direction: column; height: auto; min-height: 100dvh; padding-bottom: 60px; }
  .rail { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; flex-direction: row; justify-content: space-around; padding: 4px; border-right: 0; border-top: 1px solid var(--vien); height: 58px; overflow-x: auto; }
  .rail .logo, .bb { display: none; }
  .rail { align-items: center; gap: 0; }
  .rail a { flex: 1 1 0; width: auto; min-width: 0; height: 50px; padding: 4px 0; grid-template-rows: auto auto; gap: 0; }
  .rail a em { display: block; font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .rail a .so { right: 18%; }
  .rail .nguoi { margin: 0 4px; width: 32px; height: 32px; }
  .rail a.on { box-shadow: inset 0 3px 0 var(--vang); }
  .sb { border-right: 0; border-bottom: 1px solid var(--vien); overflow: visible; }
  /* Danh sách lọc trong cột bên thành một hàng cuộn ngang để nội dung chính không bị đẩy xuống quá xa */
  .sb > div:has(> .muc-sb) { display: flex; overflow-x: auto; padding: 0 8px 8px; gap: 6px; }
  .sb .muc-sb { flex: none; border: 1px solid var(--vien); border-radius: 99px; padding: 5px 12px; }
  .sb .muc-sb.on { border-color: var(--vang); }
  .sb .muc-sb span { overflow: visible; }
  .sb-nhom, .sb-ghi { display: none; }
  .sb-loc .o2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .rb { border-left: 0; border-top: 1px solid var(--vien); max-height: none; overflow: visible; }
  main { overflow: visible; }
  .app.chi-noi .sb, .app.chi-noi .rb { display: none; }
  .app.chi-sb .giua, .app.chi-sb .rb { display: none; }
  .app.chat.chi-noi .giua { height: calc(100dvh - 60px); }
  .app.chat.chi-noi main { overflow: hidden; }
  .chi-dt { display: inline-flex; }
  .trang { padding: 14px 12px 30px; }
  .o3 { grid-template-columns: 1fr 1fr; }
  .tabs-tren button { flex: none; }
}
