:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --ink: #111820;
  --muted: #65717d;
  --line: #dce2e8;
  --dark: #080b10;
  --green: #11834f;
  --green-soft: #e7f6ee;
  --red: #c33434;
  --red-soft: #fdecec;
  --amber: #a96b00;
  --amber-soft: #fff5da;
  --blue: #2f67d8;
  --blue-soft: #eaf0ff;
  --shadow: 0 12px 28px rgba(18, 28, 38, .08);
  --radius: 18px;
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
.hidden { display: none !important; }
.grow { flex: 1 1 240px; }
.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 4px; color: var(--green); font-size: .75rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(1.55rem, 4vw, 2.35rem); letter-spacing: -.04em; }
h2 { margin: 0; font-size: 1.2rem; letter-spacing: -.02em; }

.app-header { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); min-height: 70px; color: white; background: var(--dark); border-bottom: 1px solid rgba(255,255,255,.1); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; color: white; background: none; border: 0; padding: 0; text-align: left; }
.brand img { width: 118px; height: 48px; object-fit: contain; object-position: left center; }
.brand span { display: flex; flex-direction: column; min-width: 0; }
.brand strong { font-size: 1rem; white-space: nowrap; }
.brand small { margin-top: 2px; color: #aeb6bf; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; padding: 8px 11px; border-radius: 999px; font-size: .8rem; font-weight: 750; background: rgba(255,255,255,.09); }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #60d394; box-shadow: 0 0 0 4px rgba(96,211,148,.15); }
.status-pill.status-offline .dot { background: #ff7777; box-shadow: 0 0 0 4px rgba(255,119,119,.15); }
.status-pill.status-local .dot { background: #f9c74f; box-shadow: 0 0 0 4px rgba(249,199,79,.15); }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); color: inherit; background: transparent; font-size: 1.5rem; }
.app-header .icon-btn { border-color: rgba(255,255,255,.18); color: white; }

.main-nav { position: sticky; top: 70px; z-index: 35; display: flex; gap: 6px; padding: 8px 14px; overflow-x: auto; background: rgba(244,246,248,.96); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.main-nav::-webkit-scrollbar { display: none; }
.main-nav.locked .nav-btn:not([data-page="scanner"]) { display: none; }
.nav-btn { display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto; padding: 10px 14px; border: 0; border-radius: 12px; color: var(--muted); background: transparent; font-weight: 750; }
.nav-btn:hover { background: var(--surface-2); color: var(--ink); }
.nav-btn.active { color: white; background: var(--dark); }

main { padding: 22px max(16px, env(safe-area-inset-right)) max(44px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.page { display: none; width: min(1280px, 100%); margin: 0 auto; }
.page.active { display: block; }
.scanner-shell { width: min(760px, 100%); margin: 0 auto; }
.scanner-topline, .page-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-heading { align-items: center; }
.heading-actions, .scanner-controls, .toolbar, .stack-actions { display: flex; align-items: center; gap: 10px; }
.stack-actions { align-items: stretch; flex-direction: column; }

.message { margin-bottom: 14px; padding: 13px 15px; border-radius: 13px; font-weight: 700; border: 1px solid transparent; }
.message.info { color: #315074; background: #eef5ff; border-color: #dce9ff; }
.message.success { color: #09653b; background: var(--green-soft); border-color: #bce8d0; }
.message.error { color: #a52323; background: var(--red-soft); border-color: #f5caca; }
.message.warning { color: #835100; background: var(--amber-soft); border-color: #f2db9e; }
.camera-card { position: relative; min-height: 360px; overflow: hidden; border-radius: 24px; background: #111820; box-shadow: var(--shadow); }
.qr-reader { min-height: 360px; }
.qr-reader video { object-fit: cover; }
.qr-reader > div { border: 0 !important; }
.camera-placeholder { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; color: white; text-align: center; padding: 24px; background: radial-gradient(circle at center, #25303a 0, #111820 62%, #080b10 100%); }
.camera-placeholder p { margin: 0; color: #b4bec7; }
.scan-frame { position: relative; width: min(240px, 65vw); aspect-ratio: 1; margin-bottom: 12px; border: 1px solid rgba(255,255,255,.15); border-radius: 24px; }
.scan-frame span { position: absolute; width: 42px; height: 42px; border-color: #5de09c; }
.scan-frame span:nth-child(1) { top: -2px; left: -2px; border-top: 5px solid; border-left: 5px solid; border-radius: 14px 0 0 0; }
.scan-frame span:nth-child(2) { top: -2px; right: -2px; border-top: 5px solid; border-right: 5px solid; border-radius: 0 14px 0 0; }
.scan-frame span:nth-child(3) { bottom: -2px; left: -2px; border-bottom: 5px solid; border-left: 5px solid; border-radius: 0 0 0 14px; }
.scan-frame span:nth-child(4) { bottom: -2px; right: -2px; border-bottom: 5px solid; border-right: 5px solid; border-radius: 0 0 14px 0; }
.scanner-controls { margin: 14px 0; }
.manual-scan-box { display: flex; align-items: end; gap: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }

.scanner-lookup-results { display: grid; gap: 8px; margin-top: 10px; }
.scanner-lookup-heading { margin: 0 2px 2px; color: var(--muted); font-size: .8rem; font-weight: 750; }
.scanner-lookup-option { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--surface); text-align: left; }
.scanner-lookup-option:hover, .scanner-lookup-option:focus-visible { border-color: #68a98a; background: var(--green-soft); outline: 0; }
.scanner-lookup-person { display: flex; align-items: center; gap: 11px; min-width: 0; }
.scanner-lookup-person strong, .scanner-lookup-person small { display: block; }
.scanner-lookup-person strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scanner-lookup-person small { margin-top: 3px; color: var(--muted); }
.scanner-lookup-id { flex: 0 0 auto; color: var(--muted); font-size: .8rem; font-weight: 850; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 10px 15px; border-radius: 12px; border: 1px solid transparent; font-weight: 800; line-height: 1.1; }
.btn.primary { color: white; background: var(--green); }
.btn.primary:hover { background: #0d7545; }
.btn.secondary { color: var(--ink); background: white; border-color: var(--line); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.dark { color: white; background: var(--dark); }
.btn.success { color: white; background: var(--green); }
.btn.danger { color: white; background: var(--red); }
.btn.large { min-height: 50px; padding-inline: 19px; }
.btn.xlarge { min-height: 58px; font-size: 1rem; }
.btn.mini { min-height: 34px; padding: 7px 10px; border-radius: 9px; font-size: .78rem; }
.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.volunteer-result { margin-top: 16px; padding: 20px; border-radius: 22px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.result-main { display: flex; align-items: center; gap: 16px; }
.avatar { display: grid; place-items: center; flex: 0 0 86px; width: 86px; height: 86px; overflow: hidden; border-radius: 22px; color: white; background: var(--dark); font-size: 1.4rem; font-weight: 900; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.result-details { min-width: 0; }
.result-details h2 { margin-top: 8px; font-size: clamp(1.55rem, 5vw, 2.25rem); }
.result-details p { margin: 5px 0 0; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-top: 18px; }
.status-chip { display: inline-flex; align-items: center; padding: 6px 10px; border-radius: 999px; font-size: .75rem; font-weight: 850; }
.status-chip.neutral { color: #4b5966; background: #edf0f3; }
.status-chip.checked_in { color: #09653b; background: var(--green-soft); }
.status-chip.checked_out { color: #315074; background: var(--blue-soft); }
.status-chip.absent { color: #a52323; background: var(--red-soft); }
.status-chip.late { color: #835100; background: var(--amber-soft); }

.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { position: relative; overflow: hidden; min-height: 112px; padding: 18px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 8px 20px rgba(18,28,38,.05); }
.stat-card::after { content: ''; position: absolute; right: -20px; bottom: -32px; width: 92px; height: 92px; border-radius: 50%; background: #edf0f3; }
.stat-card.checked-in::after { background: var(--green-soft); }
.stat-card.checked-out::after { background: var(--blue-soft); }
.stat-card.absent::after { background: var(--red-soft); }
.stat-card.late::after { background: var(--amber-soft); }
.stat-card span { position: relative; z-index: 1; display: block; color: var(--muted); font-weight: 700; font-size: .82rem; }
.stat-card strong { position: relative; z-index: 1; display: block; margin-top: 12px; font-size: 2rem; letter-spacing: -.05em; }
.panel { padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: 0 8px 20px rgba(18,28,38,.04); }
.search-field { display: flex; align-items: center; gap: 9px; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.search-field input { width: 100%; border: 0; outline: 0; background: transparent; }
.toolbar select, .report-filters select { min-height: 44px; padding: 0 36px 0 12px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.table-wrap { margin-top: 14px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
td { font-size: .9rem; }
tbody tr:hover { background: #fafbfc; }
.table-person { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.mini-avatar { display: grid; place-items: center; flex: 0 0 38px; width: 38px; height: 38px; overflow: hidden; border-radius: 11px; color: white; background: var(--dark); font-size: .72rem; font-weight: 900; }
.mini-avatar img { width: 100%; height: 100%; object-fit: cover; }
.table-person strong { display: block; }
.table-person small { display: block; color: var(--muted); margin-top: 2px; }
.table-actions { display: flex; gap: 6px; white-space: nowrap; }
.empty-state { padding: 34px 12px; color: var(--muted); text-align: center; }

.manual-results { display: grid; gap: 12px; margin-top: 16px; }
.manual-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 15px; }
.manual-card-info { display: flex; align-items: center; gap: 12px; min-width: 0; }
.manual-card-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: end; }

.report-filters { display: flex; align-items: end; gap: 12px; margin-bottom: 16px; }
.report-stats { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.settings-card h2 { margin-bottom: 8px; }
.settings-card > .muted { margin-top: 0; line-height: 1.5; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.danger-zone { border-color: #f1c5c5; }
.small-note { margin-bottom: 0; color: var(--muted); font-size: .83rem; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { color: #4f5c68; font-size: .78rem; font-weight: 800; }
.field input, .field select, .field textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: white; outline: 0; }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .search-field:focus-within { border-color: #68a98a; box-shadow: 0 0 0 3px rgba(17,131,79,.11); }
.compact-field { min-width: 170px; }
.input-action { display: flex; gap: 7px; }
.input-action input { flex: 1; min-width: 0; }

.modal { width: min(680px, calc(100% - 24px)); max-height: min(90vh, 850px); padding: 0; overflow: auto; border: 0; border-radius: 22px; color: var(--ink); background: white; box-shadow: 0 28px 80px rgba(0,0,0,.28); }
.modal::backdrop { background: rgba(4,8,12,.66); backdrop-filter: blur(4px); }
.modal form, .modal > div:not(.modal-header):not(.modal-actions) { padding-inline: 20px; }
.modal form { padding: 0; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px; border-bottom: 1px solid var(--line); }
.modal .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; padding: 20px; }
.modal .field.full { grid-column: 1 / -1; }
.modal-actions { display: flex; align-items: center; justify-content: end; gap: 10px; padding: 16px 20px 20px; border-top: 1px solid var(--line); }
.modal-actions.split { justify-content: start; }
.compact-modal { width: min(450px, calc(100% - 24px)); }
.compact-modal .field { padding: 20px; }
.qr-preview { display: grid; justify-items: center; gap: 6px; padding: 22px !important; }
.qr-preview img { width: min(280px, 75vw); border: 12px solid white; border-radius: 14px; box-shadow: 0 8px 24px rgba(18,28,38,.12); }
.error-text { margin: 0 20px; color: var(--red); font-weight: 750; }
.toast-container { position: fixed; z-index: 100; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(380px, calc(100% - 32px)); pointer-events: none; }
.toast { padding: 13px 15px; border-radius: 13px; color: white; background: #202a34; box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
.toast.success { background: #09653b; }
.toast.error { background: #a52323; }
.toast.warning { color: #332000; background: #f7c95c; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-grid .stat-card:first-child { grid-column: span 2; }
  .report-stats .stat-card:first-child { grid-column: span 1; }
  .settings-grid { grid-template-columns: 1fr; }
  .report-filters { flex-wrap: wrap; }
}
@media (max-width: 640px) {
  .app-header { min-height: 62px; }
  .brand img { width: 92px; height: 38px; }
  .brand strong { font-size: .88rem; }
  .brand small { max-width: 150px; font-size: .7rem; }
  .status-pill span:last-child { display: none; }
  .main-nav { top: 62px; }
  main { padding-top: 16px; }
  .scanner-topline, .page-heading { align-items: stretch; flex-direction: column; }
  .heading-actions { width: 100%; }
  .heading-actions .btn, .heading-actions .field { flex: 1 1 auto; }
  .camera-card, .qr-reader { min-height: 300px; }
  .scanner-controls { display: grid; grid-template-columns: 1fr 1fr; }
  .scanner-controls .btn:first-child, .scanner-controls .btn:nth-child(2) { grid-column: span 2; }
  .manual-scan-box { align-items: stretch; flex-direction: column; }
  .result-main { align-items: flex-start; }
  .avatar { flex-basis: 72px; width: 72px; height: 72px; border-radius: 18px; }
  .result-actions { grid-template-columns: 1fr 1fr; }
  .result-actions .btn:last-child { grid-column: span 2; }
  .manual-card { align-items: stretch; flex-direction: column; }
  .manual-card-actions { justify-content: stretch; }
  .manual-card-actions .btn { flex: 1; }
  .modal .form-grid { grid-template-columns: 1fr; }
  .modal .field.full { grid-column: auto; }
  .two-col { grid-template-columns: 1fr; }
}
@media print {
  .app-header, .main-nav, .heading-actions, .toolbar, .report-filters, .btn, .toast-container { display: none !important; }
  body, html, main { background: white; }
  main { padding: 0; }
  .page { display: none !important; }
  #page-reports.active { display: block !important; }
  .panel, .stat-card { box-shadow: none; border-color: #bbb; }
}
