:root {
    --primary-color: #2563eb;
    /* Royal Blue */
    --hover-color: #1d4ed8;
    --bg-color: #f3f4f6;
    --text-color: #1f2937;
    --secondary-text: #6b7280;
    --border-color: #e5e7eb;
    --chat-bg-user: #2563eb;
    /* Solid Blue */
    --chat-bg-bot: #ffffff;
    --status-online: #10b981;
    --avatar-user-bg: #f97316;
    /* Orange */
    --avatar-bot-bg: #ffffff;
    /* White */
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    color: var(--text-color);
    overflow: hidden;
}

/* Header */
.app-header {
    background-color: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.logo-icon img {
    width: 80%;
    height: 80%;
    object-fit: contain;
}

.header-text h1 {
    margin: 0;
    font-size: 1.4rem;
    line-height: 1.1;
    font-weight: 700;
}

.header-text .subtitle {
    font-size: 0.75rem;
    opacity: 0.85;
    font-weight: 400;
}

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

#session-id-display {
    font-size: 0.7rem;
    color: var(--primary-color);
    font-family: monospace;
    margin-right: 4px;
}

.header-right .icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    /* Rounded square */
    cursor: pointer;
    margin-left: 8px;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.header-right .icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Status Bar */
.status-bar {
    background-color: #fff;
    border-bottom: 1px solid var(--border-color);
    padding: 8px 1.5rem;
    font-size: 0.85rem;
    color: var(--secondary-text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ccc;
}

.status-indicator.online {
    background-color: var(--status-online);
}

.status-help {
    margin-left: auto;
    color: var(--secondary-text);
}

/* Main Content */
.main-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Welcome Screen */
.welcome-screen {
    max-width: 800px;
    width: 100%;
    text-align: center;
    margin-top: 4vh;
    animation: fadeIn 0.5s ease-out;
}

.welcome-content {
    background: #ffffff;
    border-radius: 24px;
    padding: 3rem 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    /* Added shadow for card look */
}

.brand-logo-large {
    width: 80px;
    height: 80px;
    background-color: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    overflow: hidden;
}

.brand-logo-large img {
    width: 70%;
    height: 70%;
    object-fit: contain;
}

.welcome-screen h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #111827;
}

.welcome-screen p {
    color: var(--secondary-text);
    max-width: 500px;
    margin: 0 auto 1.5rem;
    line-height: 1.6;
}

.disclaimer-container {
    text-align: left;
    background: #f9fafb;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin: 0 auto 2rem;
    max-width: 700px;
}

.disclaimer-container h3 {
    font-size: 1.1rem;
    margin-top: 0;
    margin-bottom: 1rem;
    color: #111827;
}

.disclaimer-text {
    font-size: 0.9rem;
    color: #4b5563;
    line-height: 1.5;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 1.5rem;
    padding-right: 10px;
}

.disclaimer-text p {
    margin: 0 0 1rem 0;
    max-width: none;
}

.disclaimer-text p:last-child {
    margin-bottom: 0;
}

.acceptance-container {
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 4px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-text {
    font-size: 0.95rem;
    font-weight: 500;
    color: #374151;
}

.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
    max-width: 700px;
    margin-left: auto;
    margin-right: auto;
}

.card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    text-align: center;
}

.card.invisible-placeholder {
    visibility: hidden;
    pointer-events: none;
    border: none;
    box-shadow: none;
    background: transparent;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border-color: var(--primary-color);
}

.card i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.card span {
    font-size: 0.9rem;
    font-weight: 500;
    color: #374151;
}

.prompt-text {
    font-size: 0.95rem;
    font-weight: 500;
    color: #4b5563;
}

/* Chat Screen */
.chat-screen {
    width: 100%;
    max-width: 900px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-bottom: 2rem;
}

/* Message Container (Flex for Avatar + Bubble) */
.message-container {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: 85%;
    animation: messageSlide 0.3s ease-out;
}

.message-container.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-container.bot {
    align-self: flex-start;
}

/* Avatars */
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.avatar.user {
    background-color: var(--avatar-user-bg);
}

.avatar.bot {
    background-color: var(--avatar-bot-bg);
    overflow: hidden;
}

.avatar.bot img {
    width: 70%;
    height: 70%;
    object-fit: contain;
}

