/* Sitetisfy floating chatbot (Initiative 5 / Sprint 7).
   Self-contained: every rule is prefixed .sfy-cb- and resets what a template's global
   button/input/heading styles could leak in. The widget is a light card on purpose so it reads
   the same on all 33 templates (including the dark ones) — and anywhere else it gets embedded
   (e.g. new-sitetisfy-compro). The widget builds plain HTML tags (section, header, form, strong,
   span) with no attribute marking them as "not part of the page", so a host's generic element
   selector (seen in the wild: `section { padding-block: 6rem }`, which silently padded the whole
   chat panel) wins on any box-model property this stylesheet doesn't explicitly set itself —
   margin/padding/border win by specificity, not by being more "correct", so they must be zeroed
   here for every element this widget creates, not just the ones that currently need it. */

.sfy-cb-root, .sfy-cb-root * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    text-align: left;
    list-style: none;
    background: none;
    box-shadow: none;
    float: none;
    position: static;
    line-height: inherit;
    font-size: inherit;
}

.sfy-cb-root {
    position: fixed;
    bottom: 20px;
    z-index: 2147483000;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: var(--sfy-cb-font, 14px);
    line-height: 1.45;
    letter-spacing: normal;
    text-transform: none;
    text-align: left;
    color: #1f2937;
}
.sfy-cb-root[data-pos="right"] { right: 20px; }
.sfy-cb-root[data-pos="left"] { left: 20px; }

.sfy-cb-root button,
.sfy-cb-root input {
    font: inherit;
    letter-spacing: inherit;
    text-transform: none;
    margin: 0;
    box-shadow: none;
    outline-offset: 2px;
}

/* ── launcher ─────────────────────────────────────────── */
.sfy-cb-root .sfy-cb-launcher {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--sfy-cb-size, 58px);
    height: var(--sfy-cb-size, 58px);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--sfy-cb-color);
    color: var(--sfy-cb-on-color);
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
    transition: transform .15s ease, box-shadow .15s ease;
}
.sfy-cb-root .sfy-cb-launcher:hover { transform: scale(1.06); box-shadow: 0 8px 22px rgba(0, 0, 0, .32); }
.sfy-cb-root .sfy-cb-launcher:focus-visible,
.sfy-cb-root .sfy-cb-close:focus-visible,
.sfy-cb-root .sfy-cb-chip:focus-visible,
.sfy-cb-root .sfy-cb-thumb:focus-visible,
.sfy-cb-root .sfy-cb-send:focus-visible { outline: 3px solid #1d4ed8; }

.sfy-cb-icon { display: inline-flex; align-items: center; justify-content: center; font-size: calc(var(--sfy-cb-size, 58px) * 0.448); line-height: 1; }
.sfy-cb-icon svg { width: 28px; height: 28px; fill: currentColor; }

/* ── panel ────────────────────────────────────────────── */
.sfy-cb-root .sfy-cb-panel {
    position: absolute;
    bottom: 72px;
    display: flex;
    flex-direction: column;
    width: var(--sfy-cb-panel-w, 360px);
    max-width: calc(100vw - 24px);
    height: var(--sfy-cb-panel-h, 520px);
    max-height: calc(100vh - 110px);
    background: #ffffff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
}
.sfy-cb-root .sfy-cb-panel[hidden] { display: none; }
.sfy-cb-root[data-pos="right"] .sfy-cb-panel { right: 0; }
.sfy-cb-root[data-pos="left"] .sfy-cb-panel { left: 0; }

.sfy-cb-root .sfy-cb-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 16px;
    background: var(--sfy-cb-color);
    color: var(--sfy-cb-on-color);
}
.sfy-cb-head-text { display: flex; flex-direction: column; min-width: 0; }
.sfy-cb-root .sfy-cb-title { font-size: 1.15em; font-weight: 700; line-height: 1.25; color: inherit; margin: 0; }
.sfy-cb-root .sfy-cb-subtitle { font-size: 0.85em; opacity: .85; color: inherit; }
.sfy-cb-root .sfy-cb-close {
    flex: none;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: inherit;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}
.sfy-cb-root .sfy-cb-close:hover { background: rgba(127, 127, 127, .25); }

