/* ==============================================
   CHATBOT CUSTOM — Leonardo Virtual
   Glassmorphism oscuro con avatar 3D
   ============================================== */

.leo-chat {
    --leo-accent: #00bcd4;
    --leo-accent-2: #7c3aed;
    --leo-bg: rgba(12, 14, 24, 0.85);
    --leo-bg-2: rgba(20, 22, 36, 0.92);
    --leo-border: rgba(255, 255, 255, 0.10);
    --leo-border-strong: rgba(255, 255, 255, 0.18);
    --leo-text: #f0f0f0;
    --leo-text-dim: rgba(240, 240, 240, 0.6);
    --leo-bubble-bot: rgba(255, 255, 255, 0.06);
    --leo-bubble-user: linear-gradient(135deg, #00838f 0%, #00bcd4 100%);
    --leo-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--leo-border) inset;

    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---------- Toggle button ---------- */
.leo-chat__toggle {
    position: relative;
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.18);
    background: linear-gradient(135deg, #00838f 0%, #00bcd4 60%, #7c3aed 130%);
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 188, 212, 0.35), 0 0 0 0 rgba(0, 188, 212, 0.4);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    animation: leoBob 4s ease-in-out infinite;
}

.leo-chat__toggle:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 14px 40px rgba(0, 188, 212, 0.5);
}

.leo-chat__toggle:active {
    transform: translateY(-1px) scale(1.02);
}

.leo-chat__toggle-avatar {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 20%;
    display: block;
    border-radius: 50%;
    pointer-events: none;
}

.leo-chat__toggle-pulse {
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    border: 2px solid var(--leo-accent);
    opacity: 0;
    pointer-events: none;
    animation: leoPulse 2.4s ease-out infinite;
}

.leo-chat__toggle-dot {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    background: #22c55e;
    border: 2px solid #0a0a14;
    border-radius: 50%;
    pointer-events: none;
}

@keyframes leoBob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@keyframes leoPulse {
    0% { transform: scale(0.9); opacity: 0.7; }
    100% { transform: scale(1.4); opacity: 0; }
}

.leo-chat--open .leo-chat__toggle {
    transform: scale(0.85);
    opacity: 0;
    pointer-events: none;
}

/* ---------- Window ---------- */
.leo-chat__window {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 400px;
    height: 620px;
    max-height: calc(100vh - 3rem);
    background: linear-gradient(155deg, var(--leo-bg) 0%, var(--leo-bg-2) 100%);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border: 1px solid var(--leo-border-strong);
    border-radius: 20px;
    box-shadow: var(--leo-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.25s ease;
}

.leo-chat--open .leo-chat__window {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* ---------- Header ---------- */
.leo-chat__header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.1rem;
    background: linear-gradient(135deg, rgba(0, 131, 143, 0.25) 0%, rgba(124, 58, 237, 0.2) 100%);
    border-bottom: 1px solid var(--leo-border);
    flex-shrink: 0;
}

.leo-chat__header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.leo-chat__avatar {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.25);
    flex-shrink: 0;
    background: #0a0a14;
}

.leo-chat__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 20%;
}

.leo-chat__status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 11px;
    height: 11px;
    background: #22c55e;
    border: 2px solid #0a0a14;
    border-radius: 50%;
}

.leo-chat__title-group {
    min-width: 0;
}

.leo-chat__title {
    color: var(--leo-text);
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
}

.leo-chat__subtitle {
    color: var(--leo-text-dim);
    font-size: 0.72rem;
    margin: 2px 0 0;
    display: flex;
    align-items: center;
    gap: 5px;
    line-height: 1.2;
}

.leo-chat__pulse-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    animation: leoStatusPulse 2s ease-out infinite;
}

@keyframes leoStatusPulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.leo-chat__header-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

.leo-chat__icon-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--leo-border);
    color: var(--leo-text-dim);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

.leo-chat__icon-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--leo-text);
    transform: translateY(-1px);
}

