/* ========================================================
   🎨 IALCO - ESTILOS VISUALES COMPLETOS (ADMIN)
   ======================================================== */

:root {
    --bg-main: #060a13;
    --bg-card: rgba(21, 31, 50, 0.45);
    --bg-sidebar: rgba(7, 10, 18, 0.55);
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --success: #10b981;
    --border: rgba(255, 255, 255, 0.08);
    --glass-blur: 16px;
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* --- ANIMATED BACKGROUND BLOBS --- */
#animated-bg-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -2;
    overflow: hidden;
    background: radial-gradient(circle at 50% 50%, #0c1524 0%, #03050a 100%);
    pointer-events: none;
}

.bg-blob {
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(130px);
    opacity: 0.3;
    mix-blend-mode: screen;
    pointer-events: none;
}

.blob-blue {
    background: radial-gradient(circle, #2563eb 0%, rgba(37, 99, 235, 0) 70%);
    top: -100px;
    left: -100px;
    animation: float-blob-1 25s infinite alternate ease-in-out;
}

.blob-purple {
    background: radial-gradient(circle, #a855f7 0%, rgba(168, 85, 247, 0) 70%);
    bottom: -150px;
    right: -100px;
    animation: float-blob-2 30s infinite alternate ease-in-out;
}

.blob-orange {
    background: radial-gradient(circle, #f97316 0%, rgba(249, 115, 22, 0) 70%);
    top: 50%;
    left: 60%;
    width: 500px;
    height: 500px;
    animation: float-blob-3 28s infinite alternate ease-in-out;
}

@keyframes float-blob-1 {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(120px, 80px) scale(1.1); }
    100% { transform: translate(-50px, 150px) scale(0.9); }
}

@keyframes float-blob-2 {
    0% { transform: translate(0, 0) scale(0.9); }
    50% { transform: translate(-100px, -120px) scale(1.15); }
    100% { transform: translate(80px, -40px) scale(1); }
}

@keyframes float-blob-3 {
    0% { transform: translate(0, 0) scale(1.1); }
    50% { transform: translate(150px, -90px) scale(0.95); }
    100% { transform: translate(-100px, 60px) scale(1.05); }
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Contenedor Principal */
.app-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* --- BARRA LATERAL (SIDEBAR) --- */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-right: 1px solid var(--border);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
    box-shadow: var(--glass-shadow);
}

.logo-area h2 {
    font-size: 1.4rem;
    color: #fff;
}

.logo-area .subtext {
    font-size: 0.8rem;
    color: var(--accent);
    font-weight: bold;
    text-transform: uppercase;
    display: block;
    margin-top: 0.2rem;
}

.user-profile {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: 8px;
    margin-top: 2rem;
}

.badge {
    background-color: var(--accent);
    color: #fff;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    display: inline-block;
    margin-top: 0.5rem;
}

/* Botones de Navegación Lateral */
.btn-nav {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border: 1px solid var(--border);
    padding: 0.75rem;
    width: 100%;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

.btn-nav:hover {
    background-color: var(--accent);
    border-color: var(--accent);
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 100%;
    padding: 0.6rem;
    margin-top: 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

.btn-logout:hover {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

/* --- CUERPO DE CONTENIDO --- */
.main-content {
    flex: 1;
    padding: 2.5rem;
    overflow-y: auto;
}

.modulo-vista {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.header-seccion h3 {
    font-size: 1.6rem;
    color: #fff;
}

.bloque-dashboard {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    padding: 2rem;
    border-radius: 10px;
}

.texto-mutado {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.oculto { display: none !important; }

/* --- SECCIÓN MÉTRICAS SUPERIORES --- */
.rejilla-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
    margin-bottom: 2rem;
}

.card-metric {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
}

.card-metric h4 {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.card-metric p {
    font-size: 1.8rem;
    font-weight: bold;
    color: #fff;
}

/* --- DIVISIÓN EN COLUMNAS (FORMULARIO Y TABLA) --- */
.split-container {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.formulario-alta {
    width: 340px;
    flex-shrink: 0;
}

.tabla-usuarios-bloque {
    flex: 1;
}

/* --- FORMULARIOS, INPUTS Y CONTROLES --- */
.ia-form-group {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

textarea {
    width: 100%;
    height: 140px;
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    color: #fff;
    padding: 1rem;
    border-radius: 8px;
    resize: none;
    font-size: 0.95rem;
}

.ia-controles {
    display: flex;
    gap: 1rem;
}

input {
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    color: #fff;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
}

button {
    background-color: var(--accent);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

button:hover { background-color: var(--accent-hover); }

.resultado-box {
    margin-top: 1.5rem;
    background-color: var(--bg-main);
    border-left: 4px solid var(--accent);
    padding: 1.5rem;
    border-radius: 4px;
}

/* --- TABLAS DE DATOS CENTRALES --- */
.tabla-contenedor {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow-x: auto;
}

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

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background-color: rgba(0, 0, 0, 0.2);
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
}

/* --- GRID DE LA BIBLIOTECA (VISTA ABOGADO) --- */
.rejilla-biblioteca {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.tarjeta-documento {
    background-color: var(--bg-main);
    border: 1px solid var(--border);
    padding: 1.5rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 1.5rem;
}

.badge-categoria {
    font-size: 0.75rem;
    background-color: rgba(37, 99, 235, 0.15);
    color: #60a5fa;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: bold;
}

.btn-descargar {
    display: block;
    text-align: center;
    background-color: var(--success);
    color: #fff;
    text-decoration: none;
    padding: 0.7rem;
    border-radius: 6px;
    font-weight: bold;
    font-size: 0.9rem;
}

/* --- SPLASH SCREEN: REDISEÑADO PREMIUM --- */
#loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #0e172a 0%, #030712 100%);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.8s;
    opacity: 1;
}

#loader-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-content {
    text-align: center;
    width: 85%;
    max-width: 480px;
    position: relative;
    padding: 3rem;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(16px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    animation: loaderEntrance 1s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes loaderEntrance {
    0% { transform: scale(0.9) translateY(20px); opacity: 0; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

#loader-text {
    color: #e2e8f0;
    margin-bottom: 2.5rem;
    height: 1.5em;
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    opacity: 0.85;
    animation: textPulse 2s infinite ease-in-out;
}

@keyframes textPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

@keyframes logoGlowPulse {
    0% {
        transform: scale(0.95);
        opacity: 0.6;
        filter: blur(20px) saturate(1.2);
    }
    100% {
        transform: scale(1.05);
        opacity: 0.95;
        filter: blur(30px) saturate(1.6);
    }
}

.progress-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 99px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
}

#progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ec4899, #8b5cf6, #3b82f6);
    border-radius: 99px;
    box-shadow: 0 0 12px #3b82f6, 0 0 20px #8b5cf6;
    transition: width 5s linear;
}

/* ========================================================
   📱 WHATSAPP WEB CLONE — CHAT MODULE STYLES
   ======================================================== */
.wa-container {
    display: flex;
    height: calc(100vh - 4rem);
    border: 1px solid #222d34;
    border-radius: 10px;
    overflow: hidden;
    background: #0b141a;
}

/* --- Panel izquierdo: Lista de chats --- */
.wa-sidebar {
    width: 340px;
    min-width: 280px;
    background: #111b21;
    border-right: 1px solid #222d34;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.wa-sidebar-header {
    padding: 1rem 1.25rem;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.wa-sidebar-header h3 {
    margin: 0;
    font-size: 1rem;
    color: #f1f5f9;
}

.wa-sidebar-header .wa-badge {
    background: #10b981;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 999px;
}

.wa-search {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid #1e293b;
}

.wa-search input {
    width: 100%;
    background: #0b0f19;
    border: 1px solid #334155;
    color: #e2e8f0;
    padding: 0.55rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    margin: 0;
}

.wa-chat-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}

.wa-chat-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    cursor: pointer;
    border-bottom: 1px solid #0f172a;
    transition: background 0.15s;
}

.wa-chat-item:hover {
    background: #1e293b;
}

.wa-chat-item.active {
    background: #1e293b;
    border-left: 3px solid #10b981;
}

.wa-chat-item .wa-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.wa-chat-item .wa-chat-info {
    flex: 1;
    min-width: 0;
}

.wa-chat-item .wa-chat-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-chat-item .wa-chat-preview {
    font-size: 0.78rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.wa-chat-item .wa-chat-meta {
    text-align: right;
    flex-shrink: 0;
}

.wa-chat-item .wa-chat-time {
    font-size: 0.7rem;
    color: #475569;
}

.wa-chat-item .wa-unread {
    background: #10b981;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 999px;
    margin-top: 4px;
    display: inline-block;
}

.wa-status-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    margin-top: 3px;
    display: inline-block;
}
.wa-status-badge.escalamiento { background: #2563eb; color: #fff; }
.wa-status-badge.en-cola { background: #f59e0b; color: #0f172a; }
.wa-status-badge.espera { background: #ea580c; color: #fff; }
.wa-status-badge.en-proceso { background: #2563eb; color: #fff; }
.wa-status-badge.cerrado { background: #8b5cf6; color: #fff; }
.wa-status-badge.pausado { background: #ef4444; color: #fff; }

/* --- Panel derecho: Ventana de chat --- */
.wa-chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #0b141a;
}

.wa-chat-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #475569;
    gap: 1rem;
}

.wa-chat-placeholder .wa-placeholder-icon {
    font-size: 4rem;
    opacity: 0.3;
}

.wa-chat-header {
    padding: 0.75rem 1.25rem;
    background: #202d33;
    border-bottom: 1px solid #222d34;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.wa-chat-header .wa-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
}

.wa-chat-header .wa-header-info {
    flex: 1;
}

.wa-chat-header .wa-header-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: #f1f5f9;
}

.wa-chat-header .wa-header-status {
    font-size: 0.75rem;
    color: #64748b;
}

.wa-chat-header .wa-header-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.wa-chat-header .wa-header-actions button {
    width: auto !important;
    margin-bottom: 0 !important;
    padding: 6px 12px !important;
    font-size: 0.75rem !important;
    border-radius: 6px !important;
    border: none !important;
    cursor: pointer !important;
    font-weight: 600 !important;
    white-space: nowrap !important;
}

/* --- Mensajes (burbujas) --- */
.wa-messages {
    flex: 1;
    padding: 1rem 1.25rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23111827' fill-opacity='0.6'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.wa-msg {
    max-width: 75%;
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    font-size: 0.88rem;
    line-height: 1.45;
    position: relative;
    word-wrap: break-word;
    animation: fadeInMsg 0.2s ease-out;
}

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

.wa-msg.incoming {
    align-self: flex-start;
    background: #1e293b;
    color: #e2e8f0;
    border-bottom-left-radius: 2px;
}

.wa-msg.outgoing {
    align-self: flex-end;
    background: #064e3b;
    color: #d1fae5;
    border-bottom-right-radius: 2px;
}

.wa-msg.system {
    align-self: center;
    background: #334155;
    color: #94a3b8;
    font-size: 0.78rem;
    border-radius: 6px;
    padding: 0.4rem 0.75rem;
}

.wa-msg .wa-msg-sender {
    font-size: 0.72rem;
    font-weight: 700;
    margin-bottom: 2px;
    display: block;
}

.wa-msg.incoming .wa-msg-sender { color: #10b981; }
.wa-msg.outgoing .wa-msg-sender { color: #34d399; }

.wa-msg .wa-msg-time {
    font-size: 0.65rem;
    color: #64748b;
    text-align: right;
    margin-top: 4px;
    display: block;
}

/* --- Input area --- */
.wa-input-area {
    padding: 0.75rem 1.25rem;
    background: #1e293b;
    border-top: 1px solid #334155;
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
}

.wa-input-area textarea {
    flex: 1 !important;
    width: auto !important;
    background: #0b0f19 !important;
    border: 1px solid #334155 !important;
    color: #e2e8f0 !important;
    padding: 0.65rem 0.85rem !important;
    border-radius: 20px !important;
    font-size: 0.88rem !important;
    resize: none !important;
    height: 42px !important;
    max-height: 120px !important;
    margin: 0 !important;
    margin-bottom: 0 !important;
    line-height: 1.3 !important;
}

.wa-input-area .wa-send-btn {
    width: 42px !important;
    height: 42px !important;
    background: #10b981 !important;
    border: none !important;
    border-radius: 50% !important;
    color: #fff !important;
    font-size: 1.1rem !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    margin: 0 !important;
    margin-bottom: 0 !important;
    flex-shrink: 0 !important;
    transition: background 0.2s !important;
}

.wa-input-area .wa-send-btn:hover {
    background: #059669 !important;
}

/* ========================================================
   📱 RESPONSIVE GLOBAL — style.css
   ======================================================== */

/* --- WhatsApp back button (solo visible en móvil) --- */
.wa-back-btn {
    display: none;
}

/* ---- TABLET ≤ 1024px ---- */
@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }
    .main-content {
        padding: 1.5rem;
    }
    .split-container {
        flex-direction: column;
    }
    .formulario-alta {
        width: 100%;
    }
    .rejilla-biblioteca {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

/* ---- MÓVIL ≤ 768px ---- */
@media (max-width: 768px) {

    /* --- WhatsApp Module responsive --- */
    .wa-container {
        height: calc(100vh - 56px - 2rem) !important;
        border-radius: 6px !important;
    }

    .wa-container.chat-open .wa-sidebar {
        display: none !important;
    }
    .wa-container.chat-open .wa-chat-window {
        display: flex !important;
        width: 100% !important;
    }
    .wa-container:not(.chat-open) .wa-sidebar {
        display: flex !important;
        width: 100% !important;
    }
    .wa-container:not(.chat-open) .wa-chat-window {
        display: none !important;
    }
    .wa-sidebar {
        width: 100% !important;
        min-width: 0 !important;
    }

    .wa-back-btn {
        display: block !important;
        background: none !important;
        border: none !important;
        color: #aebac1 !important;
        font-size: 1.5rem !important;
        padding: 0 10px 0 0 !important;
        margin: 0 !important;
        margin-bottom: 0 !important;
        cursor: pointer !important;
        width: auto !important;
    }

    .wa-chat-header {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        padding: 0.5rem 0.75rem !important;
    }
    .wa-chat-header .wa-header-actions {
        width: 100% !important;
        justify-content: flex-start !important;
    }
    .wa-chat-header .wa-header-actions button {
        padding: 5px 10px !important;
        font-size: 0.72rem !important;
    }

    /* --- Biblioteca --- */
    .rejilla-biblioteca {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .rejilla-metrics {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* --- Tablas: scroll horizontal --- */
    .tabla-contenedor {
        overflow-x: auto;
    }
    table {
        min-width: 500px;
    }
    th, td {
        padding: 0.6rem 0.5rem;
        font-size: 0.82rem;
    }

    /* --- App container: quitar flex fijo --- */
    .app-container {
        flex-direction: column;
    }
    .main-content {
        padding: 1rem;
    }

    /* --- Controles IA --- */
    .ia-controles {
        flex-direction: column;
    }
}

/* ---- MÓVIL PEQUEÑO ≤ 480px ---- */
@media (max-width: 480px) {
    .main-content {
        padding: 0.75rem;
    }
    .bloque-dashboard {
        padding: 1rem;
    }
    .tarjeta-documento {
        padding: 1rem;
    }
    th, td {
        padding: 0.45rem 0.35rem !important;
        font-size: 0.75rem !important;
    }
    .wa-msg {
        max-width: 90% !important;
    }
    .loader-content {
        padding: 1.5rem 1rem !important;
    }
}