:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --ink: #2a211c;
  --muted: #7a6d64;
  --line: #e8ded3;
  --brand: #7a2e1d;
  --brand-ink: #ffffff;
  --accent: #c8541f;
  --price: #b3261e;
  --danger: #b3261e;
  --ok: #2e7d32;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 30, 10, .06), 0 4px 14px rgba(60, 30, 10, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17120f; --surface: #221b17; --ink: #f3ebe4; --muted: #b3a59a; --line: #3a2f29;
    --brand: #e0876a; --brand-ink: #1a110d; --accent: #f0a27a; --price: #ff9d8a;
    --danger: #ff8a7a; --ok: #8fd694;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ===== Trang khách ===== */
.hero { background: var(--brand); color: var(--brand-ink); padding: 28px 0 22px; }
.hero h1 { margin: 0; font-size: clamp(1.9rem, 6vw, 2.8rem); line-height: 1.1; letter-spacing: -.01em; font-weight: 800; }
.eyebrow { margin: 0 0 4px; text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; opacity: .85; }
.contact { margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .95rem; }
.contact a { color: inherit; font-weight: 600; text-decoration: none; }
.updated { margin: 6px 0 0; font-size: .8rem; opacity: .8; }

.toolbar { position: sticky; top: 0; z-index: 5; background: var(--bg); background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 12px 0 10px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 0 14px; height: 46px; }
.search svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; flex: none; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; height: 100%; font-size: 16px; }
.search:focus-within { border-color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; cursor: pointer; white-space: nowrap; font-size: .9rem; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip-n { margin-left: 6px; opacity: .6; font-size: .8em; }

.status { text-align: center; color: var(--muted); padding: 32px 0; margin: 0; }
.status.error { color: var(--danger); }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 16px 0 24px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 960px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; } }

.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  display: flex; flex-direction: column; }
.card-media { aspect-ratio: 1 / 1; width: 100%; border: 0; padding: 0; background: var(--line); cursor: zoom-in; display: block; }
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-media.empty { display: grid; place-items: center; cursor: default; font-size: 2.4rem; font-weight: 800; color: var(--muted); }
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.card-name { margin: 0; font-size: .98rem; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.card-note { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.35; }
.card-price { margin: auto 0 0; padding-top: 6px; color: var(--price); font-size: 1.1rem; }
.card-price .unit { color: var(--muted); font-size: .8rem; }

.foot { color: var(--muted); font-size: .8rem; padding-bottom: 32px; text-align: center; }

.viewer { border: 0; padding: 0; background: transparent; max-width: min(96vw, 900px); max-height: 94vh; }
.viewer::backdrop { background: rgba(0,0,0,.85); }
.viewer img { max-height: 80vh; width: auto; margin: 0 auto; border-radius: 8px; background: #fff; }
.viewer-cap { color: #fff; text-align: center; padding: 10px; display: flex; flex-direction: column; }
.viewer-cap span { color: #ffb4a6; font-weight: 700; }
.viewer-close { position: fixed; top: 12px; right: 12px; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 28px; cursor: pointer; }

/* ===== Nút & form chung ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px;
  padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; text-decoration: none; font-weight: 600; white-space: nowrap; }
.btn.small { min-height: 34px; padding: 0 10px; font-size: .85rem; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0 4px; min-height: 36px; }
.danger-text { color: var(--danger) !important; }
.btn:disabled { opacity: .55; cursor: progress; }
.icon-btn { border: 0; background: none; font-size: 28px; line-height: 1; width: 40px; height: 40px; cursor: pointer; color: var(--muted); }

label { display: flex; flex-direction: column; gap: 4px; font-size: .875rem; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; font-weight: 400; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 1px; border-color: var(--accent); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; align-self: end; min-height: 44px; }
label.check input { width: 20px; height: 20px; }
.form-msg { margin: 4px 0 0; min-height: 1.2em; color: var(--danger); font-size: .9rem; }
.form-msg.ok { color: var(--ok); }
code { background: var(--line); padding: 1px 5px; border-radius: 4px; }

/* ===== Quản trị ===== */
.auth-box { max-width: 380px; margin: 10vh auto; padding: 28px 22px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-box h1 { margin: 0 0 4px; font-size: 1.5rem; }
.auth-box form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
@media (max-width: 420px) { .auth-box { margin: 24px 12px; } }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-in { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 6px; }
#app-user { overflow: hidden; text-overflow: ellipsis; max-width: 40vw; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 10px 12px; border-bottom: 3px solid transparent; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }

.tab { padding: 16px 0 40px; }
.row-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.row-tools input[type=search], .row-tools input[type=text] { flex: 1 1 200px; }
.row-tools select { flex: 0 1 200px; width: auto; }

.plist, .clist { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.prow-btn { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.prow-btn img, .thumb-empty { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; background: var(--line); }
.prow-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.prow-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow-sub { color: var(--muted); font-size: .8rem; }
.prow-price { color: var(--price); font-weight: 700; white-space: nowrap; }
.hidden-item .prow-btn { opacity: .55; border-style: dashed; }

.crow { display: grid; grid-template-columns: 1fr 72px auto auto auto; gap: 6px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
@media (max-width: 520px) { .crow { grid-template-columns: 1fr 64px; } .crow .muted { grid-column: 1; } }

.card-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; max-width: 460px; display: flex; flex-direction: column; gap: 12px; }
.card-form h2 { margin: 0; font-size: 1.1rem; }

.editor { border: 0; padding: 0; border-radius: var(--radius); width: min(560px, 100vw); max-height: 92vh;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.editor::backdrop { background: rgba(20, 10, 5, .55); }
.editor form { display: flex; flex-direction: column; max-height: 92vh; }
.editor-head, .editor-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.editor-foot { border-bottom: 0; border-top: 1px solid var(--line); }
.editor-head h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.editor-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
@media (max-width: 600px) {
  .editor { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  .editor form { max-height: 100dvh; height: 100%; }
  .editor-body { flex: 1; }
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.img-pick { display: flex; gap: 14px; align-items: center; }
.img-preview { width: 120px; height: 120px; border-radius: 12px; background: var(--line); overflow: hidden;
  display: grid; place-items: center; flex: none; color: var(--muted); font-size: .8rem; text-align: center; }
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.img-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.img-actions label.btn { flex-direction: row; font-size: .95rem; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 140%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600;
  transition: transform .25s ease; z-index: 50; max-width: 92vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }
