:root {
  --paper: #f6efe0;
  --paper-2: #efe4cc;
  --card: #fffaf0;
  --ink: #1f1a17;
  --ink-2: #5b524a;
  --ink-3: #8c8278;
  --line: #e2d5bb;
  --seal: #a8231b;
  --seal-2: #c8402f;
  --gold: #b8892f;
  --ok: #2f7a4a;
  --warn: #b26b00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60,40,10,.06), 0 6px 20px rgba(60,40,10,.07);
  --f-body: 'Be Vietnam Pro', system-ui, sans-serif;
  --f-head: 'Playfair Display', Georgia, serif;
  --f-brush: 'Dancing Script', 'Playfair Display', cursive;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--f-body); color: var(--ink); font-size: 15px; line-height: 1.5;
  background: var(--paper) radial-gradient(circle at 20% 0%, #fbf6ea 0, transparent 60%);
  min-height: 100vh; -webkit-font-smoothing: antialiased;
}
a { color: var(--seal); }
h1, h2, h3 { font-family: var(--f-head); line-height: 1.25; margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: 26px; } h2 { font-size: 21px; } h3 { font-size: 17px; }
.muted { color: var(--ink-3); } .small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- khung ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: rgba(246,239,224,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--f-head); font-weight: 700; font-size: 18px; text-decoration: none; color: var(--ink); }
.seal-mark {
  width: 34px; height: 34px; border-radius: 6px; background: var(--seal); color: #fff3e6; display: grid; place-items: center;
  font-family: var(--f-brush); font-size: 22px; box-shadow: inset 0 0 0 2px rgba(255,255,255,.25);
}
.topbar .spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.chip.vip { background: linear-gradient(135deg, #fff4d6, #f3dca0); border-color: #e3c477; color: #6d4b0c; font-weight: 600; }
.chip.seal { background: var(--seal); color: #fff; border-color: var(--seal); }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px 110px; }
.staff main { max-width: 1180px; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav .inner { display: flex; width: 100%; max-width: 760px; }
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px;
  text-decoration: none; color: var(--ink-3); font-size: 12px; position: relative;
}
.bottomnav a .ic { font-size: 20px; line-height: 1; }
.bottomnav a.active { color: var(--seal); font-weight: 600; }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); background: var(--seal); color: #fff; font-size: 11px; border-radius: 999px; padding: 0 6px; min-width: 18px; text-align: center; }

/* ---------- thành phần ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.section { margin-top: 20px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: 10px 16px; border-radius: 10px; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; transition: transform .05s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--seal); border-color: var(--seal); color: #fff; }
.btn.primary:hover { background: var(--seal-2); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(168,35,27,.25); border-color: var(--seal); }
textarea { resize: vertical; min-height: 70px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

/* chủ đề */
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; }
.theme {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 8px; text-align: center;
  cursor: pointer; text-decoration: none; color: var(--ink); transition: border-color .15s, transform .1s;
}
.theme:hover { border-color: var(--seal); transform: translateY(-1px); }
.theme .ic { font-size: 28px; display: block; margin-bottom: 4px; }
.theme b { font-size: 14px; font-weight: 600; }

/* câu mẫu */
.phrases { display: grid; gap: 8px; }
.phrase { display: flex; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.phrase:hover, .phrase.sel { border-color: var(--seal); background: #fff6f2; }
.phrase .txt { font-family: var(--f-brush); font-size: 24px; line-height: 1.2; flex: 1; }
.phrase .mean { font-size: 13px; color: var(--ink-3); font-family: var(--f-body); display: block; margin-top: 2px; }
.phrase .pick { color: var(--seal); font-weight: 700; font-size: 13px; }

.ai-box { background: linear-gradient(160deg, #fffaf0, #f8ecd6); }
.ai-tag { display: inline-block; background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; letter-spacing: .04em; }

/* xem trước bức chữ */
.preview {
  border-radius: 10px; padding: 26px 18px; min-height: 160px; display: grid; place-items: center; text-align: center;
  font-family: var(--f-brush); font-size: 38px; line-height: 1.25; color: #1b1612; position: relative; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.08), inset 0 0 40px rgba(120,80,20,.12);
  white-space: pre-line; word-break: break-word;
}
.preview.dark-paper { color: #f6d47a; }
.preview .insc { position: absolute; left: 14px; bottom: 10px; font-size: 13px; font-family: var(--f-body); opacity: .75; writing-mode: horizontal-tb; }
.preview .stamp { position: absolute; right: 14px; bottom: 12px; width: 26px; height: 26px; background: var(--seal); border-radius: 4px; opacity: .85; }

.papers { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.paper { border: 2px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; background: var(--card); }
.paper.sel { border-color: var(--seal); }
.paper .sw { height: 56px; }
.paper .bd { padding: 8px 10px; }
.paper .bd b { display: block; font-size: 14px; }
.sizes { display: flex; flex-wrap: wrap; gap: 8px; }
.size { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; cursor: pointer; font-size: 14px; }
.size.sel { border-color: var(--seal); background: #fff1ec; font-weight: 600; }
.size small { display: block; color: var(--seal); font-weight: 700; }

.writers { display: grid; gap: 8px; }
.writer { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; background: #fff; }
.writer.sel { border-color: var(--seal); background: #fff6f2; }
.avatar { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; background: var(--paper-2); display: grid; place-items: center; font-family: var(--f-brush); font-size: 22px; flex: none; }

.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.qty button { border: 0; background: transparent; width: 36px; height: 36px; font-size: 18px; cursor: pointer; }
.qty span { min-width: 28px; text-align: center; font-weight: 600; }

/* giỏ & đơn */
.line-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.line-item:last-child { border-bottom: 0; }
.line-item .thumb { width: 64px; height: 64px; border-radius: 8px; display: grid; place-items: center; font-family: var(--f-brush); font-size: 18px; text-align: center; padding: 4px; flex: none; overflow: hidden; line-height: 1.1; }
.line-item .info { flex: 1; min-width: 0; }
.line-item .ct { font-family: var(--f-brush); font-size: 20px; line-height: 1.2; }
.price { font-weight: 700; white-space: nowrap; }
.sum-row { display: flex; justify-content: space-between; padding: 4px 0; }
.sum-row.total { font-size: 18px; font-weight: 700; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }
.sum-row.total .price { color: var(--seal); }

.seg { display: flex; background: var(--paper-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font: inherit; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.status { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--paper-2); color: var(--ink-2); }
.st-pending_payment { background: #fdeccf; color: #8a5300; }
.st-payment_submitted { background: #fff3c4; color: #7a5d00; }
.st-paid, .st-in_progress { background: #e5eefc; color: #23468a; }
.st-ready, .st-shipping { background: #e2f3e7; color: #22663b; }
.st-completed { background: #ece8e2; color: #4d4740; }
.st-cancelled { background: #f6e1df; color: #8a2a22; }

.order-row { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); text-decoration: none; color: inherit; }
.order-row + .order-row { margin-top: 8px; }
.order-row .code { font-weight: 700; font-family: ui-monospace, monospace; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { position: relative; padding: 0 0 12px 22px; font-size: 14px; }
.timeline li::before { content: ''; position: absolute; left: 5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--seal); }
.timeline li::after { content: ''; position: absolute; left: 8px; top: 18px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::after { display: none; }

.pay-box { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
.pay-box img { width: 100%; border-radius: 10px; background: #fff; border: 1px solid var(--line); }
@media (max-width: 560px) { .pay-box { grid-template-columns: 1fr; } .pay-box img { max-width: 260px; margin: 0 auto; display: block; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; font-weight: 600; word-break: break-all; }

.qr-card { text-align: center; }
.qr-card img { width: 240px; max-width: 80%; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
.vip-bar { height: 8px; background: var(--paper-2); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.vip-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), #e6c06a); }

/* hero đăng nhập */
.hero { text-align: center; padding: 40px 8px 16px; }
.hero .big-seal { width: 84px; height: 84px; margin: 0 auto 18px; font-size: 54px; border-radius: 14px; }
.hero h1 { font-size: 30px; }
.hero p { color: var(--ink-2); max-width: 440px; margin: 0 auto 22px; }
.hero .steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 28px 0 8px; font-size: 12px; color: var(--ink-2); }
.hero .steps div b { display: block; font-family: var(--f-head); font-size: 22px; color: var(--seal); }
#gsi-btn { display: flex; justify-content: center; min-height: 44px; }

/* toast & modal */
#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 100; display: grid; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
#toast div { background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: tin .2s; }
#toast div.err { background: var(--seal); }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }
.modal-bg { position: fixed; inset: 0; background: rgba(20,14,8,.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--card); border-radius: 16px; padding: 18px; width: min(560px, 100%); max-height: 88vh; overflow: auto; }
.empty { text-align: center; padding: 40px 10px; color: var(--ink-3); }
.empty .ic { font-size: 42px; display: block; margin-bottom: 6px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--seal); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); text-decoration: none; font-size: 14px; margin-bottom: 10px; }
.stepper { display: flex; gap: 6px; margin-bottom: 14px; font-size: 12px; color: var(--ink-3); }
.stepper span { flex: 1; text-align: center; padding-bottom: 6px; border-bottom: 3px solid var(--line); }
.stepper span.on { color: var(--seal); border-color: var(--seal); font-weight: 700; }

/* ---------- trang cửa hàng ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: transparent; padding: 12px 14px; font: inherit; font-weight: 600; color: var(--ink-3); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--seal); border-bottom-color: var(--seal); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); background: var(--paper-2); position: sticky; top: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #fff6ea; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.stat b { display: block; font-size: 24px; font-family: var(--f-head); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; flex: 1; min-width: 160px; }
.work-card { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; }
.work-card .ct { font-family: var(--f-brush); font-size: 30px; line-height: 1.2; white-space: pre-line; }
#reader { width: 100%; max-width: 420px; margin: 0 auto; border-radius: 12px; overflow: hidden; }
.receipt-img { max-width: 100%; max-height: 420px; border-radius: 10px; border: 1px solid var(--line); }
.inline-edit { display: flex; gap: 6px; align-items: center; }
.inline-edit input { padding: 6px 8px; }
