/* Casaè - Assistente AI: stile interfaccia */
:root {
    --oro: #D4AF37;
    --oro-scuro: #B8941F;
    --antracite: #504f55;
    --antracite-scuro: #3e3d43;
    --bg: #F5F4F2;
    --testo: #3a3940;
    --testo-soft: #77767d;
    --bordo: #E6E4E0;
    --radius: 14px;
    --ombra: 0 2px 10px rgba(40, 39, 44, 0.08);
    --ombra-hover: 0 8px 24px rgba(40, 39, 44, 0.14);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--testo);
    display: flex;
    flex-direction: column;
    font-size: 15px;
    line-height: 1.5;
}

/* ---------- HEADER ---------- */
.header {
    background: linear-gradient(150deg, var(--antracite) 0%, var(--antracite-scuro) 100%);
    color: white;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
    flex-shrink: 0;
    border-bottom: 2px solid var(--oro);
}

.header img.logo {
    height: 34px;
    object-fit: contain;
}

.logo-text { flex: 1; }

.logo-subtitle {
    font-size: 11px;
    letter-spacing: 0.04em;
    opacity: 0.85;
}

.btn-reset-top {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: white;
    font-size: 12px;
    padding: 7px 12px;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background 0.2s;
}
.btn-reset-top:hover { background: rgba(255, 255, 255, 0.2); }

/* ---------- CONTENITORE CHAT ---------- */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    background: white;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--bg);
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* ---------- FILTRI ATTIVI (CHIP) ---------- */
.filtri-bar {
    display: none;
    gap: 8px;
    padding: 10px 16px;
    background: white;
    border-bottom: 1px solid var(--bordo);
    overflow-x: auto;
    flex-shrink: 0;
    align-items: center;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.filtri-bar::-webkit-scrollbar { display: none; }
.filtri-bar.attiva { display: flex; }

.filtri-bar .filtri-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--testo-soft);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #FBF6E8;
    border: 1px solid #E8D9A8;
    color: #7A6215;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 6px 5px 11px;
    border-radius: 20px;
    white-space: nowrap;
    flex-shrink: 0;
}

.chip .chip-x {
    background: #E8D9A8;
    color: #7A6215;
    border: none;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.chip .chip-x:hover { background: var(--oro); color: white; }

/* ---------- MESSAGGI ---------- */
.msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    animation: slideIn 0.25s ease;
    word-wrap: break-word;
    font-size: 14px;
}

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

.bot {
    background: white;
    color: var(--testo);
    align-self: flex-start;
    border: 1px solid var(--bordo);
    border-bottom-left-radius: 4px;
    box-shadow: var(--ombra);
}

.bot strong { color: var(--oro-scuro); }

.user {
    background: linear-gradient(135deg, var(--antracite) 0%, var(--antracite-scuro) 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Indicatore "sta scrivendo" (fuori dalla chatbox, sopra l'input) */
.typing {
    display: none;
    align-self: flex-start;
    background: white;
    border: 1px solid var(--bordo);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    padding: 14px 18px;
    margin: 0 16px 10px;
    flex-shrink: 0;
    box-shadow: var(--ombra);
}
.typing.active { display: flex; gap: 5px; }
.typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--oro);
    animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- GRIGLIA IMMOBILI ---------- */
.immobili-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    width: 100%;
}

.card-immo {
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--ombra);
    border: 1px solid var(--bordo);
    transition: box-shadow 0.25s ease, transform 0.25s ease;
    position: relative;
    display: flex;
    flex-direction: column;
}
@media (hover: hover) {
    .card-immo:hover { box-shadow: var(--ombra-hover); transform: translateY(-2px); }
}

