/* Z4 NFC — shared design system (admin + public pages) */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #15803d;
  --ok-soft: #e6f5ec;
  --warn: #b45309;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d12; --surface: #13161d; --surface-2: #1a1e27; --border: #262b36;
    --text: #e8ebf1; --muted: #8b94a6; --accent-soft: #172447;
    --danger-soft: #3a1618; --ok-soft: #12301f; --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font: 15px/1.5 var(--font); color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg.lucide { width: 16px; height: 16px; flex: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(.93); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-color: transparent; background: transparent; color: var(--muted); }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; height: 44px; }

/* ── Forms ── */
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); outline: none;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .row2 { grid-template-columns: 1fr; } }
.form { display: grid; gap: 14px; }

/* ── Cards / badges ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Toast ── */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; pointer-events: none; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow); animation: pop .2s ease;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .5);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto;
}
.modal { width: 100%; max-width: 460px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); animation: pop .15s ease; }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

/* ═══════════ ADMIN ═══════════ */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 800;
}
.auth-card h1 { font-size: 20px; margin: 22px 0 4px; }
.auth-card .form { margin-top: 20px; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px; background: var(--accent-soft); color: var(--accent); }
.notice.warn { background: #fff4e0; color: var(--warn); }
.notice.err { background: var(--danger-soft); color: var(--danger); }

.topbar {
  height: 58px; display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav button {
  height: 34px; padding: 0 12px; border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--muted); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 8px;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }
.menu-btn { display: none; }

.layout { display: grid; grid-template-columns: 290px 1fr; min-height: calc(100vh - 58px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.sidebar-list { display: grid; gap: 2px; align-content: start; flex: 1; overflow-y: auto; }
.client-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 0; background: transparent; text-align: left; width: 100%;
}
.client-item:hover { background: var(--surface-2); }
.client-item.active { background: var(--accent-soft); }
.avatar {
  width: 34px; height: 34px; border-radius: 9px; color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; flex: none;
}
.client-item .name { font-weight: 600; font-size: 14px; }
.client-item .sub { font-size: 12px; color: var(--muted); }

.main { padding: 28px; max-width: 1040px; width: 100%; margin: 0 auto; min-width: 0; }
.page-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .avatar { width: 48px; height: 48px; font-size: 17px; border-radius: 12px; }
.page-head h1 { font-size: 22px; letter-spacing: -.02em; }
.page-head .meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.page-head .grow { flex: 1; min-width: 200px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { font-size: 13px; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; padding: 10px 14px; font-weight: 600; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-color: var(--accent); }
.tabs .count { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; line-height: 18px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.toolbar h2 { font-size: 15px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.stand { padding: 16px; display: grid; gap: 10px; }
.stand .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stand h3 { font-size: 15px; }
.stand .url { color: var(--accent); }
.stand .foot { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; border-top: 1px solid var(--border); }
.stand.off { opacity: .6; }

.list { display: grid; }
.list .item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.list .item:last-child { border-bottom: 0; }
.cat-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 14px 16px 6px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.thumb { width: 44px; height: 44px; border-radius: 8px; background: var(--surface-2); object-fit: cover; flex: none; display: grid; place-items: center; color: var(--muted); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; }
.price { font-weight: 600; font-variant-numeric: tabular-nums; }

.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; top: 2px; left: 2px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }

.fb { padding: 16px; display: grid; gap: 6px; border-bottom: 1px solid var(--border); }
.fb:last-child { border-bottom: 0; }
.fb.unread { box-shadow: inset 3px 0 0 var(--accent); }
.stars { color: #f59e0b; letter-spacing: 2px; font-size: 15px; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h3 { color: var(--text); font-size: 16px; margin: 10px 0 4px; }
.empty .btn { margin-top: 14px; }

.qr-box { display: grid; place-items: center; padding: 18px; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); }
.qr-box canvas { max-width: 100%; height: auto !important; }
.help { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg label { cursor: pointer; position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: 9px 6px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; }
.seg input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.gen { max-width: 920px; margin: 0 auto; padding: 28px; display: grid; gap: 18px; }
.gen-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; inset: 58px auto 0 0; width: 290px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .menu-btn { display: inline-flex; }
  .main, .gen { padding: 18px 16px; }
  .stats { grid-template-columns: 1fr 1fr 1fr; }
  .gen-grid { grid-template-columns: 1fr; }
  #domainChip { display: none; }
}

/* ═══════════ PUBLIC PAGES (/r/<code>) ═══════════ */
.pub { max-width: 520px; margin: 0 auto; min-height: 100vh; background: var(--bg); }
.pub-center { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.pub-card { width: 100%; max-width: 440px; padding: 28px 24px; text-align: center; }
.pub-card h1 { font-size: 22px; letter-spacing: -.02em; margin: 10px 0 6px; }
.pub-card p { color: var(--muted); }
.pub-logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: #fff; display: grid; place-items: center; margin: 0 auto; font-weight: 800; font-size: 20px; }
.rate { display: flex; justify-content: center; gap: 6px; margin: 22px 0 8px; }
.rate button { border: 0; background: transparent; padding: 4px; font-size: 40px; line-height: 1; color: var(--border); transition: transform .1s, color .1s; }
.rate button.on { color: #f59e0b; }
.rate button:active { transform: scale(.88); }
.pub-card .form { text-align: left; margin-top: 18px; }
.pub .btn-primary { background: var(--accent); border-color: var(--accent); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.m-head { padding: 22px 18px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.m-head h1 { font-size: 22px; letter-spacing: -.02em; }
.m-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.m-cats { position: sticky; top: 0; z-index: 10; display: flex; gap: 8px; padding: 10px 18px; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--border); scrollbar-width: none; }
.m-cats::-webkit-scrollbar { display: none; }
.m-cats button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.m-cats button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.m-body { padding: 8px 18px 120px; }
.m-section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; scroll-margin-top: 64px; }
.m-item { display: flex; gap: 12px; padding: 12px; margin-bottom: 10px; }
.m-item img { width: 84px; height: 84px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-2); }
.m-item .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.m-item .t { font-weight: 600; }
.m-item .d { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.m-item .buy { margin-top: auto; display: flex; align-items: center; justify-content: space-between; padding-top: 6px; }
.qty { display: inline-flex; align-items: center; gap: 10px; }
.qty button { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); font-size: 18px; line-height: 1; display: grid; place-items: center; padding: 0; }
.qty button.add { background: var(--accent); border-color: var(--accent); color: #fff; }
.qty b { min-width: 16px; text-align: center; font-variant-numeric: tabular-nums; }
.cartbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; justify-content: center; pointer-events: none; }
.cartbar button { pointer-events: auto; width: 100%; max-width: 488px; height: 52px; border: 0; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; background: var(--surface); border-radius: 18px 18px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .2s ease; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h2 { font-size: 18px; margin-bottom: 12px; }
.line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.total { display: flex; justify-content: space-between; font-weight: 700; font-size: 17px; padding: 14px 0; }
.wa { background: #16a34a !important; border-color: #16a34a !important; }
.foot-note { text-align: center; font-size: 12px; color: var(--muted); padding: 18px; }
