/* =========================================================
   Login con PIN
   Tableta horizontal: marca a la izquierda, teclado a la derecha.
   Tableta vertical / teléfono: barra de marca compacta arriba.
   ========================================================= */

.login {
  --key: clamp(60px, min(10.5vh, 22vw), 92px);

  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

/* ---------- Panel de marca ---------- */

.login-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(34, 197, 94, 0.14), transparent 55%),
    var(--card);
}

.brand-top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 12px;
}

.brand-name {
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: var(--fs-xs);
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-clock {
  text-align: right;
}

.clock-time {
  font-size: var(--fs-lg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.clock-date {
  font-size: var(--fs-xs);
  color: var(--text-2);
}

.brand-bottom {
  display: none;
}

/* ---------- Panel de acceso ---------- */

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.step {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fade-in 0.25s ease-out;
}

.step-head {
  text-align: center;
  margin-bottom: 20px;
}

.step-head h1 {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.step-head p {
  margin: 8px 0 0;
  color: var(--text-2);
  font-size: var(--fs-sm);
}

/* ---------- Vincular tableta ---------- */

#step-tableta {
  max-width: 460px;
}

.form-tableta {
  display: grid;
  gap: 16px;
  width: 100%;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
}

.field input {
  width: 100%;
  min-height: var(--touch);
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--card);
  font-size: var(--fs-md);
}

.field input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.form-msg {
  min-height: 1.4em;
  margin: 0;
  color: var(--danger);
  font-size: var(--fs-sm);
  text-align: center;
}

.btn-block {
  width: 100%;
}

/* ---------- Chip de sucursal ---------- */

.sucursal-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-bottom: 20px;
  padding: 0 16px 0 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 600;
}

.sucursal-chip svg {
  width: 18px;
  height: 18px;
  fill: var(--green);
}

/* ---------- Puntos del PIN ---------- */

.pin-dots {
  display: flex;
  gap: 16px;
  height: 22px;
  align-items: center;
}

.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--text-3);
  transition: background-color 0.12s, border-color 0.12s, transform 0.12s;
}

.pin-dot.filled {
  background: var(--green);
  border-color: var(--green);
  transform: scale(1.1);
}

.pin-dot.optional {
  border-style: dashed;
  opacity: 0.5;
}

.pin-dots.error .pin-dot {
  border-color: var(--danger);
}

.pin-dots.error .pin-dot.filled {
  background: var(--danger);
}

.pin-dots.shake {
  animation: shake 0.4s;
}

.pin-msg {
  min-height: 1.5em;
  margin: 14px 0 18px;
  font-size: var(--fs-sm);
  color: var(--danger);
  text-align: center;
}

.pin-msg.info {
  color: var(--text-2);
}

/* ---------- Teclado ---------- */

.keypad {
  display: grid;
  grid-template-columns: repeat(3, var(--key));
  gap: clamp(10px, 2vh, 18px) clamp(14px, 3vw, 24px);
}

.key {
  display: grid;
  place-items: center;
  width: var(--key);
  height: var(--key);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card);
  font-size: calc(var(--key) * 0.36);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: background-color 0.1s, transform 0.08s, border-color 0.1s;
}

.key:active,
.key.pressed {
  background: var(--card-2);
  border-color: var(--green);
  transform: scale(0.94);
}

.key svg {
  width: 40%;
  height: 40%;
  fill: currentColor;
}

.key-fn {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.key-ok {
  background: var(--green);
  border-color: var(--green);
  color: #052E16;
}

.key-ok:active {
  background: var(--green-600);
}

.key:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.keypad.busy .key {
  pointer-events: none;
}

.keypad.busy .key-ok svg {
  display: none;
}

.keypad.busy .key-ok::after {
  content: '';
  width: 40%;
  height: 40%;
  border: 3px solid rgba(5, 46, 22, 0.3);
  border-top-color: #052E16;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ---------- Tableta horizontal y escritorio ---------- */

@media (min-width: 900px) and (orientation: landscape) {
  .login {
    grid-template-columns: minmax(340px, 0.9fr) 1.1fr;
    grid-template-rows: 1fr;
  }

  .login-brand {
    flex-direction: column;
    align-items: stretch;
    padding: 40px;
    border-bottom: 0;
    border-right: 1px solid var(--border);
  }

  .brand-logo {
    width: 56px;
    height: 56px;
    border-radius: 14px;
  }

  .brand-name {
    font-size: 1.75rem;
  }

  .brand-clock {
    text-align: left;
  }

  .clock-time {
    font-size: clamp(3.5rem, 7vw, 5.5rem);
    font-weight: 300;
    letter-spacing: -0.03em;
    line-height: 1;
  }

  .clock-date {
    margin-top: 8px;
    font-size: var(--fs-lg);
  }

  .brand-bottom {
    display: block;
  }
}

/* ---------- Pantallas bajas (teléfono horizontal) ---------- */

@media (max-height: 560px) and (orientation: landscape) {
  .login {
    --key: clamp(40px, 12.5vh, 60px);
    grid-template-rows: 1fr;
  }

  .login-brand,
  .step-head h1,
  .step-head p {
    display: none;
  }

  .login-panel {
    padding: 8px 16px;
  }

  .step-head {
    margin-bottom: 8px;
  }

  .sucursal-chip {
    min-height: 36px;
    margin-bottom: 0;
  }

  .pin-msg {
    margin: 4px 0 8px;
  }

  .keypad {
    gap: 8px 16px;
  }
}

@media (max-width: 480px) {
  .clock-date {
    display: none;
  }
}

@media (max-width: 360px) {
  .brand-clock {
    display: none;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
