:root {
  --brand: #4f5bd5;
  --brand-dark: #3d47b8;
  --bg: #f4f5fb;
  --panel: #ffffff;
  --border: #e6e8f0;
  --text: #1f2333;
  --muted: #8a90a6;
  --green: #1fbf75;
  --red: #e5484d;
  --amber: #f5a524;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(30, 35, 60, .06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }
.hidden { display: none !important; }

/* ---------- Đăng nhập ---------- */
#login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f5bd5, #7b5fe0);
}
.login-card {
  background: #fff; padding: 40px; border-radius: 16px; width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; color: var(--brand); }
.login-card p { color: var(--muted); margin-bottom: 24px; }
.login-card label { display: block; margin: 14px 0 6px; font-weight: 600; }
.login-card input {
  width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px;
}
.login-card button {
  width: 100%; margin-top: 24px; padding: 12px; border: none; border-radius: 10px;
  background: var(--brand); color: #fff; font-weight: 600; font-size: 15px;
}
.login-card button:hover { background: var(--brand-dark); }
.login-error { color: var(--red); margin-top: 12px; font-size: 13px; }

/* ---------- Khung chính ---------- */
#app { display: flex; height: 100vh; }
.sidebar {
  width: 76px; background: var(--brand); color: #fff; display: flex;
  flex-direction: column; align-items: center; padding: 16px 0; gap: 6px;
}
.sidebar .logo { font-size: 26px; margin-bottom: 20px; }
.nav-item {
  width: 52px; height: 52px; border-radius: 12px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: #fff; background: transparent;
  border: none; font-size: 11px; gap: 3px; opacity: .8;
}
.nav-item .ic { font-size: 20px; }
.nav-item:hover { background: rgba(255,255,255,.15); opacity: 1; }
.nav-item.active { background: rgba(255,255,255,.25); opacity: 1; }
.sidebar .spacer { flex: 1; }

.main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.topbar {
  height: 56px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 16px; flex-shrink: 0;
}
.topbar h2 { font-size: 17px; }
.topbar .grow { flex: 1; }
.user-chip { color: var(--muted); font-size: 13px; }
.user-chip b { color: var(--text); }
.btn {
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: #fff; font-weight: 600; color: var(--text);
}
.btn:hover { background: #f7f8fc; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--red); border-color: #f3c9ca; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.view { flex: 1; overflow: auto; padding: 20px; }
.view.no-pad { padding: 0; }

/* ---------- Hội thoại 3 cột ---------- */
.chat-layout { display: flex; height: 100%; }
.conv-list { width: 320px; border-right: 1px solid var(--border); background: #fff;
  display: flex; flex-direction: column; }
.conv-list .search { padding: 12px; border-bottom: 1px solid var(--border); }
.conv-list .search input, .filter-bar select, .field input, .field textarea, .field select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
}
.conv-items { flex: 1; overflow: auto; }
.conv-item { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid #f0f1f6;
  cursor: pointer; align-items: center; }
.conv-item:hover { background: #f7f8fc; }
.conv-item.active { background: #eef0fb; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; flex-shrink: 0; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.conv-meta { flex: 1; min-width: 0; }
.conv-meta .row1 { display: flex; justify-content: space-between; }
.conv-meta .name { font-weight: 600; }
.conv-meta .time { color: var(--muted); font-size: 12px; }
.conv-meta .preview { color: var(--muted); font-size: 13px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--red); color: #fff; border-radius: 10px; padding: 1px 7px;
  font-size: 11px; font-weight: 700; }
.page-tag { font-size: 11px; color: var(--brand); background: #eef0fb; padding: 1px 6px;
  border-radius: 6px; }

.chat-main { flex: 1; display: flex; flex-direction: column; background: #fbfbfd; }
.chat-head { height: 56px; border-bottom: 1px solid var(--border); background: #fff;
  display: flex; align-items: center; padding: 0 16px; gap: 10px; }
.chat-head .grow { flex: 1; }
.messages { flex: 1; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 68%; padding: 9px 13px; border-radius: 14px; line-height: 1.4;
  white-space: pre-wrap; word-break: break-word; }
.msg.in { background: #fff; border: 1px solid var(--border); align-self: flex-start;
  border-bottom-left-radius: 4px; }
.msg.out { background: var(--brand); color: #fff; align-self: flex-end;
  border-bottom-right-radius: 4px; }
.msg.bot { background: #eafaf2; border: 1px solid #bfead4; color: #146c48; align-self: flex-end;
  border-bottom-right-radius: 4px; }
.msg .meta { font-size: 10px; opacity: .7; margin-top: 3px; }
.msg img { max-width: 220px; border-radius: 8px; display: block; }
.compose { border-top: 1px solid var(--border); background: #fff; padding: 12px;
  display: flex; gap: 10px; }
.compose textarea { flex: 1; resize: none; height: 44px; padding: 11px;
  border: 1px solid var(--border); border-radius: 10px; }
.empty { flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: var(--muted); gap: 10px; }
.empty .big { font-size: 44px; }

.info-panel { width: 300px; border-left: 1px solid var(--border); background: #fff;
  overflow: auto; padding: 18px; }
.info-panel h3 { margin-bottom: 12px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px;
  font-weight: 600; }

/* ---------- Bảng ---------- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { max-width: 240px; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid #f0f1f6; }
th { background: #f7f8fc; font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .03em; }
tr:hover td { background: #fafbff; }
.pill { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
  display: inline-block; }
.pill.new { background: #eef0fb; color: var(--brand); }
.pill.confirmed { background: #fff3d9; color: #b8790f; }
.pill.shipping { background: #e0f0ff; color: #1668c1; }
.pill.done { background: #e3f8ee; color: var(--green); }
.pill.cancel { background: #fdeaea; color: var(--red); }

/* ---------- Thống kê ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px; }
.card { background: #fff; padding: 18px; border-radius: var(--radius); box-shadow: var(--shadow); }
.card .k { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.card .v { font-size: 26px; font-weight: 700; }
.chart-box { background: #fff; padding: 20px; border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px; }
.chart-box h3 { margin-bottom: 16px; }
.bars { display: flex; gap: 12px; align-items: flex-end; height: 160px; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bars .bar { width: 60%; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 3px; }
.bars .lbl { font-size: 11px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(20,24,45,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 440px;
  max-height: 88vh; overflow: auto; }
.modal h3 { margin-bottom: 16px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.toast { position: fixed; bottom: 24px; right: 24px; background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: 10px; z-index: 100; box-shadow: var(--shadow); }
.toast.err { background: var(--red); }

.section-title { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.section-title .grow { flex: 1; }
.muted { color: var(--muted); }
.notice { background: #fff8e6; border: 1px solid #f5df9e; padding: 12px 14px;
  border-radius: 10px; color: #8a6d1a; margin-bottom: 16px; font-size: 13px; }
