@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Tipografía de piezas Clip (titulares) */
@font-face {
    font-family: 'Momo Trust Display';
    src: url('../assets/fonts/MomoTrustDisplay-Regular.ttf') format('truetype');
    font-weight: 400;
    font-display: swap;
}

/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
    /* Paleta Clip (brandbook): naranja core #FC4C02, franja #FF5700,
       negro, blanco, gris #63666A. Se conservan los nombres de variable
       heredados de MELISA para no tocar cada regla. */
    --ml-yellow: #FC4C02;   /* fondo del header */
    --ml-blue: #FC4C02;     /* acento: burbuja usuario, botones, progreso */
    --ml-dark: #000000;     /* textos fuertes y botones oscuros */
    --clip-stripe: #FF5700;
    --clip-grey: #63666A;

    /* Layout */
    --header-height: 15vh;
    --chat-max-width: 780px;

    /* Messages */
    --bot-bg: #FFFFFF;
    --user-bg: #FC4C02;
    --bot-text: #1E1E1E;
    --user-text: #FFFFFF;

    /* Neutral */
    --page-bg: #F0F0F0;
    --input-bg: #FFFFFF;
    --border: #E0E0E0;
    --timestamp: #9E9E9E;
}

/* ─── Reset & Base ───────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--page-bg);
    display: flex;
    flex-direction: column;
    /* dvh = dynamic viewport height: se ajusta cuando aparecen/desaparecen
       las barras del navegador en mobile. Fallback a 100vh para browsers viejos. */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: relative;
    /* Respeta el área segura en iPhones (notch, home bar) */
    padding-bottom: env(safe-area-inset-bottom);
}

/* ─── Topographic Background Pattern ───────────────────────── */
body::before {
    content: '';
    position: fixed;
    inset: var(--header-height) 0 0 0;
    background-image: url('../assets/fondo.jpg');
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 0;
}

/* ─── Header ─────────────────────────────────────────────────── */
.header {
    width: 100%;
    height: 15vh;
    background: var(--ml-yellow);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
    border-bottom: 4px solid var(--clip-stripe);
    position: relative;
    z-index: 10;
}

.header-logo {
    display: flex;
    align-items: center;
}

.header-logo {
    gap: 14px;
}

.header-logo-img {
    height: 64px;
    width: auto;
    display: block;
}

.header-title {
    display: flex;
    flex-direction: column;
    color: #fff;
    line-height: 1.1;
}

.header-title strong {
    font-family: 'Momo Trust Display', 'Inter', sans-serif;
    font-weight: 400;
    font-size: 1.9rem;
    letter-spacing: 0.5px;
}

.header-sub {
    font-size: 0.78rem;
    opacity: 0.9;
}

@media (max-width: 640px) {
    .header-logo-img { height: 44px; }
    .header-title strong { font-size: 1.35rem; }
    .header-sub { display: none; }
}

/* Hide old h1 / p inside header */
.header h1,
.header p {
    display: none !important;
}

/* Botón "Generar documento" — disponible desde el inicio de la conversación,
   no solo cuando el brief está completo (ver descargarBrief()). */


/* Botón "Enviar documento" — junto al de generar. Se ve atenuado hasta que
   haya un documento generado (clase .ready), pero siempre es clickeable:
   si no hay documento, primero lo genera y luego lo envía. */




/* ─── Main Content Area ──────────────────────────────────────── */
.page-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 28px 16px 24px;
    position: relative;
    z-index: 1;
}

/* ─── Chat Window ─────────────────────────────────────────────── */
#chat-window {
    width: 100%;
    max-width: var(--chat-max-width);
    flex: 1;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 20px;
    overflow-y: auto;
    padding: 28px 28px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.07);
    scroll-behavior: smooth;
}

/* Scrollbar */
#chat-window::-webkit-scrollbar {
    width: 5px;
}

#chat-window::-webkit-scrollbar-track {
    background: transparent;
}

#chat-window::-webkit-scrollbar-thumb {
    background: #D0D0D0;
    border-radius: 10px;
}

/* ─── Date / Time Separators ────────────────────────────────── */
.chat-date-separator {
    text-align: center;
    font-size: 0.72rem;
    color: var(--timestamp);
    letter-spacing: 0.5px;
    padding: 4px 0 8px;
    font-weight: 400;
}

.msg-time {
    font-size: 0.68rem;
    color: var(--timestamp);
    margin-top: 4px;
    display: block;
}

