/*
 * Punch app. Mobile-first: a single column that fills a phone, sits centred on
 * a tablet or desktop, and reflows side-by-side for the camera in landscape.
 * Colours and radii are tokens so the admin stylesheet can stay in step.
 */
:root {
  --brand: #2563eb;
  --brand-600: #1d4ed8;
  --brand-900: #0f2557;
  --brand-soft: #eff6ff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --green: #16a34a; --green-ink: #166534; --green-soft: #dcfce7;
  --red: #dc2626;   --red-ink: #991b1b;   --red-soft: #fee2e2;
  --amber: #d97706; --amber-ink: #92400e; --amber-soft: #fef3c7;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.08);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh; min-height: 100dvh;
  position: relative;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
}
/* The coloured band the header and greeting sit on; cards overlap its edge. */
body::before {
  content: ""; position: absolute; z-index: 0; top: 0; left: 0; right: 0;
  height: calc(232px + var(--safe-t));
  background: linear-gradient(180deg, var(--brand-900) 0%, #17389a 62%, var(--brand-600) 100%);
  border-radius: 0 0 28px 28px;
}
h1, h2, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }

/* !important because .btn (and other rules below) declare their own display
   at the same specificity - without it, a later rule silently wins and the
   element stays visible. */
.hidden { display: none !important; }

