/*
 * Componentes compartidos — Reserva Princesa (Pantalla 1 y Pantalla 2)
 * Ver DESIGN.md secciones 6-10 para el detalle de cada componente y estado.
 * Requiere tokens.css cargado antes que este archivo.
 */

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-content {
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 0 var(--space-4);
  flex: 1;
}

@media (min-width: 768px) {
  .page-content {
    padding: 0 var(--space-6);
  }
}

/* ---------- Header (Pantalla 1) ---------- */

.restaurant-header {
  background: var(--bg-alt);
  padding: var(--space-5) var(--space-4);
  margin: 0 calc(var(--space-4) * -1) var(--space-5);
}

@media (min-width: 768px) {
  .restaurant-header {
    margin: 0 calc(var(--space-6) * -1) var(--space-5);
    padding: var(--space-6);
  }
}

.restaurant-header__name {
  word-break: break-word;
}

.restaurant-header__address {
  display: block;
  margin-top: var(--space-2);
  color: var(--text-secondary);
  font-size: 0.875rem;
  word-break: break-word;
}

/* ---------- Secciones del formulario ---------- */

.form-section {
  margin-bottom: var(--space-6);
}

.form-section__title {
  /* Visual "H3" del sistema tipográfico (DESIGN.md sección 4), aunque el
     elemento sea un <h2> real: mantiene la jerarquía de encabezados
     correcta (h1 > h2, sin saltos) sin cambiar el tamaño/peso visual de
     los títulos de sección. */
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: var(--space-4);
}

@media (min-width: 768px) {
  .form-section__title {
    font-size: 1.125rem;
  }
}

.form-section[hidden] {
  display: none;
}

.form-section--enter {
  animation: section-enter 0.25s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .form-section--enter {
    animation: none;
  }
}

@keyframes section-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 14px 24px;
  border-radius: var(--radius-button);
  border: none;
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease;
  text-decoration: none;
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:disabled,
.btn-primary[aria-disabled="true"] {
  background: var(--surface-sunken);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-primary.is-danger {
  background: var(--error);
}

.btn-secondary {
  background: transparent;
  border: 1.5px solid var(--border-strong);
  color: var(--text-primary);
  width: 100%;
}

.btn-tertiary {
  background: none;
  border: none;
  color: var(--accent-hover);
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  font-weight: 600;
  cursor: pointer;
}

.btn-tertiary.is-danger {
  color: var(--error);
}

/* Hover solo para dispositivos con puntero fino (mouse/trackpad): evita que
   los estados de :hover queden "pegados" tras un tap en touch. */
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
  }

  .btn-primary.is-danger:hover:not(:disabled) {
    background: #8f1e18;
  }

  .btn-secondary:hover:not(:disabled) {
    background: var(--surface-sunken);
  }

  .btn-tertiary:hover {
    text-decoration: underline;
  }
}

.btn__spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .btn__spinner {
    animation: spin 1.4s steps(8) infinite;
  }
}

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

.btn[data-loading="true"] .btn__label {
  visibility: hidden;
}

.btn[data-loading="true"] {
  position: relative;
}

.btn[data-loading="true"] .btn__spinner {
  position: absolute;
}

/* ---------- Honeypot anti-bot (Fase 11, ver DECISIONS.md) ---------- */
/* Escondido fuera de la pantalla: no display:none/visibility:hidden/type=hidden
   (muchos bots los detectan y saltean), pero un input real e interactuable
   sigue en el DOM para que un autocompletado agresivo lo siga completando. */
.hp-field {
  position: absolute;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ---------- Inputs ---------- */

.field {
  margin-bottom: var(--space-4);
}

.field:last-child {
  margin-bottom: 0;
}

.field__label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.field__label .field__optional {
  text-transform: none;
  font-weight: 400;
  letter-spacing: normal;
  color: var(--text-muted);
}

.field__input,
.field__textarea {
  width: 100%;
  min-height: 48px;
  border-radius: var(--radius-input);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 1rem;
  padding: 0 var(--space-4);
}

.field__textarea {
  min-height: 64px;
  padding: var(--space-3) var(--space-4);
  resize: vertical;
  max-height: 120px;
}

.field__input:focus,
.field__textarea:focus {
  outline: none;
  border: 2px solid var(--accent);
  padding-left: calc(var(--space-4) - 1px);
}

.field__input:disabled,
.field__textarea:disabled {
  background: var(--surface-sunken);
  color: var(--text-muted);
  cursor: not-allowed;
}

.field.has-error .field__input,
.field.has-error .field__textarea {
  border: 2px solid var(--error);
}

.field__error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-1);
  margin-top: var(--space-2);
  color: var(--error);
  font-size: 0.875rem;
}

