:root {
  --bg: #eef2f9;
  --bg-grad-1: #eaf0fb;
  --bg-grad-2: #f6f8fc;
  --card: #ffffff;
  --ink: #1f2733;
  --muted: #6b7686;
  --brand: #2563eb;
  --brand-2: #4f46e5;
  --brand-ink: #fff;
  --brand-soft: #eef2ff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #f59e0b;
  --line: #e6e9f0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, .10), 0 2px 6px rgba(16, 24, 40, .06);
  --ring: 0 0 0 3px rgba(37, 99, 235, .18);
}
* { box-sizing: border-box; }
body {
  margin: 0; color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-grad-1), transparent 60%),
    radial-gradient(1000px 500px at -10% 0%, var(--bg-grad-2), transparent 55%),
    var(--bg);
  min-height: 100vh;
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 11px 20px;
  background: rgba(255, 255, 255, .82);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; letter-spacing: -.01em; font-size: 16px; }
.nav { display: flex; align-items: center; gap: 12px; }
.nav .who { color: var(--ink); font-size: 13px; font-weight: 600; }
.navlink { font-weight: 600; }
.navlink:hover { text-decoration: none; }

/* Avatar + chip người dùng trên topbar */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-weight: 700; font-size: 13px;
  box-shadow: 0 2px 6px rgba(37, 99, 235, .35);
}
.avatar.lg { width: 52px; height: 52px; font-size: 22px; }
.who-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  transition: box-shadow .15s ease, transform .15s ease;
}
.who-chip:hover { text-decoration: none; box-shadow: var(--shadow); transform: translateY(-1px); }

.container { max-width: 1160px; margin: 0 auto; padding: 22px 18px; }
.page-title { font-size: 22px; letter-spacing: -.02em; margin: 4px 0; }
.page-sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

/* Buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff;
  color: var(--ink); padding: 9px 15px; border-radius: 10px; cursor: pointer;
  font-size: 14px; font-weight: 600; line-height: 1;
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: var(--brand-ink); border-color: transparent;
  box-shadow: 0 4px 12px rgba(37, 99, 235, .28);
}
.btn.primary:hover { box-shadow: 0 8px 20px rgba(37, 99, 235, .34); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 6px; }
.inline { display: inline; }
form input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; margin: 6px 0 12px; font-size: 14px; background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
form input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
form input:disabled { background: #f1f4f9; color: var(--muted); cursor: not-allowed; }
form label { font-size: 13px; color: var(--muted); font-weight: 600; }
form label .opt { font-weight: 400; color: #9aa4b2; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row input { width: auto; flex: 1 1 160px; margin: 0; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.auth-card { max-width: 400px; margin: 7vh auto 0; box-shadow: var(--shadow-lg); }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.profile-head h1 { margin: 0; }
.hint { color: var(--muted); font-size: 13px; }
.alert { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca;
  padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.alert.info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.alert.ok { background: var(--ok-soft); color: #15803d; border-color: #86efac; }
.empty { color: var(--muted); padding: 18px; text-align: center; }

/* Trạng thái rỗng (không có đơn) */
.empty-state { background: var(--card); border: 1px dashed #d6dce8; border-radius: var(--radius);
  padding: 34px 20px; text-align: center; box-shadow: var(--shadow); }
.empty-state .empty-ic { font-size: 34px; display: block; margin-bottom: 8px; opacity: .85; }
.empty-state p { margin: 0; color: var(--muted); font-size: 14px; }

/* Hộp "Đồng bộ từ Telegram" trong Hồ sơ */
.sync-box { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 16px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: #f6f9ff; }
.sync-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sync-info .tg-ic { font-size: 20px; }
.sync-title { font-size: 12px; color: var(--muted); }
.sync-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sections */
.section { margin-bottom: 22px; }
.section-title { font-size: 16px; display: flex; align-items: center; gap: 8px; font-weight: 700;
  margin: 0 0 12px; }
.section-title .count { background: var(--brand-soft); color: var(--brand);
  border-radius: 999px; padding: 1px 10px; font-size: 12px; font-weight: 700; }
.toggle { cursor: pointer; }
summary.section-title { list-style: none; }
summary.section-title::-webkit-details-marker { display: none; }
summary.section-title::before { content: "▸"; color: var(--muted); font-size: 12px; }
details[open] > summary.section-title::before { content: "▾"; }

/* Order card (legacy layout) */
.orders { display: grid; gap: 12px; }
.order { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); }
.order-head { display: flex; align-items: center; gap: 10px; }
.carrier-ic { width: 34px; height: 34px; border-radius: 8px; object-fit: contain;
  display: flex; align-items: center; justify-content: center; }
