:root {
  --teal: #1F9BB1; --teal-dark: #167486; --teal-light: #e6f4f7;
  --ink: #1a2b2e; --ink-soft: #425257; --muted: #6b7a7d; --line: #e2e8ea;
  --bg: #fff; --bg-tint: #f6fafb; --radius: 10px;
  --green: #15803d; --amber: #d97706; --red: #b91c1c;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg-tint); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; min-height: 100dvh; }
a { color: var(--teal-dark); }
#app { max-width: 1120px; margin: 0 auto; padding: 1.25rem; padding-bottom: calc(1.5rem + var(--safe-bot)); }

/* header */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .7rem 1.25rem; padding-top: calc(.7rem + var(--safe-top));
  background: var(--bg); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 900; }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; font-weight: 700; color: var(--teal-dark); }
.brand img { height: 40px; width: auto; }
#nav { display: flex; gap: .3rem; align-items: center; margin-left: auto; flex-wrap: wrap; }
#nav button, #nav .nav-ext { background: transparent; color: var(--ink-soft); border: 1px solid transparent; font: inherit;
  font-weight: 500; padding: .5rem .85rem; border-radius: 8px; cursor: pointer; min-height: 40px; text-decoration: none;
  display: inline-flex; align-items: center; }
#nav button:hover, #nav .nav-ext:hover { background: var(--teal-light); color: var(--teal-dark); }
#nav button.active { background: var(--teal); color: #fff; }
.who { color: var(--muted); font-size: .85em; }
#nav-toggle { display: none; margin-left: auto; background: transparent; border: 1px solid var(--line); border-radius: 8px;
  font-size: 1.3rem; padding: .35rem .7rem; cursor: pointer; }
@media (max-width: 720px) {
  #nav-toggle { display: block; }
  #nav { position: fixed; top: calc(60px + var(--safe-top)); right: .75rem; width: 240px; flex-direction: column; align-items: stretch;
    background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .5rem; box-shadow: 0 8px 24px rgba(0,0,0,.1);
    transform: translateX(calc(100% + 1rem)); transition: transform .2s; z-index: 1000; }
  #nav.open { transform: none; }
}

