/* Member site: mobile first. --brand comes from the network (set by app.js). */
:root {
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #646b78;
  --line: #e3e6eb;
  --danger: #c62828;
  --ok: #2e7d32;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1b1e24;
    --ink: #eceef2;
    --muted: #9aa1ad;
    --line: #2c3038;
    --danger: #ef6b6b;
    --ok: #6fcf7a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.top {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  background: var(--brand); color: var(--brand-ink);
}
.logo { height: 32px; width: auto; border-radius: 6px; background: rgba(255,255,255,.15); }
.brand-name { font-weight: 700; font-size: 1.1rem; letter-spacing: .01em; }

main { max-width: 520px; margin: 0 auto; padding: 16px; }

.loading { text-align: center; color: var(--muted); padding: 48px 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 14px;
}

h1 { font-size: 1.35rem; margin: 0 0 6px; }
h2 { font-size: 1.05rem; margin: 0 0 6px; }
.muted { color: var(--muted); margin: 0 0 14px; }
.small { font-size: .85rem; }

form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .95rem; }
.optional { font-weight: 400; color: var(--muted); }
input[type=text], input[type=tel], input[type=email], input[type=password], input:not([type]) {
  font: inherit; font-weight: 400;
  padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--ink);
  width: 100%;
}
input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
label.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; }
label.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--brand); flex: none; }

button { font: inherit; cursor: pointer; border-radius: 12px; padding: 13px 16px; border: 0; width: 100%; font-weight: 600; }
button.primary { background: var(--brand); color: var(--brand-ink); }
button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); margin-top: 12px; }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button:disabled { opacity: .6; cursor: default; }

.error { color: var(--danger); margin: 0; font-size: .92rem; }
.ok { color: var(--ok); margin: 0; font-size: .92rem; }
.switch { text-align: center; margin: 16px 0 0; color: var(--muted); }
.switch a { color: var(--brand); font-weight: 600; }

.terms summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.terms-text { white-space: pre-wrap; color: var(--muted); font-size: .9rem; }

