/* ════════════════════════════════════════════════════════
   WP AI Chatbot v6 — Nicepage-safe, plně responzivní
   Barvy a zaoblení přes CSS custom properties z adminu
   Autor: Pavel Bílek | webstrankylevne.cz
   ════════════════════════════════════════════════════════ */

/* Výchozí hodnoty proměnných (přepsány inline stylem z PHP) */
:root {
    --wpaic-primary:   #1a1a2e;
    --wpaic-accent:    #4ade80;
    --wpaic-user-text: #ffffff;
    --wpaic-r-window:  16px;
    --wpaic-r-button:  10px;
    --wpaic-r-qr:      20px;
    --wpaic-r-bubble:  14px;
    --wpaic-toggle-sz: 56px;
    --wpaic-bg-window: #ffffff;
    --wpaic-bg-chat:   #f9fafb;
    --wpaic-border-chat: 1px solid #e5e7eb;
    --wpaic-send-btn:  #1a1a2e;
    --wpaic-user-bg:   #1a1a2e;
    --wpaic-user-border: 0px solid transparent;
    --wpaic-bot-bg:    #f3f4f6;
    --wpaic-bot-border: 1px solid #e5e7eb;
}

#wpaic-root, #wpaic-root * {
    box-sizing: border-box;
    margin: 0; padding: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ── Toggle ─────────────────────────────────────────────── */
#wpaic-root {
    position: fixed;
    bottom: var(--wpaic-toggle-bottom, 24px);
    right:  calc(var(--wpaic-toggle-side, right) == left ? auto : 24px);
    left:   calc(var(--wpaic-toggle-side, right) == left ? 24px : auto);
    z-index: 2147483647;
}
/* CSS custom properties can't do conditionals directly, so we use data-side attribute */
#wpaic-root[data-side="left"]  { right: auto; left: 24px; }
#wpaic-root[data-side="right"] { right: 24px; left: auto; }
#wpaic-toggle {
    width:  var(--wpaic-toggle-sz);
    height: var(--wpaic-toggle-sz);
    border-radius: 50%;
    background: var(--wpaic-primary);
    color: #fff;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,.3);
    transition: transform .2s, background .2s;
    margin-left: auto;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden; padding: 0; outline: none;
}
#wpaic-toggle:hover  { filter: brightness(1.15); transform: scale(1.07); }
#wpaic-toggle:active { transform: scale(.95); }
#wpaic-toggle:focus-visible { outline: 3px solid #4a9eff; outline-offset: 3px; }
#wpaic-toggle svg { width: 22px; height: 22px; pointer-events: none; }
#wpaic-toggle-avatar {
    width: 100%; height: 100%;
    object-fit: cover; border-radius: 50%;
    display: block; pointer-events: none;
}
#wpaic-root[data-open="true"] #wpaic-toggle-avatar { display: none; }

/* ── Okno chatu ─────────────────────────────────────────── */
#wpaic-window {
    position: absolute;
    bottom: calc(var(--wpaic-toggle-bottom, 24px) + var(--wpaic-toggle-sz) + 12px);
    right: 0; left: auto;
}
#wpaic-root[data-side="left"] #wpaic-window {
    left: 0; right: auto;
}
#wpaic-window {
    right: 0;
    width: 350px; max-height: 560px; min-height: 300px;
    background: var(--wpaic-bg-window);
    border-radius: var(--wpaic-r-window);
    box-shadow: 0 8px 48px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.08);
    display: flex; flex-direction: column;
    overflow: hidden;
    animation: wpaic-in .22s cubic-bezier(.34,1.26,.64,1);
    border: 1px solid rgba(0,0,0,.06);
}
@keyframes wpaic-in {
    from { opacity:0; transform: translateY(16px) scale(.96); }
    to   { opacity:1; transform: translateY(0)    scale(1);   }
}

