/* ZPS Bot — hệ giao diện theo ZPS Brand Book v1.2 (Phần VII: màu, typography, hexagon)
   Màu thương hiệu: Navy #0D1B3D (Zero) · Teal #16B1B5 (Plus) · Green #5DBB46 (Scale)
   Tỷ lệ 60-30-10: Neutral 60% · Navy 30% · Teal/Green 10% (Teal = hành động, Green = thành công).
   --primary dùng teal đậm #0D8699 (như website ZPS) để chữ trắng trên nút và link đạt độ tương phản;
   teal gốc #16B1B5 dùng cho mảng trang trí và cho hành động trên nền tối. */
:root {
  --navy: #0D1B3D; --navy-deep: #081230; --teal: #16B1B5; --green: #5DBB46;
  --ink: #1E293B; --slate: #64748B; --mist: #94A3B8; --cloud: #F6F8FB;
  --bg: #F6F8FB; --surface: #FFFFFF; --surface-2: #EEF2F7; --border: #E2E8F0;
  --heading: #0D1B3D; --text: #1E293B; --muted: #64748B; --faint: #94A3B8;
  --primary: #0D8699; --primary-2: #16B1B5; --primary-soft: #E3F5F6; --on-primary: #FFFFFF;
  --ok: #3F8F2E; --ok-soft: #EAF6E6; --ok-fill: #5DBB46; --warn: #A16207; --warn-soft: #FEF6E4;
  --danger: #DC2626; --danger-soft: #FDECEC;
  --radius: 8px; --radius-sm: 6px; --shadow: 0 1px 2px rgba(13,27,61,.06), 0 2px 8px rgba(13,27,61,.04);
  --font: "Montserrat", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #081230; --surface: #0D1B3D; --surface-2: #14264F; --border: #1F3360;
    --heading: #FFFFFF; --text: #E6EBF3; --muted: #A3B0C6; --faint: #6F7F9C;
    --primary: #16B1B5; --primary-2: #16B1B5; --primary-soft: #0F2E4A; --on-primary: #081230;
    --ok: #7FCF6A; --ok-soft: #12321F; --warn: #F2C14E; --warn-soft: #2C2614; --danger: #F87171; --danger-soft: #3A1A22;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #081230; --surface: #0D1B3D; --surface-2: #14264F; --border: #1F3360;
  --heading: #FFFFFF; --text: #E6EBF3; --muted: #A3B0C6; --faint: #6F7F9C;
  --primary: #16B1B5; --primary-2: #16B1B5; --primary-soft: #0F2E4A; --on-primary: #081230;
  --ok: #7FCF6A; --ok-soft: #12321F; --warn: #F2C14E; --warn-soft: #2C2614; --danger: #F87171; --danger-soft: #3A1A22;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; color: var(--heading); font-weight: 700; }
h3, h4 { font-weight: 600; }
p { margin: 0 0 1em; }
code, pre { font-family: var(--mono); font-size: 13px; }
pre { background: var(--surface-2); border: 1px solid var(--border); padding: 12px; border-radius: var(--radius-sm); overflow: auto; white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 13px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; } .grow { flex: 1; } .right { margin-left: auto; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { font-size: 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; color: var(--heading); }
.stat .sub { color: var(--faint); font-size: 12px; margin-top: 2px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm); font: 600 14px/1.2 var(--font); cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); } .btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; } .btn.lg { padding: 12px 22px; font-size: 16px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.field { margin-bottom: 14px; }
input, select, textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: 14px/1.4 var(--font); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; }
input[type=color] { height: 42px; padding: 4px; cursor: pointer; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--text); font-size: 14px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); } .badge.primary { background: var(--primary-soft); color: var(--primary); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.toast { font-family: var(--font); position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 1000; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.toast.err { background: var(--danger); color: #fff; }
.modal-bg { position: fixed; inset: 0; background: rgba(10,14,25,.5); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 900; overflow-y: auto; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 620px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.empty { text-align: center; color: var(--faint); padding: 40px 16px; }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: 14px; margin-bottom: 16px; }
.alert.info { background: var(--primary-soft); color: var(--primary); }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.logo { display: inline-flex; align-items: center; gap: 20px; text-decoration: none !important; color: var(--heading); }
.logo img { height: 30px; width: auto; display: block; }
.logo .product { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding-left: 20px; border-left: 1px solid var(--border); white-space: nowrap; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo img { background: #fff; padding: 6px 10px; border-radius: 6px; box-sizing: content-box; } }
:root[data-theme="dark"] .logo img { background: #fff; padding: 6px 10px; border-radius: 6px; box-sizing: content-box; }
.eyebrow { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--primary); }
/* Icon trong khung hexagon outline (Brand Book §33) */
.hex { width: 44px; height: 50px; display: grid; place-items: center; color: var(--primary); position: relative; flex: none; }
.hex::before { content: ""; position: absolute; inset: 0; background: currentColor; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); opacity: 1; }
.hex::after { content: ""; position: absolute; inset: 1.5px; background: var(--surface); clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); }
.hex svg { position: relative; z-index: 1; width: 20px; height: 20px; }
.hex-bullet { display: inline-block; width: 9px; height: 10px; background: var(--primary); clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); flex: none; }

/* Nhân viên: ẩn thao tác chỉ chủ tài khoản làm được (máy chủ cũng chặn) */
.role-staff #view [data-d], .role-staff #csv, .role-staff .nav a[href="#billing"] { display: none !important; }

/* Bố cục dashboard */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .logo { padding: 4px 10px 18px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 500; font-size: 14px; text-decoration: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--navy); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .nav a.active, :root:not([data-theme="light"]) .bubble.staff { background: var(--surface-2); color: #fff; box-shadow: inset 3px 0 0 var(--teal); } }
:root[data-theme="dark"] .nav a.active, :root[data-theme="dark"] .bubble.staff { background: var(--surface-2); color: #fff; box-shadow: inset 3px 0 0 var(--teal); }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 16px 12px 6px; }
.nav .count { margin-left: auto; background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; }
.main { padding: 24px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; margin: 0; }
.menu-btn { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; z-index: 800; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px 16px 60px; }
}

/* Hộp thư */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; height: calc(100vh - 120px); min-height: 480px; }
.inbox .list { overflow-y: auto; padding: 0; }
.inbox .item { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.inbox .item:hover, .inbox .item.active { background: var(--surface-2); }
.thread { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.thread .head { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.thread .msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.thread .compose { border-top: 1px solid var(--border); padding: 10px 84px 10px 10px; display: flex; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; }
.bubble.customer { background: var(--surface); border: 1px solid var(--border); align-self: flex-start; }
.bubble.bot { background: var(--primary-soft); color: var(--text); align-self: flex-end; }
.bubble.staff { background: var(--navy); color: #fff; align-self: flex-end; }
.bubble.system { align-self: center; background: transparent; color: var(--faint); font-size: 12px; }
.bubble .meta { font-size: 11px; opacity: .7; margin-top: 4px; }
@media (max-width: 860px) { .inbox { grid-template-columns: 1fr; height: auto; } .inbox .list { max-height: 300px; } .thread { height: 70vh; } }

/* ===== Điện thoại: bảng điều khiển hiển thị như một app =====
   Thanh tab dưới đáy, tiêu đề dính trên cùng, bảng thành thẻ, hộp thoại thành bottom sheet,
   hội thoại mở toàn màn hình như ứng dụng nhắn tin. */
.tabbar, .side-bg, .thread .back { display: none; }
@media (max-width: 760px) {
  :root { --tabbar-h: 60px; --safe-b: env(safe-area-inset-bottom, 0px); }
  body { overscroll-behavior-y: none; }
  input, select, textarea { font-size: 16px; } /* iOS không tự phóng to khi chạm vào ô nhập */
  .menu-btn { display: none !important; }
  .main { padding: 0 12px calc(var(--tabbar-h) + var(--safe-b) + 24px); }
  .topbar { position: sticky; top: 0; z-index: 700; margin: 0 -12px 12px; padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
    background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); gap: 8px; flex-wrap: nowrap; }
  .topbar h1 { font-size: 18px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar #actions { order: 3; flex: 0 1 auto; flex-wrap: nowrap; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-left: 0; max-width: 62%; }
  .topbar #actions::-webkit-scrollbar { display: none; }
  .topbar #actions .btn, .topbar #actions select, .topbar #actions input { padding: 6px 10px; font-size: 13px; flex: none; }
  .topbar #actions input { width: 130px !important; }
  .topbar #actions a[href^="/huong-dan"] { display: none; } /* hướng dẫn nằm trong menu Thêm */
  #planbadge { display: none; }

  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 820;
    height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -2px 12px rgba(13,27,61,.06); }
  .tabbar a, .tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; background: none; border: 0; color: var(--faint);
    font: 600 11px/1 var(--font); text-decoration: none !important; cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar .active { color: var(--primary); }
  .tabbar .active svg { stroke-width: 2.3; }
  .tabbar .count { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--danger); color: #fff; font: 700 10px/16px var(--font); min-width: 16px; padding: 0 4px; border-radius: 99px; font-style: normal; }

  /* Menu "Thêm": toàn bộ chức năng, trượt lên từ dưới */
  .side { position: fixed; inset: auto 0 0 0; top: auto; width: auto; height: auto; max-height: 82dvh; z-index: 860; border-radius: 18px 18px 0 0; border-right: 0;
    padding: 8px 12px calc(16px + var(--safe-b)); transform: translateY(105%); transition: transform .25s ease; box-shadow: 0 -10px 40px rgba(0,0,0,.25); }
  .side::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 4px auto 10px; }
  .side.open { transform: none; }
  .side .logo { display: none; }
  .nav { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 8px; }
  .nav .sep { grid-column: 1 / -1; padding: 12px 8px 4px; }
  .nav a { padding: 11px 10px; font-size: 14px; }
  .nav a[href="#inbox"], .nav a[href="#orders"], .nav a[href="#overview"], .nav a[href="#customers"] { display: none; }
  .side-bg { position: fixed; inset: 0; z-index: 850; background: rgba(10,14,25,.45); }
  .side.open + .side-bg { display: block; }

  .card { padding: 14px; }
  .grid[style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; }
  .grid:has(> .stat) { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
  .stat .value { font-size: 22px; }
  .g2, .g3, .g4 { gap: 12px; }

  /* Bảng → danh sách thẻ (nhãn cột lấy từ data-label do app.js gắn) */
  .table-wrap { border: 0; background: none; overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap tr:has(> th) { display: none; }
  .table-wrap tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
  .table-wrap td { border: 0; padding: 4px 0; text-align: left !important; }
  .table-wrap td[data-label] { text-align: right !important; overflow: hidden; }
  .table-wrap td[data-label]::before { content: attr(data-label); float: left; margin-right: 12px; font-size: 12px; line-height: 22px; color: var(--faint); font-weight: 600; }
  .table-wrap td:first-child { font-size: 15px; padding-top: 2px; }
  .table-wrap td:first-child::before { display: none; }
  .table-wrap td:first-child > * { text-align: left; }
  .table-wrap td:empty { display: none; }
  .table-wrap td.act { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding-top: 8px; margin-top: 6px; border-top: 1px solid var(--border); }
  .table-wrap td.act::before { display: none; }
  .table-wrap td[colspan] { text-align: center !important; }

  /* Hộp thoại → bottom sheet */
  .modal-bg { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 18px 18px 0 0; max-height: 94dvh; overflow-y: auto; padding: 18px 16px calc(16px + var(--safe-b)); animation: sheet-up .22s ease; }
  .modal > .row:last-child { position: sticky; bottom: calc(-16px - var(--safe-b)); background: var(--surface); margin: 8px -16px calc(-16px - var(--safe-b)) !important; padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--border); }
  .modal > .row:last-child .btn { flex: 1; padding: 12px; }
  .toast { bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); }

  /* Hộp thư: danh sách toàn màn hình; chạm vào hội thoại → mở khung chat toàn màn hình */
  .inbox { display: block; height: auto; min-height: 0; }
  .inbox .list { max-height: none; overflow: visible; border-radius: var(--radius); }
  .inbox .item { padding: 14px; }
  .inbox .thread { display: none; }
  .inbox.open .list { display: none; }
  .inbox.open .thread { display: flex; position: fixed; inset: 0; z-index: 880; height: 100dvh; border: 0; border-radius: 0; }
  .inbox.open .thread .head { padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px 6px; flex-wrap: nowrap; gap: 6px; background: var(--surface); }
  .inbox.open .thread .head > div:first-of-type { min-width: 0; flex: 1; }
  .inbox.open .thread .head b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .inbox.open .thread .head .faint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
  .inbox.open .thread .head .row { flex-wrap: nowrap; gap: 6px; }
  .thread .back { display: inline-flex; font-size: 26px; line-height: 1; padding: 4px 10px; }
  .thread .msgs { padding: 12px; }
  .bubble { max-width: 84%; font-size: 15px; }
  .thread .compose { padding: 8px 8px calc(8px + var(--safe-b)); background: var(--surface); }
  .thread .compose input { border-radius: 20px; padding: 10px 14px; }
  .thread .compose select { max-width: 74px !important; padding: 9px 6px; border-radius: 20px; }
  .thread .compose .btn { border-radius: 20px; padding: 10px 16px; }
  body.chat-open .tabbar, body.chat-open #zps-chat-widget { display: none; }
  /* Widget chat thử chỉ hiện ở màn Bắt đầu, nằm trên thanh tab */
  body.dash:not(.v-onboarding) #zps-chat-widget { display: none; }
  body.dash #zps-chat-widget { bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px) !important; right: 12px !important; }

  .install { display: flex; gap: 12px; align-items: center; background: var(--navy); color: #fff; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
  .install img { width: 40px; height: 40px; border-radius: 10px; background: #fff; }
  .install .btn.ghost { color: #fff; }
}
@keyframes sheet-up { from { transform: translateY(40px); } }
@media (display-mode: standalone) { .topbar h1 { font-size: 19px; } }
