/**
 * SISTEMA DE ESTILOS RESPONSIVE - MOBILE FIRST
 * Diseñado para funcionar perfectamente en iPhone y otros dispositivos móviles
 * Se adapta automáticamente a tablets, laptops y desktops
 */

/* ========================================================================
   RESET Y BASE - Compatible con todos los dispositivos
   ======================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    /* Prevenir zoom en iPhone al enfocar inputs */
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #f5f5f5;
    overflow-x: hidden;
    min-height: 100vh;
}

/* ========================================================================
   CONTENEDOR RESPONSIVE - Mobile First
   ======================================================================== */

.container {
    width: 100%;
    padding: 0 16px;
    margin: 0 auto;
}

/* Tablets */
@media (min-width: 768px) {
    .container {
        padding: 0 32px;
        max-width: 720px;
    }
}

/* Laptops */
@media (min-width: 1024px) {
    .container {
        max-width: 960px;
    }
}

/* Desktops */
@media (min-width: 1280px) {
    .container {
        max-width: 1200px;
    }
}

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

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

/* Mobile: 1 columna */
.grid-1 { grid-template-columns: 1fr; }

/* Mobile: 2 columnas para items pequeños */
.grid-2-mobile { grid-template-columns: repeat(2, 1fr); }

/* Tablets y superior */
@media (min-width: 768px) {
    .grid-2 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(4, 1fr); }
    .grid { gap: 24px; }
}

/* Desktop */
@media (min-width: 1024px) {
    .grid { gap: 32px; }
}

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