.carrier-ic.emoji { font-size: 24px; }
.order-id { flex: 1; min-width: 0; }
.order-id .code { font-weight: 700; }
.order-id .name { color: var(--muted); font-size: 13px; }
.carrier-name { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Progress */
.progress { display: flex; align-items: flex-start; margin: 14px 2px 6px; }
.step { display: flex; flex-direction: column; align-items: center; width: 64px; text-align: center; }
.step .dot { width: 30px; height: 30px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 14px;
  background: #eef1f6; color: var(--muted); border: 2px solid var(--line); }
.step .dot img { width: 20px; height: 20px; object-fit: contain; }
.step.done .dot { background: var(--ok-soft); color: var(--ok); border-color: #86efac; }
.step.current .dot { background: var(--brand); color: #fff; border-color: var(--brand); }
.step-label { font-size: 11px; margin-top: 5px; color: var(--muted); }
.step.current .step-label { color: var(--brand); font-weight: 600; }
.bar { flex: 1; height: 3px; background: var(--line); margin-top: 15px; border-radius: 2px; }
.bar.filled { background: #86efac; }

.latest { margin-top: 8px; font-size: 14px; }
.timeline { margin-top: 8px; }
.timeline summary { cursor: pointer; color: var(--brand); font-size: 13px; }
.timeline ul { list-style: none; padding-left: 4px; margin: 8px 0 0; }
.timeline li { padding: 4px 0; border-left: 2px solid var(--line); padding-left: 10px; }
.timeline .t { color: var(--muted); font-size: 12px; margin-right: 6px; }

/* Admin */
.carrier-row .ic-preview { width: 30px; text-align: center; }
.carrier-row .ic-preview img { width: 26px; height: 26px; object-fit: contain; }
.carrier-row .cname { flex: 0 0 120px; }
table.users { width: 100%; border-collapse: collapse; }
table.users th, table.users td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.users th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

/* Animations cho chặng hiện tại */
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }
@keyframes truck { 0% { transform: translateX(-3px); } 50% { transform: translateX(3px); } 100% { transform: translateX(-3px); } }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
.anim-pulse { animation: pulse 1.2s ease-in-out infinite; }
.anim-truck-move { animation: truck 1.1s ease-in-out infinite; }
.anim-check { animation: pop .5s ease; }

@media (max-width: 520px) {
  .step { width: 52px; }
  .carrier-name { display: none; }
  .who .who { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ── Dashboard bảng: stats / filter / table / modal ─────────────────────── */

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px; margin: 4px 0 18px; }
.stat { position: relative; overflow: hidden; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease; }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--warn); }
.stat.ok::before { background: var(--ok); }
.stat.total::before { background: var(--brand); }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-num { font-size: 30px; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; }
.stat.ok .stat-num { color: var(--ok); }
.stat.total .stat-num { color: var(--brand); }

/* Filter bar */
.filter-bar { display: flex; align-items: center; gap: 8px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px; margin-bottom: 18px;
  box-shadow: var(--shadow); transition: border-color .15s ease, box-shadow .15s ease; }
.filter-bar:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
.filter-bar .fi { color: var(--muted); }
.filter-bar input { border: none; outline: none; width: 100%; padding: 9px 4px; margin: 0;
  background: transparent; font-size: 14px; }

/* Table */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); }
.orders-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 780px; }
.orders-table thead th { text-align: left; padding: 12px; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700;
  background: #fafbfe; border-bottom: 1px solid var(--line); white-space: nowrap;
  position: sticky; top: 0; }
.orders-table td { padding: 12px; border-bottom: 1px solid var(--line);
  vertical-align: top; }
