/* ============================================================
   Asistente Fina — estilos base
   Branding: #171a1c oscuro, #eecb3b amarillo, blanco neutro.
   Mobile-first. Tipografía Inter.
   ============================================================ */

:root {
    --color-dark:        #171a1c;
    --color-yellow:      #eecb3b;
    --color-yellow-soft: #f5e6a3;
    --color-white:       #ffffff;
    --color-gray-50:     #f7f7f8;
    --color-gray-100:    #f3f3f4;
    --color-gray-200:    #e6e7e9;
    --color-gray-400:    #b3b6ba;
    --color-gray-500:    #6b6f74;
    --color-error:       #c0392b;
    --radius:            12px;
    --radius-lg:         16px;
    --radius-pill:       9999px;
    --shadow-sm:         0 1px 2px rgba(23, 26, 28, 0.04);
    --shadow-md:         0 6px 24px rgba(23, 26, 28, 0.10);
    --font-sans:         "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-white);
    color: var(--color-dark);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100dvh;
}

button {
    font-family: inherit;
    cursor: pointer;
}

/* ============================================================
   LOGIN
   ============================================================ */

.page-login {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    background: #ffffff;
}

/* Fondo de marca (mosaico amarillo) cubriendo toda la pantalla, fijo */
.page-login::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url('../img/fondo-degradado.webp');
    background-size: cover;
    background-position: center top;
    background-repeat: no-repeat;
    z-index: 0;
    pointer-events: none;
}
/* Velo blanco MUY suave para mejorar legibilidad de la card */
.page-login::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.35);
    z-index: 0;
    pointer-events: none;
}

.login {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    position: relative;
    z-index: 1;
}

.login__card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 380px;
    background: var(--color-white);
    border-radius: var(--radius-lg);
    padding: 24px 24px 28px;
    box-shadow: 0 20px 50px rgba(23, 26, 28, 0.18), 0 2px 6px rgba(23, 26, 28, 0.06);
    border: 1px solid rgba(23, 26, 28, 0.06);
}

.login__logo {
    text-align: center;
    margin-bottom: 16px;
}
.login__logo-img {
    width: 180px;
    height: auto;
    max-width: 70%;
    display: block;
    margin: 0 auto 6px;
}
.login__logo-sub {
    display: inline-block;
    margin-top: 0;
    padding: 4px 12px;
    background: var(--color-dark);
    color: var(--color-yellow);
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.login__title {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-align: center;
}
.login__subtitle {
    margin: 0 0 20px;
    text-align: center;
    color: var(--color-gray-500);
    font-size: 14px;
}

.login__error {
    background: #fdecea;
    border: 1px solid #f4c7c3;
    color: var(--color-error);
    border-radius: var(--radius);
    padding: 12px 14px;
    font-size: 14px;
    margin-bottom: 16px;
    line-height: 1.4;
}

.login__form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.login__label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-gray-500);
    margin-bottom: -6px;
}
.login__input {
    appearance: none;
    border: 1.5px solid var(--color-gray-200);
    border-radius: var(--radius);
    padding: 14px 16px;
    font-size: 16px;
    font-family: inherit;
    color: var(--color-dark);
    background: var(--color-white);
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}
.login__input:focus {
    outline: none;
    border-color: var(--color-dark);
    box-shadow: 0 0 0 4px rgba(238, 203, 59, 0.25);
}

.login__button {
    background: var(--color-yellow);
    color: var(--color-dark);
    border: none;
    border-radius: var(--radius);
    padding: 14px 16px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.01em;
    transition: transform 0.05s, box-shadow 0.15s, background 0.15s;
    margin-top: 4px;
}
.login__button:hover { box-shadow: 0 4px 12px rgba(238, 203, 59, 0.35); }
.login__button:active { transform: translateY(1px); }

.login__footer {
    margin: 20px 0 0;
    text-align: center;
    font-size: 12px;
    color: var(--color-gray-500);
}

/* ============================================================
   CHAT
   ============================================================ */

.page-chat {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background-color: var(--color-white);
    position: relative;
    isolation: isolate;
}

/* Fondo de marca: cover, sin repetir, fijo al viewport */
.page-chat::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -2;
    background-image: url('../img/fondo-chat.png');
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    pointer-events: none;
}

/* Viñeta blanca sutil — difumina los bordes hacia el blanco */
.page-chat::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: radial-gradient(
        ellipse at center,
        transparent 45%,
        rgba(255, 255, 255, 0.45) 80%,
        rgba(255, 255, 255, 0.85) 100%
    );
}

