/* Xe Nâng 360 — bố cục CRM: menu trái theo nhóm + thanh trên lọc ngày + thẻ số liệu, học từ CRM 360 (Tân Nông / Cô Ba).
   Màu là token trên :root; chế độ tối theo máy hoặc theo nút (data-theme). */
:root {
  --nen: #f4f6f9; --the: #ffffff; --chu: #16191f; --phu: #4a5260; --mo: #6b7280; --vien: #e3e7ed; --vien2: #eef1f5;
  --chinh: #c2410c; --chinh-dam: #9a3412; --tren-chinh: #ffffff; --nhat: #fff1e8;
  --canh: #b45309; --canh-nen: #fef3c7; --do: #b91c1c; --do-nen: #fee2e2; --xanh: #15803d; --xanh-nen: #dcfce7;
  --tim: #6d28d9; --tim-nen: #ede9fe; --lam: #1d4ed8; --lam-nen: #dbeafe;
  --menu: #ffffff; --menu-on: #fff1e8; --bo: 14px; --bong: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.07);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --nen: #0f1216; --the: #171b21; --chu: #eef1f5; --phu: #b3bac5; --mo: #8b93a1; --vien: #2a3039; --vien2: #20252d;
    --chinh: #fb923c; --chinh-dam: #fdba74; --tren-chinh: #2a1204; --nhat: #3a1d0c;
    --canh: #fbbf24; --canh-nen: #3a2c0c; --do: #f87171; --do-nen: #3b1414; --xanh: #4ade80; --xanh-nen: #0f2e1b;
    --tim: #c4b5fd; --tim-nen: #2e2350; --lam: #93c5fd; --lam-nen: #172a4d; --menu: #13171c; --menu-on: #3a1d0c; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --nen: #0f1216; --the: #171b21; --chu: #eef1f5; --phu: #b3bac5; --mo: #8b93a1; --vien: #2a3039; --vien2: #20252d;
  --chinh: #fb923c; --chinh-dam: #fdba74; --tren-chinh: #2a1204; --nhat: #3a1d0c;
  --canh: #fbbf24; --canh-nen: #3a2c0c; --do: #f87171; --do-nen: #3b1414; --xanh: #4ade80; --xanh-nen: #0f2e1b;
  --tim: #c4b5fd; --tim-nen: #2e2350; --lam: #93c5fd; --lam-nen: #172a4d; --menu: #13171c; --menu-on: #3a1d0c; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--nen); color: var(--chu); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--chinh); }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Khung CRM ---------- */
.crm { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.menu { background: var(--menu); border-right: 1px solid var(--vien); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; padding: 14px 12px; z-index: 15; }
.thuong-hieu { display: flex; gap: 10px; align-items: center; padding: 4px 6px 14px; text-decoration: none; color: var(--chu); }
.thuong-hieu img { width: 40px; height: 40px; border-radius: 10px; flex: none; }
.thuong-hieu b { display: block; font-size: 15px; line-height: 1.2; }
.thuong-hieu span { display: block; font-size: 11.5px; color: var(--mo); text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.nhom-menu { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--mo); margin: 14px 10px 4px; }
.menu a.muc { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--phu); text-decoration: none; font-size: 14.5px; border: 1px solid transparent; }
.menu a.muc:hover { background: var(--vien2); color: var(--chu); }
.menu a.muc.on { background: var(--menu-on); color: var(--chinh-dam); border-color: color-mix(in srgb, var(--chinh) 25%, transparent); font-weight: 600; }
.menu a.muc .dem { margin-left: auto; background: var(--chinh); color: var(--tren-chinh); border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.menu .chan { margin-top: auto; padding-top: 14px; }
.the-nguoi { display: flex; align-items: center; gap: 10px; border: 1px solid var(--vien); border-radius: 12px; padding: 10px; background: var(--the); }
.the-nguoi b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.the-nguoi span { font-size: 12px; color: var(--xanh); }
.the-nguoi button { margin-left: auto; border: 0; background: transparent; color: var(--mo); cursor: pointer; padding: 4px; }
.chu-cai { width: 34px; height: 34px; border-radius: 50%; background: var(--nhat); color: var(--chinh-dam); display: grid; place-items: center; font-weight: 700; flex: none; }

.chinh { min-width: 0; display: flex; flex-direction: column; }
.thanh-tren { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 10px 20px; background: color-mix(in srgb, var(--nen) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--vien); }
.thanh-tren .tim { flex: 1 1 220px; max-width: 360px; position: relative; }
.thanh-tren .tim input { width: 100%; padding: 8px 12px 8px 34px; border: 1px solid var(--vien); border-radius: 10px; background: var(--the); }
.thanh-tren .tim svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--mo); }
.loc-ngay { display: inline-flex; background: var(--vien2); border: 1px solid var(--vien); border-radius: 12px; padding: 3px; gap: 2px; }
.loc-ngay button { border: 0; background: transparent; padding: 5px 10px; border-radius: 9px; font-size: 13px; color: var(--phu); cursor: pointer; white-space: nowrap; }
.loc-ngay button.on { background: var(--the); color: var(--chinh-dam); font-weight: 600; box-shadow: var(--bong); }
.nut-tron { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--vien); background: var(--the); display: grid; place-items: center; cursor: pointer; color: var(--phu); flex: none; }
.ngon { display: inline-flex; border: 1px solid var(--vien); border-radius: 999px; overflow: hidden; flex: none; background: var(--the); }
.ngon button { border: 0; background: transparent; padding: 4px 10px; font-size: 12.5px; cursor: pointer; }
.ngon button.on { background: var(--chinh); color: var(--tren-chinh); }
.mo-menu { display: none; }
.trang { padding: 20px; max-width: 1400px; width: 100%; }
.trang-hep { max-width: 860px; }