/* ─── Messages ───────────────────────────────────────────────── */
.msg {
    padding: 14px 18px;
    border-radius: 16px;
    max-width: 72%;
    line-height: 1.65;
    font-size: 0.95rem;
    position: relative;
    animation: msgIn 0.25s ease-out both;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Bot bubble – left, light grey bg */
.bot {
    align-self: flex-start;
    background: #F4F4F4;
    color: var(--bot-text);
    border-bottom-left-radius: 4px;
}

/* Row wrapper: avatar + bot bubble side by side */
.bot-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    align-self: flex-start;
    max-width: 80%;
}

.bot-row .msg.bot {
    align-self: unset;
    max-width: 100%;
}

/* Circular avatar */
.bot-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}


/* User bubble – right, blue */
.user {
    align-self: flex-end;
    background: var(--user-bg);
    color: var(--user-text);
    border-bottom-right-radius: 4px;
}

.bot p,
.bot ul,
.bot li {
    margin: 0.4rem 0;
}

.bot strong {
    color: var(--ml-dark);
}

/* ─── Typing Dots ─────────────────────────────────────────────── */
.dots {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    height: 20px;
}

.dot {
    width: 7px;
    height: 7px;
    background: var(--ml-blue);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) {
    animation-delay: -0.32s;
}

.dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0.4);
    }

    40% {
        transform: scale(1.0);
    }
}

/* ─── Input Bar ──────────────────────────────────────────────── */
.input-group {
    width: 100%;
    max-width: var(--chat-max-width);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    background: var(--input-bg);
    border-radius: 40px;
    padding: 6px 6px 6px 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* Clip icon button */
.input-group .btn-attach {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.3rem;
    color: #888;
    transition: color 0.2s, background 0.2s;
    padding: 0;
}

.input-group .btn-attach:hover {
    background: #F0F0F0;
    color: var(--ml-blue);
    transform: none;
}

/* Text input – fills space */
.input-group textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 0.96rem;
    color: #333;
    padding: 10px 4px;
    outline: none;
    font-family: 'Inter', sans-serif;
    resize: none;
    height: 42px;
    min-height: 42px;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.4;
}

.input-group textarea::placeholder {
    color: #AAAAAA;
}

/* Send button */
.input-group .btn-send {
    padding: 11px 26px;
    border-radius: 30px;
    border: none;
    background: var(--ml-dark);
    color: #FFFFFF;
    font-weight: 600;
    font-size: 0.94rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    flex-shrink: 0;
}

.input-group .btn-send:hover {
    background: var(--ml-blue);
    transform: translateY(-1px);
}

.input-group .btn-send:active {
    transform: translateY(0);
}

/* ─── Botón de descarga dentro del chat ─────────────────────── */
.btn-download-brief {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 10px 24px;
    background: var(--ml-dark);
    color: #FFFFFF;
    border: none;
    border-radius: 30px;
    font-size: 0.92rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}

.btn-download-brief:hover {
    background: var(--ml-blue);
    transform: translateY(-1px);
}

.btn-download-brief:active {
    transform: translateY(0);
}

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
    .page-body {
        /* padding-bottom extra para no tapar con la home bar de iPhone */
        padding: 16px 10px max(16px, env(safe-area-inset-bottom));
    }



    /* En pantallas chicas el logo ocupa casi todo el ancho — dejamos
       solo el ícono para no encimarnos con él. */

    #chat-window {
        padding: 18px 16px 12px;
        border-radius: 14px;
    }

    .msg {
        max-width: 88%;
        font-size: 0.9rem;
    }

    .input-group .btn-send {
        padding: 11px 18px;
    }
}

/* ─── Closing Card (brief ready + next steps) ────────────────── */
.closing-card {
    max-width: 100% !important;
}

.closing-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ml-dark);
    margin-bottom: 4px !important;
}

.closing-sub {
    font-size: 0.88rem;
    color: #555;
    margin-bottom: 14px !important;
    line-height: 1.5;
}

.next-steps {
    background: linear-gradient(135deg, #f0f5ff 0%, #fffbea 100%);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 16px;
    border-left: 3px solid var(--ml-blue);
}

.next-steps-label {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--ml-blue);
    margin-bottom: 10px !important;
}

.next-steps-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.next-steps-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.88rem;
    color: #333;
    line-height: 1.45;
}

