/* ============================================================
   Arte e Tradizione — AI Chatbot Widget
   ============================================================ */

/* --- Variabili colore (sovrascrivibili via JS) --- */
:root {
    --atcb-primary:     #8B4513;
    --atcb-primary-dk:  #6a340f;
    --atcb-primary-lt:  #c4722a;
    --atcb-bg:          #ffffff;
    --atcb-radius:      16px;
    --atcb-shadow:      0 8px 32px rgba(0,0,0,0.18);
    --atcb-font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --atcb-z:           99999;
}

/* ---- Contenitore principale ---- */
#atcb-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--atcb-z);
    font-family: var(--atcb-font);
    font-size: 15px;
    line-height: 1.5;
}

/* ---- Pulsante toggle ---- */
#atcb-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--atcb-primary);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    outline: none;
    color: #fff;
    position: relative;
    z-index: 1;
}

#atcb-toggle:hover {
    background: var(--atcb-primary-dk);
    transform: scale(1.07);
    box-shadow: 0 6px 20px rgba(0,0,0,0.30);
}

#atcb-toggle:active {
    transform: scale(0.97);
}

/* Pulse animation (quando chiuso) */
#atcb-toggle::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--atcb-primary);
    animation: atcb-pulse 2.5s ease-out infinite;
    pointer-events: none;
}

@keyframes atcb-pulse {
    0%   { transform: scale(1);   opacity: 0.7; }
    70%  { transform: scale(1.5); opacity: 0;   }
    100% { transform: scale(1.5); opacity: 0;   }
}

/* Stop pulse when open */
#atcb-widget.atcb-open #atcb-toggle::after {
    animation: none;
}

/* ---- Finestra chat ---- */
#atcb-window {
    position: absolute;
    bottom: 74px;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--atcb-bg);
    border-radius: var(--atcb-radius);
    box-shadow: var(--atcb-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: atcb-slide-in 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: bottom right;
}

@keyframes atcb-slide-in {
    from { opacity: 0; transform: scale(0.85) translateY(20px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

/* ---- Header ---- */
#atcb-header {
    background: var(--atcb-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    border-radius: var(--atcb-radius) var(--atcb-radius) 0 0;
}

#atcb-header-emoji {
    font-size: 24px;
    flex-shrink: 0;
}

#atcb-header-info {
    flex: 1;
    min-width: 0;
}

#atcb-header-info strong {
    display: block;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#atcb-status {
    font-size: 12px;
    opacity: 0.85;
}

#atcb-close-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.15s;
    flex-shrink: 0;
    line-height: 1;
}

#atcb-close-btn:hover { opacity: 1; }

/* ---- Area messaggi ---- */
#atcb-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #f7f3ef;
    scroll-behavior: smooth;
}

#atcb-messages::-webkit-scrollbar { width: 4px; }
#atcb-messages::-webkit-scrollbar-track { background: transparent; }
#atcb-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

/* ---- Bubble messaggi ---- */
.atcb-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
    animation: atcb-fade-in 0.2s ease;
}

@keyframes atcb-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0);   }
}

.atcb-msg.atcb-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.atcb-msg.atcb-bot {
    align-self: flex-start;
}

.atcb-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.atcb-msg.atcb-user .atcb-bubble {
    background: var(--atcb-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.atcb-msg.atcb-bot .atcb-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* Link nelle bubble */
.atcb-bubble a {
    color: inherit;
    text-decoration: underline;
}

/* ---- Slot disponibili (grid di pulsanti) ---- */
.atcb-slots-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.atcb-slot-btn {
    background: #fff;
    border: 2px solid var(--atcb-primary);
    color: var(--atcb-primary);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}

.atcb-slot-btn:hover {
    background: var(--atcb-primary);
    color: #fff;
    transform: scale(1.04);
}

/* ---- Typing indicator ---- */
.atcb-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    align-self: flex-start;
    animation: atcb-fade-in 0.2s ease;
}

.atcb-typing-dots {
    background: #fff;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    display: flex;
    gap: 5px;
    align-items: center;
}

.atcb-dot {
    width: 7px;
    height: 7px;
    background: #bbb;
    border-radius: 50%;
    animation: atcb-bounce 1.2s infinite;
}

.atcb-dot:nth-child(2) { animation-delay: 0.2s; }
.atcb-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes atcb-bounce {
    0%, 60%, 100% { transform: translateY(0);   background: #ccc; }
    30%            { transform: translateY(-6px); background: var(--atcb-primary-lt); }
}

/* ---- Messaggio di successo (prenotazione) ---- */
.atcb-success-card {
    background: linear-gradient(135deg, #e8f5e9, #f1f8e9);
    border: 1px solid #a5d6a7;
    border-radius: 12px;
    padding: 12px 14px;
    margin-top: 4px;
    font-size: 13px;
    color: #2e7d32;
}

.atcb-success-card strong {
    display: block;
    font-size: 15px;
    margin-bottom: 4px;
}

/* ---- Area di input ---- */
#atcb-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid #e8e0d8;
    background: #fff;
    flex-shrink: 0;
}

#atcb-input {
    flex: 1;
    resize: none;
    border: 1.5px solid #ddd;
    border-radius: 22px;
    padding: 9px 16px;
    font-size: 14px;
    font-family: var(--atcb-font);
    outline: none;
    max-height: 110px;
    overflow-y: auto;
    transition: border-color 0.15s;
    line-height: 1.4;
    background: #faf8f5;
}

#atcb-input:focus {
    border-color: var(--atcb-primary);
    background: #fff;
}

#atcb-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--atcb-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
    outline: none;
}