/* ---------- Đầu trang + thẻ ---------- */
.dau-trang { background: var(--the); border: 1px solid var(--vien); border-radius: 18px; padding: 18px 20px; box-shadow: var(--bong); margin-bottom: 16px;
  display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.dau-trang h1 { font-size: 21px; margin: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dau-trang p { margin: 4px 0 0; color: var(--phu); font-size: 14px; }
.dau-trang .nut-dau { display: flex; gap: 8px; flex-wrap: wrap; }
.huy-hieu { font-size: 12px; font-weight: 600; background: var(--xanh-nen); color: var(--xanh); border-radius: 999px; padding: 3px 10px; }
.the { background: var(--the); border: 1px solid var(--vien); border-radius: var(--bo); padding: 16px; box-shadow: var(--bong); margin-bottom: 14px; }
.the h2 { font-size: 15.5px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.the h2 .phai { margin-left: auto; font-weight: 400; }
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 16px; }
.so { background: var(--the); border: 1px solid var(--vien); border-radius: 16px; padding: 16px; box-shadow: var(--bong); position: relative; }
.so .nhan-so { font-size: 13.5px; color: var(--phu); padding-right: 40px; }
.so b { display: block; font-size: 27px; line-height: 1.25; margin-top: 6px; font-variant-numeric: tabular-nums; }
.so small { display: block; font-size: 12.5px; color: var(--mo); margin-top: 4px; }
.so .bieu { position: absolute; right: 14px; top: 14px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--nhat); color: var(--chinh-dam); }
.so.xanh .bieu { background: var(--xanh-nen); color: var(--xanh); } .so.tim .bieu { background: var(--tim-nen); color: var(--tim); }
.so.lam .bieu { background: var(--lam-nen); color: var(--lam); } .so.canh .bieu { background: var(--canh-nen); color: var(--canh); }
.so.do b { color: var(--do); } .so.canh b { color: var(--canh); }
.luoi { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; }
.luoi .so { padding: 12px 14px; } .luoi .so b { font-size: 22px; margin-top: 2px; } .luoi .so span { color: var(--phu); font-size: 13px; }
.hai-cot { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 14px; align-items: start; }
.hai-cot > aside { position: sticky; top: 74px; max-height: calc(100vh - 94px); overflow-y: auto; }
.cot-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

/* ---------- Thành phần chung ---------- */
label { display: block; font-size: 13.5px; color: var(--phu); margin: 10px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=datetime-local], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--vien); border-radius: 10px; background: var(--the); }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--chinh); outline-offset: 0; border-color: transparent; }
.tick { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--chu); margin: 10px 0; }
.tick input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; accent-color: var(--chinh); }
.nut { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--vien); background: var(--the); border-radius: 10px; padding: 8px 13px;
  cursor: pointer; text-decoration: none; color: var(--chu); font-size: 14px; white-space: nowrap; }