/* ── Hlavička ────────────────────────────────────────────── */
#wpaic-header {
    background: var(--wpaic-primary);
    color: #fff;
    padding: 13px 16px;
    display: flex; align-items: center;
    justify-content: space-between;
    flex-shrink: 0; gap: 8px;
}
#wpaic-header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
#wpaic-header-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    object-fit: cover; flex-shrink: 0;
    border: 2px solid rgba(255,255,255,.25);
}
#wpaic-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--wpaic-accent); flex-shrink: 0;
    animation: wpaic-pulse 2s ease-in-out infinite;
}
@keyframes wpaic-pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
#wpaic-header-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#wpaic-close {
    background: transparent; border: none;
    color: rgba(255,255,255,.7); font-size: 22px; line-height: 1;
    cursor: pointer; padding: 2px 4px; border-radius: 4px;
    transition: color .15s, background .15s; flex-shrink: 0;
}
#wpaic-close:hover { color: #fff; background: rgba(255,255,255,.12); }

/* ── Zprávy ──────────────────────────────────────────────── */
#wpaic-messages {
    flex: 1; overflow-y: auto;
    padding: 14px 12px;
    display: flex; flex-direction: column; gap: 8px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--wpaic-bg-chat);
    border: var(--wpaic-border-chat);
}
#wpaic-messages::-webkit-scrollbar       { width: 3px; }
#wpaic-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