.ns-icon {
    font-size: 1.05rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.next-steps-list li strong {
    color: var(--ml-dark);
}

/* ─── Brief Progress Bar ─────────────────────────────────────── */

#debugPdfBtn,
#debugEmailBtn {
    font-size: 0.65rem;
    font-family: 'Inter', sans-serif;
    padding: 2px 7px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: #f5f5f5;
    color: #888;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}
#debugPdfBtn:hover,
#debugEmailBtn:hover {
    background: var(--ml-dark);
    color: #fff;
    border-color: var(--ml-dark);
}

.brief-progress-wrap {
    width: 100%;
    max-width: var(--chat-max-width);
    margin-top: 10px;
    padding: 0 4px;
}

.brief-progress-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 5px;
}

.brief-progress-label {
    font-size: 0.70rem;
    font-weight: 500;
    color: #888;
    letter-spacing: 0.2px;
    text-transform: uppercase;
}

.brief-progress-pct {
    font-size: 0.70rem;
    font-weight: 700;
    color: var(--ml-dark);
    letter-spacing: 0.3px;
    transition: color 0.4s ease;
}

.brief-progress-track {
    width: 100%;
    height: 5px;
    background: rgba(0, 0, 0, 0.09);
    border-radius: 99px;
    overflow: hidden;
}

.brief-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #FF9E1B 0%, #FF5700 60%, #FC4C02 100%);
    border-radius: 99px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 6px rgba(255, 230, 0, 0.5);
}

/* When complete, turn fully blue */
.brief-progress-fill.complete {
    background: var(--ml-blue);
    box-shadow: 0 0 8px rgba(252, 76, 2, 0.4);
}

/* ─── Disclaimer ──────────────────────────────────────────────── */
.disclaimer {
    font-size: 0.72rem;
    color: #888;
    text-align: center;
    margin-top: 10px;
    letter-spacing: 0.1px;
    line-height: 1.5;
}

.disclaimer a {
    color: var(--ml-blue);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.disclaimer a:hover {
    color: var(--ml-dark);
    text-decoration: underline;
}

/* ─── Quick Reply Buttons ────────────────────────────────────── */
.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    align-self: flex-start;
    max-width: 72%;
    animation: msgIn 0.3s ease-out both;
}

.qr-btn {
    padding: 7px 16px;
    border-radius: 20px;
    border: 1.5px solid var(--ml-blue);
    background: #fff;
    color: var(--ml-blue);
    font-family: 'Inter', sans-serif;
    font-size: 0.87rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.18s, color 0.18s, transform 0.12s, opacity 0.18s;
    white-space: nowrap;
}

.qr-btn:hover {
    background: var(--ml-blue);
    color: #fff;
    transform: translateY(-1px);
}

.qr-btn:active {
    transform: translateY(0);
}

/* Fade out after selection */
.quick-replies.used {
    opacity: 0.35;
    pointer-events: none;
}

@media (max-width: 600px) {
    .quick-replies {
        max-width: 92%;
    }
    .qr-btn {
        font-size: 0.83rem;
        padding: 6px 13px;
    }
}
/* --- Tooltip --------------------------------------------------- */
.tooltip-icon { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; background: #eef2ff; color: var(--ml-blue); border-radius: 50%; font-size: 11px; font-weight: bold; margin-left: 8px; cursor: help; position: relative; vertical-align: baseline; font-style: normal; border: 1px solid #c7d2fe; opacity: 0.85; transition: opacity 0.2s, background 0.2s; }
.tooltip-icon:hover { opacity: 1; background: #c7d2fe; }
.tooltip-icon[data-tooltip]::after { content: attr(data-tooltip); position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%); background: #1e293b; color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 12.5px; white-space: normal; min-width: 200px; max-width: 280px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 9999; font-family: 'Inter', sans-serif; font-weight: 400; line-height: 1.5; opacity: 0; pointer-events: none; transition: opacity 0.2s, bottom 0.2s; }
.tooltip-icon[data-tooltip]::before { content: ''; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); border-width: 6px; border-style: solid; border-color: #1e293b transparent transparent transparent; opacity: 0; pointer-events: none; transition: opacity 0.2s, bottom 0.2s; }
.tooltip-icon[data-tooltip]:hover::after, .tooltip-icon[data-tooltip]:hover::before { opacity: 1; pointer-events: auto; }
.tooltip-icon[data-tooltip]:hover::after { bottom: 140%; }
.tooltip-icon[data-tooltip]:hover::before { bottom: calc(140% - 12px); }

/* --- Multi-select Quick Replies -------------------------------- */
.qr-multi.selected { background: var(--ml-blue); color: #fff; border-color: var(--ml-dark); transform: scale(1.02); }
.qr-confirm { margin-left: 8px; font-weight: 600; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
