/* ==============================================================================
   web/style.css — eDrop
   Màu nhấn: xanh dương của logo eDrop (#0159E4); nền xám ánh xanh.
   Bố cục: thanh trên + tab gạch chân, nội dung rộng tối đa 1200px, bảng là bề mặt chính;
   tạo listing mở ngăn kéo bên phải; trang /admin có cột điều hướng trái.
   ============================================================================== */

:root {
  --gutter: clamp(16px, 2.5vw, 40px); /* lề trái/phải co giãn theo trình duyệt, không còn khung 1200px */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --border: #dde3ec;
  --fg: #111827;
  --muted: #5b6678;
  --accent: #0159e4;
  --accent-hover: #0148b8;
  --accent-fg: #ffffff;
  --accent-soft: #e8f0fd;
  --ok: #1d7348;
  --ok-soft: #e3f3ea;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --danger: #b42318;
  --danger-soft: #fbe9e7;
  --focus: #2f7cf6;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --scrim: rgb(10 16 28 / 42%);
  /* Trạng thái đơn (nền nhạt để chữ mặc định nổi; dải màu trái giúp phân biệt kể cả khi khó nhìn màu) */
  --emerald: #0d7a5f;
  --emerald-soft: #ddf4ec;
  --st-ordered-bg: #eef4ff;
  --st-ordered-bar: #5b8def;
  --st-shipped-bg: #e9f8f2;
  --st-shipped-bar: #1fa67a;
  --st-delivered-bg: #eef8e6;
  --st-delivered-bar: #5aa832;
  --st-cancelled-bg: #f1f2f4;

  --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 8px;
  --radius-sm: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e131a;
    --surface: #141a23;
    --surface-2: #1a212c;
    --border: #2a3342;
    --fg: #e6ebf3;
    --muted: #94a0b3;
    --accent: #6aa4ff;
    --accent-hover: #8bb8ff;
    --accent-fg: #06172f;
    --accent-soft: #172845;
    --ok: #5cc48d;
    --ok-soft: #133022;
    --warn: #e0a54a;
    --warn-soft: #33270f;
    --danger: #f07a6c;
    --danger-soft: #3a1a17;
    --focus: #8bb8ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 30%);
    --scrim: rgb(0 0 0 / 55%);
    --emerald: #4fd1a5;
    --emerald-soft: #113128;
    --st-ordered-bg: #152238;
    --st-ordered-bar: #5b8def;
    --st-shipped-bg: #102b25;
    --st-shipped-bar: #2bbd8b;
    --st-delivered-bg: #172a12;
    --st-delivered-bar: #6cc040;
    --st-cancelled-bg: #1b2028;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e131a;
  --surface: #141a23;
  --surface-2: #1a212c;
  --border: #2a3342;
  --fg: #e6ebf3;
  --muted: #94a0b3;
  --accent: #6aa4ff;
  --accent-hover: #8bb8ff;
  --accent-fg: #06172f;
  --accent-soft: #172845;
  --ok: #5cc48d;
  --ok-soft: #133022;
  --warn: #e0a54a;
  --warn-soft: #33270f;
  --danger: #f07a6c;
  --danger-soft: #3a1a17;
  --focus: #8bb8ff;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 30%);
  --scrim: rgb(0 0 0 / 55%);
  --emerald: #4fd1a5;
  --emerald-soft: #113128;
  --st-ordered-bg: #152238;
  --st-ordered-bar: #5b8def;
  --st-shipped-bg: #102b25;
  --st-shipped-bar: #2bbd8b;
  --st-delivered-bg: #172a12;
  --st-delivered-bar: #6cc040;
  --st-cancelled-bg: #1b2028;
  color-scheme: dark;
}

