/* ==========================================================================
   RG Chat Widget
   Prefix: rgchat-
   ========================================================================== */

.rgchat-widget {
    --rgchat-accent: var(--rgas-accent, #0048FE);
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #1a1a2e;
}

/* ---------- Bubble ---------- */
.rgchat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--rgchat-accent);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    z-index: 2;
}

.rgchat-bubble:focus {
    outline: none;
}

.rgchat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
    background: var(--rgas-accent-hover, #0036c8);
}

.rgchat-bubble svg {
    width: 28px;
    height: 28px;
    transition: opacity 0.2s, transform 0.2s;
}

.rgchat-bubble-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

.rgchat-widget--open .rgchat-bubble-icon {
    opacity: 0;
    transform: rotate(90deg);
}

.rgchat-widget--open .rgchat-bubble-close {
    opacity: 1;
    transform: rotate(0);
}

/* ---------- Panel ---------- */
.rgchat-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 380px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.rgchat-widget--open .rgchat-panel {
    display: flex;
    animation: rgchat-slideUp 0.3s ease;
}

@keyframes rgchat-slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Header ---------- */
.rgchat-header {
    background: var(--rgchat-accent);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.rgchat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rgchat-header-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #00c853;
    flex-shrink: 0;
}

.rgchat-header-title {
    font-weight: 600;
    font-size: 15px;
}

.rgchat-header-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.rgchat-header-close:hover {
    opacity: 1;
}

.rgchat-header-close svg {
    width: 20px;
    height: 20px;
}

/* ---------- Messages ---------- */
.rgchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.rgchat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.rgchat-msg--bot {
    background: #f0f2f5;
    color: #1a1a2e;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.rgchat-msg--user {
    background: var(--rgchat-accent);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Typing indicator */
.rgchat-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: #f0f2f5;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    align-items: center;
}

.rgchat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: rgchat-bounce 1.4s infinite ease-in-out both;
}

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

@keyframes rgchat-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Vehicle cards — rich design */
.rgchat-vehicles {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 8px 0;
    align-self: flex-start;
    max-width: 100%;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.rgchat-vehicles::-webkit-scrollbar {
    height: 4px;
}

.rgchat-vehicles::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.rgchat-vehicle-card {
    flex-shrink: 0;
    width: 180px;
    background: #fff;
    border: 1px solid #e8eaed;
    border-radius: 14px;
    overflow: hidden;
    font-size: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    cursor: pointer;
    transition: border-color 0.25s, transform 0.25s, box-shadow 0.25s;
    text-decoration: none;
    color: #1a1a2e;
    display: flex;
    flex-direction: column;
    scroll-snap-align: start;
    position: relative;
}

.rgchat-vehicle-card:hover {
    border-color: var(--rgchat-accent);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,72,254,0.13);
    color: #1a1a2e;
}

/* Image */
.rgchat-vehicle-img {
    width: 100%;
    height: 100px;
    overflow: hidden;
    background: #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rgchat-vehicle-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.rgchat-vehicle-card:hover .rgchat-vehicle-img img {
    transform: scale(1.05);
}

.rgchat-vehicle-img--placeholder {
    color: #bbb;
}

/* Badge */
.rgchat-vehicle-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 3px 8px;
    border-radius: 6px;
    line-height: 1;
    z-index: 1;
}

.rgchat-badge--nuovo {
    background: #00c853;
    color: #fff;
}

.rgchat-badge--usato {
    background: #ff6d00;
    color: #fff;
}

/* Card body */
.rgchat-vehicle-brand {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--rgchat-accent);
    padding: 10px 12px 0;
}

.rgchat-vehicle-name {
    font-weight: 700;
    font-size: 13px;
    padding: 2px 12px 0;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rgchat-vehicle-specs {
    font-size: 10px;
    color: #777;
    padding: 4px 12px 0;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rgchat-vehicle-price {
    font-weight: 800;
    color: #1a1a2e;
    font-size: 15px;
    padding: 6px 12px 0;
}

.rgchat-vehicle-cta {
    font-size: 11px;
    font-weight: 600;
    color: var(--rgchat-accent);
    padding: 8px 12px 10px;
    margin-top: auto;
    transition: padding-left 0.2s;
}

.rgchat-vehicle-card:hover .rgchat-vehicle-cta {
    padding-left: 16px;
}

/* ---------- Contact Form (always visible) ---------- */
.rgchat-contact-form {
    border-top: 1px solid #eee;
    background: #fafbfc;
    flex-shrink: 0;
}

.rgchat-contact-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--rgchat-accent);
    user-select: none;
}

.rgchat-contact-toggle:hover {
    background: #f0f2f5;
}

.rgchat-contact-chevron {
    margin-left: auto;
    transition: transform 0.2s;
}

.rgchat-contact-form--open .rgchat-contact-chevron {
    transform: rotate(180deg);
}

.rgchat-contact-fields {
    display: none;
    padding: 0 16px 12px;
    gap: 8px;
    flex-direction: column;
    position: relative;
}

.rgchat-contact-form--open .rgchat-contact-fields {
    display: flex;
}

.rgchat-contact-fields .rgchat-input {
    padding: 8px 12px;
    font-size: 13px;
}

.rgchat-privacy {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 11px;
    line-height: 1.4;
    color: #555;
    cursor: pointer;
}

.rgchat-privacy input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
}

.rgchat-privacy a {
    color: var(--rgchat-accent);
    text-decoration: underline;
}

.rgchat-lead-submit {
    padding: 8px 16px;
    background: var(--rgchat-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.rgchat-lead-submit:hover {
    background: var(--rgas-accent-hover, #0036c8);
}

.rgchat-lead-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.rgchat-lead-feedback {
    font-size: 12px;
    padding: 0;
    display: none;
}

.rgchat-lead-feedback--success {
    display: block;
    color: #2e7d32;
}

.rgchat-lead-feedback--error {
    display: block;
    color: #c62828;
}

/* ---------- Input Area ---------- */
.rgchat-input-area {
    display: flex;
    padding: 12px 16px;
    gap: 8px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    background: #fff;
}

.rgchat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.rgchat-input:focus {
    border-color: var(--rgchat-accent);
}

.rgchat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--rgchat-accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.rgchat-send:hover {
    background: var(--rgas-accent-hover, #0036c8);
}

.rgchat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.rgchat-send svg {
    width: 18px;
    height: 18px;
}

/* ---------- Bubble pulse attention ---------- */
@keyframes rgchat-pulse {
    0%   { box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 0 0 0 rgba(0,72,254,0.5); }
    70%  { box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 0 0 14px rgba(0,72,254,0); }
    100% { box-shadow: 0 4px 16px rgba(0,0,0,0.2), 0 0 0 0 rgba(0,72,254,0); }
}

.rgchat-bubble--attention {
    animation: rgchat-pulse 2s ease-in-out 3;
}

.rgchat-bubble--pulse {
    animation: rgchat-pulse 1.2s ease-in-out 2;
}

/* ==========================================================================
   Responsive — Mobile compact panel (no fullscreen)
   ========================================================================== */
@media (max-width: 480px) {
    .rgchat-widget {
        bottom: 16px;
        right: 12px;
    }

    .rgchat-panel {
        width: calc(100vw - 24px);
        max-height: 70vh;
        bottom: 68px;
        right: 0;
        border-radius: 14px;
    }
}
