/* ============================================================
   Sistema de fichajes · Sistema de Fichajes — base compartida
   Paleta cálida tierra (#6A5749 / #6B6158)
   ============================================================ */

:root {
  --band: #6B6158;          /* fondo exacto del logo */
  --brand: #6A5749;         /* marrón corporativo */
  --brand-deep: #51453B;
  --ink: #322A24;
  --paper: #FBF8F2;
  --bg: #F1EBE0;
  --card: #FDFBF6;
  --line: #E2D9C8;
  --line-soft: #EDE7D9;
  --muted: #8B8071;
  --faint: #B5AA96;
  --green: #3E744D;
  --green-deep: #2E5A3B;
  --green-soft: #E9F1E6;
  --green-line: #C5DAC3;
  --red: #A8512E;
  --red-deep: #87401F;
  --red-soft: #F8E9DF;
  --gold: #B98A4A;
  --gold-deep: #8A6326;
  --gold-soft: #F6ECD8;
  --gold-line: #E6D3A9;
  --f-display: 'Roboto Slab', 'Georgia', serif;
  --f-body: 'Roboto', 'Helvetica Neue', sans-serif;
  --f-mono: 'Roboto Mono', 'Courier New', monospace;
  --radius: 18px;
  --shadow-card: 0 2px 8px rgba(50, 42, 36, .06), 0 1px 2px rgba(50, 42, 36, .05);
  --shadow-pop: 0 18px 50px rgba(40, 31, 22, .28);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--f-body);
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(1200px 500px at 85% -10%, rgba(107, 97, 88, .10), transparent 60%),
    radial-gradient(900px 420px at -10% 100%, rgba(185, 138, 74, .07), transparent 55%);
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* grano de papel sutil por encima de todo */
.grain {
  position: fixed; inset: 0; z-index: 1000; pointer-events: none; opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.42 0 0 0 0 0.36 0 0 0 0 0.30 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

/* pantalla de arranque */
.app-boot { min-height: 100dvh; display: grid; place-items: center; }
.boot-logo img { border-radius: 20px; animation: bootPulse 1.4s ease-in-out infinite; box-shadow: 0 14px 40px rgba(50, 42, 36, .25); }
@keyframes bootPulse { 0%, 100% { transform: scale(1); opacity: .85; } 50% { transform: scale(1.06); opacity: 1; } }

/* ---------------------------------------------------------- botones */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 54px; padding: 12px 22px; border-radius: 15px; border: none;
  font-family: var(--f-body); font-size: 17px; font-weight: 700; letter-spacing: .01em;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease, opacity .2s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.96); }
.btn svg { width: 19px; height: 19px; flex: none; }
.btn-sm svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 6px 16px rgba(106, 87, 73, .35), inset 0 1px 0 rgba(255, 255, 255, .18); }
.btn-primary:hover { background: var(--brand-deep); }
.btn-green { background: var(--green); color: #fff; box-shadow: 0 6px 16px rgba(62, 116, 77, .35), inset 0 1px 0 rgba(255, 255, 255, .18); }
.btn-green:hover { background: var(--green-deep); }
.btn-red { background: var(--red); color: #fff; box-shadow: 0 6px 16px rgba(168, 81, 46, .35), inset 0 1px 0 rgba(255, 255, 255, .18); }
.btn-red:hover { background: var(--red-deep); }
.btn-gold { background: var(--gold); color: #fff; box-shadow: 0 6px 16px rgba(185, 138, 74, .35), inset 0 1px 0 rgba(255, 255, 255, .2); }
.btn-gold:hover { background: var(--gold-deep); }
.btn-ghost { background: transparent; border: 2px solid var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--faint); background: rgba(50, 42, 36, .04); }
.btn-sm { min-height: 40px; padding: 8px 16px; font-size: 14px; border-radius: 11px; }
.btn-block { width: 100%; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 13px; border: 2px solid var(--line);
  background: var(--paper); cursor: pointer; transition: transform .12s, background .2s;
  flex: none;
}
.iconbtn:active { transform: scale(.92); }
.iconbtn svg { width: 21px; height: 21px; }

/* ---------------------------------------------------------- formularios */

.field { margin-bottom: 16px; text-align: left; }
.field > label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; margin-bottom: 7px; }
.input, select.input, textarea.input {
  width: 100%; padding: 13px 15px; border-radius: 13px; border: 2px solid var(--line);
  background: #fff; font: inherit; font-size: 16px; color: var(--ink);
  transition: border-color .2s, box-shadow .2s; -webkit-appearance: none; appearance: none;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(106, 87, 73, .15); }
textarea.input { resize: vertical; min-height: 72px; }
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%238B8071' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px;
}
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* contraseña única (XXXX-XXXX) */
.input-code {
  font-family: var(--f-mono); font-size: 25px; font-weight: 700; letter-spacing: .22em;
  text-align: center; text-transform: uppercase;
}

/* ---------------------------------------------------------- reCAPTCHA v2 */

