/* jidelnicky/chat-widget.css
   Live chat widget — plovoucí bublina + okno (pre-chat / chat).
   Všechny selektory prefixované .pkchat- (widget jede na všech stránkách,
   nesmí kolidovat s lokálními styly). Barvy projektu:
   fialová #5346ec · lime #c5ff4d · tmavě zelená #0c3b25 · error #e63946 */

.pkchat-root {
  --pkchat-purple: #5346ec;
  --pkchat-purple-dark: #4438c9;
  --pkchat-lime: #c5ff4d;
  --pkchat-green: #0c3b25;
  --pkchat-error: #e63946;
  --pkchat-text: #0e1a23;
  --pkchat-muted: #6b7480;
  --pkchat-border: #e2e6ec;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 99990;
  font-family: "Montserrat", Arial, Helvetica, sans-serif;
  color: var(--pkchat-text);
  font-size: 14px;
  line-height: 1.5;
}
.pkchat-root *, .pkchat-root *::before, .pkchat-root *::after { box-sizing: border-box; }

/* ---------- Bublina ---------- */
.pkchat-bubble {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--pkchat-lime);
  color: var(--pkchat-green);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(12, 59, 37, 0.3);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
.pkchat-bubble:hover { transform: scale(1.06); box-shadow: 0 10px 28px rgba(12, 59, 37, 0.4); }
.pkchat-bubble svg { width: 28px; height: 28px; display: block; }
/* Badge nové zprávy (fialová tečka na limetkové bublině) */
.pkchat-bubble .pkchat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--pkchat-purple);
  border: 2.5px solid var(--pkchat-lime);
  display: none;
}
.pkchat-bubble.pkchat-has-unread .pkchat-badge { display: block; }