/* Message Bubble */
.message-bubble {
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.message-container.user .message-bubble {
    background-color: var(--chat-bg-user);
    color: white;
    border-bottom-right-radius: 4px;
    /* Sharp corner */
}

.message-container.bot .message-bubble {
    background-color: var(--chat-bg-bot);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    /* Card style */
    border-bottom-left-radius: 4px;
    /* Sharp corner */
}

/* Content within bubble */
.message-content {
    word-break: break-word;
    /* Handle overflow */
    overflow-wrap: break-word;
}

.message-content p {
    margin: 0 0 0.5rem 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* Links in user bubble should be white */
.message-container.user .message-bubble a {
    color: white;
    text-decoration: underline;
}

/* Timestamp */
.message-time {
    font-size: 0.7rem;
    margin-top: 6px;
    display: block;
    text-align: right;
    opacity: 0.7;
}

.message-container.user .message-time {
    color: rgba(255, 255, 255, 0.8);
}

.message-container.bot .message-time {
    color: var(--secondary-text);
}


/* Footer / Input */
.app-footer {
    padding: 1rem 2rem;
    background: white;
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    /* Pill shape */
    background: white;
    padding: 4px;
    transition: all 0.2s;
    /* Removed blue border/shadow by default */
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#user-input {
    width: 100%;
    display: block;
    min-height: 40px;
    max-height: 150px;
    border: none;
    outline: none;
    padding: 8px 20px;
    padding-right: 100px;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    color: #1f2937;
    background: transparent;
    resize: none;
    overflow-x: hidden;
    overflow-y: auto;
}

.input-actions {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 8px;
}

.send-btn {
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    /* Circle */
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    transition: background 0.2s;
}

.send-btn:hover {
    background-color: var(--hover-color);
}

.chips-container {
    max-width: 900px;
    margin: 4px auto 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
}

.chip {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    color: #4b5563;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.chip:hover {
    background: #e5e7eb;
    color: #1f2937;
}

.chip:disabled {
    opacity: 0.5;
    cursor: default;
}

.footer-info {
    text-align: right;
    font-size: 0.7rem;
    color: #9ca3af;
    max-width: 900px;
    margin: 4px auto 0;
    padding-right: 12px;
}

/* Typing Indicator */
.typing-indicator-container {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 20px;
}

.typing-indicator {
    background-color: var(--chat-bg-bot);
    padding: 12px 20px;
    border-radius: 1rem;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
    display: inline-block;
}

.typing-dot {
    height: 8px;
    width: 8px;
    background-color: #6b7280;
    border-radius: 50%;
    display: inline-block;
    margin: 0 2px;
    animation: typing 1.4s infinite ease-in-out both;
}

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

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

@keyframes typing {

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

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

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

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

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* Responsive */
@media (max-width: 640px) {
    .suggestion-cards {
        grid-template-columns: 1fr;
    }

    .chat-screen {
        padding-bottom: 80px;
    }

    .app-header h1 {
        font-size: 1rem;
    }

    /* --- Mobile: full-width bubbles, avatars removed, minimal padding --- */

    /* Minimize the lateral gutters so bubbles can use (almost) all the popup
       width: ~12px breathing margin instead of the 2rem (32px) default. */
    .main-container {
        padding: 0.75rem;
    }

    .app-footer {
        padding: 0.75rem;
    }

    /* Tighter vertical rhythm between full-width bubbles. */
    .chat-messages {
        gap: 0.75rem;
    }

    /* Drop the avatars on mobile to give the text the full width. */
    .avatar {
        display: none;
    }

    /* Each message spans the whole content width (no narrow central column). */
    .message-container.user,
    .message-container.bot {
        align-self: stretch;
        max-width: 100%;
    }

    /* Bubbles fill the available width with minimal internal padding. */
    .message-bubble {
        flex: 1;
        padding: 0.5rem 0.75rem;
    }
}

/* Message Images */
.message-content img {
    max-width: 100%;
    height: auto;
    margin-top: 10px;
    margin-bottom: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: block;
}
/* ============================================================================
   Stack agentico — status line e card auto strutturate (dati verificati dal
   backend; la narrativa non contiene mai prezzi/km, vivono solo qui).
   ========================================================================== */

.agent-status-line {
    font-size: 0.82rem;
    color: var(--secondary-text, #6b7280);
    padding: 0.25rem 0.75rem;
    font-style: italic;
    animation: qpaFadeIn 0.3s ease;
}

.car-card-bubble {
    padding: 0 !important;
    overflow: hidden;
    background: transparent !important;
    box-shadow: none !important;
    width: 100%;
    max-width: 720px;
}

/* Le card consecutive dello stesso turno condividono una griglia: 1 colonna
   su mobile, 2 su desktop. */
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    width: 100%;
}

.car-card {
    width: 100%;
    max-width: 340px;
    border-radius: 12px;
    border: 1px solid var(--border-color, #e5e7eb);
    background: var(--chat-bg-bot, #fff);
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    animation: qpaFadeIn 0.3s ease;
    display: flex;
    flex-direction: column; /* mobile: immagine sopra, testo sotto */
}

.car-card-imgwrap {
    display: block;
    flex-shrink: 0;
}

.car-card-img {
    display: block;
    width: 100%;
    height: 170px;
    object-fit: cover;
    background: #f3f4f6;
}

/* Corpo testo: colonna flex per tenere la CTA in fondo alla scheda. */
.car-card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.car-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.7rem 0.9rem 0.35rem;
}

.car-card-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-color, #111);
    min-width: 0;
}

.car-card-price {
    font-weight: 800;
    font-size: 1rem;
    color: var(--primary-color, #2563eb);
    white-space: nowrap;
}

.car-card-specs {
    padding: 0.45rem 0.9rem 0.15rem;
    font-size: 0.85rem;
    color: var(--secondary-text, #4b5563);
}

.car-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.4rem 0.9rem 0.1rem;
}

.car-card-badge {
    font-size: 0.72rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--primary-color, #2563eb) 12%, white);
    color: var(--primary-color, #2563eb);
    font-weight: 600;
}

.car-card-location {
    padding: 0.25rem 0.9rem;
    font-size: 0.8rem;
    color: var(--secondary-text, #6b7280);
}

.car-card-cta {
    display: block;
    margin: 0.55rem 0.9rem 0.85rem;
    margin-top: auto;
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
    background: var(--primary-color, #2563eb);
    color: #fff !important;
    font-weight: 700;
    font-size: 0.88rem;
    text-align: center;
    text-decoration: none !important;
}

.car-card-cta:hover {
    filter: brightness(1.08);
}

/* Desktop: card affiancate in 2 colonne, layout orizzontale con immagine a
   sinistra e descrizione a destra (esigenza Marco 11/09/2026). */
@media (min-width: 640px) {
    .card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .car-card {
        max-width: none;
        flex-direction: row; /* immagine a sinistra, testo a destra */
        align-items: stretch;
        min-height: 172px;
    }

    .car-card-imgwrap {
        flex: 0 0 44%;
    }

    .car-card-img {
        height: 100%;
        min-height: 170px;
    }

    .car-card-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.1rem;
        padding: 0.7rem 0.85rem 0.2rem;
    }

    .car-card-price {
        font-size: 1.05rem;
    }
}

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

/* --- Sidebar cronologia (LINEE-GUIDA §5-bis) --------------------------------
   Drawer a scomparsa su qualunque larghezza (il widget vive in iframe spesso
   stretto): si apre con ☰, si chiude con ✕, tocco fuori o selezione chat. */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 85vw);
    background: var(--chat-bg-bot, #fff);
    border-right: 1px solid var(--border-color, #e5e7eb);
    box-shadow: 4px 0 16px rgba(0, 0, 0, 0.12);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    z-index: 60;
    display: flex;
    flex-direction: column;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 55;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.sidebar-title {
    font-weight: 700;
    color: var(--text-color, #1f2937);
    font-size: 0.95rem;
}

.sidebar-head .icon-btn {
    background: transparent;
    border: none;
    color: var(--secondary-text, #6b7280);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

.sidebar-head .icon-btn:hover {
    background: var(--bg-color, #f3f4f6);
}

.sidebar-new {
    margin: 0.75rem 0.75rem 0.25rem;
    padding: 0.6rem 0.8rem;
    border: 1px dashed var(--primary-color, #2563eb);
    border-radius: 10px;
    background: transparent;
    color: var(--primary-color, #2563eb);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
}

.sidebar-new:hover {
    background: var(--bg-color, #f3f4f6);
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0.75rem 1rem;
}

.sidebar-section {
    margin-bottom: 0.9rem;
}

.sidebar-section-title {
    margin: 0.4rem 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--secondary-text, #6b7280);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.sidebar-archive-header {
    cursor: pointer;
    user-select: none;
}

.sidebar-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    border-radius: 10px;
    padding: 0.1rem 0.25rem 0.1rem 0.55rem;
    cursor: pointer;
}

.sidebar-item:hover {
    background: var(--bg-color, #f3f4f6);
}

.sidebar-item.active {
    background: var(--bg-color, #f3f4f6);
    box-shadow: inset 3px 0 0 var(--primary-color, #2563eb);
}

.sidebar-item-title {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    color: var(--text-color, #1f2937);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0.45rem 0;
}

.sidebar-item-date {
    display: block;
    font-size: 0.68rem;
    color: var(--secondary-text, #6b7280);
}

.sidebar-item-actions {
    display: none;
    gap: 0.1rem;
}

.sidebar-item:hover .sidebar-item-actions,
.sidebar-item.active .sidebar-item-actions {
    display: flex;
}

.sidebar-item-actions button {
    border: none;
    background: transparent;
    color: var(--secondary-text, #6b7280);
    width: 26px;
    height: 26px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.72rem;
    padding: 0;
}

.sidebar-item-actions button:hover {
    background: var(--border-color, #e5e7eb);
    color: var(--primary-color, #2563eb);
}

.sidebar-item-actions button.danger:hover {
    color: #dc2626;
}

.sidebar-item-actions button.pinned {
    color: var(--primary-color, #2563eb);
}

.sidebar-empty {
    margin: 0.35rem;
    font-size: 0.8rem;
    color: var(--secondary-text, #6b7280);
}

/* --- CSAT (👍/👎 sotto l'ultima risposta) ----------------------------------- */

.csat-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin: 0.75rem auto;
    font-size: 0.8rem;
    color: var(--secondary-text, #6b7280);
}

.csat-btn {
    border: 1px solid var(--border-color, #e5e7eb);
    background: var(--chat-bg-bot, #fff);
    color: var(--secondary-text, #6b7280);
    width: 30px;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s ease;
}

.csat-btn:hover {
    color: var(--primary-color, #2563eb);
    border-color: var(--primary-color, #2563eb);
}

.csat-thanks {
    font-style: italic;
}
