/* Chat: a single panel switches between the conversation list and the selected conversation. */

.store-chat, .store-chat * { box-sizing: border-box; }
.store-chat [hidden] { display: none !important; }
.store-chat {
    --chat-bg: #ffffff;
    --chat-text: #1b2427;
    --chat-muted: #6b787c;
    --chat-line: rgba(25, 35, 39, .12);
    --chat-soft: #f3f5f4;
    --chat-accent: #1f655b;
    --chat-accent-text: #ffffff;
    --chat-mine: #1f655b;
    --chat-mine-text: #ffffff;
    --chat-theirs: #f0f2f1;
    --chat-badge: #d93025;
    font-family: Inter, "Helvetica Neue", Helvetica, Arial, sans-serif;
    color: var(--chat-text);
}
html[data-storefront-theme="dark"] .store-chat {
    --chat-bg: #172023;
    --chat-text: #edf3f1;
    --chat-muted: #9fb0ad;
    --chat-line: rgba(237, 243, 241, .14);
    --chat-soft: #1e2a2d;
    --chat-accent: #5fc2b0;
    --chat-accent-text: #0f1a1c;
    --chat-mine: #2f8b7b;
    --chat-mine-text: #ffffff;
    --chat-theirs: #243236;
}

/* The button: same 42px circle and right edge as the language, theme and WhatsApp buttons below it.
   The script moves it just above whichever of those the page shows. */
.store-chat-launcher {
    position: fixed; right: 18px; bottom: calc(186px + env(safe-area-inset-bottom)); z-index: 99991;
    width: 42px; height: 42px; display: grid; place-items: center; padding: 0;
    border: 1px solid var(--chat-line); border-radius: 50%; background: var(--chat-accent); color: var(--chat-accent-text);
    box-shadow: 0 8px 24px rgba(18, 28, 32, .18); cursor: pointer; transition: transform .18s ease;
}
.store-chat-launcher:hover { transform: translateY(-1px); }
.store-chat-launcher:focus-visible { outline: 3px solid rgba(31, 101, 91, .4); outline-offset: 3px; }
.store-chat-launcher svg { width: 21px; height: 21px; }
.store-chat-badge {
    min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center;
    border-radius: 999px; background: var(--chat-badge); color: #fff; font-size: 10px; font-weight: 700; line-height: 1;
}
.store-chat-badge[hidden] { display: none; }
.store-chat-launcher .store-chat-badge { position: absolute; top: -5px; right: -5px; border: 2px solid var(--chat-bg); height: 20px; }

/* The dock holds the list and the windows, bottom-aligned, to the left of the button column. */
.store-chat-dock {
    position: fixed; right: 72px; bottom: 0; z-index: 99992;
    display: flex; flex-direction: row-reverse; align-items: flex-end; gap: 12px;
    max-width: calc(100vw - 88px); pointer-events: none;
}
.store-chat-dock > * { pointer-events: auto; }

.store-chat-panel, .store-chat-window {
    display: flex; flex-direction: column; overflow: hidden;
    background: var(--chat-bg); border: 1px solid var(--chat-line); border-bottom: 0;
    border-radius: 14px 14px 0 0; box-shadow: 0 -6px 30px rgba(18, 28, 32, .16);
}
.store-chat-panel { width: 380px; max-width: 100%; height: min(620px, calc(100dvh - 70px)); }
.store-chat-panel[hidden], .store-chat-window[hidden] { display: none; }
.store-chat-window { position: relative; flex: 1; min-height: 0; width: 100%; border: 0; border-radius: 0; box-shadow: none; }

