/* Mobile-first, high-contrast, touch-friendly styles. */
:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #111827;
  --muted: #5b6472;
  --border: #d1d5db;
  --line: #e5e7eb;
  --brand: #0f3d2e;
  --primary: #1d4ed8;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }
a { color: var(--primary); }
code, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .85em; }
pre.json { white-space: pre-wrap; word-break: break-word; margin: .25rem 0 0; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem;
  padding: .55rem 1rem;
  background: var(--brand); color: #fff;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.nav { display: flex; align-items: center; gap: .15rem; margin-left: auto; overflow-x: auto; max-width: 100%; }
.nav a, .linklike {
  color: #e6f4ec; text-decoration: none; white-space: nowrap;
  padding: .45rem .6rem; border-radius: 8px;
  background: none; border: 0; font: inherit; font-size: .95rem; cursor: pointer;
}
.nav a:hover, .linklike:hover { background: rgba(255, 255, 255, .14); }
form.inline { display: inline; margin: 0; }

/* Operating mode: a segmented switch in the top bar. Administrator mode turns
   the bar dark red so an elevated session is never mistaken for a normal one. */
form.mode-switch {
  display: inline-flex; flex-shrink: 0; gap: 2px; padding: 2px; margin: 0;
  border-radius: 10px; background: rgba(0, 0, 0, .25);
}
.mode-btn {
  color: #e6f4ec; background: none; border: 0; font: inherit; font-size: .85rem; white-space: nowrap;
  padding: .3rem .55rem; border-radius: 8px; cursor: pointer;
}
.mode-btn:hover { background: rgba(255, 255, 255, .14); }
.mode-btn.is-active { background: #fff; color: var(--brand); font-weight: 700; cursor: default; }
body.mode-admin .topbar { background: #7f1d1d; }
body.mode-admin .mode-btn.is-active { color: #7f1d1d; }

/* Layout */
.container { max-width: 960px; margin: 0 auto; padding: 1rem; }
.page-narrow .container { max-width: 520px; }
.page-card .container, .page-scan .container { max-width: 520px; }
h1 { font-size: 1.5rem; margin: .25rem 0 1rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
.section { margin-top: 1rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.stack > * + * { margin-top: .6rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }
.grid-2 { display: grid; gap: .75rem; grid-template-columns: 1fr; margin-bottom: 1rem; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; font-weight: 700; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem;
  border: 2px solid transparent; border-radius: 10px;
  background: #e5e7eb; color: var(--text);
  font: inherit; font-weight: 650; text-decoration: none; text-align: center;
  cursor: pointer; touch-action: manipulation;
}
.btn:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--primary); padding-left: 0; padding-right: .5rem; }
.btn-small { min-height: 38px; padding: .3rem .75rem; font-size: .9rem; }
.btn-xl { min-height: 64px; font-size: 1.2rem; text-transform: uppercase; letter-spacing: .03em; }
.btn-block { display: flex; width: 100%; }

/* Status and tags */
.status { display: inline-block; padding: .2rem .65rem; border-radius: 999px; font-weight: 700; font-size: .9rem; }
.status:empty { display: none; }
.status--active { background: #dcfce7; color: #14532d; }
.status--fee_unpaid { background: #fef3c7; color: #78350f; }
.status--inactive { background: #fee2e2; color: #7f1d1d; }
.tag { display: inline-block; padding: .1rem .5rem; border-radius: 6px; font-size: .8rem; font-weight: 700; background: #e5e7eb; color: #374151; white-space: nowrap; }
.tag-ok { background: #dcfce7; color: #14532d; }
.tag-warn { background: #fef3c7; color: #78350f; }
.tag-fail { background: #fee2e2; color: #7f1d1d; }
/* "Your custody": the signed-in operator is holding this weapon right now. */
.tag-mine { background: #dbeafe; color: #1e3a8a; }

/* Sign-off integrity */
.integrity { background: var(--surface); border: 3px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; margin: 1rem 0; }
.integrity--intact { border-color: var(--success); background: #f0fdf4; }
.integrity--altered, .integrity--unsigned { border-color: var(--danger); background: #fef2f2; }
.integrity--inconsistent { border-color: var(--warning); background: #fffbeb; }
.integrity__headline { font-weight: 800; font-size: 1.05rem; margin-bottom: .4rem; }
.integrity--altered .integrity__headline, .integrity--unsigned .integrity__headline { color: var(--danger); }
.integrity__checks { list-style: none; margin: 0 0 .5rem; padding: 0; }
.integrity__checks li { padding: .1rem 0; }
.integrity__checks li.ok::before { content: "✓ "; color: var(--success); font-weight: 800; }
.integrity__checks li.fail { color: var(--danger); font-weight: 700; }
.integrity__checks li.fail::before { content: "✗ "; }
.integrity__checks li.na { color: var(--muted); }
.integrity__checks li.na::before { content: "– "; }
code.hash { overflow-wrap: anywhere; word-break: break-all; }

/* Ammunition counter and inventory */
.calibre-list { list-style: none; margin: 0; padding: 0; }
.calibre-list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: 1.1rem; }
.calibre-list li:last-child { border-bottom: 0; }
.calibre--ok { color: var(--success); font-weight: 800; }
.calibre--warn { color: var(--warning); font-weight: 800; }
.calibre--no { color: var(--muted); }
.checkbox-list { display: grid; gap: .4rem; margin: .5rem 0 1rem; }
.checkbox-list label { display: flex; align-items: center; gap: .6rem; font-size: 1.1rem; font-weight: 600; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.variance--neg { color: var(--danger); font-weight: 700; }
.variance--pos { color: var(--warning); font-weight: 700; }
.lookup-video { width: 100%; max-height: 50vh; object-fit: cover; background: #000; border-radius: var(--radius); margin-bottom: .75rem; }
.count-table input[type=number] { max-width: 8rem; }
.input-row select { width: auto; flex: 0 1 12rem; }
.input-row input[type=number] { flex: 0 1 7rem; }
pre.canonical { white-space: pre-wrap; overflow-wrap: anywhere; background: #f9fafb; border: 1px solid var(--line); border-radius: 8px; padding: .6rem; max-height: 24rem; overflow: auto; }

/* Messages */
.messages { margin-bottom: .75rem; }
.msg { padding: .75rem 1rem; border-radius: 10px; margin-bottom: .5rem; font-weight: 600; }
.msg p { margin: 0 0 .5rem; }
.msg-success { background: #dcfce7; color: #14532d; }
.msg-info { background: #dbeafe; color: #1e3a8a; }
.msg-warning { background: #fef3c7; color: #78350f; }
.msg-error { background: #fee2e2; color: #7f1d1d; }

/* Forms */
.field { margin: 0 0 .9rem; }
label { display: block; font-weight: 600; margin-bottom: .25rem; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=time], input[type=file], select, textarea {
  width: 100%; min-height: 44px;
  padding: .55rem .7rem;
  font: inherit; font-size: 16px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
input[type=checkbox] { width: 1.3rem; height: 1.3rem; margin: 0; }
.field--checkbox label { display: flex; align-items: center; gap: .5rem; }
.errorlist { list-style: none; margin: .25rem 0; padding: 0; color: var(--danger); font-size: .9rem; font-weight: 600; }
.helptext { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.search-form, .input-row { display: flex; gap: .5rem; }
.search-form { margin-bottom: 1rem; }
.search-form input, .input-row input { flex: 1; min-width: 0; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.filters select, .filters input { width: auto; flex: 1 1 10rem; }
details summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }

/* Lists and tables */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.list li { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li form { margin: 0; }
.list__main { min-width: 0; }
.list__title { font-weight: 700; font-size: 1.05rem; }
.list__item--stack { flex-wrap: wrap; }
.list__item--stack form { flex: 1 1 16rem; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; vertical-align: top; padding: .55rem .7rem; border-bottom: 1px solid var(--line); }
th { background: #f9fafb; color: var(--muted); font-size: .85rem; font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
dl.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; margin-bottom: .75rem; }
.tabs a { padding: .45rem .8rem; border-radius: 999px; text-decoration: none; color: var(--text); background: #e5e7eb; white-space: nowrap; font-weight: 600; font-size: .9rem; }
.tabs a.is-active { background: var(--brand); color: #fff; }
.pager { display: flex; align-items: center; justify-content: center; gap: .75rem; margin-top: 1rem; }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; color: inherit; text-decoration: none; }
.stat--link:hover { border-color: var(--primary); }
.stat__value { font-size: 1.8rem; font-weight: 800; line-height: 1.1; }
.stat__label { color: var(--muted); font-size: .9rem; }

/* Training session */
.session-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.session-head h1 { margin: .1rem 0 .2rem; }
.session-head__count { text-align: center; }
.count-big { font-size: 2.6rem; font-weight: 800; line-height: 1; }

/* Membership card */
.member-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .08);
  padding: 1.25rem; text-align: center; margin-bottom: 1rem;
}
.member-card__club { text-transform: uppercase; letter-spacing: .08em; font-weight: 800; color: var(--brand); font-size: .9rem; }
.member-card__name { font-size: 1.6rem; font-weight: 800; margin: .5rem 0; line-height: 1.2; }
.member-card__meta { margin-top: .5rem; color: var(--muted); }
.member-card__meta strong { color: var(--text); font-size: 1.1rem; }
.qr { background: #fff; margin: 1rem auto; max-width: 300px; }
.qr svg { display: block; width: 100%; height: auto; }
.qr svg path { fill: #000; }
.rotating-card__timer { max-width: 300px; height: 6px; margin: -.5rem auto .4rem; background: var(--border); border-radius: 3px; overflow: hidden; }
.rotating-card__timer span { display: block; height: 100%; width: 100%; background: var(--brand); transform-origin: left; }
.rotating-card__status { color: var(--muted); margin: 0; }
.rotating-card.is-expired .qr { opacity: .15; }
.rotating-card.is-expired .rotating-card__status { color: var(--danger, #b91c1c); font-weight: 700; }

/* Scanner */
.scan__top { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.scan__viewport {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .75rem;
  width: 100%; aspect-ratio: 1 / 1; max-height: 62vh; margin: 0 auto .75rem;
  background: #000; border-radius: var(--radius);
}
.scan__viewport video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan__frame { position: absolute; inset: 14%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .28); pointer-events: none; }
.scan__message { position: relative; color: #fff; text-align: center; padding: 0 1rem; margin: 0; font-weight: 600; }
.scan__viewport .btn { position: relative; }
.has-result .scan__viewport { max-height: 26vh; }
.result { background: var(--surface); border: 3px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: .75rem; text-align: center; }
.result__name { font-size: 1.6rem; font-weight: 800; text-transform: uppercase; line-height: 1.15; margin-bottom: .4rem; overflow-wrap: anywhere; }
.result__meta { margin: .5rem 0 .9rem; color: var(--muted); font-weight: 700; }
.result__actions { display: grid; gap: .5rem; }
.result--added { border-color: var(--success); background: #f0fdf4; }
.result--added .result__meta { color: var(--success); font-size: 1.4rem; }
.result--error { border-color: var(--danger); background: #fef2f2; }
.result--error .result__name { color: var(--danger); font-size: 1.25rem; }
.manual-token { margin: .5rem 0 1rem; }
.offline-banner {
  background: #fef3c7; color: #78350f; border-radius: var(--radius);
  padding: .55rem .9rem; margin-bottom: .75rem; font-weight: 700; text-align: center; font-size: .9rem;
}
.offline-banner.is-offline { background: #fee2e2; color: #7f1d1d; }
.offline-search { margin-top: .75rem; }
.offline-search label { display: block; margin-bottom: .3rem; font-weight: 700; }
.offline-search input { width: 100%; }
.offline-search .list { margin-top: .5rem; }
.offline-search .list button.linklike { padding: .5rem 0; display: block; width: 100%; text-align: left; }

/* Ammunition counter */
.person-head { margin-bottom: .75rem; }
.person-head__name { font-size: 1.6rem; font-weight: 800; line-height: 1.2; margin-bottom: .25rem; }
.person-head__verification { margin: .4rem 0 .5rem; }
.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; border: 2px solid var(--primary); border-radius: 999px; overflow: hidden; margin: .5rem 0 1rem; }
.mode-toggle__option { display: flex; align-items: center; justify-content: center; min-height: 52px; padding: .5rem; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; color: var(--primary); text-decoration: none; }
.mode-toggle__option.is-selected { background: var(--primary); color: #fff; }
.product-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .75rem; }
.calibre-group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; }
.calibre-group__head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.product { margin-top: .5rem; }
.product + .product { margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--line); }
.product--disabled .product__variant { color: var(--muted); }
.product__name { font-size: 1.15rem; font-weight: 800; }
.product__variant { font-weight: 700; }
.product__reason { margin: .35rem 0 0; font-weight: 700; color: var(--warning); }
.quantity-buttons { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-start; margin-top: .35rem; }
.quantity-btn { min-width: 4.5rem; min-height: 56px; font-size: 1.25rem; font-weight: 800; justify-content: center; }
.custom-quantity summary { list-style: none; cursor: pointer; }
.custom-quantity summary::-webkit-details-marker { display: none; }
.custom-quantity[open] { flex-basis: 100%; }
.custom-quantity[open] summary { margin-bottom: .5rem; }
.custom-quantity .input-row input { flex: 0 1 8rem; font-size: 1.2rem; }
.review__total { font-size: 1.6rem; }
.take-home-ready { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: center; }
.check-dialog { border: 0; border-radius: var(--radius); padding: 1.25rem; width: min(34rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto; background: var(--surface); color: inherit; box-shadow: 0 20px 50px rgba(15, 23, 42, .35); }
.check-dialog::backdrop { background: rgba(15, 23, 42, .55); }
.check-dialog h2 { margin-top: 0; }
.check-dialog fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; margin: 0; }
.check-dialog legend { font-weight: 700; padding: 0 .35rem; }
.check-dialog__confirm { display: flex; align-items: center; gap: .6rem; font-weight: 700; }
.check-dialog__close { margin-top: .6rem; }
.check-dialog__links { margin-top: .5rem; }

/* Club weapons */
.weapon-status { text-align: right; flex-shrink: 0; }
.weapon-status .small { margin-top: .2rem; }
.check-table select { min-width: 10rem; }

/* Install button, in the top bar */
#pwa-install {
  color: #e6f4ec; border: 1px solid rgba(255, 255, 255, .35); border-radius: 8px;
  padding: .35rem .6rem; font-size: .85rem; background: transparent; cursor: pointer;
}
#pwa-install:hover { background: rgba(255, 255, 255, .12); }

/* Offline fallback page */
.offline-page { max-width: 32rem; margin: 2rem auto; text-align: center; }
.offline-page p { color: var(--muted); }

@media print {
  .topbar, .no-print, .messages { display: none !important; }
  body { background: #fff; }
  .container { padding: 0; }
  .member-card { box-shadow: none; }
}
