/* Trình tạo thiệp: bàn làm việc hai cột (form trái, điện thoại xem thử phải). Thiệp: mỗi mẫu một thế giới màu riêng. */
:root {
  --bg: #f3efeb; --panel: #ffffff; --line: #e4dbd3; --fg: #2b221c; --muted: #76675b;
  --accent: #a36743; --accent-ink: #ffffff; --soft: #f6ece4; --danger: #b3402f; --ok: #3d7a4e;
  --f-ui: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191512; --panel: #231d19; --line: #3a3029; --fg: #efe7df; --muted: #a8998b;
    --accent: #d39a72; --accent-ink: #1b1511; --soft: #2f2621; --danger: #e5806e; --ok: #7cc08d; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #191512; --panel: #231d19; --line: #3a3029; --fg: #efe7df; --muted: #a8998b;
  --accent: #d39a72; --accent-ink: #1b1511; --soft: #2f2621; --danger: #e5806e; --ok: #7cc08d; color-scheme: dark;
}
html, body { height: 100%; }
body { background: var(--bg); color: var(--fg); font-family: var(--f-ui); font-size: 14px; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Trình sửa ---------- */
.ed { display: flex; flex-direction: column; min-height: 100%; }
.ed-top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
body.mode-ed::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--panel); }
.brand { display: flex; flex-direction: column; line-height: 1.15; margin-right: 6px; }
.brand b { font-weight: 700; letter-spacing: .02em; }
.brand span { font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.ed-top select { min-width: 0; max-width: 260px; flex: 1 1 180px; }
.ed-top .grow { flex: 1 1 0; }
.save-state { font-size: 12px; color: var(--muted); white-space: nowrap; }
.save-state.dirty { color: var(--accent); }
.save-state.err { color: var(--danger); }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--fg); }
.btn.danger { color: var(--danger); }
.btn[disabled] { opacity: .5; cursor: default; }

.ed-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 440px; gap: 24px; align-items: start;
  padding-block: 20px 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  max-width: 1280px; width: 100%; margin: 0 auto; }