.nut:hover { border-color: var(--chinh); }
.nut.chinh { background: var(--chinh); color: var(--tren-chinh); border-color: var(--chinh); font-weight: 600; }
.nut.vien { border-color: color-mix(in srgb, var(--chinh) 50%, var(--vien)); color: var(--chinh-dam); }
.nut.do { color: var(--do); border-color: var(--do); }
.nut.nho { padding: 5px 10px; font-size: 13px; }
.nut.rong { width: 100%; padding: 11px; margin-top: 14px; }
.nut:disabled { opacity: .5; cursor: default; }
.hang { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hang > * { flex: 1 1 140px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--vien); background: var(--the); border-radius: 999px; padding: 4px 11px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--chu); color: var(--nen); border-color: var(--chu); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.ds { list-style: none; margin: 0; padding: 0; }
.ds li { display: flex; gap: 12px; align-items: center; padding: 11px 6px; border-bottom: 1px solid var(--vien2); cursor: pointer; border-radius: 8px; }
.ds li:hover { background: var(--vien2); }
.ds li.on { background: var(--menu-on); }
.ds li:last-child { border-bottom: 0; }
.ds .ten { font-weight: 600; }
.ds .phai { margin-left: auto; text-align: right; flex: none; }
.phu { color: var(--phu); font-size: 13px; }
.mo { color: var(--mo); font-size: 12.5px; }
.nho-chu { font-size: 13px; }
.nhan { display: inline-block; font-size: 12px; border-radius: 999px; padding: 2px 9px; background: var(--nhat); color: var(--chinh-dam); white-space: nowrap; }
.nhan.sap-mat, .nhan.canh { background: var(--canh-nen); color: var(--canh); }
.nhan.da-mat, .nhan.do { background: var(--do-nen); color: var(--do); }
.nhan.moi, .nhan.xanh { background: var(--xanh-nen); color: var(--xanh); }
.nhan.tim { background: var(--tim-nen); color: var(--tim); } .nhan.lam { background: var(--lam-nen); color: var(--lam); }
.nhan.tt-san_sang { background: var(--xanh-nen); color: var(--xanh); }
.nhan.tt-dang_thue { background: var(--lam-nen); color: var(--lam); }
.nhan.tt-dang_sua, .nhan.tt-da_coc { background: var(--canh-nen); color: var(--canh); }
.nhan.tt-da_ban, .nhan.tt-ngung { background: var(--vien2); color: var(--phu); }
.nhan.buoc-chot { background: var(--xanh-nen); color: var(--xanh); } .nhan.buoc-mat { background: var(--do-nen); color: var(--do); }
.cs { border-bottom: 1px solid var(--vien2); padding: 12px 0 12px 12px; }
.cs:last-child { border-bottom: 0; }
.cs .hang { margin-top: 8px; } .cs .hang .nut { flex: 0 1 auto; }
.cs.muc-do { border-left: 3px solid var(--do); } .cs.muc-canh { border-left: 3px solid var(--canh); } .cs.muc-thuong { border-left: 3px solid var(--vien); }
.tin { background: var(--vien2); border-radius: 10px; padding: 10px; font-size: 14px; color: var(--phu); margin-top: 8px; white-space: pre-wrap; }
.canh-chu { color: var(--canh); background: var(--canh-nen); }
.bang { margin-top: 6px; }
.bang .dong { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--vien); font-size: 14px; }
.bang .dong:last-child { border-bottom: 0; }
.bang .dong span { color: var(--phu); } .bang .dong b { font-weight: 600; text-align: right; }
.hanh-dong { margin-top: 12px; } .hanh-dong > * { flex: 0 1 auto; }
.thanh { display: grid; grid-template-columns: minmax(0, 1.4fr) 2fr auto; gap: 10px; align-items: center; font-size: 14px; margin: 7px 0; }
.thanh div { background: var(--vien2); border-radius: 6px; height: 10px; overflow: hidden; }
.thanh i { display: block; height: 100%; background: var(--chinh); border-radius: 6px; }
.thanh span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bang-so { width: 100%; border-collapse: collapse; font-size: 14px; }
.bang-so th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--mo); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--vien); white-space: nowrap; }
.bang-so td { padding: 10px 8px; border-bottom: 1px solid var(--vien2); vertical-align: top; }
.cuon-ngang { overflow-x: auto; }
.luoi2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.trong { text-align: center; color: var(--mo); padding: 28px 10px; }
.loi { color: var(--do); font-size: 14px; margin-top: 8px; min-height: 1em; }
.bao { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--chu); color: var(--nen); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 40; max-width: calc(100% - 32px); }
.ma { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--vien2); border-radius: 6px; padding: 2px 6px; word-break: break-all; }