.store-chat-head {
    display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 8px 8px 14px;
    border-bottom: 1px solid var(--chat-line); background: var(--chat-bg);
}
.store-chat-head { flex-shrink: 0; }
.store-chat-head-title { flex: 1 1 auto; min-width: 0; }
.store-chat-head-title strong { display: block; overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.store-chat-head-title small { display: block; color: var(--chat-muted); font-size: 11px; }
.store-chat-icon-button {
    flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; padding: 0;
    border: 0; border-radius: 50%; background: transparent; color: var(--chat-muted); cursor: pointer; font-size: 15px;
}
.store-chat-icon-button:hover { background: var(--chat-soft); color: var(--chat-text); }
.store-chat-icon-button:focus-visible { outline: 2px solid var(--chat-accent); outline-offset: 1px; }
.store-chat-back { display: grid; }

.store-chat-avatar {
    flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; overflow: hidden;
    border-radius: 50%; background: var(--chat-soft); color: var(--chat-accent); font-size: 13px; font-weight: 700;
}
.store-chat-avatar img { width: 100%; height: 100%; object-fit: contain; background: var(--chat-soft); }
.store-chat-tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px; background: var(--chat-soft); color: var(--chat-muted); font-size: 10px; font-weight: 600; vertical-align: middle; }

