/* QR Wallet: phone-first, light and dark. CSP is style-src 'self': every style lives in this file. */

:root {
  color-scheme: light dark;
  --gutter: 16px;
  --radius: 12px;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #e8eaee;
  --text: #1a1c1f;
  --muted: #5f6672;
  --border: #e3e5e9;
  --border-strong: #cfd4db;
  --accent: #2563eb; /* button fill: white text on it in both themes */
  --accent-press: #1d4ed8;
  --on-accent: #ffffff;
  --link: #2563eb;
  --track: #dde1e7;
  --focus: #2563eb;
  --ok-bg: #dcfce7;
  --ok-text: #15803d;
  --warn-bg: #fff7ed;
  --warn-text: #9a3412;
  --info-bg: #e0ebff;
  --info-text: #1e40af;
  --danger: #b91c1c;
  --danger-fill: #dc2626;
  --shadow: 0 1px 0 rgba(16, 24, 40, 0.06);
  --menu-shadow: 0 10px 30px rgba(16, 24, 40, 0.18);
  --fab-shadow: 0 6px 18px rgba(37, 99, 235, 0.35);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #1a1d23;
    --surface-2: #252932;
    --text: #e8eaed;
    --muted: #9aa2ad;
    --border: #2a2f38;
    --border-strong: #3a404b;
    --accent-press: #1e40af;
    --link: #7aa7ff;
    --track: #2c313a;
    --focus: #7aa7ff;
    --ok-bg: #0f2e1c;
    --ok-text: #6ee7a0;
    --warn-bg: #33200f;
    --warn-text: #fdba74;
    --info-bg: #172440;
    --info-text: #a9c6ff;
    --danger: #f87171;
    --shadow: none;
    --menu-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    --fab-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  }
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }
h2 { font-size: 17px; }
a { color: var(--link); }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-size: 17px; font-weight: 700; }
.center { text-align: center; }
.spacer { flex: 1 1 auto; }
.grow { flex: 1 1 auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.boot { padding: 48px var(--gutter); text-align: center; color: var(--muted); }

/* ---------- screens ---------- */

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px var(--gutter) 20px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: max(8px, env(safe-area-inset-top)) var(--gutter) 8px;
}
.topbar > :first-child { justify-self: start; }
.topbar > :last-child { justify-self: end; }
.topbar-title { font-size: 17px; font-weight: 650; text-align: center; }
.topbar.large { grid-template-columns: 1fr auto; padding-top: max(16px, env(safe-area-inset-top)); }
.topbar.large .topbar-title { font-size: 26px; font-weight: 750; text-align: left; }

.link-btn {
  min-height: 44px;
  margin: 0 -8px;
  padding: 0 8px;
  border: 0;
  background: none;
  color: var(--link);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn {
  width: 44px;
  height: 44px;
  margin-right: -8px;
  border: 0;
  border-radius: 22px;
  background: none;
  color: var(--link);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn[aria-expanded="true"], .icon-btn:active { background: var(--surface-2); }

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  top: calc(100% + 4px);
  right: -8px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 190px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--menu-shadow);
}
.menu-item {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 11px 12px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--text);
  font-size: 16px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu-item:hover, .menu-item:active { background: var(--surface-2); }

/* ---------- buttons, fields, notices ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:active { background: var(--accent-press); }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); font-weight: 600; }
.btn.secondary:active { background: var(--surface-2); }
.btn.danger { background: var(--danger-fill); color: #fff; }
.btn.danger-text { color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

.card {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-hint { font-weight: 400; }
.field input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
}
.field input:focus { border-color: var(--accent); outline: none; }
.field input::placeholder { color: var(--muted); opacity: 0.8; }
.field input[readonly] { border-color: var(--border); background: var(--surface-2); color: var(--muted); }

.form-msg { font-size: 14px; }
.form-msg.error { color: var(--danger); }
.form-msg.ok { color: var(--ok-text); }

.notice { padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.notice.ok { background: var(--ok-bg); color: var(--ok-text); }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.info { background: var(--info-bg); color: var(--info-text); }

.empty { padding: 24px 8px; text-align: center; color: var(--muted); overflow-wrap: anywhere; }

/* ---------- login ---------- */