.rc-slot {
  min-height: 78px; display: flex; justify-content: center; align-items: center;
  margin-bottom: 14px;
}
.rc-fail {
  font-size: 13.5px; color: var(--red-deep); text-align: center; line-height: 1.5;
  padding: 12px 14px; background: var(--red-soft); border-radius: 11px;
}

/* ---------------------------------------------------------- ticket / modal */

.overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px;
  background: rgba(44, 36, 29, .5); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .22s ease;
}
.overlay.open { opacity: 1; }
.sheet-wrap { filter: drop-shadow(0 22px 44px rgba(35, 27, 19, .4)); width: min(460px, 100%); }
.ticket {
  background: var(--paper); border-radius: 22px 22px 0 0; padding: 26px 24px 30px;
  -webkit-mask: radial-gradient(circle 9px at 11px calc(100% + 3px), transparent 9px, #000 9.5px) repeat-x;
  -webkit-mask-size: 22px 100%;
  mask: radial-gradient(circle 9px at 11px calc(100% + 3px), transparent 9px, #000 9.5px) repeat-x;
  mask-size: 22px 100%;
  transform: translateY(46px) scale(.95); opacity: 0;
  transition: transform .32s cubic-bezier(.32, 1.4, .46, 1), opacity .22s ease;
}
.overlay.open .ticket { transform: translateY(0) scale(1); opacity: 1; }
.ticket-eyebrow {
  font-family: var(--f-mono); font-size: 11px; font-weight: 700; letter-spacing: .32em;
  text-transform: uppercase; color: var(--faint); text-align: center; margin-bottom: 14px;
}
.ticket h2 { font-family: var(--f-display); font-size: 26px; font-weight: 700; text-align: center; }
.ticket .tear { border-top: 2px dashed var(--line); margin: 18px -24px; }
.ticket-rows { margin: 0 0 6px; }
.ticket-row { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; padding: 7px 0; font-size: 15.5px; }
.ticket-row .k { color: var(--muted); }
.ticket-row .v { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.ticket-row .v.mono { font-family: var(--f-mono); }
.ticket-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; margin-top: 18px; }
.ticket-actions.single { grid-template-columns: 1fr; }
.ticket-actions-col { grid-template-columns: 1fr; gap: 10px; }
@media (max-width: 380px) { .ticket-actions { grid-template-columns: 1fr; } }

/* sello de confirmación */
.stamp-scene { display: grid; place-items: center; padding: 26px 0 16px; }
.stamp {
  font-family: var(--f-mono); font-weight: 700; font-size: 21px; letter-spacing: .14em;
  text-transform: uppercase; padding: 14px 22px; border-radius: 12px; text-align: center;
  border: 3.5px solid currentColor; transform: rotate(-6deg);
  animation: stampIn .5s cubic-bezier(.18, 1.5, .42, 1) both;
  position: relative;
}
.stamp small { display: block; font-size: 12px; letter-spacing: .26em; opacity: .75; margin-top: 4px; }
.stamp.in { color: var(--green-deep); background: var(--green-soft); }
.stamp.out { color: var(--red-deep); background: var(--red-soft); }
@keyframes stampIn {
  0% { transform: rotate(-6deg) scale(2.4); opacity: 0; }
  55% { transform: rotate(-6deg) scale(.94); opacity: 1; }
  100% { transform: rotate(-6deg) scale(1); opacity: 1; }
}

/* ---------------------------------------------------------- avatar grande */

.big-avatar {
  width: 72px; height: 72px; border-radius: 22px; flex: none; margin: 0 auto;
  display: grid; place-items: center; color: #fff;
  font-family: var(--f-display); font-weight: 700; font-size: 28px;
  background: var(--wc, var(--brand));
  background-image: linear-gradient(145deg, rgba(255, 255, 255, .32), rgba(255, 255, 255, 0) 44%, rgba(0, 0, 0, .17));
  box-shadow: 0 10px 22px -8px var(--wc, var(--brand)), inset 0 1px 0 rgba(255, 255, 255, .3);
  text-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.big-avatar.emoji {
  background: #fff; background-image: none; color: initial; font-size: 38px; text-shadow: none;
  box-shadow: 0 10px 22px -9px var(--wc, var(--brand)), inset 0 0 0 2.5px var(--wc, var(--brand));
}

/* ---------------------------------------------------------- teclado numérico de PIN */

.pin-avatar { margin-bottom: 12px; }
.pin-sub { text-align: center; color: var(--muted); font-size: 14.5px; margin: 7px 0 0; min-height: 20px; transition: color .2s; }
.pin-sub.is-err { color: var(--red-deep); font-weight: 600; }

.pin-dots { display: flex; justify-content: center; gap: 16px; margin: 20px 0 22px; }
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: transparent; border: 2.5px solid var(--line);
  transition: transform .15s cubic-bezier(.3, 1.6, .5, 1), background .15s, border-color .15s;
}
.pin-dot.on {
  background: var(--accent, var(--brand)); border-color: var(--accent, var(--brand));
  transform: scale(1.16);
}
.pin-dots.err { animation: pinShake .42s ease; }
@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); } 40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); } 80% { transform: translateX(4px); }
}

