:root {
  --blue:    #1d4ed8;
  --blue-dk: #1e40af;
  --blue-lt: #dbeafe;
  --green:   #16a34a;
  --green-lt:#dcfce7;
  --amber:   #d97706;
  --amber-lt:#fef3c7;
  --red:     #dc2626;
  --red-lt:  #fee2e2;
  --text:    #1e293b;
  --muted:   #64748b;
  --border:  #e2e8f0;
  --bg:      #f1f5f9;
  --white:   #ffffff;
  --r:       12px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Header ─────────────────────────────────── */
.header {
  background: var(--blue);
  color: var(--white);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.header h1 { font-size: 1.1rem; font-weight: 700; }
.header-sub { font-size: .78rem; opacity: .85; }
.btn-logout {
  background: rgba(255,255,255,.2);
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: .82rem;
  cursor: pointer;
}
.btn-logout:hover { background: rgba(255,255,255,.3); }

/* ── Offline banner ──────────────────────────── */
.offline-banner {
  background: var(--amber);
  color: white;
  text-align: center;
  padding: 8px;
  font-size: .85rem;
  font-weight: 600;
  display: none;
}
.offline-banner.show { display: block; }

/* ── Tabs ────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--white);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 53px;
  z-index: 90;
}
.tab-btn {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: none;
  font-size: .9rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: .15s;
}
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Login ───────────────────────────────────── */
.login-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 20px;
  background: linear-gradient(160deg, var(--blue) 0%, var(--blue-dk) 100%);
}
.login-card {
  background: white;
  border-radius: var(--r);
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo .logo-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}
.login-logo h2 { font-size: 1.4rem; color: var(--blue); }
.login-logo p { font-size: .88rem; color: var(--muted); margin-top: 4px; }

/* ── Cards ───────────────────────────────────── */
.page { padding: 16px; max-width: 600px; margin: 0 auto; }
.card {
  background: var(--white);
  border-radius: var(--r);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Form elements ───────────────────────────── */
.field { margin-bottom: 16px; }
label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
input[type="text"],
input[type="tel"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 13px 14px;
  font-size: 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  color: var(--text);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-lt);
}
input[type="text"]::placeholder,
input[type="tel"]::placeholder { color: #94a3b8; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748b' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
textarea { resize: vertical; min-height: 80px; }
.field-error { font-size: .82rem; color: var(--red); margin-top: 5px; }
.input-err { border-color: var(--red) !important; }

/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 20px;
  border-radius: 8px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary  { background: var(--blue); color: white; width: 100%; }
.btn-primary:hover  { background: var(--blue-dk); }
.btn-success  { background: var(--green); color: white; }
.btn-success:hover  { background: #15803d; }
.btn-danger   { background: var(--red);  color: white; }
.btn-danger:hover   { background: #b91c1c; }
.btn-ghost    { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-ghost:hover    { background: var(--border); }
.btn-sm { padding: 8px 14px; font-size: .88rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Photo picker ────────────────────────────── */
.photo-input-label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  border: 2px dashed var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: .95rem;
  color: var(--muted);
  transition: .15s;
}
.photo-input-label:hover { border-color: var(--blue); color: var(--blue); }
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-thumb .del-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,.55);
  border: none;
  color: white;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: .7rem;
  cursor: pointer;
  line-height: 22px;
  text-align: center;
  padding: 0;
}
.photo-count { font-size: .82rem; color: var(--muted); margin-top: 6px; }

/* ── Status badges ───────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.badge-wait    { background: var(--amber-lt); color: var(--amber); }
.badge-ok      { background: var(--green-lt); color: var(--green); }
.badge-ret     { background: var(--red-lt);   color: var(--red);   }
.badge-draft   { background: var(--bg);       color: var(--muted); border: 1px solid var(--border); }

/* ── Record list ─────────────────────────────── */
.rec-list { display: flex; flex-direction: column; gap: 12px; }
.rec-card {
  background: var(--white);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.07);
  border-left: 4px solid var(--border);
}
.rec-card.wait { border-left-color: var(--amber); }
.rec-card.ok   { border-left-color: var(--green); }
.rec-card.ret  { border-left-color: var(--red); }
.rec-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.rec-spz { font-size: 1.15rem; font-weight: 800; letter-spacing: .06em; }
.rec-meta { font-size: .83rem; color: var(--muted); margin-bottom: 8px; }
.rec-note {
  background: var(--red-lt);
  border-left: 3px solid var(--red);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: .88rem;
  color: var(--red);
  margin-top: 8px;
}
.rec-note strong { display: block; margin-bottom: 3px; }

/* ── Verifier detail panel ───────────────────── */
.detail-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.detail-photos img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
}
.action-row { display: flex; gap: 10px; margin-top: 14px; }
.action-row .btn { flex: 1; }

/* ── Modal ───────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--white);
  border-radius: var(--r) var(--r) 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 480px;
  transform: translateY(30px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal h3 { font-size: 1.1rem; margin-bottom: 16px; }

/* ── Image lightbox ──────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 95vw; max-height: 90dvh; object-fit: contain; border-radius: 6px; }
.lightbox-close {
  position: absolute;
  top: 16px; right: 16px;
  background: rgba(255,255,255,.2);
  border: none;
  color: white;
  width: 38px; height: 38px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
}

/* ── Admin table ─────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { background: var(--bg); padding: 10px 12px; text-align: left; font-weight: 700; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.tbl td { padding: 10px 12px; border-top: 1px solid var(--border); }
.tbl tr:hover td { background: var(--bg); }
.tbl-wrap { overflow-x: auto; border-radius: var(--r); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ── Utility ─────────────────────────────────── */
.text-center { text-align: center; }
.text-muted { color: var(--muted); font-size: .88rem; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state .icon { font-size: 3rem; display: block; margin-bottom: 12px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1e293b;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 500;
  z-index: 400;
  transition: transform .25s;
  white-space: nowrap;
  max-width: 90vw;
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }

@media (min-width: 640px) {
  .page { padding: 24px; }
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--r); max-height: 90dvh; overflow-y: auto; }
}

/* ── Missing vars alias ──────────────────────── */
:root { --surface: var(--white); }

/* ── Section title ───────────────────────────── */
.section-title { font-size: .95rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 12px; }

/* ── Stats (admin) ───────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 4px; }
@media (min-width: 480px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-card { background: var(--white); border-radius: var(--r); padding: 16px; text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.07); border-top: 4px solid var(--border); }
.stat-card.wait { border-top-color: var(--amber); }
.stat-card.ok   { border-top-color: var(--green); }
.stat-card.ret  { border-top-color: var(--red); }
.stat-num { font-size: 2rem; font-weight: 800; }
.stat-lbl { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.stat-table { background: var(--white); border-radius: var(--r); padding: 4px 0; box-shadow: 0 1px 3px rgba(0,0,0,.07); }
.stat-row { display: flex; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: .9rem; }
.stat-row:last-child { border-bottom: none; }

/* ── Photo area (app) ────────────────────────── */
.photo-area { border: 2px dashed var(--border); border-radius: 8px; padding: 14px; }
.photo-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-top: 10px; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--border); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; }
.photo-remove { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.55); border: none; color: white; border-radius: 50%; width: 22px; height: 22px; font-size: .7rem; cursor: pointer; }
.rec-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 6px; margin: 8px 0; }
.rec-photos img.thumb { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: pointer; }
