:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f9fafb;
  --line: #e5e7eb;
  --line-2: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --accent: #0f766e;
  --accent-2: #115e59;
  --accent-soft: #ccfbf1;
  --bubble-in: #ffffff;
  --bubble-out: #d9f5ef;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warn: #92400e;
  --warn-soft: #fef3c7;
  --ok: #166534;
  --ok-soft: #dcfce7;
  --shopee: #ee4d2d;
  --tiktok: #111111;
  --zalo: #0068ff;
  --facebook: #1877f2;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f14; --panel: #12171e; --panel-2: #171d26; --line: #232b36; --line-2: #2f3946;
    --text: #e5e7eb; --muted: #9aa4b2; --faint: #6b7686; --accent: #2dd4bf; --accent-2: #5eead4;
    --accent-soft: #0f3b37; --bubble-in: #1b222c; --bubble-out: #12372f; --danger: #f87171;
    --danger-soft: #3b1414; --warn: #fbbf24; --warn-soft: #3a2a07; --ok: #4ade80; --ok-soft: #0f2e1a;
    --tiktok: #fe2c55; --shadow: 0 1px 2px rgb(0 0 0 / .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f14; --panel: #12171e; --panel-2: #171d26; --line: #232b36; --line-2: #2f3946;
  --text: #e5e7eb; --muted: #9aa4b2; --faint: #6b7686; --accent: #2dd4bf; --accent-2: #5eead4;
  --accent-soft: #0f3b37; --bubble-in: #1b222c; --bubble-out: #12372f; --danger: #f87171;
  --danger-soft: #3b1414; --warn: #fbbf24; --warn-soft: #3a2a07; --ok: #4ade80; --ok-soft: #0f2e1a;
  --tiktok: #fe2c55; --shadow: 0 1px 2px rgb(0 0 0 / .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- Khung chính ---------- */
.shell { display: grid; grid-template-columns: 64px 1fr; height: 100vh; }
.rail {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 6px;
}
.rail .logo { width: 36px; height: 36px; margin-bottom: 10px; }
.rail button {
  width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; cursor: pointer;
  display: grid; place-items: center; color: var(--muted); position: relative;
}
.rail button:hover { background: var(--panel-2); color: var(--text); }
.rail button.on { background: var(--accent-soft); color: var(--accent); }
.rail button svg { width: 22px; height: 22px; }
.rail .dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; line-height: 16px; font-weight: 700; }
.rail .spacer { flex: 1; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; overflow: hidden; position: relative;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar .away-dot { position: absolute; bottom: 0; right: 0; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--panel); background: var(--warn); }
.view { min-width: 0; height: 100vh; overflow: hidden; }

