/* ============================================
   MENSAJES PARA EL ALMA - CSS RESPONSIVE
   ============================================ */

.divi-mensajes-alma-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* HEADER */
.divi-mensajes-alma-container .app-header {
    text-align: center;
    margin-bottom: 20px;
}

.divi-mensajes-alma-container .app-header h1 {
    color: #e09900;
    font-size: clamp(24px, 5vw, 32px);
    margin-bottom: 10px;
    line-height: 1.3;
    word-wrap: break-word;
}

.divi-mensajes-alma-container .app-header p {
    color: #7828a7;
    font-weight: bold;
    font-size: clamp(14px, 3vw, 18px);
    line-height: 1.4;
    padding: 0 10px;
}

/* USER SECTION */
.divi-mensajes-alma-container .user-sections-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.divi-mensajes-alma-container .user-section {
    flex: 1 1 100%;
    min-width: 0;
    text-align: center;
}

.divi-mensajes-alma-container .user-info {
    flex: 1 1 100%;
    min-width: 0;
    color: #e09900;
    font-weight: bold;
    font-size: clamp(14px, 3vw, 16px);
    text-align: center;
    line-height: 1.4;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
    margin-top: 10px;
}

.divi-mensajes-alma-container .progress-text {
    flex: 1 1 100%;
    min-width: 0;
    text-align: center;
    font-size: clamp(14px, 3vw, 16px);
    display: none;
    color: #e09900;
    font-weight: bold;
    line-height: 1.4;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 8px;
    margin-top: 10px;
}

.divi-mensajes-alma-container .progress-text #cards-viewed {
    font-weight: bold;
}

/* INPUTS Y BOTONES */
.divi-mensajes-alma-container input[type="text"] {
    padding: 14px;
    margin: 0 0 10px 0;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    width: 100%;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.divi-mensajes-alma-container button {
    min-height: 50px;
    min-width: 50px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.divi-mensajes-alma-container #set-user {
    padding: 15px 25px;
    margin: 0;
    width: 100%;
    font-size: 16px;
    font-weight: 600;
    background: #8e44ad;
    color: white;
    border: none;
    border-radius: 8px;
    display: block;
}

/* PROGRESS BAR */
.divi-mensajes-alma-container .progress-bar {
    width: 100%;
    background-color: #f3f3f3;
    border-radius: 10px;
    overflow: hidden;
    margin: 20px 0;
    display: none;
}

.divi-mensajes-alma-container .progress {
    width: 0%;
    height: 20px;
    background-color: #e09900;
    transition: width 0.5s ease-in-out;
}

/* CARDS CONTAINER - CRÍTICO PARA MÓVILES */
.divi-mensajes-alma-container .cards-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-bottom: 25px;
    width: 100%;
}

.divi-mensajes-alma-container .cards-container > div {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    padding: 0 5px;
}

.divi-mensajes-alma-container .card {
    width: 100%;
    height: auto;
    aspect-ratio: 2/3;
    max-height: 70vh;
    border: 3px solid #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    background: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin: 0 auto;
    position: relative;
}

.divi-mensajes-alma-container .card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}

.divi-mensajes-alma-container .card.revealed {
    animation: reveal 0.5s ease-in-out;
}

.divi-mensajes-alma-container .card-placeholder,
.divi-mensajes-alma-container .history-placeholder {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #8e44ad, #9b59b6);
    font-size: clamp(18px, 4vw, 24px);
    color: white;
    padding: 20px;
    text-align: center;
}

.divi-mensajes-alma-container .card-placeholder i,
.divi-mensajes-alma-container .history-placeholder i {
    font-size: clamp(40px, 8vw, 60px);
    margin-bottom: 15px;
    color: #f1c40f;
}

.divi-mensajes-alma-container .card-label {
    text-align: center;
    margin-top: 12px;
    font-weight: bold;
    color: #8e44ad;
    font-size: clamp(16px, 3vw, 20px);
    line-height: 1.3;
    padding: 0 5px;
}

/* BOTONES PRINCIPALES */
.divi-mensajes-alma-container .buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-bottom: 25px;
    width: 100%;
}

.divi-mensajes-alma-container .btn {
    padding: 16px 20px;
    margin: 0;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: clamp(15px, 3vw, 17px);
    color: white;
    flex: 1 1 100%;
    min-width: 0;
    text-align: center;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 600;
    text-decoration: none;
}

.divi-mensajes-alma-container .btn i {
    font-size: clamp(18px, 4vw, 22px);
    flex-shrink: 0;
}

