:root {
  --bg: #f6f4f2;
  --panel: #ffffff;
  --ink: #1f1a17;
  --muted: #7a6f68;
  --line: #e7e1dc;
  --brand: #d7261e;
  --brand-dark: #a91b15;
  --brand-soft: #fdecea;
  --ok: #18864b;
  --ok-soft: #e4f5ea;
  --warn: #b26a00;
  --warn-soft: #fff3dd;
  --bad: #c62828;
  --bad-soft: #fde7e7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: 'Poppins', system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: 'Roboto Mono', monospace; }
.hidden { display: none !important; }

/* layout */
.app { display: flex; min-height: 100vh; }
.side { width: 230px; background: #1f1a17; color: #eee; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 18px 18px 14px; font-weight: 700; font-size: 19px; letter-spacing: .3px; display: flex; align-items: center; gap: 10px; }
.brand .logo { width: 32px; height: 32px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; font-size: 17px; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: #b9aea6; }
.nav { padding: 6px 10px; flex: 1; }
.nav .sec { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: #8d827a; padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #ddd; padding: 9px 10px; border-radius: 8px; margin: 1px 0; }
.nav a:hover { background: #2d2622; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a .ic { width: 18px; text-align: center; }
.side .me { padding: 12px 16px; border-top: 1px solid #3a322d; font-size: 12.5px; color: #c9beb6; }
.side .me b { color: #fff; display: block; font-size: 13.5px; }
.side .me a { color: #ff9b94; margin-right: 10px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.topbar { display: none; }

@media (max-width: 860px) {
  .side { position: fixed; left: -260px; z-index: 50; transition: left .2s; width: 250px; }
  .side.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 12px; background: #1f1a17; color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 40; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; padding: 0 4px; cursor: pointer; }
  .main { padding: 16px 16px 60px; }
  .app { flex-direction: column; }
}

/* components */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.row > .auto { flex: 0 0 auto; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12.5px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
input, select, textarea { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid #d8d0ca; border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #f3b3ae; border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; margin-right: 6px; }
input[type=color] { padding: 2px; height: 38px; }
.check { display: flex; align-items: center; font-size: 13.5px; color: var(--ink); cursor: pointer; margin: 4px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; background: var(--brand); color: #fff; white-space: nowrap; }
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border-color: #d8d0ca; }
.btn.ghost:hover { background: #f4efeb; }
.btn.ok { background: var(--ok); }
.btn.danger { background: #fff; color: var(--bad); border-color: #efc4c4; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.lg { padding: 14px 22px; font-size: 16px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head h1 { margin: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; background: #faf8f6; }
tr:hover td { background: #fcfaf9; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: #eee; color: #555; }
.badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.redeemed { background: #e6eefc; color: #2756b3; }
.badge.void, .badge.blocked { background: var(--bad-soft); color: var(--bad); }
.badge.expired { background: var(--warn-soft); color: var(--warn); }
.badge.notyet { background: #efe9ff; color: #6345b5; }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 12px; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
#toast div { background: #1f1a17; color: #fff; padding: 10px 18px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 13.5px; }
#toast div.bad { background: var(--bad); }

.modal-bg { position: fixed; inset: 0; background: rgba(20,15,12,.45); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal .btns { justify-content: flex-end; margin-top: 16px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 30% 20%, #ffe1dc, #f6f4f2 60%); }
.login { width: 100%; max-width: 360px; }
.login .brand { color: var(--ink); justify-content: center; padding: 0 0 18px; font-size: 22px; }

/* redeem */
.big-input { font-size: 22px; font-family: 'Roboto Mono', monospace; text-transform: uppercase; letter-spacing: 1px; padding: 14px; text-align: center; }
.result { border-radius: 12px; padding: 18px; margin-top: 16px; border: 2px solid var(--line); }
.result.active { border-color: #9fd7b5; background: #f6fcf8; }
.result.redeemed, .result.void { border-color: #f0b4b4; background: #fff8f8; }
.result.expired, .result.notyet { border-color: #f3d29a; background: #fffaf0; }
.result .val { font-size: 28px; font-weight: 700; margin: 6px 0; }
.result .code { font-family: 'Roboto Mono', monospace; font-size: 18px; letter-spacing: 1px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; font-size: 13.5px; margin: 10px 0; }
.kv div:nth-child(odd) { color: var(--muted); }
.narrow { max-width: 620px; }

/* loyalty stamp grid */
.stamps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; max-width: 360px; margin: 14px 0; }
.stamps .s { aspect-ratio: 1; border-radius: 50%; border: 2px dashed #d9cfc8; display: grid; place-items: center; font-weight: 700; color: #c5b9b0; font-size: 14px; position: relative; }
.stamps .s.on { background: var(--brand); border: 2px solid var(--brand); color: #fff; }
.stamps .s.tier { border-color: #e7a33e; }
.stamps .s.tier::after { content: '🎁'; position: absolute; top: -8px; right: -6px; font-size: 13px; }
.tiers { display: flex; flex-direction: column; gap: 8px; }
.tier-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.tier-row.available { border-color: #e7a33e; background: #fff8ec; }
.tier-row.claimed { opacity: .6; }

/* designer */
.designer { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .designer { grid-template-columns: 1fr; } }
.canvas-wrap { background: repeating-conic-gradient(#ece7e3 0% 25%, #f6f3f0 0% 50%) 50% / 20px 20px; border-radius: var(--radius); border: 1px solid var(--line); padding: 30px; overflow: auto; min-height: 260px; display: flex; justify-content: center; align-items: flex-start; }
.canvas-scale { transform-origin: top left; }
.canvas-box { box-shadow: 0 4px 20px rgba(0,0,0,.18); }
.hw-el { user-select: none; }
.editor .hw-el { cursor: move; }
.editor .hw-el:hover { outline: 1px dashed #4a90e2; }
.editor .hw-el.sel { outline: 1.5px solid #1e6fd9; }
.hw-placeholder { border: 1px dashed #999; color: #888; font-size: 7pt; display: flex; align-items: center; justify-content: center; text-align: center; background: rgba(255,255,255,.6); }
.el-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.el-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; font-size: 13px; }
.el-item.sel { border-color: #1e6fd9; background: #eef5ff; }
.el-item .grow { flex: 1; }
.props .row > * { flex: 1 1 90px; }
.props input, .props select { padding: 6px 8px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 8px 12px; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.asset { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fff; }
.asset .img { height: 110px; display: grid; place-items: center; background: repeating-conic-gradient(#eee 0% 25%, #fff 0% 50%) 50% / 14px 14px; border-radius: 6px; margin-bottom: 8px; }
.asset .img img { max-width: 100%; max-height: 100%; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 16px; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.scan-video { width: 100%; max-height: 320px; border-radius: 10px; background: #000; margin-top: 10px; }