.leo-chat__icon-btn[data-action="new-chat"]:active i {
    animation: leoRotate 0.5s ease;
}

@keyframes leoRotate {
    from { transform: rotate(0); }
    to { transform: rotate(-360deg); }
}

/* ---------- Messages ---------- */
.leo-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.leo-chat__messages::-webkit-scrollbar {
    width: 6px;
}
.leo-chat__messages::-webkit-scrollbar-track {
    background: transparent;
}
.leo-chat__messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}
.leo-chat__messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

.leo-chat__msg {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    max-width: 100%;
    animation: leoFadeUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.leo-chat__msg--user {
    justify-content: flex-end;
}

.leo-chat__msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center 20%;
    border: 1px solid var(--leo-border);
    flex-shrink: 0;
    background: #0a0a14;
}

.leo-chat__msg-bubble {
    padding: 0.65rem 0.9rem;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.55;
    word-wrap: break-word;
    max-width: 80%;
    color: var(--leo-text);
}

.leo-chat__msg--bot .leo-chat__msg-bubble {
    background: var(--leo-bubble-bot);
    border: 1px solid var(--leo-border);
    border-bottom-left-radius: 4px;
}

.leo-chat__msg--user .leo-chat__msg-bubble {
    background: var(--leo-bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 188, 212, 0.25);
}

.leo-chat__msg-bubble a {
    color: #5eead4;
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
}

.leo-chat__msg--user .leo-chat__msg-bubble a {
    color: #fff;
}

.leo-chat__msg-bubble strong {
    font-weight: 600;
}

.leo-chat__msg-bubble em {
    font-style: italic;
}

/* Markdown blocks inside bubble */
.leo-chat__msg-bubble .leo-md-h {
    margin: 0.5rem 0 0.35rem;
    font-weight: 700;
    line-height: 1.3;
    color: #fff;
}

.leo-chat__msg-bubble .leo-md-h:first-child {
    margin-top: 0;
}

.leo-chat__msg-bubble .leo-md-h1 { font-size: 1.05rem; }
.leo-chat__msg-bubble .leo-md-h2 { font-size: 1rem; }
.leo-chat__msg-bubble .leo-md-h3 {
    font-size: 0.95rem;
    color: #5eead4;
}
.leo-chat__msg-bubble .leo-md-h4 {
    font-size: 0.9rem;
    color: #5eead4;
}

.leo-chat__msg--user .leo-md-h,
.leo-chat__msg--user .leo-md-h3,
.leo-chat__msg--user .leo-md-h4 {
    color: #fff;
}

.leo-chat__msg-bubble .leo-md-ul {
    margin: 0.4rem 0;
    padding-left: 1.2rem;
    list-style: none;
}

.leo-chat__msg-bubble .leo-md-ul li {
    position: relative;
    padding: 2px 0;
}

.leo-chat__msg-bubble .leo-md-ul li::before {
    content: '';
    position: absolute;
    left: -0.85rem;
    top: 0.65rem;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #5eead4;
}

.leo-chat__msg--user .leo-md-ul li::before {
    background: #fff;
}

.leo-chat__msg-bubble hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    margin: 0.7rem 0;
}

.leo-chat__msg-bubble code {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 1px 6px;
    border-radius: 5px;
    font-family: 'Fira Code', Menlo, Consolas, monospace;
    font-size: 0.82em;
    color: #5eead4;
}

.leo-chat__msg--user .leo-chat__msg-bubble code {
    background: rgba(0, 0, 0, 0.25);
    color: #fff;
}

/* Action buttons (agentic markers) */
.leo-chat__actions {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.7rem;
    padding-top: 0.6rem;
    border-top: 1px dashed rgba(255, 255, 255, 0.12);
}

.leo-chat__msg--bot .leo-chat__msg-bubble:has(.leo-chat__actions) {
    padding-bottom: 0.7rem;
}