.orders-table tbody tr:last-child td { border-bottom: none; }
.orders-table tbody tr { transition: background .12s ease; }
.orders-table tbody tr:hover { background: rgba(37, 99, 235, .045); }
.orders-table .code { font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.name-text { font-weight: 600; }
.carrier-tag { display: inline-block; background: var(--brand-soft); color: var(--brand);
  border-radius: 7px; padding: 3px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.orders-table img.carrier-ic { width: 30px; height: 30px; }
.src-tag { font-size: 10px; background: #e0e7ff; color: #3730a3; border-radius: 5px;
  padding: 1px 6px; margin-left: 6px; vertical-align: middle; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; }
.status-line { display: flex; align-items: center; gap: 8px; }
.dot-state { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none;
  box-shadow: 0 0 0 3px rgba(107, 118, 134, .15); }
.dot-state.s0 { background: var(--warn); box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.dot-state.s1 { background: #3b82f6; box-shadow: 0 0 0 3px rgba(59, 130, 246, .18); }
.dot-state.s2 { background: #8b5cf6; box-shadow: 0 0 0 3px rgba(139, 92, 246, .18); }
.dot-state.s3 { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, .18); }
.link-btn { background: none; border: none; color: var(--brand); cursor: pointer;
  font-size: 12px; padding: 4px 0 0; }
.ic-btn { background: none; border: none; cursor: pointer; font-size: 15px; padding: 4px 6px;
  border-radius: 8px; transition: background .12s ease; }
.ic-btn:hover { background: var(--line); }
.c-act { white-space: nowrap; }

/* Timeline panel trong hàng */
.timeline-d summary { cursor: pointer; color: var(--brand); font-size: 12px; margin-top: 6px;
  width: max-content; list-style: none; font-weight: 600; }
.timeline-d summary::-webkit-details-marker { display: none; }
.timeline-d summary::before { content: "▸ "; }
.timeline-d[open] summary::before { content: "▾ "; }
.timeline-panel { margin-top: 8px; padding: 12px; background: #f8fafc;
  border: 1px solid var(--line); border-radius: 10px; }
.progress.mini { display: flex; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 2px; }
.progress.mini .step { flex-direction: row; width: auto; gap: 4px; }
.progress.mini .pdot { width: 12px; height: 12px; border-radius: 50%; background: #cbd5e1; display: inline-block; }
.progress.mini .step.done .pdot { background: #86efac; }
.progress.mini .step.current .pdot { background: var(--brand); }
.progress.mini .plabel { font-size: 11px; color: var(--muted); }
.progress.mini .pbar { width: 18px; height: 2px; background: var(--line); }
.progress.mini .pbar.filled { background: #86efac; }
.timeline-panel .tl { list-style: none; margin: 0; padding: 0; }
.timeline-panel .tl li { padding: 4px 0 4px 12px; border-left: 2px solid var(--line); font-size: 13px; }
.timeline-panel .tl .t { color: var(--muted); font-size: 12px; margin-right: 6px; }
.note-line { margin-top: 8px; font-size: 13px; color: var(--muted); }

/* Modal */
.modal-backdrop[hidden] { display: none; }   /* [hidden] phải thắng display:flex bên dưới */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; }
.modal { background: var(--card); border-radius: 16px; width: 100%; max-width: 460px;
  box-shadow: 0 24px 60px rgba(2, 6, 23, .35); animation: modal-in .18s ease; }
@keyframes modal-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; max-height: 62vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px;
  border-top: 1px solid var(--line); }
.fld { margin-bottom: 12px; }
.fld label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.fld .opt { color: #9aa4b2; font-weight: 400; }
.fld input, .fld select { width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 14px; margin: 0; background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease; }
.fld input:focus, .fld select:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.form-msg { color: #b91c1c; font-size: 13px; min-height: 18px; margin: 4px 0 0; }

@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .container { padding: 16px 14px; }
  .nav .who { max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ── Chia sẻ: modal copy-row + trang công khai ───────────────────────────── */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font-size: 13px; font-family: ui-monospace, Menlo, monospace;
  background: #f8fafc; }
.copy-row input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.btn.danger-link { border: none; background: none; color: #b91c1c; padding-left: 0; }
.btn.danger-link:hover { box-shadow: none; text-decoration: underline; transform: none; }

.share-page { max-width: 560px; margin: 5vh auto 0; }
.public-card { padding: 22px; box-shadow: var(--shadow-lg); }
.pub-head { display: flex; align-items: center; gap: 12px; padding-bottom: 16px;
  border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.pub-head .carrier-ic { width: 44px; height: 44px; }
.pub-head .carrier-ic.emoji { font-size: 32px; }
.pub-id { flex: 1; min-width: 0; }
.pub-carrier { color: var(--muted); font-size: 13px; }
.pub-code { font-weight: 800; font-size: 18px; letter-spacing: -.01em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pub-badge { font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px;
  white-space: nowrap; background: var(--brand-soft); color: var(--brand); }
.pub-badge.s3 { background: var(--ok-soft); color: #15803d; }
.pub-status { display: flex; align-items: flex-start; gap: 10px; margin: 18px 0 6px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.pub-status .dot-state { margin-top: 5px; }
.pub-status-text { font-weight: 600; }
.pub-status-time { color: var(--muted); font-size: 12px; margin-top: 2px; }
.pub-h { font-size: 14px; margin: 18px 0 8px; }
.public-card .tl { list-style: none; margin: 0; padding: 0; }
.public-card .tl li { padding: 6px 0 6px 12px; border-left: 2px solid var(--line); font-size: 13px; }
.public-card .tl .t { color: var(--muted); font-size: 12px; margin-right: 6px; }
.pub-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }

.closed-card { text-align: center; padding: 40px 24px; }
.closed-card .closed-ic { font-size: 44px; display: block; margin-bottom: 10px; }
.closed-card h1 { margin: 0 0 8px; font-size: 20px; }
