/* ============================================
   Asistente Laia (Sistema365) — Widget Light
   Branding: azul #2563EB · cyan #06B6D4 · gradiente
   Light theme only. Mobile-first.
   Inspirado en dr360_ai_agent/static/src/css/dr360_laia.css
   ============================================ */

:root {
    --s365l-blue: #2563EB;
    --s365l-cyan: #06B6D4;
    --s365l-blue-700: #14507E;
    --s365l-bg: #F8FAFC;
    --s365l-white: #FFFFFF;
    --s365l-green: #16A34A;
    --s365l-text: #0F172A;
    --s365l-muted: #64748B;
    --s365l-border: rgba(37, 99, 235, 0.12);
    --s365l-grad: linear-gradient(135deg, #2563EB 0%, #06B6D4 100%);
    --s365l-glass-bg: rgba(255, 255, 255, 0.72);
    --s365l-glass-border: rgba(255, 255, 255, 0.88);
    --s365l-fab-radius: 18px;
    --s365l-fab-inner-radius: 14px;
}

/* ── FAB (avatar Laia · glass · rounded-square) ── */
.s365l-toggle {
    position: fixed;
    bottom: calc(28px + env(safe-area-inset-bottom, 0px));
    right: calc(28px + env(safe-area-inset-right, 0px));
    width: 68px;
    height: 68px;
    border-radius: var(--s365l-fab-radius);
    background: var(--s365l-glass-bg);
    backdrop-filter: blur(16px) saturate(1.35);
    -webkit-backdrop-filter: blur(16px) saturate(1.35);
    border: 1px solid var(--s365l-glass-border);
    cursor: pointer;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 10px 34px rgba(37, 99, 235, 0.22),
        0 2px 8px rgba(15, 23, 42, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.95);
    transition: transform 0.22s ease, box-shadow 0.22s ease, opacity 0.22s ease, border-color 0.22s ease;
    padding: 5px;
    overflow: visible;
    -webkit-tap-highlight-color: transparent;
}

.s365l-toggle:hover {
    transform: translateY(-2px) scale(1.03);
    border-color: rgba(255, 255, 255, 0.98);
    box-shadow:
        0 14px 40px rgba(37, 99, 235, 0.28),
        0 4px 12px rgba(15, 23, 42, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 1);
}

/* Avatar dentro del marco glass (cuadrado redondeado, no círculo) */
.s365l-toggle-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    border-radius: var(--s365l-fab-inner-radius);
    display: block;
    pointer-events: none;
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

.s365l-toggle .s365l-close-icon { display: none; }

.s365l-toggle::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: calc(var(--s365l-fab-radius) + 2px);
    padding: 1px;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.45), rgba(6, 182, 212, 0.35));
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    opacity: 0.85;
}

.s365l-toggle::after {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: calc(var(--s365l-fab-radius) + 4px);
    border: 2px solid rgba(6, 182, 212, 0.28);
    animation: s365lPing 2.6s ease-out infinite;
    z-index: -1;
    pointer-events: none;
}

@keyframes s365lPing {
    0% { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.32); opacity: 0; }
}

.s365l-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background: var(--s365l-green);
    border-radius: 50%;
    border: 2px solid var(--s365l-white);
    pointer-events: none;
    box-shadow: 0 2px 6px rgba(22, 163, 74, 0.35);
}

body.s365l-chat-open .s365l-toggle {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.85);
}

/* ── Ventana chat ── */
.s365l-chat {
    position: fixed;
    bottom: calc(105px + env(safe-area-inset-bottom, 0px));
    right: calc(28px + env(safe-area-inset-right, 0px));
    width: 400px;
    max-width: calc(100vw - 32px);
    height: min(580px, calc(100vh - 140px));
    max-height: calc(100dvh - 140px);
    background: var(--s365l-bg);
    border: 1px solid var(--s365l-border);
    border-radius: 16px;
    z-index: 99998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s ease;
    box-shadow: 0 20px 56px rgba(37, 99, 235, 0.18);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.s365l-chat.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Header (gradiente) ── */
.s365l-header {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.95rem 1rem;
    background: var(--s365l-grad);
    flex-shrink: 0;
}

.s365l-header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border: 1.5px solid rgba(255, 255, 255, 0.65);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
}

.s365l-header-avatar img,
.s365l-header-avatar .s365l-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    border-radius: 10px;
    display: block;
}

.s365l-header-info { flex: 1; min-width: 0; }

.s365l-header-info h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
    margin: 0;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.s365l-header-info span {
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.92);
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    margin-top: 2px;
}

.s365l-header-info span::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.65);
}

.s365l-header-minimize {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.18s ease;
    -webkit-tap-highlight-color: transparent;
}

.s365l-header-minimize:hover { background: rgba(255, 255, 255, 0.28); }
.s365l-header-minimize svg { width: 18px; height: 18px; fill: currentColor; }

/* ── Cuerpo ── */
.s365l-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--s365l-bg);
}