/* The card */
.member-card {
  position: relative; overflow: hidden;
  border-radius: 20px;
  padding: 20px;
  min-height: 190px;
  margin-bottom: 14px;
  color: var(--brand-ink);
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(255,255,255,.22) 0%, rgba(255,255,255,0) 55%),
    linear-gradient(135deg, var(--brand) 0%, color-mix(in srgb, var(--brand) 70%, #000) 100%);
  box-shadow: 0 10px 30px color-mix(in srgb, var(--brand) 30%, transparent);
  display: flex; flex-direction: column; justify-content: space-between;
}
.mc-top, .mc-bottom { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.mc-network { font-weight: 700; }
.mc-status { font-size: .8rem; padding: 2px 8px; border-radius: 99px; background: rgba(0,0,0,.2); }
.mc-status:empty { display: none; }
.mc-balance { margin-top: 18px; display: flex; align-items: baseline; gap: 8px; }
.mc-points { font-size: 2.6rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.mc-points-label { opacity: .85; }
.mc-value { opacity: .9; margin-bottom: 18px; }
.mc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-plan { margin-top: 6px; font-size: .85rem; opacity: .9; }
.mc-no { font-family: ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: .08em; }

.code-panel { text-align: center; }
.code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 2.6rem; font-weight: 700; letter-spacing: .18em;
  margin: 6px 0 10px; font-variant-numeric: tabular-nums;
}
.countdown { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.countdown .bar { height: 100%; background: var(--brand); width: 100%; transition: width 1s linear; }
.code-left { margin: 8px 0 0; }
.blocked-note { color: var(--danger); margin: 10px 0 0; }

.history, .shops { list-style: none; padding: 0; margin: 0; }
.history li, .shops li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.history li:last-child, .shops li:last-child { border-bottom: 0; }
.h-main { display: grid; min-width: 0; }
.h-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-sub { color: var(--muted); font-size: .85rem; }
.h-points { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.h-points.plus { color: var(--ok); }
.h-points.minus { color: var(--ink); }
.empty { color: var(--muted); padding: 8px 0; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 16px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }

.danger-zone h2 { color: var(--danger); }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs[hidden] { display: none; }
.tab {
  background: transparent; color: var(--muted); border-radius: 0;
  padding: 8px 4px 10px; display: grid; justify-items: center; gap: 2px;
  font-size: .78rem; font-weight: 600;
}
.tab-icon { font-size: 1.15rem; line-height: 1.2; }
.tab.active { color: var(--brand); }

@media (min-width: 720px) {
  main { padding-top: 28px; }
  .tabs { left: 50%; right: auto; width: 520px; transform: translateX(-50%); border: 1px solid var(--line); border-bottom: 0; border-radius: 14px 14px 0 0; }
}

/* Membership card (contract §7.6): the printed design drawn in CSS at ID-1 proportions.
   Sizes are in container units so the card scales like the printed one (85.6 mm = 100cqw). */
.scan-panel h2 { margin-bottom: 12px; }
.design-card {
  --dc-bg: #1e3a8a; --dc-ink: #fff; --dc-accent: #f59e0b;
  container-type: inline-size;
  position: relative; overflow: hidden;
  aspect-ratio: 85.6 / 54;
  border-radius: 4.2cqw;
  color: var(--dc-ink);
  background-color: var(--dc-bg);
  background-size: cover; background-position: center;
  box-shadow: 0 10px 28px rgba(0,0,0,.22), 0 1px 0 rgba(255,255,255,.08) inset;
}
.design-card:not(.has-image) {
  background-image:
    radial-gradient(circle at 91% 4%, color-mix(in srgb, var(--dc-ink) 8%, transparent) 0 40cqw, transparent 40.2cqw),
    radial-gradient(circle at 107% 74%, color-mix(in srgb, var(--dc-ink) 6%, transparent) 0 35cqw, transparent 35.2cqw),
    linear-gradient(135deg, rgba(255,255,255,.10) 0%, rgba(255,255,255,0) 55%, rgba(0,0,0,.22) 100%);
}
.design-card.has-image::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.30) 0%, rgba(0,0,0,0) 33%, rgba(0,0,0,0) 52%, rgba(0,0,0,.45) 100%);
}
.dc-top, .dc-bottom { position: absolute; left: 6.4cqw; right: 6.4cqw; display: flex; align-items: center; gap: 3.5cqw; }
.dc-top { top: 5.6cqw; height: 11.7cqw; }
.dc-bottom { bottom: calc(1.87cqw + 4.4cqw); justify-content: space-between; align-items: flex-end; }
.dc-logo { height: 11.7cqw; max-width: 32.7cqw; object-fit: contain; }
.dc-network { font-weight: 800; font-size: 5.6cqw; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-network.with-logo { font-size: 4.1cqw; font-weight: 700; white-space: normal; }
.dc-member { display: grid; min-width: 0; }
.dc-member[hidden] { display: none; }
.dc-label, .dc-kind { font-size: 2.5cqw; font-weight: 600; letter-spacing: .2em; opacity: .78; }
.dc-name { font-size: 4.3cqw; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: .6cqw; }
.dc-kind { white-space: nowrap; }
.dc-stripe { position: absolute; left: 0; right: 0; bottom: 0; height: 1.87cqw; background: var(--dc-accent); }

/* The barcode stays black on white in dark mode too, so a till scanner can read it. */
.barcode-box {
  margin-top: 14px; padding: 14px 14px 10px;
  background: #fff; color: #111827;
  border-radius: 12px; border: 1px solid var(--line);
  text-align: center;
}
.barcode { display: block; width: 100%; max-width: 420px; height: 76px; margin: 0 auto; }
.barcode-no {
  margin-top: 8px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 1.15rem; font-weight: 700; letter-spacing: .12em; font-variant-numeric: tabular-nums;
}
.scan-panel .small { margin: 10px 0 0; }

.add-card-offer .secondary { margin-top: 8px; }
.card-note {
  margin: 0 0 14px; padding: 10px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
  font-weight: 600;
}

.card-list { list-style: none; padding: 0; margin: 0 0 16px; }
.card-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.card-list li:last-child { border-bottom: 0; }
.card-no { font-family: ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: .06em; }
button.link-danger {
  width: auto; padding: 8px 12px; background: transparent; color: var(--danger);
  border: 1px solid var(--danger); border-radius: 10px; font-size: .9rem; flex: none;
}

/* Campaigns and messages (contract §12.4) */
.campaign-banner {
  background: var(--brand); color: var(--brand-ink); border-radius: 14px; padding: 12px 16px; margin: 0 0 14px;
  font-weight: 600; line-height: 1.35;
}
.campaign-banner[hidden] { display: none; }
.campaign-banner .cb-item + .cb-item { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255, 255, 255, 0.35); }
.campaign-banner .cb-sub { display: block; font-weight: 400; font-size: 0.85rem; opacity: 0.9; }
.tab { position: relative; }
.tab-badge {
  position: absolute; top: 4px; left: 50%; margin-left: 8px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: #dc2626; color: #fff; font-size: 0.7rem; font-weight: 700; line-height: 18px; text-align: center;
}
.tab-badge[hidden] { display: none; }
.messages { list-style: none; margin: 0; padding: 0; }
.messages li { border-top: 1px solid var(--line); padding: 14px 0; }
.messages li:first-child { border-top: 0; }
.messages li.unread .m-subject::before { content: "● "; color: var(--brand); }
.messages .m-subject { font-weight: 700; margin: 0 0 4px; }
.messages .m-date { color: var(--muted); font-size: 0.8rem; margin: 0 0 8px; }
.messages .m-body { white-space: pre-wrap; margin: 0; }
.messages li.empty { color: var(--muted); }
