/* ========================================================================
   Asistente IA MCV - Glassmorphism / Siri-like Design
   ========================================================================
   Paleta: #2f4783 (primary), #6b9eff (primary-light)
   Mobile-first, responsive, no emojis, horizontal carousel
   ======================================================================== */

/* ── Variables ── */
:root {
    --mcv-ia-primary: #2f4783;
    --mcv-ia-primary-light: #6b9eff;
    --mcv-ia-surface: rgba(255, 255, 255, 0.82);
    --mcv-ia-surface-solid: #ffffff;
    --mcv-ia-border: rgba(255, 255, 255, 0.45);
    --mcv-ia-shadow: 0 8px 32px rgba(47, 71, 131, 0.10);
    --mcv-ia-radius: 24px;
    --mcv-ia-radius-sm: 16px;
    --mcv-ia-radius-xs: 12px;
    --mcv-ia-text: #1e293b;
    --mcv-ia-text-secondary: #64748b;
    --mcv-ia-bg: #f0f4f8;
}

/* ── Container (invisible wrapper) ── */
.mcv-ia-container {
    position: fixed;
    bottom: 0;
    right: 16px;
    z-index: 9999;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* ========================================================================
   BOTON FLOTANTE - Liquid Glass
   ======================================================================== */
.mcv-ia-toggle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.40);
    background: rgba(47, 71, 131, 0.13);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.60),
        inset 0 -2px 6px rgba(0, 0, 0, 0.15),
        0 4px 20px rgba(47, 71, 131, 0.25);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    margin-bottom: 12px;
    position: relative;
    isolation: isolate;
    overflow: hidden;
}

/* Reflejo animado - shimmer cada 4s */
.mcv-ia-toggle::after {
    content: "";
    position: absolute;
    top: -30%;
    left: 0;
    width: 50%;
    height: 160%;
    background: linear-gradient(105deg,
        transparent 25%,
        rgba(255, 255, 255, 0.55) 50%,
        transparent 75%);
    transform: translateX(-200%) skewX(-14deg);
    z-index: 2;
    pointer-events: none;
    animation: mcv-ia-shimmer 4s ease-in-out infinite;
}

@keyframes mcv-ia-shimmer {
    0%, 70% { transform: translateX(-200%) skewX(-14deg); }
    85% { transform: translateX(280%) skewX(-14deg); }
    100% { transform: translateX(-200%) skewX(-14deg); }
}

.mcv-ia-toggle:hover {
    transform: translateY(-2px) scale(1.06);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.70),
        inset 0 -2px 6px rgba(0, 0, 0, 0.15),
        0 8px 28px rgba(47, 71, 131, 0.35);
}

.mcv-ia-toggle:active {
    transform: translateY(0) scale(0.95);
    transition-duration: 0.1s;
}

/* ========================================================================
   SHEET (Modal)
   ======================================================================== */
.mcv-ia-sheet {
    position: fixed;
    bottom: 0;
    right: 16px;
    width: 100%;
    max-width: 420px;
    height: 600px;
    max-height: 85vh;
    background: var(--mcv-ia-surface);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border-radius: 28px 28px 0 0;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.50),
        inset 0 -1px 0 rgba(255, 255, 255, 0.15),
        0 -4px 32px rgba(0, 0, 0, 0.06),
        0 0 0 1px rgba(255, 255, 255, 0.30);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    animation: mcv-ia-sheet-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes mcv-ia-sheet-in {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Handle */
.mcv-ia-handle {
    width: 36px;
    height: 4px;
    background: rgba(0, 0, 0, 0.12);
    border-radius: 2px;
    margin: 10px auto 0;
    flex-shrink: 0;
}

/* ========================================================================
   HEADER
   ======================================================================== */
.mcv-ia-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 10px;
    flex-shrink: 0;
}

.mcv-ia-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--mcv-ia-text);
    margin: 0;
    line-height: 1.3;
}

.mcv-ia-subtitle {
    font-size: 11px;
    color: var(--mcv-ia-text-secondary);
    margin: 2px 0 0;
}

.mcv-ia-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--mcv-ia-text-secondary);
    transition: background 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
}

.mcv-ia-close:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--mcv-ia-text);
}

/* ========================================================================
   CARRUSEL HORIZONTAL
   ======================================================================== */