.pin-keys {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  max-width: 290px; margin: 0 auto; transition: opacity .2s;
}
.pin-keys.busy { opacity: .5; pointer-events: none; }
.pin-key {
  height: 64px; border-radius: 16px; border: none; cursor: pointer;
  background: #fff; box-shadow: var(--shadow-card), inset 0 0 0 1.5px var(--line-soft);
  font-family: var(--f-display); font-weight: 700; font-size: 26px; color: var(--ink);
  display: grid; place-items: center; user-select: none; -webkit-user-select: none;
  transition: transform .09s ease, background .15s, box-shadow .15s;
  touch-action: manipulation;
}
.pin-key:hover { background: var(--paper); }
.pin-key:active { transform: scale(.93); background: var(--gold-soft); box-shadow: inset 0 0 0 1.5px var(--gold-line); }
.pin-key.spacer { background: none; box-shadow: none; pointer-events: none; }
.pin-key.pin-back { color: var(--muted); }
.pin-key.pin-back svg { width: 26px; height: 26px; }
.pin-cancel {
  display: block; margin: 18px auto 0; background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 14.5px; font-weight: 600; padding: 8px 16px; border-radius: 10px;
}
.pin-cancel:hover { color: var(--ink); background: rgba(50, 42, 36, .05); }

@media (max-width: 360px) {
  .pin-keys { gap: 10px; max-width: 260px; }
  .pin-key { height: 56px; font-size: 23px; }
}

/* ---------------------------------------------------------- avisos */

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 16px);
  z-index: 200; background: var(--ink); color: var(--paper); font-size: 15px; font-weight: 500;
  padding: 13px 20px; border-radius: 13px; box-shadow: var(--shadow-pop);
  opacity: 0; transition: opacity .25s, transform .25s; max-width: min(440px, calc(100vw - 32px)); text-align: center;
  pointer-events: none; /* nunca debe bloquear los toques de debajo */
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red-deep); }
.toast.okk { background: var(--green-deep); }

.shake { animation: shake .45s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); } 40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); } 80% { transform: translateX(4px); }
}

/* cuenta atrás de bloqueo */
.lockbox { text-align: center; padding: 8px 0 4px; }
.lockbox .lock-ico { font-size: 34px; margin-bottom: 8px; }
.lockbox .lock-count {
  font-family: var(--f-mono); font-size: 52px; font-weight: 700; color: var(--red-deep);
  font-variant-numeric: tabular-nums; letter-spacing: .05em; line-height: 1.1;
}
.lockbox .lock-bar { height: 7px; border-radius: 4px; background: var(--red-soft); margin: 14px 8px 10px; overflow: hidden; }
.lockbox .lock-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--red), var(--red-deep)); border-radius: 4px; transition: width 1s linear; }
.lockbox p { color: var(--muted); font-size: 14.5px; }

/* ---------------------------------------------------------- utilidades */

.muted { color: var(--muted); }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

.fade-up { animation: fadeUp .5s cubic-bezier(.2, .8, .3, 1) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 26px; height: 26px; border-radius: 50%; margin: 0 auto;
  border: 3px solid var(--line); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

/* ---------------------------------------------------------- PWA: instalación */

.is-hidden { display: none !important; }

.install-btn { gap: 9px; }

.gate-install { margin-top: 16px; padding-top: 16px; border-top: 1.5px dashed var(--line); }

/* pasos para instalar en iOS (modal) */
.install-steps {
  list-style: none; margin: 8px 0 2px; padding: 0; text-align: left;
  display: flex; flex-direction: column; gap: 14px;
}
.install-steps li { display: flex; align-items: flex-start; gap: 11px; font-size: 15px; line-height: 1.45; color: var(--ink); }
.install-steps .is-step {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand); color: #fff; font-family: var(--f-mono); font-weight: 700; font-size: 14px;
  display: grid; place-items: center; margin-top: 1px;
}
.install-steps .is-ico { display: inline-flex; align-items: center; color: var(--brand); }
.install-steps .is-ico svg { width: 18px; height: 18px; vertical-align: middle; }

/* ---------------------------------------------------------- responsive: reCAPTCHA en pantallas estrechas
   El widget mide 304 px fijos; en móviles estrechos reducimos el margen de la
   tarjeta y, en lo más pequeño, lo escalamos para que nunca se desborde. */
@media (max-width: 412px) {
  .gate { padding-left: 12px !important; padding-right: 12px !important; }
  .gate .gate-card { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 360px) {
  .gate .gate-card { padding-left: 12px; padding-right: 12px; }
}
@media (max-width: 335px) {
  /* el widget mide 304px fijos: lo encajamos y recortamos para que no ensanche la tarjeta */
  .rc-slot { width: calc(100vw - 56px); overflow: hidden; }
  .rc-slot > * { transform: scale(.82); transform-origin: center top; }
}
