/* Giao diện ứng dụng: thanh trên cố định, nội dung một cột tối đa 1080px, thẻ chỉ dùng cho khối thao tác. */
:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --fg: #1d1b18;
  --muted: #6c665d;
  --line: #e4e0d8;
  --accent: #c2410c;
  --accent-hover: #a5360a;
  --accent-soft: #fdece2;
  --on-accent: #ffffff;
  --ok: #2c7a4b;
  --ok-soft: #e3f3e9;
  --warn: #9a5b00;
  --warn-soft: #fdf2dc;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --fb: #1d4ed8; --tt: #111111; --th: #3f3f46; --ig: #be185d; --yt: #b91c1c;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06);
  --radius: 10px;
  --font-display: "Be Vietnam Pro", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141310; --surface: #1d1b17; --surface-2: #26231e; --fg: #ece8e1; --muted: #a69f93; --line: #332f29;
    --accent: #fb8a4c; --accent-hover: #ffa06a; --accent-soft: #3b2417; --on-accent: #1a0d05;
    --ok: #6cc391; --ok-soft: #173023; --warn: #e8b64a; --warn-soft: #33290f; --danger: #f2887e; --danger-soft: #3a1a17;
    --fb: #7aa2ff; --tt: #f4f4f5; --th: #d4d4d8; --ig: #f472b6; --yt: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.55 var(--font-body); }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, .mono { font-family: var(--font-mono); font-size: .9em; }