#atcb-send:hover  { background: var(--atcb-primary-dk); }
#atcb-send:active { transform: scale(0.93); }

#atcb-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ---- Footer note ---- */
#atcb-footer-note {
    text-align: center;
    font-size: 11px;
    color: #aaa;
    padding: 4px 0 8px;
    background: #fff;
    flex-shrink: 0;
}

/* ---- Calendario inline ---- */
.atcb-cal-msg {
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
    animation: atcb-fade-in 0.2s ease;
}

.atcb-cal-bubble {
    background: #fff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow: hidden;
    width: 100%;
}

.atcb-cal-title {
    font-size: 13px;
    color: #555;
    padding: 10px 12px 6px;
    font-weight: 500;
}

.atcb-cal {
    user-select: none;
    padding: 0 8px 10px;
}

.atcb-cal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 8px;
}

.atcb-cal-nav {
    background: none;
    border: none;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 16px;
    color: var(--atcb-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
    line-height: 1;
}

.atcb-cal-nav:hover {
    background: #f0e8e0;
}

.atcb-cal-nav:disabled {
    color: #ccc;
    cursor: default;
    pointer-events: none;
}

.atcb-cal-month {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    text-align: center;
    flex: 1;
}

.atcb-cal-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 4px;
}

.atcb-cal-weekdays span {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: #999;
    padding: 2px 0;
    text-transform: uppercase;
}

.atcb-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.atcb-cal-day {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 13px;
    cursor: pointer;
    color: #333;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border: none;
    background: none;
    padding: 0;
    min-width: 0;
}

.atcb-cal-day:hover:not(.atcb-cal-disabled):not(.atcb-cal-empty) {
    background: var(--atcb-primary);
    color: #fff;
}

.atcb-cal-day.atcb-cal-today {
    border: 2px solid var(--atcb-primary-lt);
    color: var(--atcb-primary);
    font-weight: 700;
}

.atcb-cal-day.atcb-cal-disabled {
    color: #ccc;
    cursor: not-allowed;
    pointer-events: none;
}

.atcb-cal-day.atcb-cal-empty {
    pointer-events: none;
}

/* ---- Card di conferma prenotazione ---- */
.atcb-confirm-card {
    background: #fff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 14px;
    width: 100%;
    animation: atcb-fade-in 0.2s ease;
}

.atcb-confirm-title {
    font-size: 14px;
    font-weight: 700;
    color: #333;
    margin-bottom: 10px;
}

.atcb-confirm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 12px;
}

.atcb-confirm-table tr:not(:last-child) td {
    border-bottom: 1px solid #f0ebe4;
}

.atcb-confirm-table td {
    padding: 5px 2px;
    vertical-align: top;
}

.atcb-confirm-table td:first-child {
    color: #888;
    width: 40%;
    padding-right: 8px;
    white-space: nowrap;
}

.atcb-confirm-table td:last-child {
    color: #222;
    font-weight: 500;
}

.atcb-confirm-btns {
    display: flex;
    gap: 8px;
}

.atcb-confirm-ok {
    flex: 1;
    background: var(--atcb-primary);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.atcb-confirm-ok:hover  { background: var(--atcb-primary-dk); }
.atcb-confirm-ok:active { transform: scale(0.97); }

.atcb-confirm-ok:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.atcb-confirm-cancel {
    background: none;
    color: #888;
    border: 1.5px solid #ddd;
    border-radius: 20px;
    padding: 9px 14px;
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}

.atcb-confirm-cancel:hover {
    border-color: #aaa;
    color: #555;
}

/* ---- Responsive mobile ---- */
@media (max-width: 520px) {

    /* Toggle rimane in basso a destra, ma più accessibile */
    #atcb-widget {
        bottom: 16px;
        right: 16px;
    }

    #atcb-toggle {
        width: 56px;
        height: 56px;
        font-size: 26px;
    }

    /* Quando la chat è aperta su mobile: finestra a schermo intero */
    #atcb-widget.atcb-open #atcb-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        animation: atcb-slide-mobile 0.28s ease;
    }

    @keyframes atcb-slide-mobile {
        from { opacity: 0.4; transform: translateY(32px); }
        to   { opacity: 1;   transform: translateY(0); }
    }

    /* Header: spazio per la barra di stato iOS */
    #atcb-header {
        padding-top: max(16px, env(safe-area-inset-top));
        padding-bottom: 14px;
    }

    /* Input area: spazio per la home bar iOS */
    #atcb-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    /* font-size: 16px previene lo zoom automatico di iOS al focus */
    #atcb-input {
        font-size: 16px;
    }

    /* Bottone chiudi più grande (target 44×44px) */
    #atcb-close-btn {
        font-size: 20px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Bottone invio più grande */
    #atcb-send {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }

    /* Messaggi: font leggermente più grande su mobile */
    .atcb-bubble {
        font-size: 15px;
    }

    /* Slot orari: più spaziosi per il tocco */
    .atcb-slot-btn {
        font-size: 15px;
        padding: 9px 18px;
        min-height: 42px;
    }

    /* Calendario: celle più alte per il tocco */
    .atcb-cal {
        padding: 0 12px 14px;
    }

    .atcb-cal-day {
        font-size: 14px;
        min-height: 36px;
    }

    .atcb-cal-nav {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    .atcb-cal-weekdays span {
        font-size: 12px;
    }

    /* Pulsanti conferma prenotazione più grandi */
    .atcb-confirm-ok,
    .atcb-confirm-cancel {
        padding: 12px 16px;
        font-size: 15px;
        min-height: 46px;
    }

    /* Messaggi: un po' meno padding per guadagnare spazio */
    #atcb-messages {
        padding: 12px;
    }
}
