/* =========================================================
   Trauma Clinic — Motion System (Apple HIG)
   Rápido, preciso, sin bounce ni tiempos innecesarios.
   ========================================================= */

:root {
  --ease-apple: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-exit: cubic-bezier(0.4, 0, 1, 1);
  --dur-micro: 150ms;
  --dur-ui: 280ms;
  --dur-page: 300ms;
}

/* ---------- Micro-interacciones ---------- */
.primary,
.login-submit,
.glass-btn,
.btn-action,
.text-action-btn,
.nav-action,
button.btn-link,
.cal-day,
.tc-pressable {
  transition:
    transform var(--dur-micro) var(--ease-apple),
    background-color var(--dur-micro) ease,
    color var(--dur-micro) ease,
    filter var(--dur-micro) ease,
    opacity var(--dur-micro) ease,
    border-color var(--dur-micro) ease,
    box-shadow var(--dur-micro) ease;
  will-change: transform;
}

.primary:hover,
.login-submit:hover,
.glass-btn:hover,
.btn-action:hover {
  filter: brightness(1.06);
}

.primary:active,
.login-submit:active,
.glass-btn:active,
.btn-action:active,
.text-action-btn:active,
.nav-action:active,
.cal-day:active,
.tc-pressable:active {
  transform: scale(0.97);
}

/* ---------- Velo de continuidad (navegación) ---------- */
.tc-page-veil {
  position: fixed;
  inset: 0;
  z-index: 100000;
  pointer-events: none;
  opacity: 0;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  transition:
    opacity var(--dur-page) var(--ease-apple),
    backdrop-filter var(--dur-page) var(--ease-apple),
    -webkit-backdrop-filter var(--dur-page) var(--ease-apple);
}
.tc-page-veil.is-active {
  opacity: 1;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Salida: cross-fade + scale sutil (sin translate de contenedores) */
html.tc-motion.page-leaving .main-wrap {
  opacity: 0;
  transform: scale(0.98);
  transition:
    opacity var(--dur-page) var(--ease-exit),
    transform var(--dur-page) var(--ease-exit);
  pointer-events: none;
  transform-origin: center top;
}
html.tc-motion.page-leaving .topbar {
  opacity: 0.82;
  transition: opacity var(--dur-page) var(--ease-exit);
  pointer-events: none;
}

/* Entrada de módulo: cross-fade + scale 0.98 → 1 */
html.tc-motion.page-enter:not(.page-ready) .main-wrap {
  opacity: 0;
  transform: scale(0.98);
  transform-origin: center top;
}
html.tc-motion.page-enter.page-ready .main-wrap {
  animation: tcCrossFadeIn var(--dur-page) var(--ease-apple) both;
}

/* Post-login: mismo idioma visual, un poco más de presencia, sin teatro */
html.tc-motion.page-enter-login:not(.page-ready) .main-wrap {
  opacity: 0;
  transform: scale(0.98);
  transform-origin: center top;
}
html.tc-motion.page-enter-login:not(.page-ready) .topbar {
  opacity: 0;
}
html.tc-motion.page-enter-login.page-ready .topbar {
  animation: tcFadeIn var(--dur-ui) 40ms var(--ease-apple) both;
}
html.tc-motion.page-enter-login.page-ready .main-wrap {
  animation: tcCrossFadeIn 360ms 60ms var(--ease-apple) both;
}

@keyframes tcCrossFadeIn {
  from {
    opacity: 0;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
@keyframes tcFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- Filas de tablas (stagger 40ms) ---------- */
html.tc-motion.page-enter.page-ready .table tbody tr,
html.tc-motion.page-enter-login.page-ready .table tbody tr {
  animation: tcRowIn 260ms var(--ease-apple) both;
}
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(1),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(1) { animation-delay: 40ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(2),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(2) { animation-delay: 80ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(3),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(3) { animation-delay: 120ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(4),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(4) { animation-delay: 160ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(5),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(5) { animation-delay: 200ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(6),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(6) { animation-delay: 240ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(7),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(7) { animation-delay: 280ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(8),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(8) { animation-delay: 320ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(9),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(9) { animation-delay: 360ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(10),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(10) { animation-delay: 400ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(11),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(11) { animation-delay: 440ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(12),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(12) { animation-delay: 480ms; }
html.tc-motion.page-enter.page-ready .table tbody tr:nth-child(n+13),
html.tc-motion.page-enter-login.page-ready .table tbody tr:nth-child(n+13) { animation-delay: 520ms; }

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

/* ---------- Modales (Glass + slide corto) ---------- */
.tc-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  transition: opacity var(--dur-ui) var(--ease-apple);
}
.tc-modal.is-open {
  display: flex;
  opacity: 1;
}
.tc-modal.is-closing {
  display: flex;
  opacity: 0;
}

.tc-modal-panel {
  width: min(400px, calc(100vw - 32px));
  background: rgba(28, 28, 30, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 30px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
  transform: translateY(10px);
  opacity: 0;
}
.tc-modal.is-open .tc-modal-panel {
  animation: tcModalIn var(--dur-ui) var(--ease-apple) both;
}
.tc-modal.is-closing .tc-modal-panel {
  animation: tcModalOut 220ms var(--ease-exit) both;
}

.tc-modal-title {
  margin: 0 0 25px;
  color: #fff;
  text-align: center;
  border-bottom: 1px solid #2c2c2e;
  padding-bottom: 15px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.5px;
}
.tc-modal-field {
  margin-bottom: 20px;
}
.tc-modal-field label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #8e8e93;
}
.tc-modal-field input,
.tc-modal-field select {
  width: 100%;
  padding: 12px;
  box-sizing: border-box;
  background: #1c1c1e;
  border: 1px solid #2c2c2e;
  border-radius: 8px;
  font-size: 14px;
  color: #fff;
  outline: none;
  color-scheme: dark;
  font-family: inherit;
}
.tc-modal-row {
  display: flex;
  gap: 15px;
  margin-bottom: 30px;
}
.tc-modal-row > div { flex: 1; }
.tc-modal-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}
.tc-modal-confirm {
  background: transparent;
  border: none;
  color: #ff9f0a;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  font-family: inherit;
  padding: 10px;
  transition:
    transform var(--dur-micro) var(--ease-apple),
    color var(--dur-micro) ease,
    opacity var(--dur-micro) ease;
}
.tc-modal-confirm:active { transform: scale(0.97); }

@keyframes tcModalIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes tcModalOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* Modal creado en JS (reprogramar cita) */
#modal-reprog.tc-modal {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#modal-reprog .tc-modal-panel {
  min-width: min(320px, calc(100vw - 32px));
  padding: 16px;
}

/* Modal reprogramar agenda: sin overlay fantasma */
#modal-reprog-agenda[hidden] {
  display: none !important;
  pointer-events: none !important;
  opacity: 0 !important;
}
#modal-reprog-agenda.is-open {
  display: flex !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}
#modal-reprog-agenda.is-open .tc-modal-panel {
  opacity: 1 !important;
  transform: none !important;
  animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html.tc-motion.page-leaving .main-wrap,
  html.tc-motion.page-enter:not(.page-ready) .main-wrap,
  html.tc-motion.page-enter-login:not(.page-ready) .main-wrap {
    opacity: 1 !important;
    transform: none !important;
  }
  .tc-page-veil { display: none !important; }
}

/* Hero assemble: no interferir con la cascada del nav */
html.hero-entrance.page-enter-login.page-ready .topbar,
html.hero-entrance.page-enter.page-ready .topbar {
  animation: none !important;
  opacity: 1 !important;
}