.leo-chat__action {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.6rem 0.85rem;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(0, 188, 212, 0.16) 0%, rgba(124, 58, 237, 0.14) 100%);
    border: 1px solid rgba(0, 188, 212, 0.3);
    color: #fff;
    font-size: 0.84rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
}

.leo-chat__action:hover {
    background: linear-gradient(135deg, rgba(0, 188, 212, 0.28) 0%, rgba(124, 58, 237, 0.24) 100%);
    border-color: rgba(0, 188, 212, 0.55);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 188, 212, 0.2);
}

.leo-chat__action:active {
    transform: translateY(0);
}

.leo-chat__action i {
    color: #5eead4;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.leo-chat__action span {
    flex: 1;
    line-height: 1.3;
}

.leo-chat__action[data-action-type="link"] i {
    color: #c4b5fd;
}

.leo-chat__action[data-action-type="project"] i {
    color: #fcd34d;
}

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

/* Typing indicator */
.leo-chat__typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.8rem 1rem;
}

.leo-chat__typing span {
    width: 7px;
    height: 7px;
    background: rgba(255, 255, 255, 0.55);
    border-radius: 50%;
    animation: leoTyping 1.4s ease-in-out infinite;
}

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

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

/* ---------- Suggestions ---------- */
.leo-chat__suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0 1.1rem 0.8rem;
    flex-shrink: 0;
}

.leo-chat__chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.85rem;
    border-radius: 100px;
    background: rgba(0, 188, 212, 0.08);
    border: 1px solid rgba(0, 188, 212, 0.2);
    color: var(--leo-text);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.leo-chat__chip:hover {
    background: rgba(0, 188, 212, 0.18);
    border-color: rgba(0, 188, 212, 0.4);
    transform: translateY(-1px);
}

.leo-chat__chip i {
    font-size: 0.72rem;
    color: var(--leo-accent);
}

/* ---------- Form ---------- */
.leo-chat__form {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.85rem 1.1rem 1.1rem;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid var(--leo-border);
    flex-shrink: 0;
}

.leo-chat__input {
    flex: 1;
    min-height: 42px;
    max-height: 120px;
    padding: 0.65rem 0.9rem;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--leo-border);
    color: var(--leo-text);
    font-size: 0.88rem;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease;
    overflow-y: auto;
}

.leo-chat__input::placeholder {
    color: var(--leo-text-dim);
}

.leo-chat__input:focus {
    border-color: rgba(0, 188, 212, 0.5);
    background: rgba(255, 255, 255, 0.08);
}

.leo-chat__send {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #00838f 0%, #00bcd4 100%);
    border: none;
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 188, 212, 0.35);
}

.leo-chat__send:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 18px rgba(0, 188, 212, 0.5);
}

.leo-chat__send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ---------- Mobile fullscreen ---------- */
@media (max-width: 640px) {
    .leo-chat {
        bottom: 1rem;
        right: 1rem;
    }

    .leo-chat__toggle {
        width: 60px;
        height: 60px;
    }

    .leo-chat__window {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        box-shadow: none;
        transform: translateY(100%);
    }

    .leo-chat--open .leo-chat__window {
        transform: translateY(0);
    }

    .leo-chat__header {
        padding: 0.85rem 1rem;
        padding-top: max(0.85rem, env(safe-area-inset-top));
    }

    .leo-chat__avatar {
        width: 40px;
        height: 40px;
    }

    .leo-chat__title {
        font-size: 1rem;
    }

    .leo-chat__messages {
        padding: 1rem 0.9rem;
        gap: 0.55rem;
    }

    .leo-chat__msg-bubble {
        max-width: 85%;
        font-size: 0.92rem;
    }

    .leo-chat__suggestions {
        padding: 0 0.9rem 0.7rem;
    }

    .leo-chat__form {
        padding: 0.75rem 0.9rem;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }

    /* Hide toggle when chat is open on mobile (no need for it underneath fullscreen) */
    .leo-chat--open .leo-chat__toggle {
        display: none;
    }
}