/* ── messages ─────────────────────────────────────────── */
.sfy-cb-root .sfy-cb-log {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    background: #f3f4f6;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overscroll-behavior: contain;
}
.sfy-cb-row { display: flex; }
.sfy-cb-row.sfy-cb-user { justify-content: flex-end; }
.sfy-cb-row.sfy-cb-bot { justify-content: flex-start; }
.sfy-cb-root .sfy-cb-bubble {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.sfy-cb-bot .sfy-cb-bubble { background: #ffffff; color: #1f2937; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.sfy-cb-user .sfy-cb-bubble { background: var(--sfy-cb-color); color: var(--sfy-cb-on-color); border-bottom-right-radius: 4px; }

.sfy-cb-typing { display: inline-flex; gap: 4px; align-items: center; padding: 12px 14px; }
.sfy-cb-typing span { width: 7px; height: 7px; border-radius: 50%; background: #9ca3af; animation: sfy-cb-blink 1.2s infinite ease-in-out; }
.sfy-cb-typing span:nth-child(2) { animation-delay: .15s; }
.sfy-cb-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes sfy-cb-blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ── choices / chips / feedback ───────────────────────── */
.sfy-cb-chips { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.sfy-cb-chips-label { font-size: 12px; color: #6b7280; }
.sfy-cb-root .sfy-cb-chip {
    max-width: 100%;
    padding: 7px 12px;
    border: 1px solid var(--sfy-cb-color);
    border-radius: 16px;
    background: #ffffff;
    color: #1f2937;
    text-align: left;
    cursor: pointer;
    transition: background .12s ease;
}
.sfy-cb-root .sfy-cb-chip:hover { background: #eef2ff; }
.sfy-cb-root .sfy-cb-chip-none { border-style: dashed; border-color: #9ca3af; color: #4b5563; }

.sfy-cb-feedback { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #6b7280; }
.sfy-cb-root .sfy-cb-thumb {
    width: 30px; height: 30px; padding: 0; border: 1px solid #d1d5db; border-radius: 50%;
    background: #ffffff; font-size: 14px; line-height: 1; cursor: pointer;
}
.sfy-cb-root .sfy-cb-thumb:hover:not(:disabled) { background: #f3f4f6; }
.sfy-cb-root .sfy-cb-thumb:disabled { opacity: .5; cursor: default; }

/* ── input ────────────────────────────────────────────── */
.sfy-cb-root .sfy-cb-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e5e7eb; background: #ffffff; }
.sfy-cb-root .sfy-cb-input {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0 12px;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    background: #ffffff;
    color: #1f2937;
    font-size: 1em;
}
.sfy-cb-root .sfy-cb-input::placeholder { color: #9ca3af; }
.sfy-cb-root .sfy-cb-input:focus { border-color: var(--sfy-cb-color); outline: 2px solid var(--sfy-cb-color); outline-offset: 0; }
.sfy-cb-root .sfy-cb-send {
    flex: none;
    height: 40px;
    padding: 0 16px;
    border: 0;
    border-radius: 20px;
    background: var(--sfy-cb-color);
    color: var(--sfy-cb-on-color);
    font-weight: 600;
    cursor: pointer;
}
.sfy-cb-root .sfy-cb-send:disabled,
.sfy-cb-root .sfy-cb-input:disabled { opacity: .6; cursor: default; }

/* ── small screens ────────────────────────────────────── */
@media (max-width: 480px) {
    .sfy-cb-root { bottom: 14px; }
    .sfy-cb-root[data-pos="right"] { right: 14px; }
    .sfy-cb-root[data-pos="left"] { left: 14px; }
    .sfy-cb-root.sfy-cb-open .sfy-cb-launcher { display: none; }
    .sfy-cb-root .sfy-cb-panel {
        position: fixed;
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }
    .sfy-cb-root .sfy-cb-input { font-size: 16px; } /* no iOS zoom on focus */
}

@media (prefers-reduced-motion: reduce) {
    .sfy-cb-root .sfy-cb-launcher, .sfy-cb-root .sfy-cb-chip { transition: none; }
    .sfy-cb-typing span { animation: none; opacity: .6; }
}