.screen.login { justify-content: center; gap: 24px; max-width: 420px; padding: 24px var(--gutter); }
.brand { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.brand img { border-radius: 16px; }
.brand h1 { font-size: 26px; font-weight: 750; }

/* ---------- library ---------- */

.search {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
.search::placeholder { color: var(--muted); }

.rows { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
}
.row:active { background: var(--surface-2); }
.row-text { display: flex; flex: 1; flex-direction: column; gap: 1px; min-width: 0; }
.row-name, .row-sub, .row-note { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-name { font-weight: 600; }
.row-sub, .row-note { font-size: 13px; color: var(--muted); }
.row-note { font-style: italic; }

.avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}
.avatar.c0 { background: #2563eb; }
.avatar.c1 { background: #7c3aed; }
.avatar.c2 { background: #0f766e; }
.avatar.c3 { background: #be185d; }
.avatar.c4 { background: #c2410c; }
.avatar.c5 { background: #0e7490; }
.avatar.c6 { background: #4338ca; }
.avatar.c7 { background: #15803d; }
.avatar.c8 { background: #a21caf; }
.avatar.c9 { background: #b45309; }

.has-fab { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
.fab {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  min-height: 52px;
  padding: 0 26px;
  border-radius: 26px;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--fab-shadow);
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transform: translateX(-50%);
}
.fab:active { background: var(--accent-press); }

/* ---------- scan (always dark, like a camera) ---------- */

.screen.scan { max-width: none; background: #111418; color: #fff; --link: #fff; }
.cam {
  position: relative;
  display: grid;
  flex: 1 1 auto;
  place-items: center;
  min-height: 320px;
  overflow: hidden;
  background: #22262d;
}
.cam-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.brackets { position: relative; width: min(64vw, 260px); aspect-ratio: 1; }
.brackets i { position: absolute; width: 36px; height: 36px; border: 4px solid #fff; }
.brackets i:nth-child(1) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 10px; }
.brackets i:nth-child(2) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 10px; }
.brackets i:nth-child(3) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 10px; }
.brackets i:nth-child(4) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 10px; }
.cam-hint {
  position: absolute;
  bottom: 20px;
  left: 50%;
  max-width: calc(100% - 2 * var(--gutter));
  padding: 8px 14px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  transform: translateX(-50%);
  width: max-content;
}
.cam-hint.bad { background: #b91c1c; }
.cam.off .cam-video, .cam.off .brackets { display: none; }
.cam.off .cam-hint { position: static; width: auto; max-width: 300px; margin: 0 var(--gutter); background: none; transform: none; }
.cam.off .cam-hint.bad { background: #b91c1c; }
.scan-actions { display: flex; flex-direction: column; gap: 10px; padding: 16px var(--gutter) calc(16px + env(safe-area-inset-bottom)); }
.btn.on-dark { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.28); color: #fff; }
.btn.on-dark.primary { background: var(--accent); border-color: transparent; }

/* ---------- live code ---------- */

.live { align-items: center; gap: 6px; text-align: center; }
.live-name { margin-top: 4px; font-size: 26px; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.live-member { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.live-note { color: var(--muted); font-size: 14px; font-style: italic; overflow-wrap: anywhere; }
.live-stage { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; margin-top: 10px; }
/* The QR always sits on white with its quiet zone, in dark mode too, so scanners read it. */
.live-qr {
  display: grid;
  place-items: center;
  width: min(100%, 340px);
  aspect-ratio: 1;
  padding: 10px;
  border-radius: 16px;
  background: #fff;
  color: #1a1c1f;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.live-qr svg { display: block; width: 100%; height: 100%; }
.live-bar { width: min(100% - 16px, 300px); height: 6px; overflow: hidden; border-radius: 3px; background: var(--track); }
.live-bar-fill { width: 100%; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left center; }
.live-countdown { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.actions { display: flex; gap: 10px; width: 100%; margin-top: auto; padding-top: 16px; }
.actions .btn { flex: 1; }

/* ---------- admin ---------- */

.screen.admin { max-width: 1100px; }
.admin-top { grid-template-columns: 1fr auto 1fr; }
.tabs { display: flex; gap: 4px; padding: 0 var(--gutter); border-bottom: 1px solid var(--border); }
.tab {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}
.tab[aria-current="page"] { border-bottom-color: var(--accent); color: var(--text); }
.admin-content { gap: 14px; padding-top: 14px; }
.admin h3 { margin: 0 0 6px; font-size: 14px; color: var(--muted); }

.field select, .filters select, .give select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.field select:focus { border-color: var(--accent); outline: none; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

/* Tables scroll inside their own container only; on phones the rows stack instead. */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); }
.grid th, .grid td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.grid th { background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.cell-note { display: block; color: var(--muted); font-size: 13px; }
.plain { margin: 0; padding: 0; list-style: none; }
.plain li + li { margin-top: 4px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; background: var(--ok-bg); color: var(--ok-text); font-size: 13px; font-weight: 600; }
.pill.disabled { background: var(--surface-2); color: var(--muted); }
.pill.locked { background: var(--warn-bg); color: var(--warn-text); }

.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.small-btn { min-height: 40px; padding: 8px 12px; font-size: 14px; }
.detail { display: flex; flex-direction: column; gap: 14px; }
.holder { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.give { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 10px; }
.detail-row td { background: var(--bg); }
.admin-live { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.admin-live > .link-btn { align-self: flex-start; }

@media (max-width: 700px) {
  .grid, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
  .grid thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .grid { border: 0; background: none; }
  .grid tr { margin-bottom: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
  .grid td { display: flex; gap: 12px; justify-content: space-between; border-bottom: 0; padding: 6px 12px; text-align: right; }
  .grid td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 13px; font-weight: 600; text-align: left; }
  .grid td[colspan] { display: block; padding: 6px 12px 12px; text-align: left; }
  .grid td[colspan]::before { content: none; }
  .grid td[data-label="Actions"] { display: block; text-align: left; }
  .grid td[data-label="Actions"]::before { display: none; }
  .cell-note { text-align: right; }
  .give { grid-template-columns: 1fr; }
}