.badge-op {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 11;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.bg-vendita { background: #C0392B; }
.bg-affitto { background: #1E8449; }
.bg-asta    { background: #CA8A04; }

/* Gallery foto */
.card-gallery {
    position: relative;
    height: 210px;
    background: var(--antracite);
    overflow: hidden;
    touch-action: pan-y;
}

.gallery-slides {
    display: flex;
    height: 100%;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.gallery-slide {
    min-width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 56px;
    cursor: zoom-in;
}
.gallery-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-nav {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 10;
}
.gallery-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.55);
    transition: all 0.3s;
    cursor: pointer;
}
.gallery-dot.active {
    background: var(--oro);
    width: 18px;
    border-radius: 3px;
}

.gallery-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.45);
    color: white;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    z-index: 10;
    transition: background 0.2s;
}
.gallery-arrow:hover { background: rgba(0, 0, 0, 0.7); }
.gallery-arrow.prev { left: 8px; }
.gallery-arrow.next { right: 8px; }

/* Corpo card */
.card-immo-body {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.card-immo-localita {
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 5px;
}
.card-immo-localita i { color: var(--oro); }

.card-immo-indirizzo {
    font-size: 12px;
    color: var(--testo-soft);
    margin: 2px 0 10px;
    padding-left: 20px;
}

.card-tech {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
.tech-badge {
    background: #F7F6F4;
    color: #5c5b62;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--bordo);
}
.tech-badge i { color: var(--oro); font-size: 13px; }

.card-immo-tipo {
    font-size: 11px;
    color: var(--testo-soft);
    background: #F0EFEC;
    padding: 3px 10px;
    border-radius: 12px;
    display: inline-block;
    align-self: flex-start;
    margin-bottom: 4px;
}

.card-immo-prezzo {
    font-size: 23px;
    font-weight: 800;
    color: var(--oro-scuro);
    margin: 6px 0 12px;
}
.card-immo-prezzo small {
    font-size: 12px;
    font-weight: 600;
    color: var(--testo-soft);
}

/* Dettagli espandibili */
.btn-dettagli {
    background: none;
    border: none;
    color: var(--antracite);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
    margin-bottom: 8px;
}
.btn-dettagli i { transition: transform 0.25s; color: var(--oro); }
.btn-dettagli.aperto i { transform: rotate(180deg); }

.card-dettagli {
    display: none;
    border-top: 1px dashed var(--bordo);
    padding-top: 10px;
    margin-bottom: 10px;
    font-size: 12.5px;
    color: var(--testo-soft);
}
.card-dettagli.aperto { display: block; }
.card-dettagli .dett-riga {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 3px 0;
}
.card-dettagli .dett-riga b { color: var(--testo); font-weight: 600; }
.card-dettagli .dett-descrizione {
    margin-top: 8px;
    line-height: 1.55;
}
.card-dettagli a { color: var(--oro-scuro); font-weight: 600; }

.btn-interesse {
    width: 100%;
    background: linear-gradient(135deg, var(--oro) 0%, var(--oro-scuro) 100%);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 9px;
    font-weight: 700;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: auto;
    transition: filter 0.2s;
}
.btn-interesse:hover { filter: brightness(1.06); }

/* ---------- LIGHTBOX ---------- */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 12, 0.95);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.lightbox.active { display: flex; opacity: 1; }
.lightbox img {
    max-width: 95%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 6px;
}
.lightbox-close {
    position: absolute;
    top: 18px;
    right: 22px;
    color: white;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
}

/* ---------- FORM CONTATTI ---------- */
.form-contatti {
    background: white;
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--ombra);
    border: 2px solid var(--oro);
    width: 100%;
    max-width: 480px;
    align-self: flex-start;
}
.form-contatti h3 {
    font-size: 15px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.form-contatti h3 i { color: var(--oro); }

.form-group { margin-bottom: 12px; }
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 13px;
}
.form-group input {
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid var(--bordo);
    border-radius: 9px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--oro); }
.form-group input.errore { border-color: #C0392B; }

.privacy-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 12px;
    color: var(--testo-soft);
    margin: 12px 0;
    line-height: 1.45;
}
.privacy-row input[type="checkbox"] {
    margin-top: 2px;
    width: 16px;
    height: 16px;
    accent-color: var(--oro);
    flex-shrink: 0;
    cursor: pointer;
}
.privacy-row a { color: var(--oro-scuro); font-weight: 600; }

.form-errore {
    display: none;
    background: #FDECEA;
    color: #A93226;
    font-size: 12.5px;
    padding: 9px 12px;
    border-radius: 8px;
    margin-bottom: 10px;
}
.form-errore.attivo { display: block; }

.btn-invia-contatti {
    width: 100%;
    background: linear-gradient(135deg, var(--oro) 0%, var(--oro-scuro) 100%);
    color: white;
    border: none;
    padding: 13px;
    border-radius: 9px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: filter 0.2s;
}
.btn-invia-contatti:hover { filter: brightness(1.06); }
.btn-invia-contatti:disabled { opacity: 0.6; cursor: wait; }

/* ---------- AREA INPUT ---------- */
.input-area {
    padding: 12px 15px;
    border-top: 1px solid var(--bordo);
    display: flex;
    gap: 10px;
    background: white;
    flex-shrink: 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

input#userInput {
    flex: 1;
    min-width: 0;
    padding: 12px 18px;
    border: 1.5px solid var(--bordo);
    border-radius: 24px;
    outline: none;
    font-size: 15px;
    transition: border-color 0.2s;
}
input#userInput:focus { border-color: var(--oro); }

button#sendBtn {
    background: linear-gradient(135deg, var(--oro) 0%, var(--oro-scuro) 100%);
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: filter 0.2s;
}
button#sendBtn:hover { filter: brightness(1.06); }

button#micBtn {
    background: white;
    color: var(--antracite);
    border: 1.5px solid var(--bordo);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}
button#micBtn.recording {
    background: #C0392B;
    border-color: #C0392B;
    color: white;
    animation: pulse-mic 1s infinite;
}
@keyframes pulse-mic {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.btn-altri {
    display: block;
    margin: 4px auto 12px;
    padding: 12px 28px;
    background: white;
    color: var(--antracite);
    border: 2px solid var(--oro);
    border-radius: 24px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-altri:hover { background: var(--oro); color: white; }

/* ---------- FOOTER ---------- */
.footer {
    background: var(--antracite-scuro);
    color: rgba(255, 255, 255, 0.85);
    text-align: center;
    padding: 9px 14px;
    font-size: 10.5px;
    flex-shrink: 0;
    border-top: 1px solid var(--oro);
    line-height: 1.5;
}
.footer a {
    color: var(--oro);
    text-decoration: none;
    font-weight: 700;
}

/* ---------- RESPONSIVE ---------- */
@media (min-width: 600px) {
    .immobili-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .chat-container {
        max-width: 1200px;
        margin: 18px auto;
        border-radius: 18px;
        box-shadow: 0 6px 28px rgba(40, 39, 44, 0.1);
        border: 1px solid var(--bordo);
    }
    .immobili-grid { grid-template-columns: repeat(3, 1fr); }
    .chat-messages { padding: 22px; }
}
