.jks-order-chat-wrap { margin-top: 15px; }
.jks-order-chat-live { border: 1px solid #e5e5e5; border-radius: 10px; background: #fff; padding: 14px; }
.jks-order-chat-statusbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.jks-order-chat-searchbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; padding: 10px; border: 1px solid #e5e5e5; border-radius: 8px; background: #fafafa; }
.jks-order-chat-search-input { flex: 1 1 280px; min-width: 220px; padding: 8px 10px; }
.jks-order-chat-search-count { font-size: 12px; color: #666; min-width: 70px; }
.jks-order-chat-pinned-area { margin-bottom: 14px; }
.jks-order-chat-pinned-box { border: 1px solid #ead9a5; background: #fff8df; border-radius: 10px; padding: 12px; }
.jks-order-chat-pinned-box--empty { display: none !important; }
.jks-order-chat-pinned-title { font-size: 13px; font-weight: 700; color: #8a6d1d; margin-bottom: 8px; }
.jks-order-chat-pinned-list { display: flex; flex-direction: column; gap: 8px; }
.jks-order-chat-pinned-link { display: block; text-decoration: none; color: inherit; background: rgba(255,255,255,0.65); border: 1px solid #ecdba6; border-radius: 8px; padding: 10px 12px; }
.jks-order-chat-pinned-link:hover { background: rgba(255,255,255,0.95); }
.jks-order-chat-pinned-meta { display: block; font-size: 12px; color: #7a6a3d; margin-bottom: 4px; }
.jks-order-chat-pinned-snippet { display: block; font-size: 13px; color: #4a4230; white-space: pre-wrap; word-break: break-word; }
.jks-order-chat-messages-area { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; max-height: 420px; overflow-y: auto; padding-right: 4px; scroll-behavior: auto; }

.jks-order-chat-msg {
    position: relative;
    padding: 10px 12px;
    border-radius: 12px;
    max-width: 85%;
    border: 1px solid #ddd;
    background: #fff;
    transition: box-shadow .2s ease, border-color .2s ease;
}

.jks-order-chat-msg--admin { align-self: flex-start; background: #f3f7ff; border-color: #cfdcff; }
.jks-order-chat-msg--customer { align-self: flex-end; background: #f6fff5; border-color: #cfe8ca; }
.jks-order-chat-msg--unread { box-shadow: 0 0 0 2px rgba(227, 52, 47, 0.12); border-color: #e3342f; }
.jks-order-chat-msg--search-match { box-shadow: 0 0 0 1px rgba(255, 193, 7, 0.35); }
.jks-order-chat-msg--search-current { box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.28); border-color: #0073aa; }
.jks-order-chat-msg--jump-highlight { box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.45); border-color: #d6a400; }
.jks-order-chat-msg--reaction-open { z-index: 5; }

.jks-order-chat-meta {
    font-size: 12px;
    color: #666;
    margin-bottom: 6px;
}

.jks-order-chat-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.35;
}

.jks-order-chat-actions {
    margin-top: 8px;
    display: flex;
    align-items: baseline;
    gap: 16px;
    flex-wrap: wrap;
    line-height: 1.2;
}

.jks-order-chat-reply-btn,
.jks-order-chat-pin-btn,
.jks-order-chat-edit-btn,
.jks-order-chat-reaction-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1.2;
    color: #0073aa;
    text-decoration: none;
    font-weight: 600;
    background: none;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
    vertical-align: middle;
}

.jks-order-chat-reply-btn:hover,
.jks-order-chat-pin-btn:hover,
.jks-order-chat-edit-btn:hover,
.jks-order-chat-reaction-toggle:hover {
    text-decoration: underline;
}

.jks-order-chat-reaction-toggle {
    gap: 0;
    color: #5f6b7a;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .02em;
    font-size: 11px;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid #d7dee7;
    background: rgba(255,255,255,.88);
    text-decoration: none !important;
}

.jks-order-chat-reaction-toggle:hover {
    background: #f3f6f9;
    border-color: #c5d0db;
    color: #3e4a58;
    text-decoration: none !important;
}

.jks-order-chat-reaction-summary {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.jks-order-chat-reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(0,0,0,0.08);
    font-size: 12px;
    line-height: 1;
    font-family: inherit;
}

.jks-order-chat-reaction-badge-emoji {
    font-family: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji","Twemoji Mozilla",sans-serif;
    font-size: 17px;
    line-height: 1;
}

.jks-order-chat-reaction-badge-count {
    font-weight: 700;
    color: #444;
}

.jks-order-chat-reactions-picker {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 10px;
    min-width: 248px;
    width: 248px;
    max-width: 248px;
    padding: 10px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #d8dee6;
    box-shadow: 0 14px 30px rgba(0,0,0,.16);
    z-index: 20;
}

.jks-order-chat-msg--customer .jks-order-chat-reactions-picker {
    left: auto;
    right: 10px;
}

.jks-order-chat-reactions-picker.is-open {
    display: block;
}

.jks-order-chat-reactions-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-auto-rows: 42px;
    gap: 8px;
    justify-items: stretch;
    align-items: stretch;
    box-sizing: border-box;
}

.jks-order-chat-reactions-picker,
.jks-order-chat-reactions-picker *,
.jks-order-chat-reactions-grid,
.jks-order-chat-reaction-option {
    box-sizing: border-box;
}

.jks-order-chat-reaction-option {
    appearance: none;
    -webkit-appearance: none;
    width: 100% !important;
    min-width: 0;
    min-height: 42px !important;
    height: 42px !important;
    max-height: 42px !important;
    margin: 0 !important;
    border-radius: 10px;
    border: 1px solid #dfe5ec;
    background: #fff;
    font-size: 22px !important;
    line-height: 1 !important;
    cursor: pointer;
    transition: transform .12s ease, background .12s ease, border-color .12s ease;
    font-family: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji","Twemoji Mozilla",sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    overflow: hidden;
    box-shadow: none !important;
}

.jks-order-chat-reaction-option:hover {
    background: #f7fafc;
    border-color: #c9d4df;
    transform: scale(1.05);
}

.jks-order-chat-reaction-option.is-active {
    background: #eef6ff;
    border-color: #8bb7e0;
}

.jks-order-chat-reaction-option.is-loading {
    opacity: .65;
    cursor: wait;
}

.jks-order-chat-reply-preview { margin-bottom: 10px; padding: 10px 12px; border-left: 3px solid #0073aa; background: #f6faff; border-radius: 8px; }
.jks-order-chat-reply-preview strong { display: block; font-size: 12px; color: #0073aa; margin-bottom: 4px; }
.jks-order-chat-reply-snippet, .jks-order-chat-reply-preview-text { font-size: 13px; color: #444; white-space: pre-wrap; word-break: break-word; }
.jks-order-chat-reply-cancel { margin-top: 8px; }
.jks-order-chat-reply-quote { margin-bottom: 10px; padding: 8px 10px; border-left: 3px solid #c7d7ea; background: rgba(255,255,255,0.55); border-radius: 8px; }
.jks-order-chat-reply-author { display: block; font-size: 12px; font-weight: 700; color: #5c6f82; margin-bottom: 4px; }
.jks-order-chat-attachments { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #ddd; }
.jks-order-chat-attachments ul { margin: 6px 0 0 18px; }
.jks-order-chat-form textarea { width: 100%; min-height: 100px; margin-bottom: 10px; }
.jks-order-chat-form input[type="file"] { display: block; margin-bottom: 12px; }
.jks-order-chat-empty { padding: 12px; background: #fafafa; border: 1px dashed #ddd; border-radius: 8px; color: #666; }
.jks-order-chat-note { font-size: 12px; color: #666; margin-top: 6px; }
.jks-order-chat-admin-button { margin-top: 10px; }
.jks-chat-badge { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.2; }
.jks-chat-badge--danger { background: #e3342f; color: #fff; }
.jks-chat-badge--ok { background: #eef7ee; color: #1f6f2d; border: 1px solid #cfe8ca; }
.jks-chat-badge--muted { background: #f4f4f4; color: #666; border: 1px solid #ddd; }
.jks-chat-badge--edited { background: #eef2ff; color: #4f46e5; border: 1px solid #c7d2fe; }
.jks-chat-orderlist-badge { display: inline-block; min-width: 24px; text-align: center; padding: 4px 7px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #e3342f; color: #fff; }
.jks-chat-orderlist-badge--empty { background: #f4f4f4; color: #777; border: 1px solid #ddd; font-weight: 600; }
.jks-header-chat-badge { position: absolute; top: -8px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #e3342f; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; z-index: 999; box-shadow: 0 0 0 2px #000; }
.jks-header-chat-badge-mobile { position: absolute; top: -6px; right: -8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #e3342f; color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; z-index: 999; box-shadow: 0 0 0 2px #000; }
.jks-customer-chat-link { display: inline-block; padding: 6px 10px; border-radius: 999px; text-decoration: none; font-size: 12px; font-weight: 600; line-height: 1.2; white-space: nowrap; }
.jks-customer-chat-link--new { background: #e3342f; color: #fff; }
.jks-customer-chat-link--normal { background: #f4f4f4; color: #333; border: 1px solid #ddd; }
.jks-chat-toast-container { position: fixed; top: 18px; right: 18px; z-index: 999999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.jks-chat-toast { width: min(340px, calc(100vw - 30px)); background: #111827; color: #fff; border-radius: 14px; box-shadow: 0 14px 36px rgba(0,0,0,.24); padding: 14px 16px; opacity: 0; transform: translateY(-8px); transition: opacity .2s ease, transform .2s ease; pointer-events: auto; cursor: pointer; }
.jks-chat-toast.is-visible { opacity: 1; transform: translateY(0); }
.jks-chat-toast-title { font-size: 14px; font-weight: 700; margin-bottom: 4px; }
.jks-chat-toast-body { font-size: 13px; opacity: .92; }
.jks-chat-toast-action { margin-top: 8px; font-size: 12px; font-weight: 700; color: #93c5fd; }
.jks-chat-debug-panel { position: fixed; bottom: 18px; right: 18px; z-index: 999998; width: min(340px, calc(100vw - 30px)); background: #fff; color: #1f2937; border: 1px solid #dbe2ea; border-radius: 14px; box-shadow: 0 14px 36px rgba(0,0,0,.16); padding: 14px; overflow: hidden; }
.jks-chat-debug-close { position: absolute; top: 8px; right: 10px; width: 28px; height: 28px; border: 0; background: transparent; color: #6b7280; font-size: 22px; line-height: 28px; text-align: center; cursor: pointer; padding: 0; }
.jks-chat-debug-close:hover { color: #111827; }
.jks-chat-debug-title { font-size: 14px; font-weight: 700; margin-bottom: 8px; padding-right: 28px; }
.jks-chat-debug-row { font-size: 13px; margin-bottom: 6px; }
.jks-chat-debug-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.jks-chat-debug-note { font-size: 11px; color: #6b7280; margin-top: 10px; line-height: 1.35; }
mark.jks-chat-search-highlight { background: #fff2a8; color: inherit; padding: 0 1px; border-radius: 2px; }

@media (max-width: 768px) {
    .jks-chat-debug-panel { right: 10px; bottom: 10px; width: calc(100vw - 20px); max-width: none; padding: 12px; }
    .jks-chat-debug-actions { flex-direction: column; }
    .jks-chat-debug-actions .button { width: 100%; justify-content: center; }
    .jks-chat-toast-container { top: 10px; right: 10px; left: 10px; }
    .jks-chat-toast { width: 100%; }

    .jks-order-chat-reactions-picker {
        min-width: 248px;
        width: 248px;
        max-width: min(248px, calc(100vw - 30px));
        padding: 10px;
    }

    .jks-order-chat-reactions-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 8px;
    }

    .jks-order-chat-reaction-option {
        min-height: 42px !important;
        height: 42px !important;
        max-height: 42px !important;
        font-size: 22px !important;
        padding: 0 !important;
    }
}

/* === Context menu (right-click / long press) === */

/* Nasconde la barra azioni sotto i messaggi: ora le azioni vivono nel menu contestuale */
.jks-order-chat-actions { display: none !important; }

.jks-order-chat-context-menu {
    position: fixed;
    z-index: 10000;
    min-width: 180px;
    padding: 6px;
    background: #fff;
    border: 1px solid #d8dee6;
    border-radius: 10px;
    box-shadow: 0 14px 30px rgba(0,0,0,.18);
    display: none;
    user-select: none;
    -webkit-user-select: none;
}
.jks-order-chat-context-menu.is-open { display: block; }
.jks-order-chat-context-menu__item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.3;
    color: #1f2a36;
    cursor: pointer;
    border-radius: 6px;
    font-family: inherit;
}
.jks-order-chat-context-menu__item:hover,
.jks-order-chat-context-menu__item:focus { background: #f3f6f9; outline: none; }

/* Evita selezione testo durante un long press attivo (touch) */
.jks-order-chat-msg.is-longpressing { user-select: none; -webkit-user-select: none; }

/* Blocca il callout iOS / menu nativo del browser su long press dei messaggi */
.jks-order-chat-msg { -webkit-touch-callout: none; }

/* === Icona graffetta allegato accanto al pulsante Invia === */
.jks-order-chat-attach {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 8px;
    cursor: pointer;
    vertical-align: middle;
}
.jks-order-chat-attach input[type="file"] {
    position: absolute !important;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
}
.jks-order-chat-attach__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid #d7dee7;
    background: #fff;
    color: #5f6b7a;
    transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.jks-order-chat-attach:hover .jks-order-chat-attach__icon,
.jks-order-chat-attach input[type="file"]:focus-visible + .jks-order-chat-attach__icon {
    background: #f3f6f9;
    border-color: #c5d0db;
    color: #3e4a58;
}
.jks-order-chat-attach__count {
    font-size: 12px;
    color: #5f6b7a;
}
.jks-order-chat-attach__count:empty { display: none; }

/* === Presence pill (header chat) === */
.jks-presence-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid #d7dee7;
    background: #fff;
}
.jks-presence-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: #b5bcc6;
    box-shadow: 0 0 0 2px rgba(255,255,255,.9);
}
.jks-presence-pill--online { color: #1f7a3a; border-color: #cfe9d7; background: #f1faf3; }
.jks-presence-pill--online .jks-presence-dot { background: #2bb04c; box-shadow: 0 0 0 2px rgba(43,176,76,.18); }
.jks-presence-pill--offline { color: #5f6b7a; }

/* === Toggle switch admin online/offline === */
.jks-admin-status-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 12px;
    color: #3e4a58;
    user-select: none;
}
.jks-admin-status-checkbox {
    position: absolute !important;
    width: 1px; height: 1px;
    opacity: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
}
.jks-admin-status-track {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
    border-radius: 999px;
    background: #c8cfd9;
    transition: background .18s ease;
    flex: 0 0 auto;
}
.jks-admin-status-thumb {
    position: absolute;
    top: 2px; left: 2px;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
    transition: transform .18s ease;
}
.jks-admin-status-checkbox:checked + .jks-admin-status-track { background: #2bb04c; }
.jks-admin-status-checkbox:checked + .jks-admin-status-track .jks-admin-status-thumb { transform: translateX(14px); }
.jks-admin-status-checkbox:focus-visible + .jks-admin-status-track {
    outline: 2px solid #4a90e2; outline-offset: 2px;
}
.jks-admin-status-checkbox:disabled + .jks-admin-status-track { opacity: .6; cursor: wait; }
.jks-admin-status-label { font-weight: 600; }

/* === Spunte messaggio (stile Telegram) === */
.jks-msg-status {
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
    vertical-align: middle;
    line-height: 1;
}
.jks-msg-status svg { display: block; }
.jks-msg-status--sent      { color: #9aa3b2; }
.jks-msg-status--delivered { color: #9aa3b2; }
.jks-msg-status--read      { color: #2b8aef; }

/* Footer del bubble con spunte allineate a destra (Telegram middle ground) */
.jks-order-chat-msg-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 4px;
    line-height: 1;
    padding-top: 2px;
}
.jks-order-chat-msg-footer .jks-msg-status { margin-left: 0; }

/* === Copia parziale mobile: modalità selezione testo === */
/* Quando il messaggio ha .is-selecting riabilitiamo selezione e callout iOS */
.jks-order-chat-msg.is-selecting {
    -webkit-touch-callout: default !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    background: #fffbeb !important; /* evidenziazione gialla discreta */
    transition: background .15s ease;
}
.jks-order-chat-msg.is-selecting .jks-order-chat-text {
    user-select: text !important;
    -webkit-user-select: text !important;
}

/* Hint flottante "Tocca a lungo per selezionare" */
.jks-order-chat-select-hint {
    position: fixed;
    z-index: 10001;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(31, 42, 54, .92);
    color: #fff;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: 999px;
    box-shadow: 0 8px 22px rgba(0,0,0,.25);
    pointer-events: none;
    animation: jksFadeOut 3s ease forwards;
}
@keyframes jksFadeOut {
    0%   { opacity: 0; transform: translate(-50%, 8px); }
    10%  { opacity: 1; transform: translate(-50%, 0); }
    80%  { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, -4px); }
}

/* Toast "Copiato" */
.jks-order-chat-copied-toast {
    position: fixed;
    z-index: 10001;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: #1f7a3a;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 999px;
    box-shadow: 0 8px 22px rgba(0,0,0,.25);
    pointer-events: none;
    animation: jksFadeOut 1.6s ease forwards;
}