.ed-form { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.ed-prev { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 76px); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.mob-switch { display: none; }

.notice { background: var(--soft); border-radius: var(--r); padding: 10px 14px; font-size: 13px; line-height: 1.5; color: var(--fg); }
.notice.err { border: 1px solid var(--danger); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 8px 12px; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab.on { background: var(--fg); color: var(--bg); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card .sub { margin: -8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.f { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.f > span { font-size: 12px; color: var(--muted); font-weight: 500; }
.f input, .f select, .f textarea, .ed-top select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
.f textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
.f input[type=color] { padding: 2px; height: 36px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.row-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* Kho mẫu */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tpl { border: 2px solid transparent; border-radius: 14px; padding: 0; background: var(--bg); cursor: pointer; text-align: left; overflow: hidden; display: flex; flex-direction: column; }
.tpl.on { border-color: var(--accent); }
.tpl-sw { aspect-ratio: 4 / 3; display: grid; place-items: center; position: relative; overflow: hidden; }
.tpl-sw .nm { font-size: 26px; line-height: 1; text-align: center; padding: 0 8px; }
.tpl-sw .dt { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; font-size: 10px; letter-spacing: .2em; }
.tpl-meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 2px; }
.tpl-meta b { font-size: 13px; }
.tpl-meta span { font-size: 11px; color: var(--muted); }

/* Ảnh */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--soft); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 24px; padding: 0; }
.thumb .mv { position: absolute; bottom: 4px; left: 4px; display: flex; gap: 2px; }
.thumb .mv button { width: 22px; height: 22px; border-radius: 6px; border: 0; background: rgba(0,0,0,.55); color: #fff; cursor: pointer; padding: 0; font-size: 11px; }
.drop { border: 1.5px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; display: block; }
.drop:hover { border-color: var(--accent); color: var(--fg); }
.drop input { display: none; }

/* Khách mời */
.guest { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.guest:last-child { border-bottom: 0; }
.guest .nm { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.guest .lk { grid-column: 1 / -1; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; user-select: all; }
.guest .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Điện thoại xem thử */
.phone { width: 390px; max-width: 100%; height: min(800px, calc(100vh - 150px)); min-height: 520px; border-radius: 40px; border: 10px solid #1c1917; position: relative; overflow: hidden; box-shadow: 0 20px 50px rgba(40, 25, 15, .18); background: #000; }
.prev-bar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* Màn hình cho người không có quyền sửa */
.gate { min-height: 100%; display: grid; place-items: center; text-align: center; padding-block: 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.gate h1 { font-family: "Cormorant Garamond", Georgia, serif; font-weight: 600; font-size: 36px; margin: 0 0 8px; text-wrap: balance; }
.gate p { color: var(--muted); max-width: 42ch; line-height: 1.6; margin: 0 auto; }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px; z-index: 100; font-size: 13px; max-width: calc(100% - 32px); }

@media (max-width: 920px) {
  .ed-body { grid-template-columns: minmax(0, 1fr); }
  .ed-prev { position: static; }
  .mob-switch { display: flex; gap: 6px; }
  .ed.show-prev .ed-form { display: none; }
  .ed:not(.show-prev) .ed-prev { display: none; }
  .phone { width: 100%; max-width: 420px; height: calc(100vh - 190px); border-width: 6px; border-radius: 28px; }
}
@media (max-width: 520px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .ed-top select { max-width: none; }
}


/* ---------- Đăng nhập ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding-block: 32px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 26px 22px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h2 { margin: 0; font-size: 18px; }
.brand.big b { font-family: "Cormorant Garamond", Georgia, serif; font-size: 32px; font-weight: 600; letter-spacing: 0; }
.seg-ui { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--bg); border-radius: 999px; padding: 4px; }
.seg-ui button { border: 0; background: transparent; border-radius: 999px; padding: 8px 6px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg-ui button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form .btn { padding: 11px; }
.auth-err { color: var(--danger); font-size: 13px; }
.mob-only { display: none; }

/* ---------- Trạng thái, bảng ---------- */
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.wait { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.pill.no { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.all { white-space: pre-wrap; font-size: 12px; background: var(--bg); border-radius: 10px; padding: 10px; max-height: 200px; overflow: auto; user-select: all; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stats div { background: var(--bg); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.stats b { font-size: 24px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; font-variant-numeric: tabular-nums; }
.tbl tr:last-child td { border-bottom: 0; }

/* ---------- Thanh toán ---------- */
.card.pay { flex-direction: row; flex-wrap: wrap; align-items: center; border-color: var(--accent); }
.pay-txt { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.pay-qr { background: #fff; border-radius: 12px; padding: 8px; width: 170px; max-width: 100%; }
.pay-qr svg { width: 100%; height: auto; display: block; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv span { color: var(--muted); }
.kv b { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

@media (max-width: 920px) { .mob-only { display: inline-block; } }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

a.btn { text-decoration: none; color: inherit; display: inline-flex; align-items: center; }
a.btn.pri { color: var(--accent-ink); }
.confirm { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px; background: var(--bg); border-radius: 14px; text-align: center; }
.confirm .ph { font-size: 28px; letter-spacing: .04em; font-variant-numeric: tabular-nums; }

/* ---------- Tùy chỉnh, lọc mẫu ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.tpl-pat { position: absolute; inset: 0; opacity: .6; }
.tpl-sw .new { position: absolute; top: 8px; left: 8px; background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 700; letter-spacing: .06em; padding: 2px 7px; border-radius: 999px; }
.sec-list { display: flex; flex-direction: column; gap: 6px; }
.sec-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: center; }
.sec-row input { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
.sec-row .sec-name { padding: 8px 10px; color: var(--muted); }
.sec-btns { display: flex; gap: 2px; }
.f input[type=range] { padding: 0; accent-color: var(--accent); }

.tpl-sw { aspect-ratio: 3 / 4; }
.tpl-sw .mini { position: absolute; inset: 0; }

/* ---------- Căn ảnh ---------- */
.thumb .cr { position: absolute; left: 4px; top: 4px; height: 24px; border-radius: 12px; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 0 8px; cursor: pointer; }
.crop { position: fixed; inset: 0; z-index: 90; background: rgba(15,10,7,.72); display: grid; place-items: center; overflow: auto; padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px)); }
.crop-card { width: 100%; max-width: 400px; background: var(--panel); color: var(--fg); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.crop-card h3 { margin: 0; font-size: 16px; }
.crop-stage { display: grid; place-items: center; background: var(--bg); border-radius: 12px; padding: 14px; }
.crop-frame { position: relative; overflow: hidden; isolation: isolate; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; background: var(--soft); }
.crop-frame:active { cursor: grabbing; }
.crop-frame img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.crop-card .row-btns { justify-content: flex-end; }