.field__error[hidden] {
  display: none;
}

.field__hint {
  margin-top: var(--space-2);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ---------- Checkbox de consentimiento (Ley 21.719, Fase 10) ---------- */

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--text-primary);
}

.checkbox-field input {
  width: 20px;
  height: 20px;
  min-width: 20px;
  margin-top: 1px;
  accent-color: var(--accent);
  cursor: pointer;
}

.field--checkbox.has-error .checkbox-field {
  color: var(--error);
}

.field--checkbox.has-error input {
  outline: 2px solid var(--error);
  outline-offset: 2px;
}

/* ---------- Stepper de personas ---------- */

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
}

.stepper__btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.stepper__btn--add {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.stepper__btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.stepper__value {
  min-width: 2.5ch;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 600;
}

.stepper__max-hint {
  margin-top: var(--space-3);
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ---------- Chips de fecha ---------- */

.date-chips {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  padding-bottom: var(--space-2);
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.date-chip {
  flex: 0 0 auto;
  scroll-snap-align: start;
  width: 64px;
  height: 72px;
  border-radius: var(--radius-chip);
  border: none;
  background: var(--surface-sunken);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  cursor: pointer;
  position: relative;
}

.date-chip__day {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
}

.date-chip__number {
  font-size: 1.25rem;
  font-weight: 600;
}

.date-chip[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

.date-chip[aria-pressed="true"] .date-chip__day {
  color: rgba(255, 255, 255, 0.85);
}

.date-chip[aria-disabled="true"] {
  color: var(--text-muted);
  cursor: not-allowed;
}

@media (hover: hover) and (pointer: fine) {
  .date-chip:not([aria-disabled="true"]):not([aria-pressed="true"]):hover {
    background: var(--border);
  }

  .time-chip:not([aria-disabled="true"]):not([aria-pressed="true"]):hover {
    background: var(--surface-sunken);
    border-color: var(--border-strong);
  }

  .stepper__btn:not(:disabled):hover {
    background: var(--surface-sunken);
  }

  .stepper__btn--add:not(:disabled):hover {
    background: var(--accent-hover);
  }
}

.date-chip[aria-disabled="true"] .date-chip__number {
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}

.date-chip__today-dot {
  position: absolute;
  bottom: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.date-chip[aria-pressed="true"] .date-chip__today-dot {
  background: #fff;
}

/* ---------- Chips de horario ---------- */

.time-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

@media (min-width: 768px) {
  .time-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.time-chip-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.time-chip {
  min-height: 44px;
  border-radius: var(--radius-chip);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
}

.time-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.time-chip[aria-disabled="true"] {
  background: var(--surface-sunken);
  color: var(--text-muted);
  text-decoration: line-through;
  cursor: not-allowed;
  border-color: var(--surface-sunken);
}

.time-chip.is-low-availability:not([aria-disabled="true"]) {
  border: 1px solid var(--warning);
}

.time-chip__badge {
  font-size: 0.6875rem;
  text-align: center;
  color: var(--warning);
  background: var(--warning-tint);
  border-radius: 6px;
  padding: 2px 4px;
}

/* ---------- Banners de estado ---------- */

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  border-radius: var(--radius-input);
  padding: var(--space-4);
  font-size: 0.875rem;
  margin-bottom: var(--space-4);
}

.banner__icon {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-top: 1px;
}

.banner__content {
  flex: 1;
  min-width: 0;
}

.banner__actions {
  margin-top: var(--space-3);
}

.banner--error {
  background: var(--error-tint);
  border: 1px solid var(--error);
  color: var(--error);
}

.banner--warning {
  background: var(--warning-tint);
  border: 1px solid var(--warning);
  color: #6b4c14;
}

.banner--success {
  background: var(--success-tint);
  border: 1px solid var(--success);
  color: var(--success);
}

.banner--info {
  background: var(--surface-sunken);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
}

.banner[hidden] {
  display: none;
}

/* ---------- Skeleton / loading ---------- */

.skeleton {
  background: var(--surface-sunken);
  border-radius: var(--radius-input);
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.55) 50%,
    transparent 100%
  );
  animation: shimmer 1.4s infinite;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after {
    animation: none;
    display: none;
  }
}

@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}

.skeleton-header {
  height: 88px;
  margin: 0 calc(var(--space-4) * -1) var(--space-5);
  border-radius: 0;
}

.skeleton-line {
  height: 16px;
  margin-bottom: var(--space-3);
}

.skeleton-chip-row {
  display: flex;
  gap: var(--space-2);
}

.skeleton-chip-row .skeleton {
  width: 64px;
  height: 72px;
  flex: 0 0 auto;
}

/* ---------- CTA sticky (mobile) ---------- */

.cta-bar {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  box-shadow: var(--shadow-sticky);
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  margin: 0 calc(var(--space-4) * -1);
}

.cta-bar__caption {
  margin-top: var(--space-2);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

@media (min-width: 768px) {
  .cta-bar {
    position: static;
    box-shadow: none;
    background: transparent;
    padding: 0;
    margin: 0;
  }
}

.form-disabled {
  opacity: 0.6;
  pointer-events: none;
}

/* ---------- Pantalla de confirmación ---------- */

.success-header {
  text-align: center;
  padding: var(--space-6) 0 var(--space-5);
}

.success-header__icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--success-tint);
  border: 1px solid var(--success);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-4);
}

