:root {
  /* Elite brand palette (Brand Style Guide, Oct 25) */
  --brand: #202944;      /* Midnight Blue — primary */
  --brand-2: #82235e;    /* Plum — accent / links */
  --plum: #82235e;
  --mint: #acddb3;
  --forest: #004538;     /* deep green — sign-in / success */
  --peach: #ffbe9e;
  --sky: #99ade3;
  --accent: #004538;     /* success (forest) */
  --signout: #82235e;    /* sign-out flow accent (plum) */
  --bg: #eef1f5;
  --card: #ffffff;
  --text: #202944;
  --muted: #667085;
  --line: #d9d9d9;       /* brand Light Grey */
  --danger: #b91c1c;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* The HTML `hidden` attribute must always win, even over rules that set
   display (e.g. .modal { display:flex }). Without this, hidden elements
   with a display rule stay visible. */
[hidden] { display: none !important; }

body {
  margin: 0;
  /* Poppins is the Elite brand font (Arial is the guide's fallback). */
  font-family: "Poppins", Arial, "Segoe UI", Roboto, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.card {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--card);
  padding: 24px 20px 40px;
}

@media (min-width: 520px) {
  .card {
    margin: 24px auto;
    min-height: auto;
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(11, 42, 74, 0.12);
  }
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.5px;
  color: var(--brand);
}
.brand-logo { height: 46px; width: auto; display: block; margin-bottom: 6px; }
.project-name {
  margin: 4px 0 20px;
  font-size: 15px;
  font-weight: 600;
  color: var(--brand-2);
}

.form label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}
.req { color: var(--danger); }

input[type=text], input[type=tel], select {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  font-size: 16px; /* 16px stops iOS zooming on focus */
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(130, 35, 94, 0.16);
}

.acks {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 0 0 18px;
}
.acks legend {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  padding: 0 6px;
}
.ack {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 10px;
}
.ack:last-child { margin-bottom: 0; }
.ack input { margin-top: 3px; width: 18px; height: 18px; flex: 0 0 auto; }
.ack a { color: var(--brand-2); }

.sig-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--brand-2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}
.sig-wrap {
  position: relative;
  border: 2px dashed var(--line);
  border-radius: 10px;
  background: #fbfcfd;
  height: 200px;
  overflow: hidden;
}
.sig-canvas {
  width: 100%;
  height: 100%;
  touch-action: none; /* critical: stops the page scrolling while signing */
  display: block;
  cursor: crosshair;
}
.sig-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #aab6c4;
  font-size: 14px;
  pointer-events: none;
}

.legal {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  margin: 16px 0 20px;
}