/* ---------- Hộp thư: 3 cột ---------- */
.inbox { display: grid; grid-template-columns: 340px minmax(360px, 1fr) 400px; height: 100%; }
.pane { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.tabs { display: flex; gap: 4px; background: var(--panel-2); padding: 3px; border-radius: 9px; border: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: transparent; padding: 6px 8px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tabs button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.tabs .n { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; }
.search { position: relative; }
.search input { width: 100%; padding: 8px 10px 8px 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.search svg { position: absolute; left: 9px; top: 9px; width: 16px; height: 16px; color: var(--faint); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 10px; cursor: pointer;
  font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip .pdot { width: 8px; height: 8px; border-radius: 50%; }
select.chip { padding-right: 6px; }

.conv-list { overflow-y: auto; flex: 1; }
.conv {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 10px 14px; cursor: pointer;
  border-bottom: 1px solid var(--line); position: relative;
}
.conv:hover { background: var(--panel-2); }
.conv.on { background: var(--accent-soft); }
.conv .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .who { font-weight: 800; }
.conv .sub { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; min-width: 0; }
.conv .preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .preview { color: var(--text); }
.conv .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 11px; color: var(--faint); }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 700; }
.waiting { color: var(--warn); font-weight: 600; }
.viewing { font-size: 11px; color: var(--accent); }
.plat { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 4px; color: #fff; }
.plat.shopee { background: var(--shopee); } .plat.tiktok { background: var(--tiktok); }
.plat.zalo { background: var(--zalo); } .plat.facebook { background: var(--facebook); }
.conv .avatar-wrap { position: relative; }
.conv .avatar-wrap .plat-dot { position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--panel); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- Khung chat ---------- */
.chat-head { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; min-height: 61px; }
.chat-head .title { font-weight: 700; font-size: 15px; }
.chat-head .sub { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chat-head .actions { margin-left: auto; display: flex; gap: 6px; }
.notice { margin: 8px 16px 0; padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--accent-2); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.day { align-self: center; font-size: 11px; color: var(--faint); margin: 10px 0 4px; }
.msg { max-width: 72%; 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: 14px; background: var(--bubble-in); box-shadow: var(--shadow); white-space: pre-wrap; word-break: break-word; }
.msg.out .bubble { background: var(--bubble-out); }
.msg.in .bubble { border-bottom-left-radius: 4px; }
.msg.out .bubble { border-bottom-right-radius: 4px; }
.msg img.media { max-width: 260px; max-height: 260px; border-radius: 12px; display: block; cursor: zoom-in; box-shadow: var(--shadow); background: var(--panel); }
.msg .time { font-size: 11px; color: var(--faint); padding: 0 4px; }
.msg.failed .bubble { outline: 1.5px solid var(--danger); }
.msg .err { font-size: 12px; color: var(--danger); }
.order-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 240px; box-shadow: var(--shadow); }
.order-card .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.order-card .v { font-weight: 700; font-family: ui-monospace, Consolas, monospace; }
.composer { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; gap: 8px; align-items: flex-end; background: var(--panel); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; max-height: 160px; min-height: 40px; background: var(--panel-2); }
.composer textarea:focus, input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.typing { font-size: 12px; color: var(--accent); padding: 0 16px 6px; min-height: 18px; background: var(--bg); }

/* ---------- Nút ---------- */
.btn {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.icon { padding: 8px; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.danger { color: var(--danger); }

/* ---------- Cột phải: khách + phiếu bảo hành ---------- */
.side { overflow-y: auto; border-right: 0; }
.section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.section h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.section h3 .right { margin-left: auto; text-transform: none; letter-spacing: 0; }
.order { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 13px; }
.order .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.order .id { font-family: ui-monospace, Consolas, monospace; font-weight: 700; }
.order .items { color: var(--muted); font-size: 12px; margin-top: 2px; }
.order.used { border-color: var(--accent); background: var(--accent-soft); }

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field label .req { color: var(--danger); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line-2); border-radius: 7px; padding: 7px 9px; background: var(--panel); width: 100%; min-width: 0;
}
.field textarea { resize: vertical; min-height: 60px; }
.field.bad input, .field.bad select, .field.bad .combo input { border-color: var(--danger); }
.field .hint { font-size: 11px; color: var(--faint); }
.field .error { font-size: 11px; color: var(--danger); }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
details.more { grid-column: 1 / -1; border: 1px dashed var(--line-2); border-radius: 8px; padding: 6px 10px; }
details.more summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
details.more .form { margin-top: 10px; }
.combo { position: relative; }
.combo .list {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); max-height: 260px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: var(--shadow);
}
.combo .opt { padding: 7px 10px; cursor: pointer; font-size: 13px; }
.combo .opt:hover, .combo .opt.hi { background: var(--accent-soft); }
.combo .opt .sku { font-family: ui-monospace, Consolas, monospace; font-weight: 700; margin-right: 6px; }
.combo .opt .b { font-size: 11px; color: var(--muted); margin-left: 6px; }
.pics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pic { position: relative; border: 2px solid transparent; border-radius: 8px; overflow: hidden; cursor: pointer; aspect-ratio: 1; background: var(--panel-2); }
.pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pic.on { border-color: var(--accent); }
.pic .tick { position: absolute; top: 4px; right: 4px; width: 18px; height: 18px; border-radius: 50%; background: var(--panel); border: 1.5px solid var(--line-2); display: grid; place-items: center; font-size: 12px; color: #fff; }
.pic.on .tick { background: var(--accent); border-color: var(--accent); }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.dup { grid-column: 1 / -1; background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 8px 10px; font-size: 12px; }
.dup ul { margin: 4px 0 0; padding-left: 18px; }
.ticket { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; font-size: 13px; }
.ticket .row1 { display: flex; gap: 8px; align-items: center; }
.status { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.status.created { background: var(--ok-soft); color: var(--ok); }
.status.dry-run { background: var(--accent-soft); color: var(--accent-2); }
.status.failed { background: var(--danger-soft); color: var(--danger); }
pre.payload { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; margin: 6px 0 0; }

/* ---------- Trang danh sách / quản trị ---------- */
.page { height: 100%; overflow-y: auto; padding: 24px 28px; }
.page h1 { margin: 0 0 4px; font-size: 22px; }
.page .lead { color: var(--muted); margin: 0 0 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; }
.card > h2 { margin: 0; padding: 14px 16px; font-size: 15px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card > h2 .right { margin-left: auto; }
.card .body { padding: 14px 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }
td .mono, .mono { font-family: ui-monospace, Consolas, monospace; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; font-size: 13px; }
.kv .k { color: var(--muted); }
.online { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.offline { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); margin-right: 6px; }

/* ---------- Đăng nhập ---------- */
.login { display: grid; place-items: center; height: 100vh; padding: 16px; }
.login .box { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
.login h1 { margin: 12px 0 4px; font-size: 22px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; }
.login .dev { margin-top: 20px; padding-top: 16px; border-top: 1px dashed var(--line-2); display: grid; gap: 8px; }
.login .dev .lbl { font-size: 12px; color: var(--muted); }

/* ---------- Hộp thoại + thông báo ---------- */
.modal-bg { position: fixed; inset: 0; background: rgb(0 0 0 / .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal.wide { max-width: 760px; }
.modal h2 { margin: 0; padding: 16px 18px; border-bottom: 1px solid var(--line); font-size: 16px; }
.modal .body { padding: 16px 18px; }
.modal .foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.lightbox { max-width: 92vw; max-height: 92vh; border-radius: 8px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; }
#toast .t { background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 90vw; }
#toast .t.err { background: var(--danger); }

/* ---------- Màn hình hẹp ---------- */
@media (max-width: 1200px) {
  .inbox { grid-template-columns: 300px 1fr 360px; }
}
@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail { flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line); order: 2; padding: 4px 8px; }
  .rail .logo, .rail .spacer { display: none; }
  .view { height: calc(100vh - 53px); }
  .inbox { grid-template-columns: 1fr; }
  .inbox > .pane { display: none; }
  .inbox[data-show="list"] > .list-pane, .inbox[data-show="chat"] > .chat-pane, .inbox[data-show="side"] > .side { display: flex; }
  .mobile-only { display: inline-flex !important; }
  .page { padding: 16px; }
  .kv { grid-template-columns: 1fr; }
}
.mobile-only { display: none !important; }