.divi-mensajes-alma-container #show-card {
    background: linear-gradient(135deg, #e09900, #f1c40f);
}

.divi-mensajes-alma-container .btn-success {
    background: linear-gradient(135deg, #7828a7, #9b59b6);
}

.divi-mensajes-alma-container .btn-secondary {
    background: linear-gradient(135deg, #28a745, #2ecc71);
}

.divi-mensajes-alma-container .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* MENSAJES */
.divi-mensajes-alma-container .error {
    color: #c0392b;
    text-align: center;
    margin: 15px 0;
    display: none;
    padding: 15px;
    background: #fee;
    border-radius: 8px;
    border-left: 5px solid #e74c3c;
    font-weight: 600;
    font-size: clamp(14px, 3vw, 16px);
    line-height: 1.4;
}

.divi-mensajes-alma-container .success {
    color: #27ae60;
    text-align: center;
    margin: 15px 0;
    display: none;
    padding: 15px;
    background: #dfffd6;
    border-radius: 8px;
    border-left: 5px solid #2ecc71;
    font-weight: 600;
    font-size: clamp(14px, 3vw, 16px);
    line-height: 1.4;
}

/* JOURNAL */
.divi-mensajes-alma-container .journal {
    display: none;
    background: white;
    padding: 20px;
    border-radius: 12px;
    margin-top: 25px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
    width: 100%;
}

.divi-mensajes-alma-container .journal h3 {
    color: #e09900;
    font-size: clamp(20px, 4vw, 24px);
    margin-bottom: 20px;
    text-align: center;
}

.divi-mensajes-alma-container .journal h3 i {
    margin-right: 10px;
}

.divi-mensajes-alma-container .journal-entry {
    border: 2px solid #e8e8e8;
    padding: 18px;
    margin-bottom: 18px;
    border-radius: 10px;
    background: #fcfcfc;
    width: 100%;
}

.divi-mensajes-alma-container .journal-date {
    font-weight: bold;
    margin-bottom: 12px;
    color: #7828a7;
    font-size: clamp(14px, 3vw, 16px);
}

.divi-mensajes-alma-container .journal-text {
    margin-bottom: 15px;
    line-height: 1.6;
    color: #333;
    font-size: clamp(14px, 3vw, 16px);
}

/* HISTORY */
.divi-mensajes-alma-container .history {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.9);
    display: none;
    z-index: 10000;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.divi-mensajes-alma-container .history-close {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(255,255,255,0.9);
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #333;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    z-index: 10001;
}

.divi-mensajes-alma-container .history h3 {
    color: #e09900;
    text-align: center;
    margin: 20px 0 30px;
    font-size: clamp(22px, 4vw, 26px);
    padding-top: 40px;
}

.divi-mensajes-alma-container .history h3 i {
    margin-right: 10px;
}

.divi-mensajes-alma-container .history-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    padding: 10px;
    max-width: 100%;
}

.divi-mensajes-alma-container .history-item {
    text-align: center;
    width: 100%;
}

.divi-mensajes-alma-container .history-item p {
    color: #fff;
    font-weight: bold;
    margin-bottom: 8px;
    font-size: clamp(14px, 3vw, 16px);
    word-break: break-word;
}

.divi-mensajes-alma-container .history-img {
    width: 100%;
    height: auto;
    aspect-ratio: 2/3;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 10px;
    background: #222;
}

.divi-mensajes-alma-container .history-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.divi-mensajes-alma-container .history-date {
    margin-top: 5px;
    font-size: clamp(12px, 2.5vw, 14px);
    color: #2ecc71;
    font-weight: bold;
}

/* MODALES */
.divi-mensajes-alma-container .modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.85);
    justify-content: center;
    align-items: center;
    z-index: 10000;
    padding: 15px;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

.divi-mensajes-alma-container .modal-content {
    background-color: white;
    padding: 20px;
    border-radius: 15px;
    max-width: 95%;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.divi-mensajes-alma-container .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}

.divi-mensajes-alma-container .modal-header h3 {
    color: #7828a7;
    font-size: clamp(18px, 4vw, 22px);
    margin: 0;
    flex: 1;
}

.divi-mensajes-alma-container .modal-close {
    background: #f0f0f0;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    margin-left: 15px;
}

.divi-mensajes-alma-container .journal-form p {
    color: #333;
    margin-bottom: 20px;
    line-height: 1.6;
    font-size: clamp(14px, 3vw, 16px);
}