/* Header */
.chat-header {
    background: var(--color-dark);
    color: var(--color-white);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 10;
    padding-top: max(12px, env(safe-area-inset-top));
}
.chat-header__inner {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.chat-header__brand {
    display: flex;
    align-items: center;
    gap: 12px;
}
.chat-header__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center;
    background: var(--color-yellow);
    box-shadow: 0 2px 8px rgba(238, 203, 59, 0.45), 0 0 0 2px rgba(238, 203, 59, 0.55);
    flex: 0 0 auto;
}
.chat-header__name {
    font-weight: 700;
    font-size: 15px;
    line-height: 1.1;
}
.chat-header__name-suffix {
    color: var(--color-yellow);
    font-weight: 600;
    letter-spacing: 0.01em;
    margin-left: 1px;
}
.chat-header__status {
    font-size: 12px;
    color: var(--color-yellow);
    margin-top: 2px;
}
.chat-header__logout button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    color: var(--color-yellow);
    border: 1.5px solid var(--color-yellow);
    border-radius: var(--radius-pill);
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
}
.chat-header__logout button:hover { background: var(--color-yellow); color: var(--color-dark); }

/* Banner del chat (anuncios/avisos) */
.chat-banner {
    position: relative;
    max-width: 720px;
    margin: 14px auto 0;
    padding: 16px 48px 18px 20px;
    background: linear-gradient(135deg, var(--color-yellow) 0%, #f5dc63 100%);
    color: var(--color-dark);
    border-radius: var(--radius-lg);
    box-shadow: 0 6px 20px rgba(238, 203, 59, 0.30);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    animation: bannerIn 0.32s cubic-bezier(0.2, 0.7, 0.3, 1.1) both;
}
.chat-banner--out {
    animation: bannerOut 0.22s ease-in forwards;
}
@keyframes bannerIn {
    from { opacity: 0; transform: translateY(-12px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}
@keyframes bannerOut {
    to { opacity: 0; transform: translateY(-12px) scale(0.97); }
}
.chat-banner__close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(23, 26, 28, 0.10);
    color: var(--color-dark);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.15s;
}
.chat-banner__close:hover { background: rgba(23, 26, 28, 0.22); }
.chat-banner__image {
    max-width: 100%;
    max-height: 140px;
    border-radius: 10px;
    object-fit: cover;
}
.chat-banner__text {
    font-size: 14.5px;
    font-weight: 500;
    line-height: 1.5;
    white-space: pre-wrap;
    max-width: 600px;
}
.chat-banner__btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--color-dark);
    color: var(--color-yellow);
    border-radius: var(--radius-pill);
    font-weight: 700;
    font-size: 13px;
    text-decoration: none;
    transition: transform 0.05s, box-shadow 0.15s;
}
.chat-banner__btn:hover {
    box-shadow: 0 4px 14px rgba(23, 26, 28, 0.30);
}
.chat-banner__btn:active { transform: translateY(1px); }

/* Cuerpo */
.chat {
    flex: 1 1 auto;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat__day {
    text-align: center;
    margin: 4px 0 12px;
}
.chat__day span {
    display: inline-block;
    padding: 4px 12px;
    background: rgba(23, 26, 28, 0.78);
    color: var(--color-white);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-radius: var(--radius-pill);
    backdrop-filter: blur(4px);
}

.chat__list {
    flex: 1 1 auto;
    overflow-y: auto;
    scroll-behavior: smooth;
    padding-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Mensajes */
.msg {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 100%;
    animation: msgIn 0.18s ease-out;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.msg--user      { justify-content: flex-end; }
.msg--assistant { justify-content: flex-start; }

.msg__avatar {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-yellow);
    object-fit: cover;
    object-position: center;
    margin-bottom: 2px;
    box-shadow: 0 0 0 1.5px rgba(238, 203, 59, 0.7);
}

.bubble {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(23, 26, 28, 0.06);
}
.bubble--assistant {
    background: #ffffff;
    color: var(--color-dark);
    border: 1px solid rgba(23, 26, 28, 0.06);
    border-bottom-left-radius: 6px;
    white-space: normal; /* sobrescribimos pre-wrap porque markdown gestiona los saltos */
}

/* ============================================================
   Markdown rendering dentro de burbujas del asistente
   ============================================================ */
.bubble--assistant > *:first-child { margin-top: 0; }
.bubble--assistant > *:last-child  { margin-bottom: 0; }

.bubble--assistant p {
    margin: 0 0 8px;
    line-height: 1.5;
}
.bubble--assistant p:last-child { margin-bottom: 0; }

.bubble--assistant strong {
    font-weight: 700;
    color: var(--color-dark);
}
.bubble--assistant em { font-style: italic; }

.bubble--assistant ul,
.bubble--assistant ol {
    margin: 6px 0 10px;
    padding-left: 24px;
}
.bubble--assistant li {
    margin: 3px 0;
    line-height: 1.5;
}
.bubble--assistant li > p { margin: 0; }

.bubble--assistant h1,
.bubble--assistant h2,
.bubble--assistant h3,
.bubble--assistant h4 {
    font-size: 15px;
    font-weight: 700;
    margin: 12px 0 6px;
    color: var(--color-dark);
    letter-spacing: -0.005em;
}
.bubble--assistant h1:first-child,
.bubble--assistant h2:first-child,
.bubble--assistant h3:first-child { margin-top: 0; }

.bubble--assistant a {
    color: var(--color-dark);
    text-decoration: underline;
    text-decoration-color: var(--color-yellow);
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
    font-weight: 600;
    word-break: break-word;
}
.bubble--assistant a:hover {
    text-decoration-color: var(--color-dark);
    background: rgba(238, 203, 59, 0.18);
    border-radius: 3px;
}

.bubble--assistant code {
    background: rgba(23, 26, 28, 0.06);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}
.bubble--assistant pre {
    background: rgba(23, 26, 28, 0.05);
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}
.bubble--assistant pre code {
    background: transparent;
    padding: 0;
    font-size: 12.5px;
}

.bubble--assistant blockquote {
    margin: 8px 0;
    padding: 4px 12px;
    border-left: 3px solid var(--color-yellow);
    background: rgba(238, 203, 59, 0.08);
    color: var(--color-dark);
    border-radius: 0 6px 6px 0;
}

.bubble--assistant hr {
    border: none;
    border-top: 1px solid rgba(23, 26, 28, 0.10);
    margin: 12px 0;
}

.bubble--assistant table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
}
.bubble--assistant th,
.bubble--assistant td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(23, 26, 28, 0.06);
}
.bubble--assistant th { font-weight: 700; }
.bubble--user {
    background: var(--color-yellow);
    color: var(--color-dark);
    border-bottom-right-radius: 6px;
    font-weight: 500;
}