/* ---------- Uvítací bublina (teaser u ikony) ---------- */
.pkchat-teaser {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: 270px;
  max-width: calc(100vw - 40px);
  background: #fff;
  border: 1px solid var(--pkchat-border);
  border-radius: 16px;
  box-shadow: 0 12px 34px rgba(14, 26, 35, 0.18);
  padding: 13px 14px 14px;
  cursor: pointer;
  transform-origin: 100% 100%;
}
.pkchat-teaser[hidden] { display: none; }
/* Ocásek mířící dolů na ikonu chatu */
.pkchat-teaser::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 22px;
  width: 13px;
  height: 13px;
  background: #fff;
  border-right: 1px solid var(--pkchat-border);
  border-bottom: 1px solid var(--pkchat-border);
  transform: rotate(45deg);
}
.pkchat-teaser--show { animation: pkchat-teaser-in 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.15) both; }
@keyframes pkchat-teaser-in {
  from { opacity: 0; transform: translateY(10px) scale(0.94); }
  to   { opacity: 1; transform: none; }
}
.pkchat-teaser-close {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 22px;
  height: 22px;
  border: none;
  background: #f0f2f5;
  color: var(--pkchat-muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pkchat-teaser-close:hover { background: #e4e7ec; color: var(--pkchat-text); }
.pkchat-teaser-inner { display: flex; gap: 11px; align-items: flex-start; padding-right: 14px; }
.pkchat-teaser-logo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--pkchat-lime);
  color: var(--pkchat-green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  flex-shrink: 0;
}
.pkchat-teaser-text { font-weight: 700; font-size: 13.5px; color: var(--pkchat-text); line-height: 1.4; }
.pkchat-teaser-text span { color: var(--pkchat-purple); }
.pkchat-teaser-status { display: flex; align-items: center; gap: 6px; margin-top: 5px; font-size: 11.5px; color: var(--pkchat-muted); white-space: nowrap; }
.pkchat-teaser-dot { width: 7px; height: 7px; border-radius: 50%; background: #12b76a; box-shadow: 0 0 0 3px rgba(18, 183, 106, 0.16); }

/* ---------- Okno ---------- */
.pkchat-window {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 110px);
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--pkchat-border);
  box-shadow: 0 18px 50px rgba(14, 26, 35, 0.22);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.pkchat-root.pkchat-open .pkchat-window { display: flex; }

/* ---------- Header ---------- */
.pkchat-header {
  background: var(--pkchat-purple);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.pkchat-header-titles { flex: 1; min-width: 0; }
.pkchat-header-title { font-weight: 800; font-size: 15px; letter-spacing: -0.2px; }
.pkchat-header-sub { font-size: 12px; opacity: 0.85; }
.pkchat-header-logo {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--pkchat-lime); color: var(--pkchat-green);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 15px; flex-shrink: 0;
}
.pkchat-close {
  background: transparent; border: none; color: #fff;
  font-size: 22px; line-height: 1; cursor: pointer; padding: 4px 6px;
  opacity: 0.85; border-radius: 8px;
}
.pkchat-close:hover { opacity: 1; background: rgba(255,255,255,0.12); }
/* Ukončení chatu návštěvníkem — decentní pill v headeru */
.pkchat-end {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 6px 12px;
  border-radius: 100px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.pkchat-end:hover { background: rgba(255,255,255,0.25); }
.pkchat-end[hidden] { display: none; }

/* ---------- Pre-chat formulář ---------- */
.pkchat-prechat {
  padding: 18px 16px;
  overflow-y: auto;
  flex: 1;
}
.pkchat-prechat-intro { font-size: 13.5px; color: var(--pkchat-muted); margin: 0 0 14px; }
/* Info po ukončení konverzace agentem */
.pkchat-prechat-note {
  background: #e6fbf0;
  border: 1.5px solid #12b76a;
  color: #054f31;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 14px;
}
.pkchat-prechat-note[hidden] { display: none; }
.pkchat-field { margin-bottom: 12px; }
.pkchat-field label {
  display: block; font-weight: 700; font-size: 12.5px;
  margin-bottom: 5px; letter-spacing: 0.2px;
}
.pkchat-field input[type="text"],
.pkchat-field input[type="email"] {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--pkchat-border);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  color: var(--pkchat-text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.pkchat-field input:focus {
  border-color: var(--pkchat-purple);
  box-shadow: 0 0 0 3px rgba(83, 70, 236, 0.14);
}
/* Chybové stavy — jednotný styl dle form.html/form.css (.invalid + .field-error ⚠) */
.pkchat-field input.invalid {
  border-color: var(--pkchat-error);
  box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.12);
}
.pkchat-consent.invalid {
  outline: 2px solid rgba(230, 57, 70, 0.45);
  outline-offset: 4px;
  border-radius: 10px;
}
.pkchat-root .field-error {
  display: block;
  margin-top: 6px;
  color: var(--pkchat-error);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.4;
}
.pkchat-root .field-error::before { content: "⚠️ "; }
.pkchat-root .field-error[hidden],
.pkchat-root .field-error:empty { display: none; }

.pkchat-consent {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 12.5px; line-height: 1.45; color: var(--pkchat-text);
  margin-bottom: 10px; cursor: pointer; font-weight: 500;
}
.pkchat-consent input[type="checkbox"] {
  width: 17px; height: 17px; margin: 1px 0 0; flex-shrink: 0;
  accent-color: var(--pkchat-purple); cursor: pointer;
}
.pkchat-consent a { color: var(--pkchat-purple); font-weight: 700; }

.pkchat-start-btn {
  width: 100%;
  margin-top: 6px;
  padding: 13px 16px;
  background: var(--pkchat-purple);
  color: #fff;
  border: none;
  border-radius: 100px;
  font: inherit;
  font-weight: 800;
  font-size: 14.5px;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.pkchat-start-btn:hover { background: var(--pkchat-purple-dark); }
.pkchat-start-btn:active { transform: scale(0.98); }
.pkchat-start-btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.pkchat-form-error {
  background: #ffeded;
  color: #a4121a;
  border: 1px solid #f6b8b8;
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 13px;
  margin-top: 12px;
}
.pkchat-form-error[hidden] { display: none; }

/* ---------- Chat ---------- */
/* GOTCHA: display:flex přebíjí UA pravidlo pro [hidden] — bez těchhle řádků
   by byly thread + inputbar vidět i schované (šedý pruh pod pre-chatem). */
.pkchat-thread[hidden],
.pkchat-inputbar[hidden],
.pkchat-prechat[hidden] { display: none !important; }

.pkchat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f7f8fb;
  /* Scroll nesmí "protéct" do stránky pod chatem (mobil fullscreen) */
  overscroll-behavior: contain;
  /* Kontrastní scrollbar v brandové tmavě zelené */
  scrollbar-width: thin;
  scrollbar-color: var(--pkchat-green) transparent;
}
.pkchat-thread::-webkit-scrollbar { width: 8px; }
.pkchat-thread::-webkit-scrollbar-track { background: transparent; }
.pkchat-thread::-webkit-scrollbar-thumb {
  background: var(--pkchat-green);
  border-radius: 8px;
}
.pkchat-thread::-webkit-scrollbar-thumb:hover { background: #0a2f1e; }
.pkchat-msg { max-width: 82%; display: flex; flex-direction: column; }
.pkchat-msg-body {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
.pkchat-msg--visitor { align-self: flex-end; align-items: flex-end; }
.pkchat-msg--visitor .pkchat-msg-body {
  background: var(--pkchat-purple);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.pkchat-msg--admin { align-self: flex-start; align-items: flex-start; }
.pkchat-msg--admin .pkchat-msg-body {
  background: #fff;
  border: 1px solid var(--pkchat-border);
  border-bottom-left-radius: 4px;
}
.pkchat-msg-agent {
  font-size: 11px;
  font-weight: 700;
  color: var(--pkchat-muted);
  margin: 0 4px 3px;
}
.pkchat-msg--system {
  align-self: center;
  max-width: 92%;
}
.pkchat-msg--system .pkchat-msg-body {
  background: #fff7e6;
  border: 1.5px solid #ffd57e;
  color: #6b4d00;
  font-size: 12.5px;
  text-align: center;
  border-radius: 10px;
}
.pkchat-msg-pending { opacity: 0.6; }

/* ---------- Animace (iMessage feel) ---------- */
/* Zpráva „vyroste" z rohu se svým ocáskem — moje z pravého dolního,
   od agenta z levého dolního (jako iMessage). Lehký spring overshoot. */
.pkchat-msg { animation: pkchat-msg-in 0.28s cubic-bezier(0.34, 1.35, 0.5, 1) both; }
.pkchat-msg--visitor { transform-origin: 100% 100%; }
.pkchat-msg--admin   { transform-origin: 0 100%; }
.pkchat-msg--system  { transform-origin: 50% 100%; }
@keyframes pkchat-msg-in {
  from { opacity: 0; transform: scale(0.5) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
/* Načtení historie po otevření: bez animace (500 bublin najednou = chaos) */
.pkchat-noanim .pkchat-msg { animation: none; }
.pkchat-window { transform-origin: 100% 100%; }
.pkchat-root.pkchat-open .pkchat-window {
  animation: pkchat-pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}
@keyframes pkchat-pop {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: none; }
}

/* „Píše…" bublina — tři poskakující tečky */
.pkchat-typing .pkchat-msg-body {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
}
.pkchat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a9b2bc;
  animation: pkchat-typing-blink 1.2s infinite ease-in-out;
}
.pkchat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.pkchat-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes pkchat-typing-blink {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .pkchat-msg,
  .pkchat-root.pkchat-open .pkchat-window,
  .pkchat-teaser--show,
  .pkchat-typing-dot { animation: none; }
}

/* ---------- Tlačítko odkazu ve zprávě agenta ---------- */
.pkchat-msg-link {
  display: inline-block;
  margin: 6px 4px 0 0;
  background: var(--pkchat-lime);
  color: var(--pkchat-green);
  font-weight: 800;
  font-size: 12.5px;
  letter-spacing: 0.2px;
  padding: 9px 15px;
  border-radius: 100px;
  text-decoration: none;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.pkchat-msg-link:hover { filter: brightness(0.95); }
.pkchat-msg-link:active { transform: scale(0.97); }

/* ---------- Vstupní řádek ---------- */
.pkchat-inputbar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--pkchat-border);
  background: #fff;
  flex-shrink: 0;
}
.pkchat-inputbar textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--pkchat-border);
  border-radius: 12px;
  padding: 9px 12px;
  font: inherit;
  font-size: 13.5px;
  max-height: 90px;
  outline: none;
  transition: border-color 0.15s ease;
}
.pkchat-inputbar textarea:focus { border-color: var(--pkchat-purple); }
.pkchat-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--pkchat-lime);
  color: var(--pkchat-green);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.pkchat-send:hover { filter: brightness(0.95); }
.pkchat-send:active { transform: scale(0.94); }
.pkchat-send[disabled] { opacity: 0.5; cursor: not-allowed; }
.pkchat-send svg { width: 18px; height: 18px; }

/* ---------- Lišta ukončené konverzace ---------- */
.pkchat-closedbar {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--pkchat-border);
  background: #fff;
  flex-shrink: 0;
  text-align: center;
}
.pkchat-closedbar[hidden] { display: none !important; }
.pkchat-closedbar-text {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--pkchat-muted);
  line-height: 1.45;
}
.pkchat-leave-btn {
  width: 100%;
  padding: 12px 16px;
  background: var(--pkchat-purple);
  color: #fff;
  border: none;
  border-radius: 100px;
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.pkchat-leave-btn:hover { background: var(--pkchat-purple-dark); }
.pkchat-leave-btn:active { transform: scale(0.98); }

/* ---------- Potvrzení ukončení chatu (dialog uprostřed stránky) ---------- */
.pkchat-confirm {
  position: fixed;
  inset: 0;
  z-index: 99999; /* nad oknem chatu */
  background: rgba(14, 26, 35, 0.5);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pkchat-confirm[hidden] { display: none !important; }
.pkchat-confirm-box {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px 22px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(14, 26, 35, 0.35);
  animation: pkchat-pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}
.pkchat-confirm-emoji {
  width: 56px; height: 56px;
  margin: 0 auto 12px;
  background: var(--pkchat-lime);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
}
.pkchat-confirm-title {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 800;
  color: var(--pkchat-text);
  letter-spacing: -0.3px;
}
.pkchat-confirm-text {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--pkchat-muted);
}
.pkchat-confirm-yes {
  width: 100%;
  padding: 13px 16px;
  background: var(--pkchat-purple);
  color: #fff;
  border: none;
  border-radius: 100px;
  font: inherit;
  font-weight: 800;
  font-size: 14.5px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}
.pkchat-confirm-yes:hover { background: var(--pkchat-purple-dark); }
.pkchat-confirm-yes:active { transform: scale(0.98); }
.pkchat-confirm-no {
  width: 100%;
  margin-top: 8px;
  padding: 11px 16px;
  background: transparent;
  color: var(--pkchat-muted);
  border: none;
  border-radius: 100px;
  font: inherit;
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.pkchat-confirm-no:hover { background: #f0f2f5; color: var(--pkchat-text); }

/* Stav připojování / chyba v chatu */
.pkchat-status {
  text-align: center;
  font-size: 12px;
  color: var(--pkchat-muted);
  padding: 4px 10px 8px;
  background: #f7f8fb;
}
.pkchat-status[hidden] { display: none; }

/* ---------- Mobil / dotyková zařízení ----------
   ⚠️ MUSÍ být na KONCI souboru — základní pravidla mají stejnou specificitu
   a pozdější v pořadí vyhrává. (Přesně tahle chyba způsobila iOS zoom.) */

/* iOS Safari zoomuje na focus, když má pole font-size < 16px. Platí pro
   VŠECHNA dotyková zařízení (pointer: coarse) — i iPad/landscape > 480px. */
@media (pointer: coarse), (max-width: 480px) {
  .pkchat-field input[type="text"],
  .pkchat-field input[type="email"],
  .pkchat-inputbar textarea { font-size: 16px; }
}

/* Malé displeje: větší bublina + chat přes CELÝ displej (jako nativní appka) */
@media (max-width: 480px) {
  .pkchat-root { right: 14px; bottom: 14px; }
  .pkchat-bubble { width: 66px; height: 66px; }
  .pkchat-bubble svg { width: 32px; height: 32px; }
  /* Otevřený chat zabírá celý displej → bublina je zbytečná
     a překrývala by odesílací tlačítko */
  .pkchat-root.pkchat-open .pkchat-bubble { display: none; }
  .pkchat-window {
    position: fixed;
    inset: 0;
    width: auto;
    max-width: none;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border: none;
  }
  /* Header/input respektují notch a home indicator */
  .pkchat-header { padding-top: max(14px, env(safe-area-inset-top)); }
  .pkchat-inputbar { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  /* Uvítací bublina výš — větší launcher (66px) */
  .pkchat-teaser { bottom: 82px; }
}
