/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --primary:       #3860B2;
  --primary-dark:  #2a4a8e;
  --success:       #4CAF50;
  --success-light: #e8f5e9;
  --warning:       #FF9800;
  --warning-light: #fff3e0;
  --danger:        #e53935;
  --danger-light:  #ffebee;
  --bg:            #f0f2f5;
  --card:          #ffffff;
  --text:          #1a1a1a;
  --text-muted:    #666666;
  --border:        #e0e0e0;
  --header-h:      56px;
  --nav-h:         62px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; font-family: 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif; background: var(--bg); color: var(--text); font-size: 16px; }

/* ── Loading Overlay ───────────────────────────────────────────────────────── */
#loading-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 999;
  background: rgba(0,0,0,.45);
  align-items: center; justify-content: center;
}
.spinner {
  width: 48px; height: 48px;
  border: 5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Screens ───────────────────────────────────────────────────────────────── */
.screen {
  display: none;
  position: fixed; inset: 0;
  flex-direction: column;
  background: var(--bg);
}
.screen.active { display: flex; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.header {
  flex-shrink: 0;
  display: flex; align-items: center;
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  padding: 0 12px;
  gap: 8px;
}
.header-title { flex: 1; font-size: 20px; font-weight: 600; }
.header-clock { font-size: 13px; opacity: .85; white-space: nowrap; }
.header-btn {
  background: none; border: none; color: #fff;
  font-size: 22px; cursor: pointer; padding: 8px;
  border-radius: 6px;
  line-height: 1;
}
.header-btn:active { background: rgba(255,255,255,.2); }

/* ── Bottom Nav ────────────────────────────────────────────────────────────── */
#app-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 11px; gap: 2px;
  padding: 6px 0;
}
.nav-btn .nav-icon { font-size: 22px; line-height: 1; }
.nav-btn.active { color: var(--primary); }
.nav-btn:active { background: var(--bg); }

/* ── Scroll content (generic padded area) ──────────────────────────────────── */
.scroll-content {
  flex: 1; overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(var(--nav-h) + 16px);
  display: flex; flex-direction: column; gap: 12px;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  display: flex; flex-direction: column; gap: 10px;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: block; width: 100%;
  padding: 14px; border: none; border-radius: 10px;
  font-size: 17px; font-weight: 600; cursor: pointer;
  text-align: center; transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn-primary   { background: var(--primary);   color: #fff; }
.btn-secondary { background: #e8edf7;           color: var(--primary); }
.btn-success   { background: var(--success);   color: #fff; }
.btn-danger    { background: var(--danger);     color: #fff; }
.btn-google    { background: #fff; color: #3c4043; border: 1px solid #dadce0; display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn:disabled  { opacity: .4; cursor: not-allowed; }

/* ── Login screen ──────────────────────────────────────────────────────────── */
#screen-login {
  align-items: center; justify-content: center;
  background: var(--primary);
}
.login-box {
  background: #fff; border-radius: 20px;
  padding: 40px 28px; width: min(360px, 92vw);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.login-icon { font-size: 52px; }
.login-box h1 { font-size: 22px; color: var(--primary); }
.login-sub { font-size: 14px; color: var(--text-muted); }
#google-signin-button { width: 304px; max-width: 100%; min-height: 40px; }

/* ── Form labels ───────────────────────────────────────────────────────────── */
.label { font-size: 14px; color: var(--text-muted); font-weight: 500; }
.text-input {
  width: 100%; padding: 12px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none;
}
.text-input:focus { border-color: var(--primary); }
.share-url-row {
  background: var(--bg); border-radius: 8px; padding: 10px 12px;
  overflow-x: auto;
}
.share-url { font-size: 12px; color: var(--primary); word-break: break-all; }
.hint-card { background: #f8f9ff; border: 1px solid #d0d8f0; }
.hint-title { font-size: 13px; font-weight: 600; color: var(--primary); }
.hint-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.hint-table th { text-align: left; padding: 4px 6px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.hint-table td { padding: 4px 6px; border-bottom: 1px solid var(--bg); }

/* ── Scan screen ───────────────────────────────────────────────────────────── */
.scan-content {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 12px calc(var(--nav-h) + 12px);
  gap: 12px;
}

/* Result banner */
.result-banner {
  width: 100%; border-radius: 12px; padding: 14px 16px;
  text-align: center; transition: background .2s;
}
.result-idle    { background: #e8edf7; }
.result-success { background: var(--success-light); border: 2px solid var(--success); }
.result-already { background: var(--warning-light); border: 2px solid var(--warning); }
.result-not-found { background: var(--danger-light); border: 2px solid var(--danger); }
.result-err     { background: var(--danger-light); }

.result-main {
  font-size: 36px; font-weight: 700; line-height: 1.1;
}
.result-idle    .result-main { color: var(--text-muted); }
.result-success .result-main { color: var(--success); }
.result-already .result-main { color: var(--warning); }
.result-not-found .result-main { color: var(--danger); }

.result-detail { font-size: 15px; color: var(--text-muted); margin-top: 4px; }

/* Person info after scan */
.scan-info {
  width: 100%; background: var(--card);
  border-radius: 12px; padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  display: flex; flex-direction: column; gap: 4px;
}
.info-id      { font-size: 15px; color: var(--text-muted); }
.info-name    { font-size: 26px; font-weight: 700; }
.info-address { font-size: 14px; color: var(--text-muted); }
.info-notes   { font-size: 16px; color: var(--danger); font-weight: 600; text-decoration: underline; }
.info-stamp   { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* QR reader container */
.qr-reader {
  width: min(300px, 86vw);
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
}
.qr-reader video { display: block; width: 100%; }

/* ── List screen ───────────────────────────────────────────────────────────── */
.search-bar {
  flex-shrink: 0;
  display: flex; align-items: center;
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 0 12px;
}
.search-icon { font-size: 18px; margin-right: 8px; }
#search-input {
  flex: 1; border: none; outline: none;
  font-size: 15px; padding: 14px 0;
  background: transparent;
}

.list-stats {
  flex-shrink: 0;
  padding: 8px 16px;
  font-size: 14px; color: var(--text-muted);
  background: #fff; border-bottom: 1px solid var(--border);
}

.list-container {
  flex: 1; overflow-y: auto;
  padding-bottom: var(--nav-h);
}

.list-row {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  cursor: pointer;
  position: relative;
}
.list-row:active { background: var(--bg); }
.list-row.checked-in { border-left: 4px solid var(--success); }

.list-row-main {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.list-id    { font-size: 14px; color: var(--text-muted); }
.list-name  { font-size: 18px; font-weight: 600; }
.list-notes { font-size: 13px; color: var(--danger); font-weight: 600; text-decoration: underline; }

.list-row-sub { margin-top: 3px; }
.list-address { font-size: 13px; color: var(--text-muted); }

.list-stamp {
  position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 12px; color: var(--success); text-align: right;
  max-width: 120px; line-height: 1.3;
}

.msg-empty { padding: 32px; text-align: center; color: var(--text-muted); }

/* ── Manual check-in screen ────────────────────────────────────────────────── */
.person-card { gap: 6px; }
.person-id      { font-size: 14px; color: var(--text-muted); }
.person-name    { font-size: 30px; font-weight: 700; }
.person-address { font-size: 15px; color: var(--text-muted); }
.person-notes   { font-size: 17px; color: var(--danger); font-weight: 600; text-decoration: underline; }
.person-stamp   { font-size: 14px; color: var(--text-muted); margin-top: 6px; border-top: 1px solid var(--border); padding-top: 8px; }

/* ── Report screen ─────────────────────────────────────────────────────────── */
.report-stats {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.stat-card {
  flex: 1; min-width: 90px;
  background: var(--card); border-radius: 12px;
  padding: 16px 12px; text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.stat-card.green { border-top: 4px solid var(--success); }
.stat-card.orange { border-top: 4px solid var(--warning); }
.stat-card.blue  { border-top: 4px solid var(--primary); }
.stat-num   { font-size: 36px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Messages ──────────────────────────────────────────────────────────────── */
.msg-error {
  color: var(--danger); font-size: 14px;
  background: var(--danger-light); border-radius: 8px;
  padding: 10px 14px; margin-top: 4px;
}
.msg-success {
  color: #2e7d32; font-size: 14px;
  background: var(--success-light); border-radius: 8px;
  padding: 10px 14px; margin-top: 4px;
}

/* ── Admin screen ──────────────────────────────────────────────────────────── */
.admin-section-title {
  font-size: 15px; font-weight: 700;
  color: var(--text);
  padding: 6px 0 6px 12px;
  border-left: 4px solid var(--primary);
  margin-top: 4px;
}

/* ── Desktop-first admin dashboard ───────────────────────────────────────── */
.admin-dashboard { gap: 16px; }
.dashboard-hero {
  background: linear-gradient(125deg, #2a4a8e, #4f78ca);
  color: #fff; border-radius: 16px; padding: 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  box-shadow: 0 8px 22px rgba(42, 74, 142, .22);
}
.dashboard-eyebrow { font-size: 13px; opacity: .78; font-weight: 600; letter-spacing: .08em; }
.dashboard-hero h2 { margin-top: 4px; font-size: 24px; line-height: 1.25; }
.dashboard-hero p:not(.dashboard-eyebrow) { margin-top: 7px; font-size: 14px; opacity: .88; }
.btn-hero { width: auto; flex-shrink: 0; padding: 12px 18px; font-size: 15px; background: #fff; color: var(--primary-dark); }
.admin-panel { min-width: 0; gap: 12px; }
.admin-panel-heading { display: flex; align-items: center; gap: 10px; }
.admin-panel-icon {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 10px;
  display: grid; place-items: center; background: #e8edf7; font-size: 20px;
}
.admin-panel-heading h3 { font-size: 17px; line-height: 1.25; }
.admin-panel-heading p { margin-top: 2px; color: var(--text-muted); font-size: 13px; }

@media (min-width: 900px) {
  #screen-admin .header { height: 64px; padding: 0 max(32px, calc((100vw - 1240px) / 2)); }
  #screen-admin .scroll-content {
    width: min(1240px, 100%); margin: 0 auto; padding: 28px 32px 40px;
    display: grid; grid-template-columns: repeat(12, minmax(0, 1fr));
    align-content: start; gap: 18px; overflow-y: auto;
  }
  .dashboard-hero { grid-column: 1 / -1; padding: 28px 30px; }
  .dashboard-hero h2 { font-size: 28px; }
  .admin-panel-current { grid-column: span 7; }
  .admin-panel-events { grid-column: span 5; }
  .admin-panel-print, .admin-panel-report { grid-column: span 6; }
  .admin-panel-volunteers { grid-column: span 8; }
  .admin-panel-disabled { grid-column: span 4; }
  .admin-panel .btn { font-size: 15px; }
  .dashboard-scan-link { display: block; }
  #screen-admin.active ~ #app-nav { display: none !important; }
}

@media (max-width: 899px) {
  .dashboard-hero { padding: 18px; align-items: flex-start; }
  .dashboard-hero h2 { font-size: 20px; }
  .dashboard-hero .btn-hero { display: none; }
  .dashboard-scan-link { display: none; }
}

.required { color: var(--danger); }

.report-event-title {
  font-size: 18px; font-weight: 700; color: var(--text);
}
.report-summary {
  font-size: 14px; color: var(--text-muted); margin-top: -2px;
}

/* Allow list */
.allowlist-loading {
  font-size: 14px; color: var(--text-muted);
  text-align: center; padding: 8px 0;
}
.allowlist-list {
  border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.allowlist-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.allowlist-row:last-child { border-bottom: none; }
.allowlist-email {
  font-size: 14px; color: var(--text);
  word-break: break-all; flex: 1; margin-right: 8px;
}
.btn-icon-danger {
  background: var(--danger-light); border: none;
  color: var(--danger); border-radius: 6px;
  padding: 4px 10px; font-size: 13px; font-weight: 600;
  cursor: pointer; flex-shrink: 0; line-height: 1.5;
}
.btn-icon-danger:active { opacity: .7; }

/* Coming-soon placeholder */
.admin-coming-soon {
  font-size: 14px; color: var(--text-muted);
  text-align: center; padding: 8px 0;
}

/* ── Admin: current event / sharing ────────────────────────────────────────── */
.event-open-link {
  display: inline-block;
  font-size: 14px; color: var(--primary);
  font-weight: 600; text-decoration: none;
  margin-top: 4px;
}
.divider {
  border: none; border-top: 1px solid var(--border);
  margin: 6px 0;
}
.share-qr {
  display: flex; justify-content: center;
  padding: 8px 0 4px;
}
.share-qr svg {
  width: 150px; height: 150px;
  border: 1px solid var(--border);
  border-radius: 8px; padding: 6px;
  background: #fff;
}

/* Recent events */
.recent-event-row {
  display: flex; width: 100%;
  align-items: center; justify-content: space-between;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px;
  margin-top: 8px; cursor: pointer;
  font-size: 15px; text-align: left;
}
.recent-event-row:active { background: #e8edf7; }
.recent-event-title { font-weight: 600; color: var(--text); flex: 1; margin-right: 8px; word-break: break-all; }
.recent-event-date  { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }

/* Advanced (paste URL) */
details.advanced { margin-top: 6px; }
details.advanced summary {
  font-size: 13px; color: var(--text-muted);
  cursor: pointer; padding: 6px 0;
}
details.advanced[open] summary { color: var(--primary); font-weight: 600; }
details.advanced .label, details.advanced .text-input, details.advanced .btn { margin-top: 8px; }
.file-input { padding: 10px; margin-top: 8px; }

/* Scan: walk-in shortcut */
#scan-walkin-btn { width: 100%; }