/* ---------- Nền tảng ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 14px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; text-wrap: balance; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--accent); }
img { max-width: 100%; }
code, .mono { font-family: var(--font-mono); font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg);
  font: 500 13.5px/1 var(--font-sans); cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--fg); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-sm { min-height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; }
.btn[aria-busy="true"] { position: relative; color: transparent; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--muted); border-right-color: transparent; animation: spin .8s linear infinite;
}
.btn-primary[aria-busy="true"]::after { border-color: var(--accent-fg); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Form ---------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
/* V2: "Đủ các biến thể" / "Chỉ biến thể" — nút tròn, chỉ chọn 1 */
.scope-choice { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px 10px; margin: 0; }
.scope-choice legend { padding: 0 4px; }
.scope-option { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; color: var(--fg); cursor: pointer; min-width: 0; }
.scope-option input { width: 16px; height: 16px; margin: 0; flex: none; accent-color: var(--accent); }
.scope-option span { min-width: 0; overflow-wrap: anywhere; }
.scope-option input:disabled + span { color: var(--muted); cursor: default; }
input[type="text"], input[type="url"], input[type="number"], input[type="password"], input[type="search"], select, textarea {
  width: 100%; min-height: 36px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--fg);
  font: 400 14px/1.4 var(--font-sans);
}
textarea { resize: vertical; font-family: var(--font-mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-grid { display: grid; gap: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: none; margin: 0 auto; padding-inline: var(--gutter);
  display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15.5px; color: var(--fg); text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.brand small { font-weight: 500; color: var(--muted); font-size: 12px; border-left: 1px solid var(--border); padding-left: 10px; }
.topbar-spacer { flex: 1; }
.account-picker { display: flex; align-items: center; gap: 8px; min-width: 0; }
.account-picker select { min-width: 0; width: 260px; max-width: 100%; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px; text-transform: uppercase;
}

.tabs { max-width: none; margin: 0 auto; padding-inline: var(--gutter); display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 12px; border: 0; background: none; color: var(--muted);
  font: 500 13.5px/1 var(--font-sans); cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; inset: auto 8px 0; height: 2px; background: var(--accent); border-radius: 2px; }
.count {
  min-width: 18px; height: 18px; padding: 0 6px; border-radius: 9px;
  display: inline-grid; place-items: center; font-size: 11px; font-weight: 600;
  background: var(--danger-soft); color: var(--danger);
}

/* ---------- Nội dung ---------- */
.page { max-width: none; margin: 0 auto; padding: 24px var(--gutter) 48px; display: grid; gap: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 4px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-body { padding: 16px; display: grid; gap: 14px; }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; min-width: 960px; border-collapse: collapse; font-size: 13.5px; } /* hẹp hơn mức này thì bảng tự cuộn ngang trong .table-wrap */
table.data th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); letter-spacing: .02em;
  padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.data .right { text-align: right; }
.product { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.thumb { width: 44px; height: 44px; border-radius: var(--radius-sm); object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); flex: none; }
.thumb-empty { display: grid; place-items: center; color: var(--muted); }
.product-title { font-weight: 500; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Trạng thái ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 11px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Trạng thái rỗng ---------- */
.empty { padding: 40px 24px; text-align: center; display: grid; justify-items: center; gap: 10px; color: var(--muted); }
.empty h3 { color: var(--fg); }
.empty p { max-width: 52ch; }
.empty .icon { width: 28px; height: 28px; stroke-width: 1.5; }

/* ---------- Cảnh báo ---------- */
.alert-list { display: grid; gap: 8px; }
.alert-item {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 14px; align-items: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 14px 0; overflow: hidden;
}
.alert-item .stripe { align-self: stretch; margin-block: -14px; background: var(--warn); }
.alert-item[data-severity="CRITICAL"] .stripe, .alert-item[data-severity="ERROR"] .stripe { background: var(--danger); }
.alert-item[data-severity="INFO"] .stripe { background: var(--accent); }
.alert-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.notice {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius);
  background: var(--accent-soft); color: var(--fg); font-size: 13px;
}
.notice .icon { color: var(--accent); margin-top: 2px; }
.notice-warn { background: var(--warn-soft); }
.notice-warn .icon { color: var(--warn); }

/* ---------- Đăng nhập ---------- */
.auth-screen { min-height: 100%; display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: min(380px, 100%); display: grid; gap: 20px; }
.auth-card .panel-body { padding: 24px; gap: 16px; }
.auth-brand { display: grid; justify-items: center; gap: 10px; text-align: center; }
.auth-brand img { width: 52px; height: 52px; }
.auth-brand p { color: var(--muted); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; gap: 3px; background: var(--surface-2); border-radius: var(--radius-sm); }
.segmented button { border: 0; background: transparent; padding: 7px; border-radius: 4px; font: 500 13px var(--font-sans); color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.form-error { color: var(--danger); font-size: 13px; min-height: 1em; }
.auth-foot { text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Ngăn kéo (tạo listing) ---------- */
.drawer-scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; }
.drawer {
  position: fixed; inset: 0 0 0 auto; width: min(560px, 100%); z-index: 41;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  display: grid; grid-template-rows: auto 1fr auto;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-body { overflow-y: auto; padding: 20px; display: grid; gap: 20px; align-content: start; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.section-title { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.summary { display: grid; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.summary-row { display: grid; grid-template-columns: 140px 1fr; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.summary-row:last-child { border-bottom: 0; }
.summary-row dt { color: var(--muted); }
.summary-row dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.metric { background: var(--surface); padding: 12px 14px; display: grid; gap: 2px; }
.metric .label { font-size: 12px; }
.metric strong { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric[data-tone="ok"] strong { color: var(--ok); }
.metric[data-tone="danger"] strong { color: var(--danger); }
.warnings { margin: 0; padding-left: 18px; color: var(--warn); font-size: 13px; display: grid; gap: 4px; }
.gallery { display: flex; gap: 8px; overflow-x: auto; }
.gallery img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); flex: none; }
.gallery img.cover { border: 2px solid var(--accent); }

/* ---------- Hộp thoại ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(440px, calc(100% - 32px));
  background: var(--surface); color: var(--fg); box-shadow: var(--shadow);
  overflow: visible; /* danh sách gợi ý của ô chọn không bị cắt */
}
dialog::backdrop { background: var(--scrim); }
.dialog-body { padding: 20px; display: grid; gap: 14px; }
.dlg-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dlg-title-row h3 { margin: 0; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#dlg-edit { width: min(560px, calc(100vw - 32px)); }
.dialog-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 60; display: grid; gap: 8px; width: min(380px, calc(100% - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius);
  background: var(--fg); color: var(--bg); box-shadow: var(--shadow); font-size: 13.5px; animation: toast-in .18s ease-out;
}
.toast[data-tone="error"] { background: var(--danger); color: #fff; }
.toast .icon { margin-top: 2px; }
.toast span { min-width: 0; overflow-wrap: anywhere; }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }

/* ---------- Admin ---------- */
.admin-layout { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: start; }
.side-nav { position: sticky; top: calc(72px + env(safe-area-inset-top, 0px)); display: grid; gap: 2px; }
.side-nav button {
  display: flex; align-items: center; gap: 10px; text-align: left; padding: 9px 12px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); font: 500 13.5px var(--font-sans); cursor: pointer;
}
.side-nav button:hover { background: var(--surface-2); color: var(--fg); }
.side-nav button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.admin-main { display: grid; gap: 16px; min-width: 0; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.status-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; }
.status-card .label { font-size: 12px; }
.status-card .detail { font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.result-box {
  margin: 0; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2);
  font-family: var(--font-mono); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere;
}

/* ---------- Nguồn, ghi chú (tab Listing) ---------- */
.source-link { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); text-decoration: none; font-weight: 500; white-space: nowrap; }
.source-link:hover { text-decoration: underline; }
.source-link .icon { width: 13px; height: 13px; }
.source-link .src-ico { width: 18px; height: 18px; display: block; border-radius: 4px; }
.ali-ico { width: 14px; height: 14px; flex: none; }
.source-preview {
  position: fixed; z-index: 70; display: grid; gap: 6px; width: 184px; padding: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  pointer-events: none;
}
.source-preview img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-2); }
.source-preview span { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
th.note-col, td.note-col { width: 220px; min-width: 180px; }
.note-view { display: grid; gap: 2px; justify-items: start; }
.note-text { margin: 0; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.note-time { font-size: 11.5px; color: var(--muted); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font: 500 12.5px var(--font-sans); cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.note-editor { display: grid; gap: 6px; }
.note-editor textarea { font-family: var(--font-sans); font-size: 13px; min-height: 64px; }
.note-actions { display: flex; align-items: center; gap: 6px; }
.note-count { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.draft-row td { background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }

/* ---------- Ô chọn có tìm kiếm ---------- */
.combo-box { position: relative; }
.combo-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 5; margin: 0; padding: 4px; list-style: none;
  max-height: 240px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.combo-list li { display: grid; gap: 1px; padding: 7px 9px; border-radius: 4px; cursor: pointer; }
.combo-list li[aria-selected="true"], .combo-list li:hover { background: var(--accent-soft); }
.combo-name { font-weight: 500; }
.combo-id { font-size: 12px; color: var(--muted); }
.combo-empty { color: var(--muted); cursor: default !important; }

/* ---------- Màn hình hẹp ---------- */
@media (max-width: 760px) {
  .topbar-inner { gap: 10px; padding-block: 8px; }
  .account-picker { order: 3; width: 100%; }
  .account-picker select { width: 100%; }
  .brand small { display: none; }
  .admin-layout { grid-template-columns: 1fr; }
  .side-nav { position: static; grid-auto-flow: column; overflow-x: auto; scrollbar-width: none; }
  .side-nav button { white-space: nowrap; }
  .metrics { grid-template-columns: 1fr; }
  .summary-row { grid-template-columns: 1fr; gap: 2px; }
  table.data th, table.data td { padding-inline: 12px; }
  .hide-sm { display: none; } /* nút chỉ còn icon, tooltip giữ tên */
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Bộ lọc bảng ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 12px; }
.filters input[type="search"] { flex: 1 1 240px; min-width: 0; }
.filters select { flex: 0 1 auto; width: auto; }
.filter-count { font-size: 12px; margin-left: auto; }

/* ---------- Đơn hàng ---------- */
.pill-emerald { background: var(--emerald-soft); color: var(--emerald); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0 0 10px; font-size: 12px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item::before { content: ""; width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--border); border-left-width: 4px; background: var(--surface); }
.legend-item[data-state="ORDERED"]::before { background: var(--st-ordered-bg); border-left-color: var(--st-ordered-bar); }
.legend-item[data-state="SHIPPED"]::before { background: var(--st-shipped-bg); border-left-color: var(--st-shipped-bar); }
.legend-item[data-state="DELIVERED"]::before { background: var(--st-delivered-bg); border-left-color: var(--st-delivered-bar); }
.order-row td { vertical-align: top; }
.order-row td:first-child { box-shadow: inset 4px 0 0 transparent; }
.order-row[data-state="ORDERED"] td { background: var(--st-ordered-bg); }
.order-row[data-state="ORDERED"] td:first-child { box-shadow: inset 4px 0 0 var(--st-ordered-bar); }
.order-row[data-state="SHIPPED"] td { background: var(--st-shipped-bg); }
.order-row[data-state="SHIPPED"] td:first-child { box-shadow: inset 4px 0 0 var(--st-shipped-bar); }
.order-row[data-state="DELIVERED"] td { background: var(--st-delivered-bg); }
.order-row[data-state="DELIVERED"] td:first-child { box-shadow: inset 4px 0 0 var(--st-delivered-bar); }
.order-row[data-state="CANCELLED"] td { background: var(--st-cancelled-bg); color: var(--muted); }
.order-row .pill, .order-row .link-btn, .order-row .btn { margin-top: 6px; }
.address { margin: 0; font: 13px/1.45 var(--font-sans); white-space: pre-wrap; word-break: break-word; }
.address-cell { min-width: 180px; }
.recipient-line { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 2px; }
.recipient-name { font-weight: 600; color: var(--fg); font-size: 13px; }
.copy-raw-btn { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; padding: 0; border: none; background: transparent; color: var(--muted); border-radius: 4px; cursor: pointer; transition: all .15s; flex-shrink: 0; }
.copy-raw-btn:hover { color: var(--accent); background: var(--surface-2); }
.copy-raw-btn.copied { color: var(--ok); }
.copy-raw-btn .icon { width: 14px; height: 14px; }

/* Dropdown trạng thái xử lý đơn hàng */
.status-select-wrap { position: relative; display: inline-flex; align-items: center; margin-top: 6px; }
.status-select-wrap::before { content: ""; position: absolute; left: 9px; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); pointer-events: none; z-index: 1; }
.status-select-wrap[data-tone="pill-accent"]::before { background: var(--accent); }
.status-select-wrap[data-tone="pill-danger"]::before { background: var(--danger); }
.status-select {
  cursor: pointer; border: 1px solid var(--border); height: 24px; line-height: 22px;
  padding: 0 22px 0 20px; border-radius: 12px; font-family: inherit; font-size: 12px; font-weight: 500; outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath fill='none' stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.2' d='m1 1 3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 7px center;
  appearance: none; -webkit-appearance: none; -moz-appearance: none; transition: all .15s;
  background-color: var(--surface-2); color: var(--muted);
}
.status-select.pill-accent { background-color: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.status-select.pill-danger { background-color: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.status-select:hover { filter: brightness(0.97); }
.status-select:focus { box-shadow: 0 0 0 2px var(--accent-soft); }
.status-select option { background: var(--surface); color: var(--fg); font-size: 13px; padding: 4px; }

/* Bảng đơn: cột co giãn theo bề ngang trang (table-layout fixed + colgroup %), mỗi ô tối đa 3 dòng, dài quá thì "…" */
table.data.orders { table-layout: fixed; min-width: 1100px; }
.orders th, .orders td { padding-left: 12px; padding-right: 12px; }
.orders td { padding-top: 10px; padding-bottom: 10px; }
.ol { height: 22px; line-height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ol.strong { font-weight: 500; }
.ol-flex { display: flex; align-items: center; gap: 4px; }
.ol-flex .recipient-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ol-stack { flex: 1; min-width: 0; }
.orders .product { min-width: 0; gap: 10px; }
.orders .thumb { width: 56px; height: 56px; }
.orders .ol .link-btn, .orders .ol .btn, .orders .pill, .orders .status-select-wrap { margin-top: 0; }
.ol.ol-btn { overflow: visible; }
.btn-tight { height: 22px; min-height: 0; padding: 0 8px; font-size: 12px; line-height: 20px; box-sizing: border-box; }
.orders .status-select { height: 22px; line-height: 20px; min-width: 124px; }
.cost-frozen { margin-left: 6px; font-size: 12px; color: var(--muted); }
.cost-frozen.cost-drift { color: var(--warn); }
.buyer-multi { color: var(--warn); font-size: 12px; }
.profit { font-size: 14px; font-weight: 600; }
.profit.pos { color: var(--ok); }
.profit.neg { color: var(--danger); }
/* Cột tracking không cao hơn 3 dòng của các cột khác (66px): ô chìm 3 dòng 21px; ô nhập 2 hàng (hãng / số + Lưu) */
.tracking-sunk { padding: 0 8px; border: 1px dashed var(--border); border-radius: var(--radius-sm); background: color-mix(in srgb, var(--surface-2) 70%, transparent); opacity: .85; cursor: default; }
.tracking-sunk .ol { height: 21px; line-height: 21px; }
.tracking-sunk .pill { height: 18px; font-size: 11.5px; }
.tracking-form { display: grid; gap: 6px; }
.tracking-form input[type="text"] { width: 100%; min-width: 0; min-height: 0; height: 28px; padding: 0 8px; font-size: 13px; }
.tracking-actions { display: flex; gap: 4px; align-items: center; }
.tracking-actions .btn { height: 28px; min-height: 0; margin-top: 0; padding: 0 10px; flex: none; }
.btn.copied { border-color: var(--ok); color: var(--ok); }
.small { font-size: 12px; }

/* Nút key AdsPower: chấm báo chưa nhập key */
#btn-adspower-key { position: relative; }
#btn-adspower-key .dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }

@media (max-width: 760px) {
  .filter-count { margin-left: 0; }
}

/* ---------- Nguồn listing, hàng chờ draft, ghép extension ---------- */
.row-actions { flex-wrap: wrap; justify-content: flex-end; }
.source-missing { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.source-card { display: grid; grid-template-columns: 96px 1fr; gap: 12px; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-top: 8px; }
.source-card img { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-2); }
.source-card-body { display: grid; gap: 8px; min-width: 0; align-content: start; }
.source-card-body strong { overflow-wrap: anywhere; font-size: 13px; }
.queue-full { color: var(--danger); font-weight: 600; }
.missing-fields { display: grid; gap: 8px; margin-top: 8px; }
.missing-fields label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.check-box { display: grid; gap: 8px; justify-items: start; border-top: 1px solid var(--border); padding-top: 12px; }
.check-box .hint { margin: 0; font-size: 12px; color: var(--muted); }
.check-result { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; width: 100%; }
.check-result li { border: 1px solid var(--border); border-left-width: 4px; border-radius: var(--radius-sm); padding: 6px 10px; font-size: 13px; overflow-wrap: anywhere; }
.check-result li[data-tone="ok"] { border-left-color: var(--ok); background: var(--ok-soft); }
.check-result li[data-tone="error"] { border-left-color: var(--danger); background: var(--danger-soft); }
.check-result li[data-tone="warn"] { border-left-color: var(--warn); background: var(--warn-soft); }
@media (max-width: 760px) { .source-card { grid-template-columns: 1fr; } }
#listings-tbody td:last-child { min-width: 250px; }
#listings-tbody .row-actions { max-width: 280px; margin-left: auto; }

/* Chữ chìm nhận diện tác giả: góc phải dưới, không chặn thao tác */
.watermark { position: fixed; right: 10px; bottom: 6px; z-index: 5; font-size: 11px; line-height: 1; color: var(--muted); opacity: .5; user-select: none; pointer-events: none; letter-spacing: .02em; }

/* Hộp Sửa listing: ô lãi đổi màu theo lãi/lỗ, lỗi eBay hiện từng dòng */
#edit-margin-box[data-tone="ok"] #edit-profit { color: var(--ok); font-weight: 600; }
#edit-margin-box[data-tone="danger"] #edit-profit { color: var(--danger); font-weight: 600; }
#edit-errors { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
#edit-errors:empty { display: none; }
#edit-errors li { border: 1px solid var(--border); border-left: 4px solid var(--danger); background: var(--danger-soft); border-radius: var(--radius-sm); padding: 6px 10px; font-size: 13px; color: var(--fg); overflow-wrap: anywhere; }
/* Ghi chú: nháy đúp để sửa */
td.note-dbl { cursor: text; }
td.note-dbl .note-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

#dlg-edit .field > .link-btn { justify-self: start; }
/* Phiên bản + thời điểm deploy ở góc dưới trái (cùng kiểu chữ chìm với watermark) */
#release-badge { position: fixed; left: 10px; bottom: 6px; z-index: 5; font-size: 11px; line-height: 1; color: var(--muted); opacity: .7; pointer-events: none; font-variant-numeric: tabular-nums; }
.update-pill { border: 0; cursor: pointer; font: inherit; }
.update-pill:disabled { opacity: .6; cursor: progress; }

/* Mẫu mô tả + xem trước (iframe sandbox, không script) */
.template-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
/* Khu "Mẫu mô tả": nền xanh nhạt + dải trái màu nhấn, để user thấy đây là nơi chọn và xem trước mô tả. */
.summary-row.template-highlight { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.summary-row.template-highlight dt { color: var(--accent); font-weight: 600; }
.summary-row.template-highlight select { background: var(--surface); }

/* Trạng thái lấy dữ liệu sản phẩm trong ngăn kéo (thay nút "Lấy dữ liệu sản phẩm"). */
.fetch-status { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; min-height: 28px; font-size: 13.5px; }
.fetch-status[data-state="idle"] { min-height: 0; }
.fetch-loading, .fetch-done { display: inline-flex; align-items: center; gap: 8px; }
.fetch-loading { color: var(--muted); }
.fetch-done { color: var(--ok); font-weight: 500; }
.fetch-done .icon { width: 16px; height: 16px; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; flex: 0 0 16px;
  border: 2px solid var(--accent); border-right-color: transparent; animation: spin .8s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
/* Bộ đếm ảnh lên eBay ở chân ngăn kéo: đang đưa / sẵn sàng / còn thiếu. */
.image-progress { margin-right: auto; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-width: 0; }
.image-progress[data-tone="ok"] { color: var(--ok); font-weight: 500; }
.image-progress[data-tone="warn"] { color: var(--warn); }
/* Ảnh đã lên eBay đủ: chỉ một dấu tích trong vòng tròn xanh (không thanh tiến độ — dễ nhầm với thanh trượt ngang). */
.img-ready { width: 24px; height: 24px; border-radius: 50%; background: var(--ok); color: #fff; display: inline-grid; place-items: center; flex: 0 0 24px; }
.img-ready .icon { width: 15px; height: 15px; stroke-width: 3; }
.template-row select { min-width: 0; max-width: 100%; }
.dlg-desc { width: min(1060px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 16px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.dlg-head h2 { margin: 0; font-size: 18px; }
.desc-frame-wrap { display: flex; justify-content: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px; overflow: auto; }
#desc-frame { width: 980px; max-width: 100%; height: min(70vh, 900px); border: 0; background: #fff; }
.desc-sizes { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }

.item-link:hover { color: var(--accent); text-decoration: underline; }

/* /admin › Nguồn hàng */
label.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 4px 0 12px; }
p.error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 6px 0 0; }
table.data.compact { min-width: 640px; } /* bảng ít cột ở /admin */
.store-test-result { min-width: 0; }
.store-test-summary { display: grid; gap: 4px; margin: 12px 0; font-size: 13.5px; }
.store-test-summary .warn { color: var(--danger); }

/* Bảng biến thể (draft shop nguồn mới) */
.plan-section { display: grid; gap: 10px; min-width: 0; }
.plan-counters { margin: 0; font-size: 13.5px; }
.plan-counters[data-tone="danger"] { color: var(--danger); }
.plan-mapping { display: grid; gap: 6px; font-size: 13.5px; }
.plan-map-row { display: grid; gap: 6px; }
.plan-map-values { display: flex; flex-wrap: wrap; gap: 8px; }
.plan-map-value { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.plan-map-value input { width: 140px; min-width: 0; }
.plan-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.plan-tools input[type="search"] { flex: 1 1 200px; min-width: 0; }
.plan-tools input[type="number"] { width: 90px; }
.plan-tools .check { margin: 0; }
table.data.plan-table { min-width: 860px; }
/* Bảng biến thể dài: thanh trượt ngang gốc (ở cuối bảng) ẩn đi, thay bằng .plan-hscroll dính đáy ngăn kéo, đồng bộ hai chiều. */
.plan-table-wrap { scrollbar-width: none; }
.plan-table-wrap::-webkit-scrollbar { display: none; }
.plan-hscroll {
  position: sticky; bottom: -20px; z-index: 2; padding: 6px 0 8px;
  box-shadow: -20px 0 0 var(--surface), 20px 0 0 var(--surface), -20px 1px 0 var(--border), 20px 1px 0 var(--border); /* nền phủ cả lề ngăn kéo; tầm cuộn = đúng bảng */
  overflow-x: auto; overflow-y: hidden; background: var(--surface); border-top: 1px solid var(--border);
}
.plan-hscroll > div { height: 1px; }
.plan-table td { vertical-align: middle; }
.plan-table input[type="number"] { width: 84px; min-height: 0; height: 30px; padding: 0 6px; }
.plan-table input[type="checkbox"] { width: 16px; height: 16px; }
.plan-table tr.plan-off td { color: var(--muted); }
.plan-thumb img { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; display: block; }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger); }
table.data.edit-var-table { min-width: 480px; } /* bảng biến thể trong dialog Sửa */
.category-picker { display: grid; gap: 6px; margin-top: 8px; }
.category-results { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.category-results button { width: 100%; text-align: left; background: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; color: var(--fg); font: inherit; cursor: pointer; }
.category-results button:hover, .category-results button:focus-visible { border-color: var(--accent); }
ol.steps { margin: 6px 0; padding-left: 20px; display: grid; gap: 4px; }
.device-list { margin: 8px 0; padding-left: 18px; display: grid; gap: 4px; }
.device-list li[data-tone="warn"] { color: var(--warn); }
.device-list li[data-tone="ok"] { color: var(--ok); }
.device-list li[data-tone="muted"] { color: var(--muted); }

/* Cổng checkout: nhãn ở tab Đơn hàng eDrop (docs/13-CHECKOUT-PLAN.md) */
.checkout-pill { background: var(--accent-soft); color: var(--accent); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.checkout-pill[data-state="TRACKING_VALID"] { background: var(--ok-soft); color: var(--ok); }
.checkout-pill[data-state="TRACKING_PENDING"], .checkout-pill[data-state="PENDING_REVIEW"] { background: var(--warn-soft); color: var(--warn); }
.checkout-pill[data-state="TRACKING_INVALID"] { background: var(--danger-soft); color: var(--danger); }
.checkout-pill[data-state="CANCELLED"] { background: var(--surface-2); color: var(--muted); }
.ck-store-checks { display: flex; flex-wrap: wrap; gap: 6px 14px; border: 0; padding: 0; margin: 0; }
.ck-store-checks legend { width: 100%; margin-bottom: 4px; }
.ck-rate-input { width: 130px; font-family: var(--font-mono); }