/* Fuentes consultadas por Fina (RAG) bajo la burbuja */
.bubble__sources {
    flex-basis: 100%;     /* salto de línea dentro del .msg flex */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 4px 0 0 36px; /* sangrado para alinear con la burbuja (no con el avatar) */
    animation: msgIn 0.2s ease-out;
}
.bubble__sources-label {
    font-size: 11px;
    color: var(--color-gray-500);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-right: 2px;
}
.bubble__source-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--color-white);
    color: var(--color-dark);
    border: 1px solid rgba(238, 203, 59, 0.6);
    border-radius: var(--radius-pill);
    padding: 3px 10px 3px 8px;
    font-size: 11.5px;
    font-weight: 500;
    line-height: 1.3;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(23, 26, 28, 0.06);
    text-decoration: none;
}
.bubble__source-chip svg {
    flex: 0 0 auto;
    color: var(--color-dark);
    opacity: 0.65;
}

/* Chip clickable (tipo enlace) — más vibrante, con hover */
.bubble__source-chip--link {
    background: var(--color-yellow);
    border-color: var(--color-dark);
    color: var(--color-dark);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
}
.bubble__source-chip--link:hover {
    background: #fde889;
    box-shadow: 0 3px 8px rgba(238, 203, 59, 0.5);
    transform: translateY(-1px);
}
.bubble__source-chip--link:active {
    transform: translateY(0);
}
.bubble__source-chip--link svg {
    color: var(--color-dark);
    opacity: 1;
}

/* Indicador de "escribiendo..." */
.bubble--typing {
    display: inline-flex;
    gap: 4px;
    padding: 12px 16px;
}
.bubble--typing .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-gray-500);
    animation: typing 1.2s infinite;
}
.bubble--typing .dot:nth-child(2) { animation-delay: 0.15s; }
.bubble--typing .dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* Footer / form de envío */
.chat-footer {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(6px);
    border-top: 1px solid rgba(23, 26, 28, 0.06);
    padding: 10px 16px max(10px, env(safe-area-inset-bottom));
    position: sticky;
    bottom: 0;
    z-index: 10;
}
.chat-form {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--color-white);
    border: 1.5px solid rgba(23, 26, 28, 0.08);
    border-radius: var(--radius-pill);
    padding: 6px 6px 6px 16px;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-shadow: 0 2px 8px rgba(23, 26, 28, 0.04);
}
.chat-form:focus-within {
    border-color: var(--color-dark);
    box-shadow: 0 0 0 4px rgba(238, 203, 59, 0.25);
}
.chat-form__input {
    flex: 1 1 auto;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
    color: var(--color-dark);
    padding: 8px 0;
    max-height: 140px;
    min-height: 24px;
}
.chat-form__input::placeholder { color: var(--color-gray-400); }
.chat-form__send {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-yellow);
    color: var(--color-dark);
    border: none;
    display: grid;
    place-items: center;
    transition: transform 0.05s, opacity 0.15s, background 0.15s;
}
.chat-form__send:hover { box-shadow: 0 4px 12px rgba(238, 203, 59, 0.4); }
.chat-form__send:active { transform: scale(0.94); }
.chat-form__send:disabled { opacity: 0.45; cursor: not-allowed; }
.chat-form--sending .chat-form__input { opacity: 0.6; }

.chat-footer__meta {
    max-width: 720px;
    margin: 6px auto 0;
    text-align: center;
    font-size: 11px;
    color: var(--color-gray-400);
}
