/**
 * PadelSystem Modal System - CSS Framework
 * Unified, responsive modal system for the entire application
 * Version: 1.0.0
 */

/* ============================================
   CSS TOKENS (Variables)
   ============================================ */
:root {
  /* Colors */
  --modal-backdrop-bg: rgba(2, 6, 23, 0.85);
  --modal-bg: rgb(15, 23, 42);
  --modal-border: rgba(255, 255, 255, 0.1);
  --modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  --modal-header-bg: rgba(15, 23, 42, 0.95);
  --modal-footer-bg: rgba(2, 6, 23, 0.5);
  
  /* Sizes */
  --modal-radius: 1rem;
  --modal-padding: 1.5rem;
  --modal-header-h: 4rem;
  --modal-footer-h: 5rem;
  --modal-gap: 1.5rem;
  
  /* Max widths */
  --modal-max-w-sm: 28rem;
  --modal-max-w-md: 32rem;
  --modal-max-w-lg: 48rem;
  --modal-max-w-xl: 56rem;
  --modal-max-w-2xl: 64rem;
  --modal-max-w-full: 95vw;
  
  /* Z-index */
  --modal-z-base: 1000;
  --modal-z-nested: 1100;
  
  /* Transitions */
  --modal-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   BACKDROP
   ============================================ */
.ps-modal {
  position: fixed;
  inset: 0;
  z-index: var(--modal-z-base);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--modal-backdrop-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.ps-modal.is-open {
  display: flex;
}

.ps-modal.is-nested {
  z-index: var(--modal-z-nested);
}

/* Animaciones */
.ps-modal.is-opening {
  animation: ps-modal-fade-in 0.2s ease-out;
}

.ps-modal.is-closing {
  animation: ps-modal-fade-out 0.15s ease-in;
}

@keyframes ps-modal-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes ps-modal-fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* ============================================
   DIALOG CONTAINER
   ============================================ */
.ps-modal__dialog {
  position: relative;
  width: 100%;
  max-width: var(--modal-max-w-lg);
  max-height: calc(100dvh - 2rem);
  margin: auto;
  background: var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: var(--modal-radius);
  box-shadow: var(--modal-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(1);
  transition: var(--modal-transition);
}

/* Animación del dialog */
.ps-modal.is-opening .ps-modal__dialog {
  animation: ps-modal-slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.ps-modal.is-closing .ps-modal__dialog {
  animation: ps-modal-slide-down 0.2s ease-in;
}

@keyframes ps-modal-slide-up {
  from {
    opacity: 0;
    transform: translateY(2rem) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes ps-modal-slide-down {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(1rem) scale(0.98);
  }
}

/* Tamaños de modal */
.ps-modal--sm .ps-modal__dialog {
  max-width: var(--modal-max-w-sm);
}

.ps-modal--md .ps-modal__dialog {
  max-width: var(--modal-max-w-md);
}

.ps-modal--lg .ps-modal__dialog {
  max-width: var(--modal-max-w-lg);
}

.ps-modal--xl .ps-modal__dialog {
  max-width: var(--modal-max-w-xl);
}

.ps-modal--2xl .ps-modal__dialog {
  max-width: var(--modal-max-w-2xl);
}

.ps-modal--full .ps-modal__dialog {
  max-width: var(--modal-max-w-full);
}

/* ============================================
   HEADER
   ============================================ */
.ps-modal__header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--modal-header-h);
  padding: var(--modal-padding);
  background: var(--modal-header-bg);
  border-bottom: 1px solid var(--modal-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.ps-modal__title {
  flex: 1;
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  color: rgb(241, 245, 249);
  text-transform: uppercase;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.ps-modal__subtitle {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.625rem;
  font-weight: 700;
  color: rgb(100, 116, 139);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.ps-modal__close {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(30, 41, 59);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 0.5rem;
  color: rgb(148, 163, 184);
  font-size: 1.25rem;
  cursor: pointer;
  transition: var(--modal-transition);
}

.ps-modal__close:hover {
  background: rgb(220, 38, 38);
  color: white;
  transform: scale(1.05);
}

.ps-modal__close:active {
  transform: scale(0.95);
}

/* ============================================
   BODY
   ============================================ */
.ps-modal__body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--modal-padding);
  overscroll-behavior: contain;
}

/* Scrollbar personalizado */
.ps-modal__body::-webkit-scrollbar {
  width: 8px;
}

.ps-modal__body::-webkit-scrollbar-track {
  background: rgb(15, 23, 42);
}

.ps-modal__body::-webkit-scrollbar-thumb {
  background: rgb(71, 85, 105);
  border-radius: 4px;
}

.ps-modal__body::-webkit-scrollbar-thumb:hover {
  background: rgb(100, 116, 139);
}

/* ============================================
   FOOTER
   ============================================ */
.ps-modal__footer {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  min-height: var(--modal-footer-h);
  padding: var(--modal-padding);
  background: var(--modal-footer-bg);
  border-top: 1px solid var(--modal-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.ps-modal__footer--start {
  justify-content: flex-start;
}

.ps-modal__footer--center {
  justify-content: center;
}

.ps-modal__footer--between {
  justify-content: space-between;
}

/* ============================================
   BUTTONS (Estandarizados)
   ============================================ */
.ps-modal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 0.625rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--modal-transition);
  white-space: nowrap;
}

.ps-modal-btn:active {
  transform: scale(0.95);
}

/* Primary */
.ps-modal-btn--primary {
  background: linear-gradient(to right, rgb(37, 99, 235), rgb(79, 70, 229));
  color: white;
  box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.2);
}

.ps-modal-btn--primary:hover {
  background: linear-gradient(to right, rgb(29, 78, 216), rgb(67, 56, 202));
  box-shadow: 0 20px 25px -5px rgba(37, 99, 235, 0.3);
}

/* Secondary */
.ps-modal-btn--secondary {
  background: rgb(30, 41, 59);
  color: rgb(203, 213, 225);
  border-color: rgba(255, 255, 255, 0.05);
}

.ps-modal-btn--secondary:hover {
  background: rgb(51, 65, 85);
  color: white;
}

/* Danger */
.ps-modal-btn--danger {
  background: rgb(220, 38, 38);
  color: white;
  box-shadow: 0 10px 15px -3px rgba(220, 38, 38, 0.2);
}

.ps-modal-btn--danger:hover {
  background: rgb(185, 28, 28);
  box-shadow: 0 20px 25px -5px rgba(220, 38, 38, 0.3);
}

/* Success */
.ps-modal-btn--success {
  background: rgb(22, 163, 74);
  color: white;
  box-shadow: 0 10px 15px -3px rgba(22, 163, 74, 0.2);
}

.ps-modal-btn--success:hover {
  background: rgb(21, 128, 61);
  box-shadow: 0 20px 25px -5px rgba(22, 163, 74, 0.3);
}

/* Tamaños */
.ps-modal-btn--sm {
  padding: 0.5rem 1rem;
  font-size: 0.5625rem;
}

.ps-modal-btn--lg {
  padding: 1rem 2rem;
  font-size: 0.75rem;
}

/* Full width */
.ps-modal-btn--full {
  width: 100%;
}

/* ============================================
   RESPONSIVE
   ============================================ */

/* Tablet y menor */
@media (max-width: 768px) {
  .ps-modal {
    padding: 0.5rem;
  }
  
  .ps-modal__dialog {
    max-height: calc(100dvh - 1rem);
  }
  
  .ps-modal__header,
  .ps-modal__body,
  .ps-modal__footer {
    padding: 1rem;
  }
  
  .ps-modal__footer {
    flex-wrap: wrap;
  }
  
  .ps-modal-btn {
    flex: 1;
    min-width: 0;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .ps-modal {
    padding: 0;
  }
  
  .ps-modal__dialog {
    max-height: 100dvh;
    border-radius: 0;
  }
  
  .ps-modal__header {
    min-height: 3.5rem;
  }
  
  .ps-modal__title {
    font-size: 1rem;
  }
  
  .ps-modal__close {
    width: 2rem;
    height: 2rem;
  }
  
  .ps-modal__footer {
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .ps-modal-btn {
    width: 100%;
  }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .ps-modal__dialog {
    max-height: 100dvh;
  }
  
  .ps-modal__header {
    min-height: 3rem;
    padding: 0.75rem 1rem;
  }
  
  .ps-modal__body {
    padding: 1rem;
  }
  
  .ps-modal__footer {
    min-height: 3.5rem;
    padding: 0.75rem 1rem;
  }
}

/* ============================================
   SAFE AREA (iOS)
   ============================================ */
@supports (padding: max(0px)) {
  .ps-modal__header {
    padding-left: max(var(--modal-padding), env(safe-area-inset-left));
    padding-right: max(var(--modal-padding), env(safe-area-inset-right));
  }
  
  .ps-modal__body {
    padding-left: max(var(--modal-padding), env(safe-area-inset-left));
    padding-right: max(var(--modal-padding), env(safe-area-inset-right));
  }
  
  .ps-modal__footer {
    padding-left: max(var(--modal-padding), env(safe-area-inset-left));
    padding-right: max(var(--modal-padding), env(safe-area-inset-right));
    padding-bottom: max(var(--modal-padding), env(safe-area-inset-bottom));
  }
}

/* ============================================
   UTILITIES
   ============================================ */

/* Scroll lock para body */
body.ps-modal-open {
  overflow: hidden;
  padding-right: var(--scrollbar-width, 0);
}

/* Loading state */
.ps-modal__loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: rgb(148, 163, 184);
}

.ps-modal__spinner {
  width: 3rem;
  height: 3rem;
  border: 3px solid rgba(59, 130, 246, 0.2);
  border-top-color: rgb(59, 130, 246);
  border-radius: 50%;
  animation: ps-modal-spin 0.8s linear infinite;
}

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

/* Empty state */
.ps-modal__empty {
  padding: 3rem;
  text-align: center;
  color: rgb(100, 116, 139);
}

.ps-modal__empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* Divider */
.ps-modal__divider {
  height: 1px;
  margin: 1.5rem 0;
  background: rgba(255, 255, 255, 0.05);
}