/* basics */
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem; margin-bottom: 1rem; }
.card.centered { max-width: 460px; margin: 3rem auto; text-align: center; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; } h2 { font-size: 1.1rem; margin: 0 0 .5rem; color: var(--teal-dark); }
.muted { color: var(--muted); } .small { font-size: .85em; } .mono { font-family: ui-monospace, Menlo, monospace; letter-spacing: .08em; }
input, select { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: .6rem .75rem; min-height: 44px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--teal); border-color: var(--teal); }
label { display: block; margin: .6rem 0; color: var(--ink-soft); font-size: .9em; font-weight: 500; }
button, .btn-primary, .btn-secondary { font: inherit; font-weight: 600; border-radius: 8px; padding: .6rem 1.1rem; min-height: 44px;
  cursor: pointer; border: 1px solid var(--teal); background: var(--teal); color: #fff; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; white-space: nowrap; }
button:hover { background: var(--teal-dark); }
button.secondary, .btn-secondary { background: var(--teal-light); color: var(--teal-dark); border-color: var(--line); }
button.danger { background: #fff; color: var(--red); border-color: var(--red); }
button.small, .btn-secondary.small { min-height: 34px; padding: .3rem .7rem; font-size: .85em; }
button[disabled] { opacity: .5; cursor: progress; }
.btn-primary { display: flex; width: 100%; margin: 1rem 0 .5rem; padding: .85rem; }
.link { background: none !important; border: none; color: var(--teal-dark); text-decoration: underline; padding: 0; min-height: 0; font-weight: 500; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }
.row > input, .row > select { flex: 1 1 180px; width: auto; }
.row.center { justify-content: center; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .72em; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.st-current, .ok { background: #dcfce7; color: #166534; } .st-past_due, .warn { background: #fef3c7; color: #92400e; }
.st-suspended, .bad { background: #fee2e2; color: #991b1b; } .neutral { background: #eef2f3; color: var(--ink-soft); }
.admin-bar { background: #fff7e6; border-color: #fcd34d; display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }

/* members */
.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.member { border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem; display: flex; gap: .8rem; }
.avatar { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; background: var(--teal-light); flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 1.8rem; color: var(--teal-dark); }
.member .m-body { flex: 1; min-width: 0; }
.member .m-name { font-weight: 700; }
.member .m-actions { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .5rem; }
.member .m-actions label { margin: 0; }
.file-btn input { display: none; }
.add-row { margin-top: .25rem; }
.guest { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .6rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* admin */
.tabs { display: flex; gap: .25rem; overflow-x: auto; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tabs button { background: none; color: var(--ink-soft); border: none; border-bottom: 3px solid transparent; border-radius: 0; font-weight: 600; }
.tabs button:hover { background: var(--teal-light); }
.tabs button.active { color: var(--teal-dark); border-bottom-color: var(--teal); }
.count { background: var(--red); color: #fff; border-radius: 999px; font-size: .72em; padding: 1px 7px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--teal); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .v { font-size: 1.8rem; font-weight: 700; line-height: 1.1; } .stat .l { color: var(--muted); font-size: .85em; }
.stat.g { border-left-color: var(--green); } .stat.a { border-left-color: var(--amber); } .stat.r { border-left-color: var(--red); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9em; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover { background: var(--bg-tint); }
.photo-queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.pq { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; text-align: center; }
.pq img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--teal-light); }
.pq .row { justify-content: center; margin: .5rem 0 0; }

/* scanner */
.scanner-card { max-width: 560px; margin: 0 auto; }
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 1; margin-bottom: 1rem; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.reticle { position: absolute; inset: 15%; border: 3px solid rgba(255,255,255,.85); border-radius: 16px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); }
.cam-msg { position: absolute; left: 0; right: 0; bottom: .75rem; text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 3px #000; padding: 0 1rem; }

/* result */
#view-result { position: fixed; inset: 0; z-index: 1100; }
.result { min-height: 100dvh; display: flex; flex-direction: column; color: #fff; padding: calc(1rem + var(--safe-top)) 1.25rem calc(1.25rem + var(--safe-bot)); }
.result.valid { background: var(--green); } .result.warning { background: var(--amber); } .result.invalid { background: var(--red); }
.result-head { font-size: clamp(2.2rem, 9vw, 3.5rem); font-weight: 800; letter-spacing: .02em; display: flex; gap: .6rem; align-items: center; justify-content: center; margin: .5rem 0 1.25rem; }
.result-body { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1.25rem; text-align: center; }
#r-photo { width: min(70vw, 300px); aspect-ratio: 1; object-fit: cover; border-radius: 18px; border: 5px solid rgba(255,255,255,.9); background: rgba(255,255,255,.2); }
.nophoto { width: min(60vw, 240px); aspect-ratio: 1; border-radius: 18px; border: 3px dashed rgba(255,255,255,.8); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.2rem; }
.r-name { font-size: clamp(1.6rem, 7vw, 2.4rem); font-weight: 800; }
.r-sub { font-size: 1.15rem; opacity: .95; margin-top: .25rem; }
.r-reason { margin-top: .9rem; font-size: 1.15rem; font-weight: 700; background: rgba(0,0,0,.2); padding: .6rem 1rem; border-radius: 10px; display: inline-block; }
.r-meta { margin-top: .75rem; font-size: .85rem; opacity: .85; }
.result-actions { display: flex; justify-content: center; margin-top: 1.5rem; }
.result-actions .big { background: #fff; color: var(--ink); border-color: #fff; font-size: 1.2rem; padding: 1rem 2rem; min-width: 240px; }

/* dialog / toast */
.dialog { border: 1px solid var(--line); border-radius: 14px; padding: 1.25rem; max-width: 420px; width: 94%; text-align: center; }
.dialog::backdrop { background: rgba(26,43,46,.6); }
#qr-img { width: 100%; max-width: 320px; margin: .75rem auto; display: block; background: #fff; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1rem + var(--safe-bot)); background: var(--ink); color: #fff;
  padding: .8rem 1.3rem; border-radius: 8px; z-index: 1200; max-width: calc(100vw - 2rem); }
.toast.err { background: var(--red); } .toast.ok { background: var(--green); }