.success-header__subtitle {
  display: block;
  margin-top: var(--space-2);
  color: var(--text-secondary);
}

.summary-card {
  background: var(--surface);
  border-radius: 16px;
  padding: var(--space-5);
  box-shadow: var(--shadow-1);
  margin-bottom: var(--space-5);
}

.summary-card__row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}

.summary-card__row:last-of-type {
  margin-bottom: 0;
}

.summary-card__label {
  color: var(--text-secondary);
  font-size: 0.875rem;
  flex: 0 0 auto;
}

.summary-card__value {
  color: var(--text-primary);
  font-weight: 500;
  text-align: right;
  word-break: break-word;
}

.summary-card__divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-4) 0;
}

.actions-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.actions-list__cancel {
  margin-top: var(--space-2);
  text-align: center;
}

@media (min-width: 768px) {
  .actions-list {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .actions-list > * {
    flex: 1 1 auto;
  }
}

.location-block {
  padding: var(--space-5) 0;
  border-top: 1px solid var(--border);
}

.location-block__address {
  margin-bottom: var(--space-4);
  word-break: break-word;
}

.location-block__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

@media (min-width: 768px) {
  .location-block__actions {
    flex-direction: row;
  }
  .location-block__actions > * {
    flex: 1 1 auto;
  }
}

.page-footer {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: var(--space-6) 0 var(--space-8);
}

.page-footer a {
  font-weight: 600;
}

/* ---------- Modal de confirmación (cancelar) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--space-4);
  z-index: 100;
  overscroll-behavior: contain;
}

.modal-overlay[hidden] {
  display: none;
}

@media (min-width: 768px) {
  .modal-overlay {
    align-items: center;
  }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-3);
  padding: var(--space-5);
  width: 100%;
  max-width: 420px;
}

.modal__title {
  margin-bottom: var(--space-4);
}

.modal__error {
  margin-top: var(--space-3);
}

.modal__actions {
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

@media (min-width: 480px) {
  .modal__actions {
    flex-direction: row;
    justify-content: flex-end;
  }
  .modal__actions > * {
    width: auto;
    min-width: 140px;
  }
}

/* ---------- Estado de página completo (token inválido / error) ---------- */

.full-page-state {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-8) var(--space-4);
  gap: var(--space-4);
}

.full-page-state__icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--error-tint);
  border: 1px solid var(--error);
  color: var(--error);
  display: flex;
  align-items: center;
  justify-content: center;
}

.full-page-state__text {
  color: var(--text-secondary);
  max-width: 40ch;
}

.full-page-state .btn-primary {
  width: auto;
  min-width: 220px;
}

[hidden] {
  display: none !important;
}