.mcv-ia-carousel {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: auto;
    padding: 0 16px 2px;
    flex-shrink: 0;
}

.mcv-ia-carousel > * {
    flex-shrink: 0;
    scroll-snap-align: start;
}

/* Espacio real al final del carrusel */
.mcv-ia-carousel::after {
    content: "";
    flex: 0 0 4px;
}

.mcv-ia-carousel::-webkit-scrollbar {
    display: none;
}

.mcv-ia-carousel-track {
    display: flex;
    gap: 8px;
    padding: 2px 18px 8px;
}

.mcv-ia-carousel-item {
    scroll-snap-align: start;
    flex-shrink: 0;
    padding: 8px 16px;
    border-radius: 100px;
    background: rgba(47, 71, 131, 0.06);
    border: 1px solid rgba(47, 71, 131, 0.10);
    color: var(--mcv-ia-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    font-family: inherit;
}

.mcv-ia-carousel-item:hover {
    background: rgba(47, 71, 131, 0.10);
    border-color: rgba(47, 71, 131, 0.18);
}

.mcv-ia-carousel-item:active {
    transform: scale(0.96);
    background: rgba(47, 71, 131, 0.14);
}

/* ========================================================================
   ACCIONES
   ======================================================================== */
.mcv-ia-actions {
    display: flex;
    gap: 8px;
    padding: 4px 18px 8px;
    flex-shrink: 0;
}

.mcv-ia-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border: 1px solid rgba(47, 71, 131, 0.12);
    background: rgba(255, 255, 255, 0.6);
    border-radius: 100px;
    font-size: 12px;
    font-weight: 500;
    color: var(--mcv-ia-text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.mcv-ia-action-btn:hover {
    background: rgba(47, 71, 131, 0.06);
    color: var(--mcv-ia-primary);
    border-color: rgba(47, 71, 131, 0.18);
}

/* ========================================================================
   AREA DE MENSAJES
   ======================================================================== */
.mcv-ia-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(241, 245, 249, 0.5);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* ── Welcome ── */
.mcv-ia-welcome {
    padding: 24px 18px;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: var(--mcv-ia-radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.50);
    text-align: center;
}

.mcv-ia-welcome-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 12px;
    background: linear-gradient(135deg, var(--mcv-ia-primary) 0%, var(--mcv-ia-primary-light) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(47, 71, 131, 0.20);
}

.mcv-ia-welcome-text {
    font-size: 13px;
    color: var(--mcv-ia-text-secondary);
    line-height: 1.6;
    margin: 0 0 16px;
}

.mcv-ia-welcome-carousel {
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin: 0 -18px;
    padding: 0 18px;
}

.mcv-ia-welcome-carousel::-webkit-scrollbar {
    display: none;
}

.mcv-ia-welcome-carousel-track {
    display: flex;
    gap: 8px;
}

/* ========================================================================
   MENSAJES
   ======================================================================== */
.mcv-ia-msg {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: mcv-ia-msg-in 0.25s ease;
}

@keyframes mcv-ia-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.mcv-ia-msg-user {
    align-self: flex-end;
    background: var(--mcv-ia-primary);
    color: #fff;
    border-radius: 18px 18px 4px 18px;
}

.mcv-ia-msg-assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.70);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--mcv-ia-text);
    border-radius: 18px 18px 18px 4px;
    border: 1px solid rgba(255, 255, 255, 0.50);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.mcv-ia-msg-content {
    line-height: 1.5;
}

.mcv-ia-msg-meta {
    display: block;
    margin-top: 6px;
    font-size: 10px;
    color: var(--mcv-ia-text-secondary);
    opacity: 0.7;
}

.mcv-ia-msg-error {
    align-self: center;
    background: rgba(254, 226, 226, 0.8);
    color: #991b1b;
    border: 1px solid rgba(252, 165, 165, 0.5);
    border-radius: 14px;
    font-size: 12px;
    text-align: center;
    max-width: 90%;
    padding: 10px 14px;
}

/* ========================================================================
   MARKDOWN RENDERED CONTENT
   ======================================================================== */