.wpaic-msg {
    padding: 9px 13px;
    border-radius: var(--wpaic-r-bubble);
    font-size: inherit;
    line-height: 1.6;
    word-break: break-word;
    animation: wpaic-bubble .16s ease-out;
    max-width: 85%;
}
@keyframes wpaic-bubble {
    from { opacity:0; transform: translateY(5px); }
    to   { opacity:1; transform: translateY(0);   }
}
.wpaic-msg.bot   { background: var(--wpaic-bot-bg); color: #1a1a2e; align-self: stretch; border-bottom-left-radius: 4px; border: var(--wpaic-bot-border); }
.wpaic-msg.user  { background: var(--wpaic-user-bg); color: var(--wpaic-user-text); align-self: flex-end; border-bottom-right-radius: 4px; border: var(--wpaic-user-border); white-space: pre-line; }
.wpaic-msg.error { background: #fef2f2; color: #c0392b; align-self: stretch; font-size: 13px; border: 1px solid #fecaca; border-bottom-left-radius: 4px; }

.wpaic-bot-row { display: flex; align-items: flex-end; gap: 7px; align-self: flex-start; width: calc(100% - 0px); animation: wpaic-bubble .16s ease-out; }
.wpaic-bot-row .wpaic-msg { align-self: unset; animation: none; }
.wpaic-bot-col { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.wpaic-msg-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; margin-bottom: 2px; }
.wpaic-msg-avatar-placeholder {
    width: 28px; height: 28px; border-radius: 50%;
    background: #e5e7eb; flex-shrink: 0; margin-bottom: 2px;
    display: flex; align-items: center; justify-content: center;
}

/* Typing */
.wpaic-typing { display: flex; gap: 4px; padding: 11px 14px; background: #f0f2f5; border-radius: var(--wpaic-r-bubble); border-bottom-left-radius: 4px; align-self: flex-start; width: 50px; align-items: center; }
.wpaic-typing span { width: 6px; height: 6px; background: #9ca3af; border-radius: 50%; animation: wpaic-dot 1.2s infinite ease-in-out; }
.wpaic-typing span:nth-child(2){ animation-delay:.2s; }
.wpaic-typing span:nth-child(3){ animation-delay:.4s; }
@keyframes wpaic-dot { 0%,80%,100%{transform:scale(.65);opacity:.5} 40%{transform:scale(1);opacity:1} }

/* Turnstile */
#wpaic-ts-wrap { padding: 10px 12px; border-top: 1px solid #f0f0f0; display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; }
#wpaic-ts-note { font-size: 12px; color: #6b7280; }

/* ── Input ───────────────────────────────────────────────── */
#wpaic-input-area { display: flex; align-items: flex-end; gap: 7px; padding: 10px 10px 12px; border-top: 1px solid #f0f0f0; flex-shrink: 0; }
#wpaic-input {
    flex: 1; resize: none;
    border: 1.5px solid #e5e7eb;
    border-radius: var(--wpaic-r-button);
    padding: 9px 11px;
    font-size: inherit;
    font-family: inherit; line-height: 1.5;
    outline: none; transition: border-color .15s;
    max-height: 100px; overflow-y: auto;
    color: #1a1a2e; background: #fff;
    -webkit-appearance: none;
}
#wpaic-input:focus    { border-color: var(--wpaic-primary); }
#wpaic-input:disabled { background: #f9f9f9; cursor: not-allowed; }
#wpaic-input::placeholder { color: #9ca3af; }
#wpaic-send {
    width: 40px; height: 40px;
    border-radius: var(--wpaic-r-button);
    background: var(--wpaic-send-btn); color: #fff;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: filter .15s, transform .1s, opacity .15s;
    -webkit-tap-highlight-color: transparent;
}
#wpaic-send:hover:not(:disabled) { filter: brightness(1.15); }
#wpaic-send:active:not(:disabled) { transform: scale(.9); }
#wpaic-send:disabled { background: #d1d5db; cursor: not-allowed; opacity: .6; }
#wpaic-send svg { width: 16px; height: 16px; pointer-events: none; }

/* ── Quick replies ───────────────────────────────────────── */
.wpaic-qr-wrap { display: flex; flex-wrap: wrap; gap: 7px; padding: 4px 0 6px 36px; animation: wpaic-bubble .18s ease-out; }
.wpaic-qr-btn {
    background: #fff; border: 1.5px solid #d1d5db;
    border-radius: var(--wpaic-r-qr);
    padding: 6px 13px;
    font-size: inherit;
    color: #1a1a2e; cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
    font-family: inherit; white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.wpaic-qr-btn:hover  { background: #f0f2f5; border-color: var(--wpaic-primary); }
.wpaic-qr-btn:active { transform: scale(.95); }

/* ── Rating ──────────────────────────────────────────────── */
.wpaic-rating { display: flex; gap: 4px; margin-top: 2px; }
.wpaic-rate-btn {
    width: 26px; height: 26px; border: 1px solid #e5e7eb; border-radius: 6px;
    background: transparent; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #9ca3af; padding: 4px;
    transition: color .15s, background .15s, border-color .15s;
    -webkit-tap-highlight-color: transparent;
}
.wpaic-rate-btn svg { width: 13px; height: 13px; pointer-events: none; }
.wpaic-rate-btn:hover { color: #1a1a2e; border-color: #9ca3af; background: #f3f4f6; }
.wpaic-rated { font-size: 12px; padding: 2px 6px; border-radius: 6px; display: inline-block; }
.wpaic-rated-up   { color: #166534; background: #dcfce7; }
.wpaic-rated-down { color: #7f1d1d; background: #fee2e2; }

/* ── Lead form ───────────────────────────────────────────── */
.wpaic-lead-form { display: flex; flex-wrap: wrap; gap: 7px; padding: 8px 12px 4px 36px; animation: wpaic-bubble .18s ease-out; }
.wpaic-lead-input { flex: 1; min-width: 160px; border: 1.5px solid #e5e7eb; border-radius: var(--wpaic-r-button); padding: 8px 11px; font-size: 14px; font-family: inherit; outline: none; transition: border-color .15s; color: #1a1a2e; -webkit-appearance: none; }
.wpaic-lead-input:focus { border-color: var(--wpaic-primary); }
.wpaic-lead-send { background: var(--wpaic-primary); color: var(--wpaic-user-text); border: none; border-radius: var(--wpaic-r-button); padding: 8px 14px; font-size: 13px; font-family: inherit; cursor: pointer; transition: filter .15s; white-space: nowrap; }
.wpaic-lead-send:hover { filter: brightness(1.15); }
.wpaic-lead-skip { background: transparent; border: 1px solid #e5e7eb; border-radius: var(--wpaic-r-button); padding: 8px 12px; font-size: 13px; font-family: inherit; color: #6b7280; cursor: pointer; transition: border-color .15s; white-space: nowrap; }
.wpaic-lead-skip:hover { border-color: #9ca3af; color: #374151; }

/* ── Responzivita ────────────────────────────────────────── */
@media (max-width: 480px) {
    #wpaic-root { bottom: max(16px, var(--wpaic-toggle-bottom, 16px)); right: 12px; left: 12px; }
    #wpaic-root[data-side="left"]  { right: 12px; left: 12px; }
    #wpaic-root[data-side="right"] { right: 12px; left: 12px; }
    #wpaic-window { position: fixed; bottom: 80px; right: 12px; left: 12px; /* mobile: full width regardless of side */ width: auto; max-height: calc(100vh - 110px); border-radius: calc(var(--wpaic-r-window) * 0.8); }
    #wpaic-toggle { position: fixed; bottom: var(--wpaic-toggle-bottom, 16px); right: 12px; }
    #wpaic-root[data-side="left"]  #wpaic-toggle { right: auto; left: 12px; }
    #wpaic-root[data-side="right"] #wpaic-toggle { right: 12px; left: auto; }
    .wpaic-qr-wrap  { padding-left: 24px; }
    .wpaic-lead-form { padding-left: 24px; }
    .wpaic-lead-input { min-width: 120px; }
}
@media (max-height: 500px) { #wpaic-window { max-height: calc(100vh - 80px); } }
@media (pointer: coarse) {
    #wpaic-close { padding: 4px 8px; }
    #wpaic-send  { width: 44px; height: 44px; }
    #wpaic-input { padding: 10px 12px; }
}

/* ════════════════════════════════════════════════
   Inline shortcode widget
   ════════════════════════════════════════════════ */
.wpaic-inline-wrap, .wpaic-inline-wrap * {
    box-sizing: border-box;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}
.wpaic-inline-wrap {
    border: 1px solid rgba(0,0,0,.08);
    border-radius: var(--wpaic-r-window);
    overflow: hidden; background: var(--wpaic-bg-window);
    box-shadow: 0 4px 24px rgba(0,0,0,.10);
    display: flex; flex-direction: column; width: 100%;
}
.wpaic-inline-header { background: var(--wpaic-primary); color: #fff; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.wpaic-inline-header-left { display: flex; align-items: center; gap: 9px; }
.wpaic-inline-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.25); flex-shrink: 0; }
.wpaic-dot-inline { width: 10px; height: 10px; border-radius: 50%; background: var(--wpaic-accent); flex-shrink: 0; animation: wpaic-pulse 2s ease-in-out infinite; }
.wpaic-inline-name   { font-size: 15px; font-weight: 600; }
.wpaic-inline-status { font-size: 11px; color: var(--wpaic-accent); letter-spacing: .02em; }
.wpaic-inline-messages { flex: none; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 8px; scroll-behavior: smooth; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; background: var(--wpaic-bg-chat); border: var(--wpaic-border-chat); }
.wpaic-inline-messages::-webkit-scrollbar { width: 3px; }
.wpaic-inline-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
.wpaic-inline-ts-wrap { padding: 10px 14px; border-top: 1px solid #f0f0f0; display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; }
.wpaic-inline-ts-note { font-size: 12px; color: #6b7280; margin: 0; }
.wpaic-inline-input-area { display: flex; align-items: flex-end; gap: 7px; padding: 10px 10px 12px; border-top: 1px solid #f0f0f0; flex-shrink: 0; }
.wpaic-inline-input { flex: 1; resize: none; border: 1.5px solid #e5e7eb; border-radius: var(--wpaic-r-button); padding: 9px 11px; font-size: inherit; font-family: inherit; line-height: 1.5; outline: none; transition: border-color .15s; max-height: 100px; overflow-y: auto; color: #1a1a2e; -webkit-appearance: none; }
.wpaic-inline-input:focus    { border-color: var(--wpaic-primary); }
.wpaic-inline-input:disabled { background: #f9f9f9; cursor: not-allowed; }
.wpaic-inline-input::placeholder { color: #9ca3af; }
.wpaic-inline-send { width: 40px; height: 40px; border-radius: var(--wpaic-r-button); background: var(--wpaic-send-btn); color: #fff; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: filter .15s, transform .1s; -webkit-tap-highlight-color: transparent; }
.wpaic-inline-send:hover:not(:disabled)  { filter: brightness(1.15); }
.wpaic-inline-send:active:not(:disabled) { transform: scale(.9); }
.wpaic-inline-send:disabled { background: #d1d5db; cursor: not-allowed; opacity: .6; }
.wpaic-inline-send svg { width: 16px; height: 16px; pointer-events: none; }

@media (max-width: 480px) { .wpaic-inline-wrap { border-radius: calc(var(--wpaic-r-window) * .75); } }
/* Barvy jsou řízeny výhradně CSS proměnnými z administrace pluginu */
/* Dark mode override záměrně odstraněn — použij nastavení barev v administraci */

/* Lead note */
.wpaic-lead-note { font-size: 12px; color: #6b7280; margin: 2px 0 0 36px; }