button.primary, button.secondary {
  width: 100%;
  padding: 15px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
button.primary { background: var(--brand); color: #fff; }
button.primary:disabled { opacity: 0.6; cursor: default; }
button.secondary {
  background: #fff;
  color: var(--brand);
  border: 1.5px solid var(--brand);
  margin-top: 16px;
}

.done { text-align: center; padding: 30px 10px; }
.tick {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 36px;
  line-height: 64px;
}
.done h2 { margin: 0 0 8px; color: var(--brand); }
.done p { color: var(--muted); font-size: 15px; line-height: 1.5; }

.error-panel { text-align: center; padding: 30px 10px; }
.error-panel h2 { color: var(--danger); }
.error-panel p { color: var(--muted); }

/* ---- Dashboard ---- */
.dash-body { background: var(--bg); }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(11, 42, 74, 0.12);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { margin: 0; color: var(--brand); font-size: 22px; }
.login-logo { height: 46px; width: auto; display: block; margin: 0 auto 10px; }
.login-card .sub { margin: 4px 0 22px; color: var(--muted); font-size: 14px; }
.login-card label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 16px; }
.login-error { color: var(--danger); font-size: 14px; margin: 12px 0 0; }

.topbar {
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  flex-wrap: wrap;
  gap: 8px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left strong { font-size: 16px; letter-spacing: 0.3px; }
.topbar-logo { height: 26px; width: auto; display: block; }
.crumb { color: #b9cbe0; font-size: 14px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar .updated { color: #9fb6cf; font-size: 12px; }
.topbar .link-btn { color: #cfe0f2; }

.dash { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }
.dash h2 { color: var(--brand); margin: 0 0 16px; }

.proj-card.clickable {
  cursor: pointer;
  text-align: left;
  font: inherit;
  width: 100%;
  transition: box-shadow 0.15s, transform 0.15s;
}
.proj-card.clickable:hover { box-shadow: 0 6px 20px rgba(11,42,74,0.15); transform: translateY(-2px); }
.proj-card.has-people { border-color: var(--accent); }
.proj-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.badge-off { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
.onsite-count { margin-top: 12px; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.onsite-count strong { color: var(--brand); font-size: 20px; }
.onsite-count .dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; }
.has-people .onsite-count .dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(0,69,56,0.22); }

.back-btn { background: none; border: none; color: var(--brand-2); font-weight: 600; font-size: 14px; cursor: pointer; padding: 0 0 12px; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.onsite-pill { background: #e2e8f0; color: var(--muted); border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: 14px; }
.onsite-pill.active { background: var(--accent); color: #fff; }

.reg-section { margin-top: 26px; }
.reg-section h3 { color: var(--brand); font-size: 16px; margin: 0 0 10px; }
.muted-note { color: var(--muted); font-weight: 400; font-size: 13px; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
table.reg { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
table.reg th { text-align: left; background: #f1f5f9; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.reg td { padding: 11px 12px; border-bottom: 1px solid #eef2f6; color: var(--text); }
table.reg tr:last-child td { border-bottom: none; }
.empty { color: var(--muted); font-size: 14px; padding: 14px 4px; }

.type-tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: #eef2f6; color: var(--brand-2); }
.type-contractor { background: #fef3c7; color: #92400e; }
.type-visitor { background: #e0f2fe; color: #075985; }
.type-employee { background: #dcfce7; color: #166534; }

.pill { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.pill-ok { background: #dcfce7; color: #166534; }
.pill-bad { background: #fee2e2; color: #991b1b; }
.pill-na { background: #f1f5f9; color: #94a3b8; }

.row-actions { white-space: nowrap; }
.mini-btn { font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--brand-2); border-radius: 6px; padding: 5px 9px; cursor: pointer; margin-right: 6px; }
.mini-btn:hover { background: #f8fafc; }
.mini-btn.danger { color: var(--danger); border-color: #fecaca; }

.modal { position: fixed; inset: 0; background: rgba(11,42,74,0.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal-card { background: #fff; border-radius: var(--radius); max-width: 460px; width: 100%; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; text-align: center; }
.sig-img { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ---- Admin page ---- */
.admin { max-width: 900px; margin: 0 auto; padding: 24px 20px; }
.admin h1 { color: var(--brand); }
.proj-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.proj-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}
.proj-card h3 { margin: 0 0 4px; color: var(--brand); }
.proj-card .slug { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.proj-card .qr { background: #fff; padding: 8px; display: inline-block; border-radius: 8px; }
.proj-card .qr img, .proj-card .qr canvas { display: block; }
.proj-card a.dl { display: inline-block; margin-top: 10px; font-size: 13px; color: var(--brand-2); font-weight: 600; }

/* Two QR codes (sign in / sign out) side by side per project */
.qr-row { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; margin-top: 12px; }
.qr-item { flex: 1 1 200px; max-width: 240px; }
.qr-label { font-weight: 700; color: var(--brand); margin-bottom: 8px; font-size: 15px; }
.qr-item .slug { word-break: break-all; margin-top: 8px; }

/* Sign-out page: "N people currently on site" line */
.onsite-line {
  background: #f1f5f9;
  color: var(--brand);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  margin: 0 0 18px;
  text-align: center;
}