.mcv-ia-msg-assistant .mcv-ia-msg-content h1,
.mcv-ia-msg-assistant .mcv-ia-msg-content h2,
.mcv-ia-msg-assistant .mcv-ia-msg-content h3,
.mcv-ia-msg-assistant .mcv-ia-msg-content h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--mcv-ia-text);
    margin: 12px 0 6px;
    line-height: 1.4;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content h3:first-child,
.mcv-ia-msg-assistant .mcv-ia-msg-content h4:first-child {
    margin-top: 0;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content p {
    margin: 0 0 8px;
    line-height: 1.5;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content p:last-child {
    margin-bottom: 0;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content strong {
    font-weight: 700;
    color: var(--mcv-ia-text);
}

.mcv-ia-msg-assistant .mcv-ia-msg-content ul,
.mcv-ia-msg-assistant .mcv-ia-msg-content ol {
    margin: 6px 0;
    padding-left: 20px;
    line-height: 1.5;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content li {
    margin: 3px 0;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content code {
    background: rgba(47, 71, 131, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content a {
    color: var(--mcv-ia-primary-light);
    text-decoration: none;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content a:hover {
    text-decoration: underline;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content hr {
    border: none;
    border-top: 1px solid rgba(47, 71, 131, 0.10);
    margin: 10px 0;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content blockquote {
    border-left: 3px solid var(--mcv-ia-primary-light);
    margin: 8px 0;
    padding: 4px 12px;
    color: var(--mcv-ia-text-secondary);
    background: rgba(241, 245, 249, 0.5);
    border-radius: 0 8px 8px 0;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 12px;
    overflow-x: auto;
    display: block;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content th,
.mcv-ia-msg-assistant .mcv-ia-msg-content td {
    border: 1px solid rgba(47, 71, 131, 0.10);
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
    white-space: normal;
    word-wrap: break-word;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content th {
    background: rgba(47, 71, 131, 0.05);
    font-weight: 600;
    font-size: 11px;
}

.mcv-ia-msg-assistant .mcv-ia-msg-content tr:nth-child(even) {
    background: rgba(241, 245, 249, 0.4);
}

.mcv-ia-msg-assistant .mcv-ia-msg-content br {
    display: block;
    content: '';
    margin: 2px 0;
}

/* ========================================================================
   INDICADOR DE ESCRITURA
   ======================================================================== */
.mcv-ia-typing {
    display: flex;
    gap: 5px;
    padding: 8px 18px;
    align-self: flex-start;
}

.mcv-ia-typing span {
    width: 7px;
    height: 7px;
    background: var(--mcv-ia-text-secondary);
    border-radius: 50%;
    opacity: 0.4;
    animation: mcv-ia-bounce 1.4s infinite ease-in-out;
}

.mcv-ia-typing span:nth-child(1) { animation-delay: -0.32s; }
.mcv-ia-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes mcv-ia-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 0.7; }
}

/* ========================================================================
   INPUT AREA
   ======================================================================== */
.mcv-ia-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 18px 14px;
    flex-shrink: 0;
}

.mcv-ia-input {
    flex: 1;
    border: 1.5px solid rgba(47, 71, 131, 0.12);
    border-radius: 100px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease;
    font-family: inherit;
    line-height: 1.5;
    background: rgba(241, 245, 249, 0.6);
    color: var(--mcv-ia-text);
}

.mcv-ia-input:focus {
    border-color: var(--mcv-ia-primary-light);
    background: rgba(255, 255, 255, 0.7);
}

.mcv-ia-input:disabled {
    background: rgba(241, 245, 249, 0.4);
    cursor: not-allowed;
    opacity: 0.6;
}

.mcv-ia-input::placeholder {
    color: var(--mcv-ia-text-secondary);
    opacity: 0.6;
}

.mcv-ia-send {
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    border: none;
    background: var(--mcv-ia-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
    box-shadow: 0 2px 8px rgba(47, 71, 131, 0.20);
}

.mcv-ia-send:hover {
    transform: scale(1.06);
}

.mcv-ia-send:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ========================================================================
   FOOTER INFO
   ======================================================================== */
.mcv-ia-footer-info {
    padding: 6px 18px;
    text-align: center;
    flex-shrink: 0;
}

.mcv-ia-model-info {
    font-size: 10px;
    color: var(--mcv-ia-text-secondary);
    opacity: 0.5;
}

/* ========================================================================
   RESPONSIVE
   ======================================================================== */

/* Mobile: sheet fullscreen, boton arriba de nav */
@media (max-width: 480px) {
    .mcv-ia-container {
        right: 16px;
        bottom: 88px;
    }

    .mcv-ia-sheet {
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        right: 0;
        bottom: 0;
    }
}

/* Small mobile */
@media (max-width: 360px) {
    .mcv-ia-container {
        right: 12px;
        bottom: 84px;
    }

    .mcv-ia-toggle {
        width: 48px;
        height: 48px;
    }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 768px) {
    .mcv-ia-container {
        bottom: 88px;
    }

    .mcv-ia-sheet {
        max-width: 400px;
        height: 540px;
    }
}

/* Desktop: sheet flotante, sin nav */
@media (min-width: 769px) {
    .mcv-ia-container {
        right: 24px;
        bottom: 25px;
    }

    .mcv-ia-sheet {
        max-width: 420px;
        height: 600px;
        bottom: 90px;
        right: 24px;
    }
}

/* ========================================================================
   DARK MODE
   ======================================================================== */
@media (prefers-color-scheme: dark) {
    :root {
        --mcv-ia-text: #f1f5f9;
        --mcv-ia-text-secondary: #94a3b8;
    }

    .mcv-ia-sheet {
        background: rgba(30, 41, 59, 0.88);
        backdrop-filter: blur(40px) saturate(180%);
        -webkit-backdrop-filter: blur(40px) saturate(180%);
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, 0.10),
            inset 0 -1px 0 rgba(255, 255, 255, 0.05),
            0 -4px 32px rgba(0, 0, 0, 0.25),
            0 0 0 1px rgba(255, 255, 255, 0.06);
    }

    .mcv-ia-handle {
        background: rgba(255, 255, 255, 0.15);
    }

    .mcv-ia-close {
        background: rgba(255, 255, 255, 0.08);
        color: #94a3b8;
    }

    .mcv-ia-close:hover {
        background: rgba(255, 255, 255, 0.12);
        color: #f1f5f9;
    }

    .mcv-ia-messages {
        background: rgba(15, 23, 42, 0.4);
    }

    .mcv-ia-msg-assistant {
        background: rgba(51, 65, 85, 0.60);
        border-color: rgba(255, 255, 255, 0.06);
    }

    .mcv-ia-welcome {
        background: rgba(51, 65, 85, 0.50);
        border-color: rgba(255, 255, 255, 0.06);
    }

    .mcv-ia-carousel-item {
        background: rgba(107, 158, 255, 0.10);
        border-color: rgba(107, 158, 255, 0.15);
    }

    .mcv-ia-action-btn {
        background: rgba(255, 255, 255, 0.06);
        border-color: rgba(255, 255, 255, 0.08);
    }

    .mcv-ia-input {
        background: rgba(51, 65, 85, 0.5);
        border-color: rgba(255, 255, 255, 0.08);
        color: #f1f5f9;
    }

    .mcv-ia-input:focus {
        border-color: var(--mcv-ia-primary-light);
        background: rgba(51, 65, 85, 0.6);
    }

    .mcv-ia-msg-assistant .mcv-ia-msg-content code {
        background: rgba(15, 23, 42, 0.5);
    }

    .mcv-ia-msg-assistant .mcv-ia-msg-content blockquote {
        background: rgba(15, 23, 42, 0.3);
    }

    .mcv-ia-msg-assistant .mcv-ia-msg-content th {
        background: rgba(15, 23, 42, 0.3);
        border-color: rgba(255, 255, 255, 0.08);
    }

    .mcv-ia-msg-assistant .mcv-ia-msg-content td {
        border-color: rgba(255, 255, 255, 0.08);
    }

    .mcv-ia-msg-error {
        background: rgba(127, 29, 29, 0.3);
        border-color: rgba(239, 68, 68, 0.3);
        color: #fca5a5;
    }

    .mcv-ia-typing span {
        background: #94a3b8;
    }
}

/* ========================================================================
   REDUCED MOTION
   ======================================================================== */
@media (prefers-reduced-motion: reduce) {
    .mcv-ia-sheet {
        animation: none;
    }

    .mcv-ia-msg {
        animation: none;
    }

    .mcv-ia-toggle {
        animation: none;
    }

    .mcv-ia-toggle::after {
        animation: none;
    }
}
