/* RESET I BASE */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

body {
    background-color: #fcfcfc; /* Blanc trencat, molt net */
    background-image: radial-gradient(circle at 50% 10%, #fff0f0 0%, #fcfcfc 60%); /* Subtilíssim brillantor vermell a dalt */
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #1a1a1a;
}

/* CONTENIDOR PRINCIPAL */
#app {
    width: 100%;
    max-width: 900px;
    height: 100vh; /* Pantalla completa en mòbil */
    max-height: 95vh; /* Marge en desktop */
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px); /* Efecte vidre al contenidor principal */
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.05); /* Ombra molt suau */
    border-radius: 24px;
    overflow: hidden;
}


/* CAPÇALERA MINIMALISTA */
header {
    padding: 1.5rem;
    text-align: center;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
    background: rgba(255, 255, 255, 0.9);
    z-index: 10;
}

header h1 {
    font-weight: 200; /* Lletra fina i elegant */
    letter-spacing: -0.5px;
    color: #8a1c26; /* Lannister Crimson fosc */
    margin-bottom: 5px;
}

header p {
    font-size: 0.85rem;
    color: #888;
    font-weight: 400;
}

/* ÀREA DE XAT */
#chat-history {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

/* BASE MISSATGES */
.message {
    max-width: 75%;
    padding: 14px 20px;
    font-size: 0.95rem;
    line-height: 1.6;
    border-radius: 18px;
    position: relative;
    animation: fadeIn 0.3s ease-out;
}

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

/* TYRION - LIQUID GLASS RED */
.message.assistant {
    align-self: flex-start;

    /* L'efecte Liquid Glass demanat */
    background: rgba(180, 20, 40, 0.06); /* Vermell molt transparent */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(180, 20, 40, 0.15); /* Vora subtil */

    color: #6a0f1a; /* Text vermell fosc per llegibilitat */
    border-bottom-left-radius: 4px;
}

.message.assistant::before {
    content: "Tyrion";
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.6;
    display: block;
    margin-bottom: 4px;
    color: #8a1c26;
}

/* USUARI - FROSTED GLASS CLEAN */
.message.user {
    align-self: flex-end;

    /* Vidre neutre */
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);

    color: #333;
    border-bottom-right-radius: 4px;
}

/* INPUT AREA */
#input-area {
    padding: 20px;
    background: rgba(255, 255, 255, 0.9);
    border-top: 1px solid rgba(0, 0, 0, 0.03);
    display: flex;
    gap: 12px;
    align-items: center;
}

input[type="text"] {
    flex: 1;
    padding: 16px;
    border: none;
    background: #f4f4f4;
    border-radius: 16px;
    font-size: 1rem;
    color: #333;
    transition: all 0.2s ease;
}

input[type="text"]:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(138, 28, 38, 0.1); /* Aura vermella suau */
}

input[type="text"]::placeholder {
    color: #aaa;
}

button {
    background: #1a1a1a; /* Negre sòlid per contrastar amb tant blanc */
    color: white;
    border: none;
    padding: 16px 32px;
    border-radius: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
}

button:hover {
    background: #8a1c26; /* Al passar per sobre, es torna vermell Lannister */
    transform: scale(1.02);
}

button:active {
    transform: scale(0.98);
}


/* Animació de càrrega (The Three Dots) */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
}

.typing-indicator span {
    display: block;
    width: 6px;
    height: 6px;
    background-color: #8a1c26; /* Vermell Lannister */
    border-radius: 50%;
    animation: blink 1.4s infinite both;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {
    0% { opacity: 0.2; transform: scale(0.8); }
    20% { opacity: 1; transform: scale(1.1); }
    100% { opacity: 0.2; transform: scale(0.8); }
}

/* --------------------------------------------- */
/* FIX D'EMERGÈNCIA PER A MÒBIL (SUPER AGRESSIU) */
/* --------------------------------------------- */
@media (max-width: 768px) {

    /* 1. RESETEJAR EL BODY */
    body {
        background: #fff !important;
        height: 100dvh !important;
        overflow: hidden !important; /* Evita scroll a la pàgina general */
    }

    /* 2. FORÇAR ESTRUCTURA VERTICAL AL CONTENIDOR PRINCIPAL */
    #app {
        display: flex !important;
        flex-direction: column !important; /* VERTICAL SI O SI */
        width: 100% !important;
        height: 100dvh !important;
        max-width: none !important;
        max-height: none !important;
        border: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 3. ASSEGURAR QUE ELS FILLS DE #APP NO ES POSIN DE COSTAT */
    /* Això arregla el problema de la teva captura (quadrants) */
    #app > * {
        width: 100% !important; /* Ocupa tot l'ample */
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 4. ARREGLAR LA CAPÇALERA (TITOL) */
    header {
        flex: 0 0 auto !important; /* No creix ni s'encongeix, alçada fixa */
        height: 60px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-bottom: 1px solid #eee !important;
        background: #fff !important;
        padding: 0 !important;
    }

    header h1 {
        font-size: 1.2rem !important;
        margin: 0 !important;
    }

    /* Amaguem qualsevol text extra que estigui molestant */
    header p { display: none !important; }


    /* 5. EL XAT (Zona central) */
    #chat-history {
        display: flex !important;
        flex-direction: column !important;
        flex: 1 1 auto !important; /* Ocupa tot l'espai sobrant */
        width: 100% !important;
        height: auto !important;
        overflow-y: auto !important; /* Scroll només aquí */
        padding: 15px !important;
        background: #fcfcfc !important;
    }

    /* 6. INPUT (Zona inferior) */
    #input-area {
        flex: 0 0 auto !important; /* Alçada fixa segons contingut */
        width: 100% !important;
        position: relative !important;
        bottom: 0 !important;
        left: 0 !important;
        background: #fff !important;
        border-top: 1px solid #eee !important;
        padding: 10px 15px !important;
        padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
        display: flex !important;
        gap: 10px !important;
    }

    /* Estil inputs mòbil */
    input[type="text"] {
        font-size: 16px !important;
        padding: 12px 15px !important;
        width: auto !important;
        flex: 1 !important;
    }

    button {
        width: auto !important;
        padding: 0 20px !important;
    }
}