.divi-mensajes-alma-container textarea {
    width: 100%;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    line-height: 1.6;
    box-sizing: border-box;
    min-height: 150px;
    resize: vertical;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

.divi-mensajes-alma-container textarea:focus {
    outline: none;
    border-color: #8e44ad;
    box-shadow: 0 0 0 3px rgba(142, 68, 173, 0.2);
}

/* ANIMACIONES */
@keyframes reveal {
    0% { opacity: 0; transform: scale(0.8) rotateY(-20deg); }
    100% { opacity: 1; transform: scale(1) rotateY(0); }
}

/* ============================================
   MEDIA QUERIES ESPECÍFICAS PARA MÓVILES
   ============================================ */

/* MÓVILES PEQUEÑOS (hasta 360px) */
@media screen and (max-width: 360px) {
    .divi-mensajes-alma-container {
        padding: 12px;
    }
    
    .divi-mensajes-alma-container .card {
        aspect-ratio: 3/4;
    }
    
    .divi-mensajes-alma-container .btn {
        padding: 18px 15px;
        font-size: 15px;
    }
    
    .divi-mensajes-alma-container .history-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

/* MÓVILES (hasta 480px) */
@media screen and (max-width: 480px) {
    .divi-mensajes-alma-container .cards-container {
        flex-direction: column;
        align-items: center;
    }
    
    .divi-mensajes-alma-container .cards-container > div {
        width: 90%;
        max-width: 300px;
    }
    
    .divi-mensajes-alma-container .buttons {
        flex-direction: column;
    }
    
    .divi-mensajes-alma-container .btn {
        width: 100%;
    }
    
    .divi-mensajes-alma-container .modal-content {
        padding: 18px;
    }
    
    .divi-mensajes-alma-container .history-list {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* TABLETS (481px a 768px) */
@media screen and (min-width: 481px) and (max-width: 768px) {
    .divi-mensajes-alma-container .cards-container > div {
        flex: 1 1 calc(50% - 20px);
        max-width: calc(50% - 20px);
    }
    
    .divi-mensajes-alma-container .buttons {
        flex-wrap: nowrap;
    }
    
    .divi-mensajes-alma-container .btn {
        flex: 1 1 auto;
        min-width: 0;
    }
    
    .divi-mensajes-alma-container .history-list {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* TABLETS LANDSCAPE Y PEQUEÑOS DESKTOPS (769px a 1024px) */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    .divi-mensajes-alma-container {
        max-width: 90%;
    }
    
    .divi-mensajes-alma-container .cards-container > div {
        flex: 1 1 calc(50% - 20px);
        max-width: calc(50% - 20px);
    }
    
    .divi-mensajes-alma-container .history-list {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* DESKTOP (1025px en adelante) */
@media screen and (min-width: 1025px) {
    .divi-mensajes-alma-container .cards-container > div {
        flex: 1 1 calc(50% - 20px);
        max-width: calc(50% - 20px);
    }
    
    .divi-mensajes-alma-container .history-list {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* ============================================
   CORRECCIONES ESPECÍFICAS PARA iOS SAFARI
   ============================================ */

@supports (-webkit-touch-callout: none) {
    .divi-mensajes-alma-container {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .divi-mensajes-alma-container .modal {
        padding: env(safe-area-inset-top) env(safe-area-inset-right) 
                env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
    
    .divi-mensajes-alma-container .history {
        padding: env(safe-area-inset-top) env(safe-area-inset-right) 
                env(safe-area-inset-bottom) env(safe-area-inset-left);
    }
}

/* ============================================
   CORRECCIONES PARA DISPOSITIVOS TÁCTILES
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    .divi-mensajes-alma-container .btn,
    .divi-mensajes-alma-container input[type="text"],
    .divi-mensajes-alma-container textarea {
        font-size: 16px !important;
    }
    
    .divi-mensajes-alma-container .btn {
        min-height: 54px;
    }
    
    .divi-mensajes-alma-container input[type="text"] {
        min-height: 54px;
    }
    
    .divi-mensajes-alma-container textarea {
        min-height: 120px;
    }
    
    /* Incrementar área táctil */
    .divi-mensajes-alma-container .modal-close,
    .divi-mensajes-alma-container .history-close {
        min-width: 54px;
        min-height: 54px;
    }
    
    /* Mejorar feedback visual */
    .divi-mensajes-alma-container .btn:active,
    .divi-mensajes-alma-container .modal-close:active,
    .divi-mensajes-alma-container .history-close:active {
        opacity: 0.7;
        transform: scale(0.96);
        transition: none;
    }
}

/* ============================================
   PREVENIR PROBLEMAS DE SCROLL HORIZONTAL
   ============================================ */

.divi-mensajes-alma-container {
    overflow-x: hidden;
}

.divi-mensajes-alma-container * {
    max-width: 100%;
}

/* ============================================
   ESTILOS PARA ORIENTACIÓN HORIZONTAL EN MÓVILES
   ============================================ */

@media screen and (max-height: 500px) and (orientation: landscape) {
    .divi-mensajes-alma-container {
        padding: 10px;
    }
    
    .divi-mensajes-alma-container .cards-container {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 10px;
    }
    
    .divi-mensajes-alma-container .cards-container > div {
        flex: 1;
        min-width: 0;
    }
    
    .divi-mensajes-alma-container .card {
        aspect-ratio: 3/4;
        max-height: 50vh;
    }
    
    .divi-mensajes-alma-container .buttons {
        flex-wrap: nowrap;
        gap: 8px;
    }
    
    .divi-mensajes-alma-container .btn {
        padding: 12px 8px;
        font-size: 13px;
    }
    
    .divi-mensajes-alma-container .btn i {
        font-size: 16px;
    }
}

/* ============================================
   MEJORAS DE ACCESIBILIDAD
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .divi-mensajes-alma-container .card.revealed,
    .divi-mensajes-alma-container .btn,
    .divi-mensajes-alma-container .progress {
        animation: none;
        transition: none;
    }
}

/* Asegurar contraste suficiente */
.divi-mensajes-alma-container .app-header h1,
.divi-mensajes-alma-container .card-label,
.divi-mensajes-alma-container .journal-date {
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

/* Foco visible para navegación por teclado */
.divi-mensajes-alma-container .btn:focus,
.divi-mensajes-alma-container input:focus,
.divi-mensajes-alma-container textarea:focus,
.divi-mensajes-alma-container .modal-close:focus,
.divi-mensajes-alma-container .history-close:focus {
    outline: 3px solid #8e44ad;
    outline-offset: 2px;
}

/* ============================================
   MEJORAS ESPECÍFICAS PARA BOTONES EN MÓVILES
   ============================================ */

/* Asegurar que los botones sean completamente táctiles */
.divi-mensajes-alma-container button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    cursor: pointer;
}

/* Feedback visual para botones presionados */
.divi-mensajes-alma-container button:active {
    transform: scale(0.97);
    opacity: 0.9;
    transition: transform 0.1s, opacity 0.1s;
}

/* Inputs más grandes en móviles */
@media (hover: none) and (pointer: coarse) {
    .divi-mensajes-alma-container input[type="text"] {
        font-size: 16px !important;
        padding: 16px !important;
        min-height: 52px !important;
        border-width: 2px !important;
    }
    
    .divi-mensajes-alma-container #set-user {
        font-size: 17px !important;
        padding: 18px !important;
        min-height: 56px !important;
        font-weight: 700 !important;
    }
    
    .divi-mensajes-alma-container textarea {
        font-size: 16px !important;
        min-height: 140px !important;
        padding: 16px !important;
    }
    
    /* Incrementar área táctil */
    .divi-mensajes-alma-container .btn,
    .divi-mensajes-alma-container .modal-close,
    .divi-mensajes-alma-container .history-close {
        min-height: 56px !important;
        min-width: 56px !important;
    }
    
    /* Espaciado adicional entre botones */
    .divi-mensajes-alma-container .buttons {
        gap: 15px !important;
    }
    
    .divi-mensajes-alma-container .btn {
        padding: 20px !important;
        margin: 5px 0 !important;
    }
}

/* Prevenir zoom en inputs en iOS */
@media screen and (max-width: 768px) {
    .divi-mensajes-alma-container input[type="text"],
    .divi-mensajes-alma-container textarea {
        font-size: 16px !important;
    }
}

/* Feedback de carga para botones */
.divi-mensajes-alma-container button.loading {
    position: relative;
    color: transparent !important;
}

.divi-mensajes-alma-container button.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

/* Estado deshabilitado */
.divi-mensajes-alma-container button:disabled {
    opacity: 0.6 !important;
    cursor: not-allowed !important;
    transform: none !important;
}

/* ============================================
   DEBUG PARA DESARROLLO (quitar en producción)
   ============================================ */

.debug-touch {
    position: fixed;
    bottom: 10px;
    right: 10px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 10px;
    border-radius: 5px;
    font-size: 12px;
    z-index: 99999;
    display: none;
}