p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.h1 { font: 700 26px/1.2 var(--font-display); margin: 0 0 4px; letter-spacing: -.01em; text-wrap: balance; }
.h2 { font: 700 22px/1.25 var(--font-display); margin: 0 0 16px; }
.h3 { font: 600 16px/1.3 var(--font-display); margin: 0 0 14px; }
.h4 { font: 600 15px/1.35 var(--font-display); margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.break { word-break: break-all; }
.eyebrow { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.warn-text { color: var(--warn); }

/* ---------- Thanh trên ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar__inner {
  max-width: 1080px; margin: 0 auto; display: flex; align-items: center; gap: 24px; min-height: 58px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.brand { display: inline-flex; align-items: center; gap: 9px; font: 700 16px/1 var(--font-display); color: var(--fg); text-decoration: none; white-space: nowrap; }
.brand:hover { color: var(--fg); }
.brand__mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; flex: none; }
.brand__mark::after { content: ""; position: absolute; inset: 6px; border: 2.5px solid var(--on-accent); border-radius: 50%; border-right-color: transparent; transform: rotate(-45deg); }
.brand--lg { font-size: 20px; }
.nav { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav__link { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; white-space: nowrap; }
.nav__link:hover { color: var(--fg); background: var(--surface-2); }
.nav__link.is-active { color: var(--fg); background: var(--accent-soft); }
.account { display: flex; align-items: center; gap: 12px; white-space: nowrap; font-size: 14px; }
.account__name { color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.account__logout { color: var(--muted); }
@media (max-width: 760px) {
  .topbar__inner { flex-wrap: wrap; gap: 4px 12px; padding-block: 10px 0; }
  .brand { order: 1; }
  .account { order: 2; margin-left: auto; }
  .account__name { display: none; }
  .nav { order: 3; flex-basis: 100%; padding-bottom: 8px; }
  .nav__link { padding: 7px 9px; font-size: 14px; }
  .today { text-align: left; }
}

/* ---------- Bố cục ---------- */
.page {
  max-width: 1080px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 28px 64px; display: flex; flex-direction: column; gap: 20px;
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head > div { max-width: 640px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card--quiet { background: var(--surface-2); box-shadow: none; border-color: transparent; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.split { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; }
@media (max-width: 820px) { .split { grid-template-columns: 1fr; } }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 500; color: var(--muted); }
input[type=text], input[type=url], input[type=email], input[type=password], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field__hint { font-size: 12.5px; color: var(--muted); }
.field__error { font-size: 13px; color: var(--danger); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
details > summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 500; }
details > summary:hover { color: var(--fg); }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 14px;
  font: 600 14px/1 var(--font-body); border-radius: 8px; cursor: pointer; text-decoration: none; white-space: nowrap;
  color: var(--fg); background: var(--surface); border: 1px solid var(--line);
}
.btn:hover { border-color: var(--muted); color: var(--fg); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--on-accent); }
.btn--done { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.btn--done:hover { border-color: var(--ok); color: var(--ok); }
.btn--done.is-ready { background: var(--ok); color: var(--surface); box-shadow: 0 0 0 4px var(--ok-soft); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn--ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn--danger { color: var(--danger); }
.btn--danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn--sm { min-height: 32px; padding: 6px 10px; font-size: 13px; }
.btn--block { width: 100%; }
.btn[aria-disabled=true] { opacity: .45; pointer-events: none; }

/* ---------- Thông báo ---------- */
.flashes { display: flex; flex-direction: column; gap: 8px; }
.flash { padding: 11px 14px; border-radius: 8px; font-size: 14px; background: var(--surface-2); }
.flash--success { background: var(--ok-soft); color: var(--ok); }
.flash--error { background: var(--danger-soft); color: var(--danger); }
.flash--warning { background: var(--warn-soft); color: var(--warn); }
.notice { display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; padding: 16px 18px; border-radius: var(--radius); background: var(--warn-soft); color: var(--fg); }
.notice--inline { padding: 10px 12px; display: block; font-size: 14px; }
.empty { padding: 36px 16px; text-align: center; display: flex; flex-direction: column; gap: 4px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- Huy hiệu / thẻ ---------- */
.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge--facebook { color: var(--fb); }
.badge--tiktok { color: var(--tt); }
.badge--threads { color: var(--th); }
.badge--instagram { color: var(--ig); }
.badge--youtube { color: var(--yt); }
.count { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); font-size: 12px; font-variant-numeric: tabular-nums; text-align: center; }
.tags { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { font-size: 12.5px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }

/* ---------- Hàng đợi ---------- */
.today { margin: 0; text-align: right; }
.today dt { font-size: 12px; color: var(--muted); }
.today dd { margin: 0; font: 700 28px/1.1 var(--font-display); }
.add-form { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.add-form .field--url { grid-column: 1 / -1; }
.add-form .field--wide { grid-column: 1 / -1; }
.add-form__actions { grid-column: 1 / -1; }
@media (min-width: 900px) { .add-form .field--url { grid-column: auto; } }
@media (max-width: 640px) { .add-form { grid-template-columns: 1fr; } }
.bulk { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.bulk form { margin-top: 12px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs__item { padding: 10px 14px; color: var(--muted); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 8px; align-items: center; }
.tabs__item:hover { color: var(--fg); }
.tabs__item.is-active { color: var(--fg); border-bottom-color: var(--accent); }
.tabs__item.is-active .count { background: var(--accent-soft); color: var(--accent); }

.tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.task { display: flex; flex-direction: column; gap: 12px; scroll-margin-top: 90px; }
.task:target { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.task__head { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; min-width: 0; }
.task__group { font-weight: 600; }
.task__url { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 100%; }
.task__context { font-size: 14px; color: var(--muted); padding-left: 10px; border-left: 2px solid var(--line); }
.task__product { display: flex; align-items: center; gap: 10px; }
.task__product label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.task__product select { max-width: 420px; }
.task__form { display: flex; flex-direction: column; gap: 8px; }
.task__form textarea { field-sizing: content; min-height: 4.6em; font-size: 15px; background: var(--surface-2); border-color: transparent; }
.task__form textarea:focus { background: var(--surface); }
.task__meta { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 12.5px; }
.task__meta code { word-break: break-all; }
.task__actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.task__hint { font-size: 13.5px; padding: 10px 12px; border-radius: 8px; background: var(--ok-soft); color: var(--ok); }
@media (max-width: 560px) {
  .task__actions .btn--primary, .task__actions .btn--done { flex: 1 1 45%; }
  .task__product { flex-direction: column; align-items: stretch; gap: 6px; }
}

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 12px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table--compact th, .table--compact td { padding: 9px 10px; }
.table--compact th:first-child, .table--compact td:first-child { padding-left: 0; }
.cell-strong { font-weight: 600; }
.cell-text { white-space: pre-wrap; word-break: break-word; min-width: 220px; max-width: 420px; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.bar { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 6px; max-width: 220px; }
.bar span { display: block; height: 100%; border-radius: 2px; background: var(--accent); min-width: 2px; }

/* ---------- Sản phẩm ---------- */
.product-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.product-form .field--wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .product-form { grid-template-columns: 1fr; } }
.more summary { margin-top: 2px; }
.products { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.product { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 24px; scroll-margin-top: 90px; }
.product:target { border-color: var(--accent); }
.product__main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.product__title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.product__stats { margin: 0; display: flex; gap: 24px; }
.product__stats dt { font-size: 12px; color: var(--muted); white-space: nowrap; }
.product__stats dd { margin: 0; font: 700 22px/1.2 var(--font-display); }
.product__edit { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 12px; }
.product__edit[open] > form:first-of-type { margin-top: 14px; }
.product__edit > form + form { margin-top: 12px; }
@media (max-width: 640px) { .product { grid-template-columns: 1fr; } }
.copyline { display: flex; align-items: center; gap: 8px; min-width: 0; }
.copyline__text { padding: 6px 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- Mẫu comment ---------- */
.templates { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
@media (max-width: 400px) { .templates { grid-template-columns: 1fr; } }
.tpl { scroll-margin-top: 90px; padding: 14px; }
.tpl:target { border-color: var(--accent); }
.preview { padding: 12px 14px; background: var(--surface-2); border-radius: 8px; font-size: 14px; word-break: break-word; }
.vars { margin: 0 0 18px; display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; font-size: 14px; }
.vars dd { margin: 0; color: var(--muted); }
.tips { margin: 8px 0 0; padding-left: 18px; font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }

/* ---------- Báo cáo ---------- */
.kpis { margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi dt { font-size: 12.5px; color: var(--muted); }
.kpi dd { margin: 4px 0 0; font: 700 26px/1.1 var(--font-display); }
.reports { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
@media (max-width: 900px) { .reports { grid-template-columns: 1fr; } }
.top { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.top li { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 12px; }
.top__clicks { font: 700 20px/1.3 var(--font-display); text-align: right; color: var(--accent); }
.top__body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.top .cell-text { min-width: 0; max-width: none; font-size: 14px; }

/* ---------- Đăng nhập / đăng ký ---------- */
.auth__wrap {
  min-height: 100vh; max-width: 1000px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 48px; align-items: center;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 40px;
}
.auth__intro { display: flex; flex-direction: column; gap: 22px; }
.auth__headline { font: 700 clamp(26px, 3.6vw, 36px)/1.2 var(--font-display); margin: 0; letter-spacing: -.01em; text-wrap: balance; }
.auth__points { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 14px; color: var(--muted); }
.auth__points li { padding-left: 18px; position: relative; }
.auth__points li::before { content: ""; position: absolute; left: 0; top: .6em; width: 7px; height: 7px; border-radius: 2px; background: var(--accent); }
.auth__points strong { color: var(--fg); font-weight: 600; }
.auth__card { padding: 28px; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 820px) {
  .auth__wrap { grid-template-columns: 1fr; gap: 24px; min-height: 0; align-items: start; }
  .auth__points { display: none; }
  .auth__headline { font-size: 22px; }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
  .btn, .nav__link, .task { transition: background-color .15s, border-color .15s, box-shadow .15s, color .15s; }
}

@media (max-width: 560px) {
  .table--compact .col-ratio { display: none; }
  .table--compact td:first-child { min-width: 140px; }
}