.s365l-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.s365l-messages::-webkit-scrollbar { width: 4px; }
.s365l-messages::-webkit-scrollbar-thumb {
    background: rgba(37, 99, 235, 0.16);
    border-radius: 2px;
}

.s365l-msg {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    animation: s365lMsgSlide 0.26s ease-out;
}

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

.s365l-msg .s365l-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--s365l-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
}

.s365l-msg .s365l-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    border-radius: 7px;
    display: block;
}

.s365l-msg.user { flex-direction: row-reverse; }

.s365l-bubble {
    max-width: 85%;
    padding: 0.72rem 0.95rem;
    border-radius: 14px;
    font-size: 0.86rem;
    line-height: 1.55;
    color: var(--s365l-text);
    word-wrap: break-word;
}

.s365l-msg.bot .s365l-bubble {
    background: var(--s365l-white);
    border: 1px solid var(--s365l-border);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 6px rgba(37, 99, 235, 0.05);
}

.s365l-msg.user .s365l-bubble {
    background: var(--s365l-grad);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.22);
}

.s365l-time {
    font-size: 0.62rem;
    color: var(--s365l-muted);
    margin-top: 0.22rem;
}

.s365l-msg.user .s365l-time { text-align: right; }

/* Typing */
.s365l-typing {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1rem 0.35rem;
}

.s365l-typing.show { display: flex; }

.s365l-typing .s365l-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--s365l-border);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
}
.s365l-typing .s365l-msg-avatar img {
    width: 100%; height: 100%;
    object-fit: cover; object-position: center top;
    border-radius: 7px; display: block;
}

.s365l-typing-dots {
    display: flex;
    gap: 4px;
    padding: 0.6rem 0.85rem;
    background: var(--s365l-white);
    border: 1px solid var(--s365l-border);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.s365l-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--s365l-muted);
    animation: s365lTyping 1.4s infinite;
}

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

@keyframes s365lTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Quick actions */
.s365l-quick {
    display: flex;
    flex-direction: column;
    gap: 0.42rem;
    padding: 0.35rem 1rem 0.75rem;
    flex-shrink: 0;
}

.s365l-quick-btn {
    width: 100%;
    text-align: left;
    padding: 0.65rem 0.95rem;
    font-size: 0.84rem;
    font-weight: 600;
    border: 1px solid var(--s365l-border);
    border-radius: 12px;
    background: var(--s365l-white);
    color: var(--s365l-blue-700);
    cursor: pointer;
    transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
    font-family: inherit;
    line-height: 1.35;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.s365l-quick-btn:hover,
.s365l-quick-btn:active {
    border-color: var(--s365l-cyan);
    background: #f0fbff;
    color: var(--s365l-blue);
}

/* Input + footer */
.s365l-input-area {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-top: 1px solid var(--s365l-border);
    background: var(--s365l-white);
    flex-shrink: 0;
}

.s365l-input {
    flex: 1;
    background: var(--s365l-white);
    border: 1px solid var(--s365l-border);
    border-radius: 12px;
    padding: 0.65rem 0.95rem;
    color: var(--s365l-text);
    font-size: 16px; /* evita zoom iOS */
    font-family: inherit;
    outline: none;
    transition: border-color 0.18s;
    resize: none;
    max-height: 96px;
    min-height: 44px;
    line-height: 1.4;
}

.s365l-input::placeholder { color: #94a3b8; }
.s365l-input:focus { border-color: var(--s365l-blue); }

.s365l-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--s365l-grad);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
}

.s365l-send:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(37, 99, 235, 0.34); }
.s365l-send:active { transform: scale(0.96); }
.s365l-send svg { width: 18px; height: 18px; fill: #fff; }

.s365l-chat-footer {
    padding: 0.3rem 1rem calc(0.55rem + env(safe-area-inset-bottom, 0px));
    text-align: center;
    font-size: 0.64rem;
    color: var(--s365l-muted);
    background: var(--s365l-white);
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.s365l-chat-footer strong {
    color: var(--s365l-blue);
    font-weight: 700;
}

body.s365l-chat-open {
    overflow: hidden;
    touch-action: none;
}

/* ── Mobile ── */
@media (max-width: 480px) {
    .s365l-chat {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
    }
    .s365l-chat.s365l-keyboard-open {
        height: var(--s365l-vv-height, 100dvh);
        max-height: var(--s365l-vv-height, 100dvh);
    }
    .s365l-toggle {
        bottom: calc(18px + env(safe-area-inset-bottom, 0px));
        right: calc(18px + env(safe-area-inset-right, 0px));
        width: 62px;
        height: 62px;
        padding: 4px;
        --s365l-fab-radius: 16px;
        --s365l-fab-inner-radius: 12px;
    }
    .s365l-bubble { max-width: 90%; }
    .s365l-header {
        padding-top: calc(0.95rem + env(safe-area-inset-top, 0px));
    }
    .s365l-quick-btn {
        font-size: 0.86rem;
        padding: 0.72rem 1rem;
    }
}