.store-chat-list { flex: 1 1 auto; overflow-y: auto; margin: 0; padding: 6px 0; list-style: none; overscroll-behavior: contain; }
.store-chat-list-item {
    width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; font: inherit;
}
.store-chat-list-item:hover, .store-chat-list-item:focus-visible { background: var(--chat-soft); outline: none; }
.store-chat-list-copy { flex: 1 1 auto; min-width: 0; }
.store-chat-list-copy strong { display: block; overflow: hidden; font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.store-chat-list-copy > span { display: block; overflow: hidden; margin-top: 2px; color: var(--chat-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.store-chat-list-item.is-unread .store-chat-list-copy > span { color: var(--chat-text); font-weight: 600; }
.store-chat-list-meta { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; color: var(--chat-muted); font-size: 11px; }
.store-chat-empty { padding: 34px 20px; color: var(--chat-muted); font-size: 13px; line-height: 1.55; text-align: center; }
.store-chat-empty i { display: block; margin-bottom: 10px; font-size: 26px; opacity: .6; }

.store-chat-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px; overscroll-behavior: contain; background: var(--chat-bg); }
.store-chat-older { display: block; margin: 0 auto 10px; padding: 5px 12px; border: 1px solid var(--chat-line); border-radius: 999px; background: transparent; color: var(--chat-muted); font-size: 11px; cursor: pointer; }
.store-chat-older[hidden] { display: none; }
.store-chat-messages { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.store-chat-day { align-self: center; margin: 8px 0 2px; color: var(--chat-muted); font-size: 11px; }
.store-chat-message { display: flex; flex-direction: column; max-width: 82%; }
.store-chat-message.is-mine { align-self: flex-end; align-items: flex-end; }
.store-chat-message.is-theirs { align-self: flex-start; align-items: flex-start; }
.store-chat-bubble {
    padding: 8px 11px; border-radius: 14px; background: var(--chat-theirs); color: var(--chat-text);
    font-size: 13px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
}
.store-chat-message.is-mine .store-chat-bubble { background: var(--chat-mine); color: var(--chat-mine-text); border-bottom-right-radius: 4px; }
.store-chat-message.is-theirs .store-chat-bubble { border-bottom-left-radius: 4px; }
.store-chat-message.is-failed .store-chat-bubble { opacity: .6; }
.store-chat-card {
    display: flex; align-items: center; gap: 6px; max-width: 100%; margin-bottom: 4px; padding: 6px 9px;
    border: 1px solid var(--chat-line); border-radius: 10px; background: var(--chat-bg); color: var(--chat-text);
    font-size: 11px; text-decoration: none; overflow: hidden;
}
.store-chat-card span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.store-chat-time { margin-top: 2px; color: var(--chat-muted); font-size: 10px; }
.store-chat-time button { padding: 0; border: 0; background: none; color: var(--chat-badge); font: inherit; text-decoration: underline; cursor: pointer; }

.store-chat-context {
    display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-top: 1px solid var(--chat-line);
    background: var(--chat-soft); color: var(--chat-muted); font-size: 11px;
}
.store-chat-context[hidden] { display: none; }
.store-chat-context span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.store-chat-context strong { color: var(--chat-text); font-weight: 600; }
.store-chat-context .store-chat-icon-button { width: 26px; height: 26px; font-size: 12px; }

.store-chat-compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 10px 10px 12px; border-top: 1px solid var(--chat-line); background: var(--chat-bg); }
.store-chat-compose textarea {
    flex: 1 1 auto; min-width: 0; max-height: 120px; min-height: 44px; padding: 10px 12px; resize: none;
    border: 1px solid var(--chat-line); border-radius: 20px; background: var(--chat-soft); color: var(--chat-text);
    font: inherit; font-size: 14px; line-height: 1.35; outline: none;
}
.store-chat-compose textarea:focus { border-color: var(--chat-accent); }
.store-chat-send {
    flex: 0 0 auto; width: 40px; height: 40px; display: grid; place-items: center; padding: 0;
    border: 0; border-radius: 50%; background: var(--chat-accent); color: var(--chat-accent-text); cursor: pointer; font-size: 15px;
}
.store-chat-send:disabled { opacity: .5; cursor: default; }
.store-chat-error { margin: 0; padding: 6px 12px 10px; color: var(--chat-badge); font-size: 12px; background: var(--chat-bg); }
.store-chat-error[hidden] { display: none; }

.store-chat-tools { display: flex; flex-wrap: wrap; flex-shrink: 0; gap: 4px; margin: 0; padding: 6px 10px; min-width: 0; border: 0; border-top: 1px solid var(--chat-line); }
.store-chat-tool { display: inline-flex; align-items: center; gap: 5px; padding: 8px; border: 0; border-radius: 8px; background: var(--chat-soft); color: var(--chat-text); font: inherit; font-size: 11px; cursor: pointer; }
.store-chat-tool:disabled { opacity: .5; }
.store-chat-photo { display: block; width: 240px; max-width: 100%; margin-bottom: 4px; }
.store-chat-photo img { display: block; width: 100%; height: auto; max-height: 280px; object-fit: contain; border-radius: 12px; background: var(--chat-soft); }
.store-chat-photo-preview { display: flex; align-items: center; flex-shrink: 0; gap: 8px; padding: 6px 12px; font-size: 11px; }
.store-chat-photo-preview img { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; }
.store-chat-photo-preview span { flex: 1; }
.store-chat-photo-preview[hidden] { display: none; }
.store-chat-camera { position: absolute; inset: 52px 0 0; z-index: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; background: var(--chat-bg); }
.store-chat-camera video { width: 100%; min-height: 0; max-height: 75%; object-fit: contain; border-radius: 10px; background: #111; }
.store-chat-camera p { margin: 0; font-size: 12px; }
.store-chat-camera > div { display: flex; gap: 12px; }
.store-chat-picker { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; padding: 10px 12px; }
.store-chat-picker-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.store-chat-search { display: flex; gap: 6px; margin: 8px 0; }
.store-chat-search input { flex: 1; min-width: 0; width: 100%; padding: 8px; border: 1px solid var(--chat-line); border-radius: 8px; background: var(--chat-bg); color: var(--chat-text); }
.store-chat-search button, .store-chat-choice-more { padding: 8px; border: 1px solid var(--chat-line); border-radius: 8px; background: var(--chat-soft); color: var(--chat-text); cursor: pointer; }
.store-chat-choices { overflow-y: auto; flex: 1; min-height: 0; font-size: 12px; }
.store-chat-choice { display: flex; align-items: center; gap: 10px; width: 100%; margin: 0 0 5px; padding: 10px; border: 1px solid var(--chat-line); border-radius: 10px; background: var(--chat-bg); color: var(--chat-text); text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.store-chat-choice:hover, .store-chat-choice:focus-visible { background: var(--chat-soft); }
.store-chat-choice-copy { flex: 1 1 auto; min-width: 0; }
.store-chat-choice strong, .store-chat-choice small { display: block; }
.store-chat-thumb { flex: 0 0 auto; width: 44px; height: 44px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--chat-line); border-radius: 8px; background: var(--chat-soft); color: var(--chat-muted); font-size: 16px; }
.store-chat-thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.store-chat-thumb.is-small { width: 30px; height: 30px; border-radius: 6px; font-size: 12px; }
.store-chat-choice small { margin-top: 4px; color: var(--chat-muted); }
.store-chat-context, .store-chat-compose, .store-chat-error { flex-shrink: 0; }

@media (max-width: 767px) {
    .store-chat-launcher { bottom: calc(240px + env(safe-area-inset-bottom)); }
}

/* Phones: the list or one conversation fills the screen. */
@media (max-width: 699px) {
    .store-chat-dock { inset: 0; right: 0; max-width: none; display: block; pointer-events: none; }
    .store-chat-panel {
        position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; box-shadow: none;
        padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
    }
    .store-chat-back { display: grid; }
    .store-chat-message { max-width: 88%; }
    .store-chat-compose textarea { font-size: 16px; }
    body.store-chat-open { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
    .store-chat-launcher { transition: none; }
    .store-chat-launcher:hover { transform: none; }
}

/* A chat button on a page (product, appointment). */
.chat-open-button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
    border: 1px solid currentColor; border-radius: 999px; background: transparent; color: inherit;
    font: inherit; font-size: 13px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.chat-open-button:hover { background: rgba(0, 0, 0, .04); }
.chat-open-button .store-chat-badge { margin-left: 2px; }
.store-chat-context span .store-chat-thumb { display: inline-grid; vertical-align: middle; margin-right: 4px; }
.store-chat-card .store-chat-thumb { margin-right: 2px; }

/* The AI assistant: a pinned row in the list and its own conversation. */
.store-chat-ai-avatar { color: var(--chat-accent); background: var(--chat-soft); font-size: 15px; }
.store-chat-ai-avatar i { line-height: 1; }
.store-chat-ai-item { border-bottom: 1px solid var(--chat-line); }
.store-chat-ai-cards { display: flex; flex-direction: column; gap: 6px; width: 100%; margin-top: 6px; }
.store-chat-ai-card {
    display: flex; align-items: center; gap: 10px; min-width: 0; padding: 8px; border: 1px solid var(--chat-line); border-radius: 10px;
    background: var(--chat-bg); color: var(--chat-text); text-decoration: none; font-size: 12px;
}
.store-chat-ai-card:hover, .store-chat-ai-card:focus-visible { background: var(--chat-soft); }
.store-chat-ai-card strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.store-chat-ai-card small { display: block; margin-top: 2px; color: var(--chat-muted); }
.store-chat-ai-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.store-chat-ai-action, .store-chat-ai-chip {
    display: inline-flex; align-items: center; min-height: 32px; padding: 6px 12px; border: 1px solid var(--chat-accent); border-radius: 999px;
    background: transparent; color: var(--chat-accent); font: inherit; font-size: 12px; font-weight: 600; text-decoration: none; cursor: pointer;
}
.store-chat-ai-action:hover, .store-chat-ai-chip:hover { background: var(--chat-soft); }
.store-chat-ai-suggestions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; flex-shrink: 0; background: var(--chat-bg); }
.store-chat-ai-chip { max-width: 100%; text-align: left; white-space: normal; }
.store-chat-ai-note { flex-shrink: 0; margin: 0; padding: 0 12px 8px; color: var(--chat-muted); font-size: 10px; text-align: center; background: var(--chat-bg); }
.store-chat-ai-typing .store-chat-bubble { display: inline-flex; gap: 4px; align-items: center; min-height: 32px; }
.store-chat-ai-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--chat-muted); animation: store-chat-ai-dot 1.2s infinite ease-in-out; }
.store-chat-ai-typing span:nth-child(2) { animation-delay: .15s; }
.store-chat-ai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes store-chat-ai-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .store-chat-ai-typing span { animation: none; } }