.flex {
    display: flex;
    gap: 16px;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.flex-wrap {
    flex-wrap: wrap;
}

.flex-column {
    flex-direction: column;
}

/* En mobile, flex se vuelve columna */
@media (max-width: 767px) {
    .flex-mobile-column {
        flex-direction: column;
    }
}

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

.btn {
    display: inline-block;
    padding: 14px 24px;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    /* Importante para iPhone */
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    min-height: 48px; /* Tamaño mínimo táctil */
}

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

.btn-primary {
    background: linear-gradient(135deg, #6A1B9A 0%, #8E24AA 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(106, 27, 154, 0.3);
}

.btn-secondary {
    background: linear-gradient(135deg, #2196F3 0%, #42A5F5 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.btn-success {
    background: linear-gradient(135deg, #4CAF50 0%, #66BB6A 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.btn-danger {
    background: linear-gradient(135deg, #F44336 0%, #EF5350 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
}

.btn-block {
    width: 100%;
    display: block;
}

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

.card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

@media (min-width: 768px) {
    .card {
        padding: 24px;
    }
}

@media (min-width: 1024px) {
    .card {
        padding: 32px;
    }
}

.card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

/* ========================================================================
   INPUTS Y FORMS RESPONSIVE
   ======================================================================== */

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: rgba(0, 0, 0, 0.87);
}

.form-control {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px; /* Mínimo 16px para evitar zoom en iPhone */
    border: 2px solid #E0E0E0;
    border-radius: 12px;
    background: white;
    transition: all 0.3s ease;
    /* Importante para iPhone */
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 48px;
}

.form-control:focus {
    outline: none;
    border-color: #6A1B9A;
    box-shadow: 0 0 0 4px rgba(106, 27, 154, 0.1);
}

textarea.form-control {
    resize: vertical;
    min-height: 120px;
}

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

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling en iOS */
}

table {
    width: 100%;
    border-collapse: collapse;
}

/* En mobile, mostrar tablas como cards */
@media (max-width: 767px) {
    .table-mobile-card {
        display: block;
    }

    .table-mobile-card thead {
        display: none;
    }

    .table-mobile-card tbody,
    .table-mobile-card tr,
    .table-mobile-card td {
        display: block;
        width: 100%;
    }

    .table-mobile-card tr {
        margin-bottom: 16px;
        padding: 16px;
        background: white;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    }

    .table-mobile-card td {
        padding: 8px 0;
        border: none;
    }

    .table-mobile-card td:before {
        content: attr(data-label);
        display: inline-block;
        font-weight: 600;
        margin-right: 8px;
        color: rgba(0, 0, 0, 0.6);
    }
}

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

/* Margins */
.m-0 { margin: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }

/* Paddings */
.p-0 { padding: 0; }
.p-1 { padding: 8px; }
.p-2 { padding: 16px; }
.p-3 { padding: 24px; }
.p-4 { padding: 32px; }

/* ========================================================================
   TIPOGRAFÍA RESPONSIVE
   ======================================================================== */

h1, .h1 {
    font-size: 28px;
    font-weight: 900;
    line-height: 1.2;
    margin-bottom: 16px;
}

h2, .h2 {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 12px;
}

h3, .h3 {
    font-size: 20px;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 12px;
}

h4, .h4 {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 8px;
}

@media (min-width: 768px) {
    h1, .h1 { font-size: 36px; }
    h2, .h2 { font-size: 28px; }
    h3, .h3 { font-size: 22px; }
    h4, .h4 { font-size: 20px; }
}

@media (min-width: 1024px) {
    h1, .h1 { font-size: 42px; }
    h2, .h2 { font-size: 32px; }
    h3, .h3 { font-size: 24px; }
}

p {
    margin-bottom: 16px;
    line-height: 1.6;
}

/* ========================================================================
   UTILIDADES
   ======================================================================== */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.d-none { display: none; }
.d-block { display: block; }
.d-inline-block { display: inline-block; }

/* Mostrar/ocultar según dispositivo */
.mobile-only {
    display: block;
}

.desktop-only {
    display: none;
}

@media (min-width: 768px) {
    .mobile-only {
        display: none;
    }

    .desktop-only {
        display: block;
    }
}

/* ========================================================================
   IMÁGENES RESPONSIVE
   ======================================================================== */

img {
    max-width: 100%;
    height: auto;
    display: block;
}

.img-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.img-contain {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ========================================================================
   ANIMACIONES
   ======================================================================== */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fadeIn {
    animation: fadeIn 0.5s ease-out;
}

.animate-fadeInUp {
    animation: fadeInUp 0.5s ease-out;
}

.animate-slideDown {
    animation: slideDown 0.5s ease-out;
}

/* ========================================================================
   ALERTAS Y MENSAJES
   ======================================================================== */

.alert {
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.alert-success {
    background: linear-gradient(135deg, #4CAF50 0%, #66BB6A 100%);
    color: white;
}

.alert-error {
    background: linear-gradient(135deg, #F44336 0%, #EF5350 100%);
    color: white;
}

.alert-warning {
    background: linear-gradient(135deg, #FF9800 0%, #FFB74D 100%);
    color: white;
}

.alert-info {
    background: linear-gradient(135deg, #2196F3 0%, #42A5F5 100%);
    color: white;
}

/* ========================================================================
   BADGES
   ======================================================================== */

.badge {
    display: inline-block;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-primary {
    background: #6A1B9A;
    color: white;
}

.badge-success {
    background: #4CAF50;
    color: white;
}

.badge-danger {
    background: #F44336;
    color: white;
}

.badge-warning {
    background: #FF9800;
    color: white;
}

.badge-info {
    background: #2196F3;
    color: white;
}

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

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 24px;
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 768px) {
    .modal-content {
        padding: 32px;
    }
}

/* ========================================================================
   LOADING SPINNER
   ======================================================================== */

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(106, 27, 154, 0.2);
    border-top-color: #6A1B9A;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========================================================================
   SCROLL SUAVE
   ======================================================================== */

html {
    scroll-behavior: smooth;
}

/* ========================================================================
   ACCESIBILIDAD EN TOUCH
   ======================================================================== */

/* Aumentar área táctil en elementos interactivos */
a, button, input, select, textarea {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* Prevenir selección de texto en elementos UI */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ========================================================================
   SAFE AREA para iPhone X, 11, 12, 13, 14, 15 (notch)
   ======================================================================== */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .container {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

/* ========================================================================
   PRINT STYLES
   ======================================================================== */

@media print {
    .no-print {
        display: none !important;
    }
}
