/* Trang quản trị Thiệp Cưới 99 */
:root {
  --bg: #f6f3ef;
  --surface: #ffffff;
  --ink: #2f2620;
  --muted: #7d6e61;
  --line: #e7ddd3;
  --accent: #b07d62;
  --accent-dark: #93654d;
  --accent-soft: #f3e8df;
  --ok: #2f7a4f;
  --ok-soft: #e3f3e9;
  --warn: #9a6a00;
  --warn-soft: #fbf0d6;
  --danger: #b23b3b;
  --danger-soft: #fbe6e6;
  --radius: 12px;
  --shadow: 0 6px 20px rgba(47, 38, 32, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); }
a { color: var(--accent-dark); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 12px; }
code { background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; font-size: 0.88em; word-break: break-all; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); font-size: 1.1rem; }
.brand span { color: var(--accent); }
.brand small { font-weight: 500; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; margin-left: 4px; }
.topnav { display: flex; gap: 4px; flex-wrap: wrap; }
.topnav a { text-decoration: none; color: var(--ink); padding: 6px 12px; border-radius: 8px; }
.topnav a:hover { background: var(--accent-soft); }
.topnav a.is-active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.topbar__right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.topbar__right form { margin: 0; }
@media (max-width: 700px) {
  .topbar { gap: 8px 12px; padding: 8px 12px; }
  .topnav { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .topnav a { padding: 5px 10px; white-space: nowrap; }
  .page { padding: 16px 12px 90px; }
  .card { padding: 16px; }
}

/* ---------- Khung trang ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 24px 20px 80px; }
.page--wide { max-width: 1320px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 2px 0 6px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.two-col { display: grid; gap: 18px; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1.2fr 1fr; align-items: start; } }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 500 0.95rem var(--font);
  text-decoration: none; cursor: pointer; transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-dark); }
.btn--ghost { background: transparent; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger-ghost { background: transparent; color: var(--danger); border-color: var(--danger-soft); }
.btn--danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn--sm { padding: 5px 11px; font-size: 0.85rem; }
.btn--block { width: 100%; margin-bottom: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-dark); font-size: 0.78rem; font-weight: 600; }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--hot { background: var(--danger-soft); color: var(--danger); }

/* ---------- Thông báo ---------- */
.flashes { display: grid; gap: 8px; margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); }
.flash--success { background: var(--ok-soft); border-color: #bfe3cc; color: var(--ok); }
.flash--error { background: var(--danger-soft); border-color: #f0c4c4; color: var(--danger); }
.flash--warning { background: var(--warn-soft); border-color: #eedaa4; color: var(--warn); }
.flash--info { background: #eef3fb; border-color: #cfdcf0; color: #2d4f7c; }
.notice { padding: 10px 14px; border-radius: 9px; background: var(--warn-soft); color: var(--warn); }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translate(-50%, 20px);
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: #fff;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field__label { font-weight: 600; font-size: 0.9rem; }
.field__help { color: var(--muted); font-size: 0.82rem; }
.req { color: var(--danger); }
input[type=text], input[type=url], input[type=tel], input[type=search], input[type=password],
input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--ink); font: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=file] { font-size: 0.85rem; max-width: 100%; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); flex-shrink: 0; }
.grid-2 { display: grid; gap: 0 14px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.form-narrow { max-width: 760px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; background: #fff; }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); }

.slug-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; background: #fff; overflow: hidden; }
.slug-input input { border: 0; border-radius: 0; min-width: 0; }
.slug-input__prefix { padding: 0 8px; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
@media (max-width: 560px) { .slug-input__prefix:first-child { display: none; } }

.tpl-pick { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tpl-option { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 2px solid var(--line); border-radius: 12px; cursor: pointer; background: #fff; }
.tpl-option input { position: absolute; opacity: 0; }
.tpl-option img { aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; background: var(--accent-soft); }
.tpl-option__name { font-weight: 600; }
.tpl-option:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tpl-option.is-disabled { opacity: 0.35; pointer-events: none; }

/* Ảnh */
.img-field { display: flex; gap: 14px; align-items: flex-start; }
.img-field__preview { width: 96px; height: 96px; flex-shrink: 0; border-radius: 10px; background: var(--accent-soft); display: grid; place-items: center; overflow: hidden; }
.img-field__preview img { width: 100%; height: 100%; object-fit: cover; }
.img-field__preview--qr img { object-fit: contain; background: #fff; }
.img-field__controls { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.img-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); margin-bottom: 10px; }
.img-grid:empty { display: none; }
.img-grid__item { position: relative; aspect-ratio: 3 / 4; border-radius: 9px; overflow: hidden; background: var(--accent-soft); }
.img-grid__item img { width: 100%; height: 100%; object-fit: cover; }
.img-grid__tools { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: 4px; background: linear-gradient(transparent, rgba(0, 0, 0, 0.55)); }
.img-grid__tools button { border: 0; background: rgba(255, 255, 255, 0.9); border-radius: 6px; width: 26px; height: 24px; cursor: pointer; font-weight: 700; }
.img-grid__tools [data-remove] { color: var(--danger); }

.gift-row { border: 1px dashed var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.gift-row .img-field { margin-bottom: 10px; }

.music-field__input { margin: -2px 0 10px 25px; width: calc(100% - 25px); }
.music-field audio { width: 100%; margin: 6px 0; }

/* ---------- Danh sách thiệp ---------- */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 18px; }
.stat { display: flex; flex-direction: column; padding: 14px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.stat__num { font-size: 1.7rem; font-weight: 700; }
.stat__label { color: var(--muted); font-size: 0.88rem; }
.stat--warn .stat__num { color: var(--warn); }

.filters { display: grid; gap: 8px; grid-template-columns: 1fr; margin-bottom: 16px; }
@media (min-width: 800px) { .filters { grid-template-columns: 2fr 1fr 1fr 1fr auto auto; } }

.inv-list { display: grid; gap: 10px; }
.inv { display: flex; gap: 14px; align-items: center; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.inv__thumb { width: 64px; height: 84px; flex-shrink: 0; border-radius: 8px; overflow: hidden; background: var(--accent-soft); }
.inv__thumb img { width: 100%; height: 100%; object-fit: cover; }
.inv__body { flex: 1; min-width: 0; }
.inv__title { font-size: 1.05rem; margin: 0 0 4px; }
.inv__title a { color: var(--ink); text-decoration: none; }
.inv__meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin: 0 0 2px; }
.inv__actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.inv__actions form { margin: 0; }
@media (max-width: 700px) {
  .inv { flex-wrap: wrap; }
  .inv__actions { width: 100%; justify-content: flex-start; }
}
.empty { text-align: center; padding: 48px 20px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- Template ---------- */
.tpl-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.tpl-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.tpl-card__thumb img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--accent-soft); }
.tpl-card__body { padding: 16px 18px 18px; }
.tpl-card__body .badge { margin: 0 2px 4px 0; }

/* ---------- Sửa thiệp ---------- */
.edit { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .edit { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; } }
.form-section { scroll-margin-top: 76px; }
.form-section h2 { padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.section-nav { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.section-nav a { font-size: 0.82rem; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.section-nav a:hover { border-color: var(--accent); }
.side-card h3 { margin-bottom: 10px; }
.sticky { position: sticky; top: 76px; }
.preview { margin-top: 12px; display: none; }
@media (min-width: 1100px) { .preview { display: block; } }
.preview__phone { width: 100%; aspect-ratio: 9 / 17; border: 8px solid var(--ink); border-radius: 30px; overflow: hidden; background: var(--ink); }
.preview__phone iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.danger-zone { border-color: var(--danger-soft); }

/* Trên điện thoại: nút Lưu dính dưới màn hình */
@media (max-width: 1099px) {
  .edit__side .sticky { position: static; }
  .edit__side .sticky .btn--primary {
    position: fixed; left: 12px; right: 12px; bottom: 12px; width: auto; z-index: 30;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); padding: 13px;
  }
}

/* ---------- Đăng nhập ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login { width: min(380px, 100%); text-align: center; }
.login__brand { font-weight: 700; font-size: 1.3rem; margin-bottom: 4px; }
.login__brand span { color: var(--accent); }
.login__card { text-align: left; margin-top: 16px; }
