:root {
  --bg: #f3f6fc;
  --card: #ffffff;
  --ink: #0e1b3a;
  --muted: #58698c;
  --line: #d6dff0;
  --brand: #0a2a6e;
  --brand-2: #0057e7;
  --ok: #17803d;
  --warn: #b45309;
  --bad: #b42318;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #080f20;
    --card: #101a33;
    --ink: #e8eefc;
    --muted: #9aabcb;
    --line: #223152;
    --brand: #0f2f7a;
    --brand-2: #4da3ff;
    --ok: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app { max-width: 480px; margin: 0 auto; min-height: 100%; }
.view { padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; min-height: 100dvh; }
.view[hidden] { display: none; }
.center { align-items: center; justify-content: center; text-align: center; }

h1 { font-size: 1.5rem; line-height: 1.2; margin: 0; }
h2.section { font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 18px 0 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--bad); font-weight: 600; }

.sim-banner { background: #fde68a; color: #4a3200; text-align: center; font-size: .85rem; font-weight: 600; padding: 6px 10px; position: sticky; top: 0; z-index: 5; }

.brand { display: flex; flex-direction: column; gap: 8px; padding-top: 18px; }
.logo { width: 64px; height: 64px; border-radius: 16px; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.logo img { width: 100%; height: 100%; display: block; }
.wordmark { margin: 0; font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; color: var(--ink); }
.wordmark span { color: var(--brand-2); }

form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
label { font-size: .85rem; font-weight: 600; margin-top: 6px; }
input {
  font: inherit; color: inherit; background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 14px; min-height: 52px; width: 100%;
}
input:focus-visible, .btn:focus-visible, .punch:focus-visible, .shutter:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 2px; }

.btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 14px; min-height: 52px; padding: 0 20px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.ghost.light { color: #fff; border-color: rgba(255,255,255,.4); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: .9rem; }
.stack { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 10px; }

.tips { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.date { color: var(--muted); }
.date::first-letter { text-transform: uppercase; }

.action { display: grid; place-items: center; padding: 18px 0 6px; }
.punch {
  width: min(78vw, 280px); aspect-ratio: 1; border-radius: 50%; border: 0; cursor: pointer;
  background: radial-gradient(circle at 30% 25%, var(--brand-2), var(--brand) 70%); color: #fff;
  font: inherit; font-weight: 800; font-size: 1.35rem; line-height: 1.2; padding: 24px;
  box-shadow: 0 14px 32px rgba(10, 42, 110, .35);
}
.punch:active { transform: scale(.98); }
.done { font-weight: 700; color: var(--ok); text-align: center; padding: 28px 0; }

.where { border: 0; padding: 0; margin: 12px 0 0; min-width: 0; }
.where legend { font-weight: 700; padding: 0; margin-bottom: 8px; }
.where .opts { display: grid; gap: 8px; }
.where .opt { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; min-height: 56px; cursor: pointer; font-weight: 700; }
.where .opt small { display: block; font-weight: 500; color: var(--muted); }
.where .opt input { width: 20px; height: 20px; flex: none; accent-color: var(--brand-2); }
.where .opt:has(input:checked) { border-color: var(--brand-2); background: color-mix(in srgb, var(--brand-2) 12%, var(--card)); }
.where .opt:has(input:focus-visible) { outline: 3px solid var(--brand-2); outline-offset: 2px; }
.where-fixed { margin: 12px 0 0; font-weight: 700; }
.punch:disabled { opacity: .45; cursor: default; box-shadow: none; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.timeline .t { font-variant-numeric: tabular-nums; font-weight: 700; }
.chip { font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--line); color: var(--ink); }
.chip.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

/* Cámara */
.camera { padding: 0; background: #000; color: #fff; gap: 0; }
.camera .stage { position: relative; flex: 1; overflow: hidden; background: #000; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.oval {
  position: absolute; left: 50%; top: 46%; width: 66%; aspect-ratio: 3 / 4; transform: translate(-50%, -50%);
  border: 3px solid #fff; border-radius: 50%; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .55);
}
.hint { position: absolute; left: 0; right: 0; bottom: 18px; text-align: center; font-weight: 600; text-shadow: 0 1px 4px #000; }
.cam-error { position: absolute; inset: 20% 24px auto; background: rgba(0,0,0,.8); padding: 16px; border-radius: 12px; text-align: center; }
.cam-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 16px 20px calc(16px + env(safe-area-inset-bottom)); background: #000; }
.cam-bar .btn { justify-self: start; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 5px solid #fff; background: transparent; padding: 0; cursor: pointer; position: relative; }
.shutter::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: #fff; }
.shutter:active::after { inset: 8px; }

/* Resultado */
.r-icon { width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; font-size: 3rem; color: #fff; font-weight: 800; }
.r-icon.ok { background: var(--ok); }
.r-icon.warn { background: var(--warn); }
.r-icon.bad { background: var(--bad); }
.r-icon.busy { background: transparent; }

.spinner { width: 48px; height: 48px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--brand-2); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

select, textarea {
  font: inherit; color: inherit; background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px; padding: 14px; min-height: 52px; width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
select:focus-visible, textarea:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 2px; }
.notice { background: color-mix(in srgb, var(--brand-2) 14%, var(--card)); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-weight: 600; }
.inc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.inc-list li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.inc-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.chip.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }

/* Marcajes sin conexión */
.chip.off { background: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--ink); }
.offline-bar { background: #fde68a; color: #4a3200; border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; justify-content: space-between; font-size: .88rem; }
.offline-bar p { margin: 0; }
.offline-bar .btn { color: #4a3200; border-color: #4a3200; white-space: nowrap; }
.offline-bar[hidden], .offline-bar [hidden] { display: none; }

/* Pantalla de ingreso centrada */
.brand-center { align-items: center; text-align: center; gap: 10px; padding-top: 28px; }
.logo-lg { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 6px 18px rgba(10, 42, 110, .15); }
.brand-center .wordmark { font-size: 2rem; }
.slogan { margin: 0; font-weight: 700; color: var(--brand-2); font-size: 1.02rem; }
.brand-center .muted { margin: 0; max-width: 32ch; }
.login-help { text-align: center; margin: 4px 0 0; }
