dialog {
    border: none;
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-sizing: border-box;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    font-family: 'Arial', sans-serif;
    background-color: var(--color-white);
}

/* Título */
dialog h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.5rem;
    font-weight: bold;
    color: #111;
}

/* Mensaje */
dialog p {
    margin-bottom: 2rem;
    color: var(--text-main);
    line-height: 1.4;
}

/* Botón */
dialog button#modalCerrar {
    display: block;
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: 8px;
    background: linear-gradient(90deg, #111, #333);
    color: var(--color-white);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s;
}

dialog button#modalCerrar:hover {
    background: linear-gradient(90deg, #333, #111);
}

/* Opcional: efecto de fondo difuminado al abrir el modal */
dialog::backdrop {
    background: rgba(0, 0, 0, 0.4);
}

/* ===================================
   CONFIRM DIALOG (2 botones)
=================================== */
.dialog-actions {
    display: flex;
    gap: 0.75rem;
}

.dialog-actions button {
    flex: 1;
    padding: 0.75rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

#btn-cancel-borrar,
#btn-cancel-linea-done {
    background: #f0f0f0;
    color: var(--text-main);
}

#btn-cancel-borrar:hover,
#btn-cancel-linea-done:hover {
    background: #e0e0e0;
}

#btn-confirm-borrar,
#btn-confirm-linea-done {
    background: var(--color-danger);
    color: var(--color-white);
}

#btn-confirm-borrar:hover,
#btn-confirm-linea-done:hover {
    background: #b02a37;
}

/* ===================================
   CHAT MODAL
=================================== */
dialog.chat-modal {
    padding: 0;
    border: none;
    outline: none;
    background: none;
    width: 480px;
    max-width: 95vw;
    height: 80vh;
    max-height: 80vh;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    overscroll-behavior: contain;
}

dialog.chat-modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

/* Wrapper: containing block real para el botón flotante */
.chat-modal-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Botón cerrar flotante arriba a la derecha */
.chat-modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 10;
    background: #128c7e;
    border: none;
    color: #fff;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: background 0.2s;
}

.chat-modal-close:hover {
    background: #0e7a6d;
}

.chat-modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* El historial ocupa todo el espacio disponible */
.chat-modal .chat-history {
    flex: 1;
    max-height: none !important;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* El input nunca se encoge aunque aparezca el teclado */
.chat-modal .chat-input-group {
    flex-shrink: 0;
}

/* El textarea ocupa todo el ancho menos el botón enviar */
.chat-modal .msg-textarea {
    flex: 1;
    min-width: 0;
    overscroll-behavior: contain;
    touch-action: pan-x pan-y;
}

/* Typing indicator */
.typing-bubble {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 48px;
    padding: 10px 14px;
}

.typing-bubble span {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #aaa;
    animation: typing-dot 1.2s infinite ease-in-out;
}

.typing-bubble span:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-dot {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
    30%            { transform: translateY(-5px); opacity: 1;   }
}

/* ── Modal overlay + popup (confirmaciones globales) ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
    z-index: 99999;
    backdrop-filter: blur(2px);
}
.tablet-popup {
    background: var(--color-white);
    border-radius: 14px;
    box-shadow: 0 20px 64px rgba(0, 0, 0, 0.22);
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.popup-header {
    padding: 1.1rem 1.5rem;
    background: var(--color-white);
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.popup-header .header-info h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
}
.popup-header .header-actions { display: flex; gap: 10px; align-items: center; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: 9px 20px;
    border-radius: 50px;
    border: none;
    font-weight: 600;
    font-size: .875rem;
    cursor: pointer;
    transition: filter .15s, transform .1s;
    white-space: nowrap;
    background: var(--color-primary);
    color: var(--color-white);
    text-decoration: none;
}
.btn:hover  { filter: brightness(1.1); }
.btn:active { transform: scale(0.95); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary {
    background: var(--color-white);
    color: var(--text-main);
    border: 1.5px solid #d0d0d0;
}
.btn-secondary:hover { background: #f4f4f4; filter: none; }

/* ===== MEDIA POPUP ===== */
.media-popup {
    max-width: 900px;
}

#media-search {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 0.45rem 0.8rem;
    font-size: 0.9rem;
    outline: none;
    width: 220px;
}

#media-search:focus {
    border-color: var(--color-primary);
}

.media-grid {
    flex: 1;
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
    overflow-y: auto;
    align-content: start;
}

.media-card {
    background: var(--color-white);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
}

.media-card-img {
    aspect-ratio: 4/3;
    overflow: hidden;
    cursor: pointer;
    background: #f0f0f0;
}

.media-card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s;
}

.media-card-img:hover img {
    transform: scale(1.04);
}

.media-card-info {
    padding: 0.55rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.78rem;
    color: var(--text-main);
    background: #fafafa;
    border-top: 1px solid #eee;
}

.media-semana { font-weight: 600; color: var(--color-primary); }
.media-fecha  { color: #666; }
.media-tipo   { color: #444; font-style: italic; }

.media-loading,
.media-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: #999;
    padding: 2rem;
}

/* Mobile / Tablet: pantalla completa sin overlay */
@media (max-width: 768px) {
    dialog.chat-modal {
        position: fixed !important;
        inset: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        margin: 0;
        transform: none !important;
    }

    dialog.chat-modal::backdrop {
        background: transparent;
    }
}