/* ---------- Hộp thư ---------- */
.hop-thu { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; gap: 0; height: calc(100vh - 57px); border-top: 0; }
.hop-thu > section { min-height: 0; display: flex; flex-direction: column; border-right: 1px solid var(--vien); background: var(--the); }
.hop-thu > section:last-child { border-right: 0; }
.ht-dau { padding: 12px; border-bottom: 1px solid var(--vien); }
.ht-ds { overflow-y: auto; flex: 1; }
.ht-muc { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--vien2); cursor: pointer; }
.ht-muc:hover { background: var(--vien2); } .ht-muc.on { background: var(--menu-on); }
.ht-muc .ten { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ht-muc .tom { font-size: 13px; color: var(--phu); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ht-muc .ht-giua { min-width: 0; flex: 1; }
.ht-muc.chua-doc .ten, .ht-muc.chua-doc .tom { color: var(--chu); font-weight: 700; }
.kenh-dau { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 800; color: #fff; flex: none; }
.k-messenger { background: #0866ff; } .k-instagram { background: #d6249f; } .k-zalo_oa { background: #0068ff; } .k-zalo_ca_nhan { background: #0aa5ff; } .k-form { background: #64748b; }
.chat { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 6px; background: var(--nen); }
.bong { max-width: 74%; padding: 8px 12px; border-radius: 14px; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.bong.vao { align-self: flex-start; background: var(--the); border: 1px solid var(--vien); border-bottom-left-radius: 4px; }
.bong.ra { align-self: flex-end; background: var(--chinh); color: var(--tren-chinh); border-bottom-right-radius: 4px; }
.bong.ra.bot { background: var(--tim); color: #fff; }
.bong .meta { display: block; font-size: 11px; opacity: .75; margin-top: 3px; }
.bong.loi-gui { outline: 2px solid var(--do); }
.soan { border-top: 1px solid var(--vien); padding: 10px; background: var(--the); }
.soan textarea { min-height: 54px; }
.goi-y-bot { border: 1px dashed var(--tim); background: var(--tim-nen); border-radius: 12px; padding: 10px; margin-bottom: 8px; font-size: 14px; }
.goi-y-bot b { color: var(--tim); }
.ht-360 { overflow-y: auto; padding: 12px; }
.ht-360 h3 { font-size: 14px; margin: 14px 0 6px; }
.ht-trong { display: grid; place-items: center; height: 100%; color: var(--mo); padding: 20px; text-align: center; }
.quay-lai { display: none; }

/* ---------- Hộp thoại ---------- */
.hop-nen { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 30; display: flex; align-items: center; justify-content: center; }
.hop { background: var(--the); width: 100%; max-width: 580px; max-height: 92vh; overflow-y: auto; border-radius: 16px; padding: 16px 18px; }
.hop-dau { display: flex; justify-content: space-between; align-items: center; }
.hop-dau h2 { margin: 0; font-size: 17px; }
.hop .dong { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--phu); padding: 4px 8px; }
.hop > .hang { margin-top: 14px; } .hop > .hang .nut { flex: 1 1 0; }

/* ---------- Đăng nhập ---------- */
.giua { max-width: 440px; margin: 7vh auto 0; padding: 0 16px; }
.giua .dau { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.giua h1 { font-size: 22px; margin: 0; }

/* ---------- Điện thoại ---------- */
.dieu-huong { display: none; }
@media (max-width: 1180px) { .hop-thu { grid-template-columns: 300px minmax(0, 1fr); } .hop-thu > section.ht-ben { display: none; } .hop-thu.mo-360 > section.ht-ben { display: flex; position: fixed; right: 0; top: 57px; bottom: 0; width: min(340px, 92vw); z-index: 12; box-shadow: -6px 0 20px rgba(0,0,0,.15); } }
@media (max-width: 900px) {
  .crm { grid-template-columns: 1fr; }
  .menu { position: fixed; left: 0; top: 0; bottom: 0; width: 268px; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 24px rgba(0,0,0,.18); }
  .crm.mo .menu { transform: none; }
  .crm.mo::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 14; }
  .mo-menu { display: grid; }
  .thanh-tren { padding: 8px 12px; flex-wrap: wrap; }
  .thanh-tren .tim { order: 5; flex-basis: 100%; max-width: none; }
  .loc-ngay { overflow-x: auto; max-width: 100%; }
  .trang { padding: 12px 12px 86px; }
  .hai-cot { grid-template-columns: 1fr; } .hai-cot > aside { display: none; }
  .cot-2 { grid-template-columns: 1fr; }
  .hop-thu { grid-template-columns: 1fr; height: calc(100vh - 106px - 62px); }
  .hop-thu > section.ht-chat, .hop-thu > section.ht-ben { display: none; }
  .hop-thu.xem-chat > section.ht-list { display: none; }
  .hop-thu.xem-chat > section.ht-chat { display: flex; }
  .quay-lai { display: inline-flex; }
  .bong { max-width: 86%; }
  .dieu-huong { display: flex; position: fixed; left: 0; right: 0; bottom: 0; background: var(--the); border-top: 1px solid var(--vien); justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 13; }
  .dieu-huong a { flex: 1; text-align: center; padding: 8px 2px 9px; text-decoration: none; color: var(--phu); font-size: 11.5px; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
  .dieu-huong a.on { color: var(--chinh); font-weight: 600; }
  .dieu-huong a .dem { position: absolute; top: 3px; left: 54%; background: var(--chinh); color: var(--tren-chinh); border-radius: 999px; font-size: 10px; padding: 0 5px; }
  .hop-nen { align-items: flex-end; } .hop { border-radius: 16px 16px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}
@media (max-width: 460px) { .luoi2 { grid-template-columns: 1fr; } .dau-trang { padding: 14px; } .dau-trang h1 { font-size: 18px; } .kpi { grid-template-columns: 1fr 1fr; gap: 10px; } .so b { font-size: 21px; } }
