/* EasyPass Chat AI — Widget Frontend
   Tutti i selettori scoped con prefix ep-chat-* per evitare collisioni con il tema.
   Il colore primario è iniettato via CSS var --epc-primary (default #1a5276). */

.ep-chat-root { --epc-primary: #1a5276; --epc-primary-dark: #134060; --epc-bg: #fff; --epc-text: #2a3035; --epc-muted: #6b7c8e; --epc-border: #e4e8ec; --epc-user-bg: #eaf2fb; --epc-shadow: 0 14px 40px rgba(15,30,60,.18); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; font-size: 14px; line-height: 1.45; color: var(--epc-text); }

/* FAB fluttuante */
.ep-chat-fab { position: fixed; right: 22px; bottom: 22px; width: 60px; height: 60px; border-radius: 50%; background: var(--epc-primary); color: #fff; border: none; box-shadow: 0 6px 22px rgba(15,30,60,.32); cursor: pointer; z-index: 99998; display: flex; align-items: center; justify-content: center; transition: transform .15s, background .15s; font-size: 26px; line-height: 1; padding: 0; }
.ep-chat-fab:hover  { background: var(--epc-primary-dark); transform: scale(1.05); }
.ep-chat-fab:focus  { outline: 2px solid #fff; outline-offset: 2px; }
.ep-chat-fab[aria-expanded="true"] { background: #555; }

/* Drawer */
.ep-chat-drawer { position: fixed; right: 22px; bottom: 92px; width: 380px; max-width: calc(100vw - 24px); height: 600px; max-height: calc(100vh - 120px); background: var(--epc-bg); border-radius: 14px; box-shadow: var(--epc-shadow); z-index: 99999; display: none; flex-direction: column; overflow: hidden; transition: width .25s ease, height .25s ease, right .25s ease, bottom .25s ease; }
.ep-chat-drawer[data-open="1"] { display: flex; }

/* Modalità espansa (desktop): occupa quasi tutto lo schermo */
.ep-chat-drawer[data-expanded="1"] {
    width: 880px;
    max-width: calc(100vw - 40px);
    height: calc(100vh - 60px);
    max-height: calc(100vh - 40px);
    right: 20px;
    bottom: 20px;
}

@media (max-width: 540px) {
    .ep-chat-drawer { right: 0; bottom: 0; left: 0; width: 100%; max-width: 100%; height: 100vh; max-height: 100vh; border-radius: 0; }
    .ep-chat-drawer[data-expanded="1"] { width: 100%; height: 100vh; right: 0; bottom: 0; }
    .ep-chat-fab    { right: 16px; bottom: 16px; }
}

/* Messaggi più larghi e leggibili in modalità espansa */
.ep-chat-drawer[data-expanded="1"] .ep-chat-msg { max-width: 75%; font-size: 15px; }
.ep-chat-drawer[data-expanded="1"] .ep-chat-body { padding: 24px 32px; gap: 14px; }
.ep-chat-drawer[data-expanded="1"] .ep-chat-input { padding: 14px 20px; }
.ep-chat-drawer[data-expanded="1"] .ep-chat-input__textarea { font-size: 15px; padding: 10px 16px; }

/* Header */
.ep-chat-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--epc-primary); color: #fff; }
.ep-chat-head__title { font-weight: 700; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ep-chat-head__btn { background: transparent; border: none; color: #fff; cursor: pointer; padding: 6px 8px; border-radius: 6px; font-size: 18px; line-height: 1; opacity: .85; }
.ep-chat-head__btn:hover { background: rgba(255,255,255,.15); opacity: 1; }

/* Body conversazione */
.ep-chat-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; background: #f7f9fb; -webkit-overflow-scrolling: touch; }
.ep-chat-empty { text-align: center; color: var(--epc-muted); padding: 32px 16px; font-size: 14px; }
.ep-chat-empty strong { color: var(--epc-text); display: block; margin-bottom: 6px; }
.ep-chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 18px; }
.ep-chat-suggestion { background: #fff; border: 1px solid var(--epc-border); border-radius: 16px; padding: 6px 12px; font-size: 12px; cursor: pointer; color: var(--epc-primary); transition: background .12s, border-color .12s; }
.ep-chat-suggestion:hover { background: var(--epc-user-bg); border-color: var(--epc-primary); }

/* Messaggi */
.ep-chat-msg { max-width: 85%; padding: 9px 13px; border-radius: 14px; word-wrap: break-word; overflow-wrap: anywhere; font-size: 14px; }
.ep-chat-msg--user { align-self: flex-end; background: var(--epc-primary); color: #fff; border-bottom-right-radius: 4px; }
.ep-chat-msg--assistant { align-self: flex-start; background: #fff; color: var(--epc-text); border: 1px solid var(--epc-border); border-bottom-left-radius: 4px; }
.ep-chat-msg--error { align-self: flex-start; background: #fef0f0; color: #a82323; border: 1px solid #f3c0c0; border-bottom-left-radius: 4px; }
.ep-chat-msg p { margin: 0 0 6px; }
.ep-chat-msg p:last-child { margin-bottom: 0; }
.ep-chat-msg ul, .ep-chat-msg ol { margin: 4px 0 6px 22px; padding: 0; }
.ep-chat-msg li { margin: 2px 0; }
.ep-chat-msg a { color: var(--epc-primary); text-decoration: underline; }
.ep-chat-msg--user a { color: #fff; }
.ep-chat-msg code { background: rgba(0,0,0,.06); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* Typing indicator */
.ep-chat-typing { align-self: flex-start; padding: 11px 14px; background: #fff; border: 1px solid var(--epc-border); border-radius: 14px; border-bottom-left-radius: 4px; }
.ep-chat-typing span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--epc-muted); margin: 0 2px; animation: ep-chat-blink 1.2s infinite; }
.ep-chat-typing span:nth-child(2) { animation-delay: .2s; }
.ep-chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes ep-chat-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

/* Card conferma */
.ep-chat-confirm { padding: 14px 16px; background: #fffaeb; border-top: 1px solid #f4d990; }
.ep-chat-confirm__title { font-weight: 700; font-size: 13px; color: #8a5a00; margin: 0 0 6px; display: flex; align-items: center; gap: 6px; }
.ep-chat-confirm__body { font-size: 13px; color: var(--epc-text); margin-bottom: 10px; }
.ep-chat-confirm__body strong { color: var(--epc-primary); }
.ep-chat-confirm__actions { display: flex; gap: 8px; }
.ep-chat-confirm__btn { flex: 1; padding: 8px 12px; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13px; }
.ep-chat-confirm__btn--cancel { background: #fff; border: 1px solid var(--epc-border); color: var(--epc-text); }
.ep-chat-confirm__btn--ok { background: var(--epc-primary); color: #fff; }
.ep-chat-confirm__btn--ok:hover  { background: var(--epc-primary-dark); }
.ep-chat-confirm__btn:disabled { opacity: .5; cursor: wait; }

/* Card pagamento (post create_order) */
.ep-chat-payment { padding: 14px 16px; background: #e8f5e9; border-top: 1px solid #a5d6a7; }
.ep-chat-payment__title { font-weight: 700; font-size: 13px; color: #1b5e20; margin: 0 0 6px; }
.ep-chat-payment__btn { display: block; width: 100%; padding: 12px 16px; background: #2e7d32; color: #fff; text-align: center; border-radius: 8px; text-decoration: none; font-weight: 700; font-size: 14px; }
.ep-chat-payment__btn:hover { background: #1b5e20; color: #fff; text-decoration: none; }

/* Input area */
.ep-chat-input { display: flex; align-items: flex-end; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--epc-border); background: #fff; }
.ep-chat-input__textarea { flex: 1; resize: none; border: 1px solid var(--epc-border); border-radius: 18px; padding: 8px 14px; font-family: inherit; font-size: 14px; line-height: 1.4; min-height: 36px; max-height: 100px; background: #fff; color: var(--epc-text); outline: none; transition: border-color .12s; }
.ep-chat-input__textarea:focus { border-color: var(--epc-primary); }
.ep-chat-input__textarea:disabled { background: #f5f5f5; opacity: .6; }
.ep-chat-input__send { width: 36px; height: 36px; border-radius: 50%; background: var(--epc-primary); color: #fff; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 18px; line-height: 1; padding: 0; flex-shrink: 0; }
.ep-chat-input__send:hover    { background: var(--epc-primary-dark); }
.ep-chat-input__send:disabled { opacity: .4; cursor: not-allowed; }

/* Blocchi UI inline (sotto messaggio assistant) */
.ep-chat-blocks { align-self: stretch; display: flex; flex-direction: column; gap: 8px; margin: -2px 0 4px; max-width: 100%; }

/* Quick reply buttons */
.ep-chat-qr { display: flex; flex-wrap: wrap; gap: 6px; }
.ep-chat-qr__btn { background: #fff; border: 1.5px solid var(--epc-primary); color: var(--epc-primary); padding: 7px 14px; border-radius: 18px; font-size: 13px; font-weight: 600; cursor: pointer; transition: background .12s, color .12s; }
.ep-chat-qr__btn:hover { background: var(--epc-primary); color: #fff; }
.ep-chat-qr__btn:active { transform: scale(.97); }

/* Card pass selezionabile */
.ep-chat-card { display: block; width: 100%; background: #fff; border: 1.5px solid var(--epc-border); border-radius: 12px; padding: 12px 14px; text-align: left; cursor: pointer; transition: border-color .15s, transform .12s, box-shadow .15s; position: relative; font-family: inherit; }
.ep-chat-card:hover  { border-color: var(--epc-primary); box-shadow: 0 4px 14px rgba(15,30,60,.08); transform: translateY(-1px); }
.ep-chat-card:active { transform: translateY(0); }
.ep-chat-card__name  { font-weight: 700; font-size: 14px; color: var(--epc-text); margin-bottom: 4px; }
.ep-chat-card__info  { font-size: 12px; color: var(--epc-muted); margin-bottom: 8px; line-height: 1.4; }
.ep-chat-card__price { display: inline-block; background: var(--epc-user-bg); color: var(--epc-primary); font-weight: 700; padding: 3px 10px; border-radius: 12px; font-size: 13px; margin-right: 4px; }
.ep-chat-card__price--res { background: #e8f5e9; color: #1b5e20; }
.ep-chat-card__cta   { display: inline-block; color: var(--epc-primary); font-size: 12px; font-weight: 600; float: right; margin-top: 4px; }

/* Date picker inline */
.ep-chat-datepick { background: #fff; border: 1.5px solid var(--epc-border); border-radius: 12px; padding: 12px 14px; }
.ep-chat-datepick__label { font-size: 13px; font-weight: 600; color: var(--epc-text); margin-bottom: 8px; }
.ep-chat-datepick__row   { display: flex; gap: 6px; }
.ep-chat-datepick__input { flex: 1; padding: 8px 10px; border: 1px solid var(--epc-border); border-radius: 8px; font-family: inherit; font-size: 14px; color: var(--epc-text); }
.ep-chat-datepick__input:focus { outline: none; border-color: var(--epc-primary); }
.ep-chat-datepick__btn   { background: var(--epc-primary); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13px; }
.ep-chat-datepick__btn:hover { background: var(--epc-primary-dark); }

/* Riepilogo (box stilato con righe key:value + Totale evidenziato) */
.ep-chat-summary { background: #fff; border: 1.5px solid var(--epc-border); border-radius: 12px; padding: 14px 16px; box-shadow: 0 2px 8px rgba(15,30,60,.04); align-self: stretch; }
.ep-chat-summary__title { font-weight: 700; font-size: 13px; color: var(--epc-primary); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--epc-border); display: flex; align-items: center; gap: 6px; }
.ep-chat-summary__title::before { content: '📋'; }
.ep-chat-summary__row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 5px 0; font-size: 13px; min-height: 22px; }
.ep-chat-summary__k   { color: var(--epc-muted); font-weight: 500; flex-shrink: 0; }
.ep-chat-summary__v   { color: var(--epc-text); font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.ep-chat-summary__row--total { border-top: 1.5px solid var(--epc-border); padding-top: 9px; margin-top: 6px; }
.ep-chat-summary__row--total .ep-chat-summary__k,
.ep-chat-summary__row--total .ep-chat-summary__v { color: var(--epc-primary); font-weight: 800; font-size: 17px; }

/* Markdown table fallback (se l'AI emette tabelle nonostante il divieto) */
.ep-chat-table { border-collapse: collapse; width: 100%; margin: 8px 0 4px; font-size: 12.5px; background: #fff; border: 1px solid var(--epc-border); border-radius: 10px; overflow: hidden; }
.ep-chat-table th, .ep-chat-table td { padding: 8px 11px; text-align: left; border-bottom: 1px solid var(--epc-border); }
.ep-chat-table th { background: #f7f9fb; font-weight: 700; color: var(--epc-text); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.ep-chat-table tr:last-child td { border-bottom: none; }
.ep-chat-table tr:nth-child(even) td { background: #fafbfc; }

/* Form inline (input strutturati) */
.ep-chat-form { background: #fff; border: 1.5px solid var(--epc-border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.ep-chat-form__row   { display: flex; flex-direction: column; gap: 3px; }
.ep-chat-form__label { font-size: 11px; font-weight: 700; color: var(--epc-muted); text-transform: uppercase; letter-spacing: .03em; }
.ep-chat-form__input { padding: 8px 10px; border: 1px solid var(--epc-border); border-radius: 8px; font-family: inherit; font-size: 14px; color: var(--epc-text); transition: border-color .12s; }
.ep-chat-form__input:focus { outline: none; border-color: var(--epc-primary); }
.ep-chat-form__submit { background: var(--epc-primary); color: #fff; border: none; padding: 9px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13px; margin-top: 4px; }
.ep-chat-form__submit:hover { background: var(--epc-primary-dark); }

/* Progress steps */
.ep-chat-steps { display: flex; align-items: center; padding: 8px 14px; background: #fafbfc; border-bottom: 1px solid var(--epc-border); gap: 4px; font-size: 11px; }
.ep-chat-step  { display: flex; align-items: center; gap: 5px; color: var(--epc-muted); }
.ep-chat-step__dot { width: 18px; height: 18px; border-radius: 50%; background: #d6dce3; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 10px; }
.ep-chat-step--active { color: var(--epc-primary); font-weight: 700; }
.ep-chat-step--active .ep-chat-step__dot { background: var(--epc-primary); }
.ep-chat-step--done   { color: #27ae60; }
.ep-chat-step--done   .ep-chat-step__dot { background: #27ae60; }
.ep-chat-step__sep { flex: 1; height: 1px; background: var(--epc-border); margin: 0 2px; }

/* Footer info */
.ep-chat-footer { padding: 6px 12px; font-size: 11px; color: var(--epc-muted); text-align: center; border-top: 1px solid var(--epc-border); background: #fafbfc; }