.ico {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

.app {
  position: relative; z-index: 1;
  width: 100%; max-width: 480px; margin: 0 auto;
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
}
main { flex: 1; }

/* ---- header ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.14); box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clock {
  flex: none; font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,.14); padding: 6px 12px; border-radius: 999px;
}

/* ---- surfaces ---- */
.card {
  background: var(--surface);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
}

/* ---- form controls ---- */
.lbl { display: block; font-size: 13px; color: var(--ink-2); font-weight: 600; margin: 14px 0 6px; }
.inp {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 12px; border: 1px solid #cbd5e1;
  background: #fff; color: var(--ink); font-size: 16px; /* 16px stops iOS zooming on focus */
  transition: border-color .15s, box-shadow .15s;
}
.inp::placeholder { color: #94a3b8; }
.inp:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(37,99,235,.16); }
.inp.sm { width: auto; min-height: 40px; padding: 8px 12px; font-size: 15px; }

.btn {
  width: 100%; min-height: 50px; padding: 12px 16px; border: 1px solid transparent; border-radius: 12px;
  font-size: 16px; font-weight: 600; margin-top: 14px; cursor: pointer;
  transition: transform .05s, box-shadow .15s, background .15s, opacity .15s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .tile:focus-visible, .iconbtn:focus-visible, .linkbtn:focus-visible { outline: 3px solid rgba(37,99,235,.45); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: default; box-shadow: none; }
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(37,99,235,.28); }
.btn.primary:hover { background: var(--brand-600); }
.btn.warn { background: #ea580c; color: #fff; box-shadow: 0 6px 16px rgba(234,88,12,.28); }
.btn.warn:hover { background: #c2410c; }
.btn.big { min-height: 58px; font-size: 18px; font-weight: 700; border-radius: 14px; }
.btn.ghost { background: #fff; color: var(--ink-2); border-color: #cbd5e1; }
.btn.ghost:hover { background: #f8fafc; }
.btn.sm { width: auto; min-height: 40px; padding: 8px 12px; font-size: 14px; margin-top: 0; }
.btn.light { background: #fff; color: var(--brand-600); }
.iconbtn {
  width: 36px; height: 36px; flex: none; border: 0; border-radius: 10px; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: inherit;
}
.linkbtn { background: none; border: none; color: var(--brand-600); font-size: 13px; cursor: pointer; padding: 6px 0 6px 8px; font-weight: 600; }

.muted { color: var(--muted); text-align: center; font-size: 14px; }
.msg { margin-top: 12px; font-size: 14px; min-height: 20px; color: var(--red); text-align: center; font-weight: 600; }
.msg:empty { margin-top: 0; min-height: 0; }
/* A rejected punch: boxed so it reads as a prompt, not a passing hint. */
.msg.alert {
  background: #fef2f2; border: 1px solid #fca5a5; border-radius: 12px;
  padding: 12px 14px; line-height: 1.45;
}

/* ---- banners ---- */
.netbar { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; font-size: 13px; font-weight: 600; text-align: center; }
.netbar.warn { background: var(--amber-soft); color: var(--amber-ink); }
.netbar.off  { background: #e2e8f0; color: #475569; }
.installbar {
  display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 8px 8px 8px 14px;
  border-radius: 12px; background: rgba(255,255,255,.14); color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); font-size: 13px; font-weight: 500;
}
.install-text { flex: 1; min-width: 0; }

/* ---- sign-in / titles ---- */
.scr-title { margin: 2px 0 4px; color: var(--ink); font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.scr-sub { color: var(--muted); margin: 0 0 6px; font-size: 14px; }

/* ---- permissions ---- */
.perm-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
.perm { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #f8fafc; }
.perm-ico { width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-600); }
.perm-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.perm-txt strong { font-size: 15px; }
.perm-txt small { color: var(--muted); font-size: 13px; line-height: 1.35; }
.perm-help { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: var(--amber-soft); color: var(--amber-ink); font-size: 13px; line-height: 1.5; }

/* ---- home ---- */
.hero { color: #fff; padding: 2px 4px 18px; }
.home-hi { font-size: 15px; opacity: .8; }
.home-name { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; overflow-wrap: anywhere; }
.home-date { margin-top: 4px; font-size: 13px; opacity: .8; }

.status-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.status-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.status-card { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 4px; }
.status-row { display: flex; flex-direction: column; gap: 4px; padding: 12px 8px; text-align: center; background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.status-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.status-val { color: var(--ink); font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.home-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 10px; margin-top: 14px; }
.tile {
  min-height: 76px; padding: 12px 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  color: var(--ink-2); font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 1px 2px rgba(15,23,42,.05); touch-action: manipulation;
}
.tile .ico { width: 22px; height: 22px; color: var(--brand-600); }
.tile:active { background: #f8fafc; }

/* ---- chips ---- */
.chip { display: inline-block; flex: none; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: #e2e8f0; color: var(--ink-2); white-space: nowrap; }
.chip.ok { background: var(--green-soft); color: var(--green-ink); }
.chip.no { background: var(--red-soft); color: var(--red-ink); }
.chip.done { background: #dbeafe; color: #1e40af; }
.chip.xs { padding: 2px 8px; font-size: 11px; margin-left: 6px; }

/* ---- camera ---- */
.who { font-size: 15px; margin-bottom: 12px; color: var(--muted); }
.who strong { color: var(--ink); }
.camera-wrap {
  position: relative; width: 100%; aspect-ratio: 3/4; max-height: 56vh; max-height: 56dvh;
  border-radius: 16px; overflow: hidden; background: #0b1220;
}
#video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.scan-ring {
  position: absolute; inset: 12% 18% 18%; border: 3px dashed rgba(255,255,255,.6);
  border-radius: 50%; pointer-events: none;
}
.scan-ring.scanning { border-color: #4ade80; border-style: solid; animation: pulse 1.1s infinite; box-shadow: 0 0 0 9999px rgba(34,197,94,.08); }
@keyframes pulse { 0%,100% { opacity: .45; transform: scale(1); } 50% { opacity: 1; transform: scale(1.02); } }
.cam-hint {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 12px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff;
  font-size: 14px; font-weight: 600; text-align: center;
}
.cam-hint:empty { display: none; }

.geo {
  margin-top: 12px; font-size: 14px; color: var(--ink-2); text-align: center;
  background: var(--bg); padding: 10px; border-radius: 12px; font-weight: 600;
}
.geo.ok { color: var(--green-ink); background: var(--green-soft); }
.geo.warn { color: var(--amber-ink); background: var(--amber-soft); }

/* ---- project, travel ---- */
.st-project { margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--muted); text-align: center; }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-top: 10px; font-size: 15px; font-weight: 500; color: var(--ink-2); cursor: pointer; }
.check-row input { width: 20px; height: 20px; flex: none; accent-color: var(--brand); margin: 0; }
#travelBox .inp { margin-top: 4px; }

/* ---- group attendance ---- */
.camera-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mirror { transform: scaleX(-1); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 14px 0; padding: 4px; background: var(--bg); border-radius: 14px; }
.seg-btn { min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 15px; font-weight: 600; cursor: pointer; touch-action: manipulation; }
.seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(15,23,42,.14); }
.seg-btn:focus-visible { outline: 3px solid rgba(37,99,235,.45); outline-offset: 2px; }
.cam-flip {
  position: absolute; top: 10px; right: 10px; width: 46px; height: 46px; border: 0; border-radius: 50%;
  display: grid; place-items: center; color: #fff; background: rgba(15,23,42,.55); cursor: pointer;
}
.cam-flip .ico { width: 22px; height: 22px; }
.g-result { margin-top: 12px; padding: 12px 14px; border-radius: 12px; font-size: 15px; font-weight: 600; line-height: 1.4; text-align: center; }
.g-result.ok { background: var(--green-soft); color: var(--green-ink); }
.g-result.warn { background: var(--amber-soft); color: var(--amber-ink); }
.g-result.bad { background: var(--red-soft); color: var(--red-ink); }
.g-confirm { display: grid; gap: 8px; margin-top: 10px; }
.g-confirm .btn { margin-top: 0; }
.btn.who { justify-content: flex-start; gap: 12px; text-align: left; padding: 8px 12px; min-height: 60px; }
.btn.who img, .who-blank { width: 44px; height: 44px; flex: none; border-radius: 10px; object-fit: cover; background: var(--line); }
.btn.who span { display: flex; flex-direction: column; }
.btn.who small { color: var(--muted); font-weight: 500; }
.g-team { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.g-team .hist-head { margin-bottom: 0; }
.seg3 { grid-template-columns: repeat(3, 1fr); margin: 12px 0; }
.seg3 .seg-btn { font-size: 13px; padding: 0 4px; }
.seg-btn b { display: inline-block; min-width: 20px; margin-left: 2px; padding: 1px 6px; border-radius: 999px; background: rgba(15,23,42,.08); font-size: 12px; }
.g-team .leave-list { margin-top: 10px; border-top: 0; }
.g-team .leave-status { flex-direction: column; gap: 4px; }

/* ---- type-to-search picker (projects) ---- */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); max-height: 244px; overflow: auto;
  margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid #cbd5e1; border-radius: 12px;
  box-shadow: 0 12px 28px rgba(15,23,42,.18); -webkit-overflow-scrolling: touch;
}
.combo-list li { padding: 12px; border-radius: 8px; font-size: 15px; cursor: pointer; overflow-wrap: anywhere; }
.combo-list li:hover, .combo-list li.sel { background: var(--brand-soft); color: var(--brand-600); }
.combo-list li.sel { font-weight: 600; }
.combo-list li.none { color: var(--muted); cursor: default; background: none; }

/* ---- iOS install steps ---- */
.sheet { position: fixed; inset: 0; z-index: 50; display: grid; align-items: end; background: rgba(15,23,42,.55); padding: 12px calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l)); }
.sheet-card { width: 100%; max-width: 456px; margin: 0 auto; background: var(--surface); border-radius: 20px; padding: 22px 20px 20px; box-shadow: var(--shadow); }
.steps { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; counter-reset: step; }
.steps li { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #f8fafc; font-size: 14px; line-height: 1.4; counter-increment: step; }
.step-ico { width: 40px; height: 40px; flex: none; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-600); }
@media (min-width: 700px) { .sheet { align-items: center; } }

/* ---- result ---- */
#scr-done { text-align: center; padding-top: 28px; }
.result-icon {
  width: 88px; height: 88px; line-height: 88px; border-radius: 50%;
  font-size: 44px; text-align: center; margin: 0 auto 16px;
}
.result-icon.good { background: var(--green-soft); color: var(--green); }
.result-icon.bad  { background: var(--red-soft); color: var(--red); }
.result-icon.pending { background: var(--amber-soft); color: var(--amber); }
#resultTitle { font-size: 24px; margin: 0 0 8px; letter-spacing: -.01em; }
.detail { color: var(--muted); font-size: 15px; }

/* ---- history ---- */
.hist-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.hist-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.hist-body { max-height: 56vh; max-height: 56dvh; overflow: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.hist-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hist-row:last-child { border-bottom: 0; }
.hist-date { color: var(--ink); font-weight: 600; font-size: 14px; }
.hist-times { color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hist-h { color: var(--ink); font-weight: 700; font-size: 13px; text-align: right; min-width: 38px; }

/* ---- leave ---- */
.row2 { display: flex; gap: 12px; }
.row2 > div { flex: 1; min-width: 0; }
.leave-form { display: flex; flex-direction: column; margin-bottom: 8px; }
.leave-list { margin-top: 14px; border-top: 1px solid var(--line); }
.leave-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.leave-row:last-child { border-bottom: 0; }
.leave-row > div:first-child { min-width: 0; overflow-wrap: anywhere; font-size: 14px; }
.leave-row .muted { text-align: left; font-size: 13px; }
.leave-status { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.leave-list > .muted, .hist-body > .muted { padding: 18px 0 6px; }

/* ---- footer ---- */
.foot { text-align: center; padding-top: 22px; }
.foot a { color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none; padding: 10px 14px; border-radius: 999px; display: inline-block; }
.foot a:hover { color: var(--ink-2); background: #e2e8f0; }

/* ---- very narrow phones ---- */
@media (max-width: 350px) {
  .app { padding-left: calc(12px + var(--safe-l)); padding-right: calc(12px + var(--safe-r)); }
  .card { padding: 16px; }
  .status-val { font-size: 15px; }
  .row2 { flex-direction: column; gap: 0; }
  .topbar h1 { font-size: 15px; }
}

/* ---- phone held sideways: camera beside the controls, not above them ---- */
@media (orientation: landscape) and (max-height: 540px) {
  .app { max-width: 760px; }
  body::before { height: calc(120px + var(--safe-t)); }
  .cam-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: center; }
  .camera-wrap { aspect-ratio: 4/3; max-height: calc(100vh - 150px); max-height: calc(100dvh - 150px); }
  .geo { margin-top: 0; }
  .hero { padding-bottom: 12px; }
  .home-name { font-size: 22px; }
}

/* ---- tablet / desktop: the same column, with room to breathe ---- */
@media (min-width: 700px) and (min-height: 541px) {
  .app { padding-top: 28px; }
  .card { padding: 26px; }
  body::before { height: 270px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
