/*
 * widget.css - vzhľad chatovacieho okna.
 *
 * Beží na cudzích weboch, preto má všetko predponu `cb-` a vlastné
 * hodnoty farieb aj písma: nič si neberie zo štýlov hostiteľskej
 * stránky a nič jej nepokazí.
 *
 * Farbu si okno berie z premennej `--cb-primary`, ktorú nastavuje
 * skript podľa chatbota. Tmavú tému má len okno vložené priamo do
 * stránky (`cb-root--auto`) - na webe zákazníka je vždy svetlé, aby sa
 * vzhľad nemenil pod rukami.
 */

.cb-root {
  --cb-primary: #2f5bea;
  --cb-primary-dark: #2247c8;
  --cb-on-primary: #fff;
  --cb-panel: #fff;
  --cb-log: #f7f8fa;
  --cb-text: #14171f;
  --cb-muted: #6b7382;
  --cb-line: #e3e6ec;
  --cb-bot: #eef0f4;
  --cb-shadow: 0 18px 48px rgba(16, 20, 30, .22), 0 4px 12px rgba(16, 20, 30, .12);
  --cb-radius: 16px;

  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--cb-text);
}

.cb-root *,
.cb-root *::before,
.cb-root *::after { box-sizing: border-box; }

/* Vlastné pravidlá nižšie nastavujú `display`, čím by prebili
   `[hidden]` z prehliadača - skript skrýva okno práve ním. */
.cb-root [hidden] { display: none !important; }

/* Ikony sedia vo flexboxe (tlačidlá, hlavička). Bez tohto ich flexbox
   stlačí na nulovú šírku a z tlačidla ostane prázdna plocha. */
.cb-root svg { flex: none; }

/* ── plavák a jeho bublina ──────────────────────────────────── */

.cb-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147483000;
  display: flex;
  width: 58px;
  height: 58px;
  padding: 0;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--cb-primary);
  color: var(--cb-on-primary);
  box-shadow: var(--cb-shadow);
  cursor: pointer;
  transition: transform .18s ease, background .18s ease;
  -webkit-tap-highlight-color: transparent;
}

.cb-launcher:hover { background: var(--cb-primary-dark); transform: translateY(-2px); }
.cb-launcher:focus-visible { outline: 3px solid var(--cb-primary); outline-offset: 3px; }
.cb-launcher svg { width: 30px; height: 30px; }

.cb-teaser {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 2147483000;
  max-width: 15em;
  padding: 11px 15px;
  border: 0;
  border-radius: 14px;
  background: var(--cb-panel);
  color: var(--cb-text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  box-shadow: 0 8px 22px rgba(16, 20, 30, .16);
  cursor: pointer;
}

.cb-teaser::after {
  content: "";
  position: absolute;
  right: 21px;
  bottom: -6px;
  width: 14px;
  height: 14px;
  border-radius: 0 0 3px 0;
  background: var(--cb-panel);
  transform: rotate(45deg);
}

/* ── zákryt na mobile ───────────────────────────────────────── */

.cb-veil {
  position: fixed;
  inset: 0;
  z-index: 2147483100;
  background: rgba(10, 13, 20, .45);
}

/* ── okno ───────────────────────────────────────────────────── */

.cb-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147483200;
  display: flex;
  width: 384px;
  height: 580px;
  max-height: calc(100vh - 44px);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--cb-line);
  border-radius: var(--cb-radius);
  background: var(--cb-panel);
  box-shadow: var(--cb-shadow);
  animation: cb-in .2s ease-out;
}

@keyframes cb-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* Okno vložené priamo do stránky - žiadny plavák, žiadne plávanie. */
.cb-panel--inline {
  position: static;
  width: 100%;
  height: min(620px, 78vh);
  max-height: none;
  animation: none;
}

/* ── hlavička ───────────────────────────────────────────────── */

.cb-head {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  background: var(--cb-primary);
  color: var(--cb-on-primary);
}

.cb-head-avatar {
  display: flex;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, .18);
}

.cb-head-avatar svg { width: 24px; height: 24px; }

.cb-head-text { min-width: 0; flex: 1; }
.cb-head-name { font-weight: 600; }

.cb-head-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: .9;
}

.cb-head-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
}

.cb-head-close {
  display: flex;
  padding: 7px;
  align-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.cb-head-close:hover { background: rgba(255, 255, 255, .18); }
.cb-head-close svg { width: 18px; height: 18px; }

/* ── výpis správ ────────────────────────────────────────────── */

.cb-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 16px 14px;
  background: var(--cb-log);
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.cb-log::-webkit-scrollbar { width: 7px; }
.cb-log::-webkit-scrollbar-thumb { border-radius: 4px; background: rgba(120, 130, 150, .4); }

.cb-msg { max-width: 86%; }
.cb-msg.is-user { align-self: flex-end; }

.cb-text {
  padding: 10px 13px;
  border-radius: 15px;
  overflow-wrap: anywhere;
}

.is-bot .cb-text {
  border-bottom-left-radius: 5px;
  background: var(--cb-bot);
}

.is-user .cb-text {
  border-bottom-right-radius: 5px;
  background: var(--cb-primary);
  color: var(--cb-on-primary);
}

.cb-time {
  margin-top: 4px;
  color: var(--cb-muted);
  font-size: 11px;
}

.is-user .cb-time { text-align: right; }

.cb-text a { color: var(--cb-primary); overflow-wrap: anywhere; }
.is-user .cb-text a { color: inherit; }

.cb-text p { margin: 0 0 .5em; }
.cb-text > :last-child { margin-bottom: 0; }
.cb-text h3, .cb-text h4 { margin: .6em 0 .3em; font-size: 1em; }
.cb-text ul, .cb-text ol { margin: .4em 0; padding-left: 1.35em; }
.cb-text li { margin: .15em 0; }
.cb-text strong { font-weight: 600; }

.cb-text code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(120, 130, 150, .18);
  font: .87em ui-monospace, Consolas, monospace;
}

.cb-table {
  display: block;
  overflow-x: auto;
  margin: .5em 0;
  border-collapse: collapse;
  font-size: .93em;
}

.cb-table th,
.cb-table td {
  padding: 4px 8px;
  border: 1px solid var(--cb-line);
  text-align: left;
  vertical-align: top;
}

.cb-table th { background: rgba(120, 130, 150, .12); }

/* ── karty tovaru ───────────────────────────────────────────── */

.cb-goods {
  display: flex;
  margin: 8px 0 0;
  padding: 0;
  flex-direction: column;
  gap: 8px;
  list-style: none;
}

.cb-good {
  display: flex;
  gap: 11px;
  padding: 9px;
  border: 1px solid var(--cb-line);
  border-radius: 13px;
  background: var(--cb-panel);
  color: inherit;
  text-decoration: none;
  transition: border-color .15s ease, transform .15s ease;
}

.cb-good:hover { border-color: var(--cb-primary); transform: translateY(-1px); }

.cb-good-img {
  width: 62px;
  height: 62px;
  flex-shrink: 0;
  border-radius: 9px;
  background: #fff;
  object-fit: contain;
}

.cb-good-body { display: flex; min-width: 0; flex-direction: column; gap: 2px; }

.cb-good-name {
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.cb-good-price { color: var(--cb-primary); font-weight: 600; }
.cb-good-stock { color: var(--cb-muted); font-size: 12px; }

/* ── ponúknuté otázky ───────────────────────────────────────── */

/* Uvádzacia veta nad ponúknutými otázkami. Vyzerá ako čas pri správe,
   ale nie je to čas - a od otázok potrebuje odsadiť. */
.cb-hint {
  margin: 0 0 9px 2px;
  color: var(--cb-muted);
  font-size: 12px;
}

.cb-chips {
  display: flex;
  margin: 0;
  padding: 0;
  flex-wrap: wrap;
  gap: 7px;
  list-style: none;
}

.cb-chip {
  padding: 8px 13px;
  border: 1px solid var(--cb-line);
  border-radius: 999px;
  background: var(--cb-panel);
  color: var(--cb-primary);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

.cb-chip:hover { border-color: var(--cb-primary); background: rgba(47, 91, 234, .07); }

/* ── píše… ──────────────────────────────────────────────────── */

.cb-typing {
  display: flex;
  align-self: flex-start;
  gap: 4px;
  padding: 13px 15px;
  border-radius: 15px;
  border-bottom-left-radius: 5px;
  background: var(--cb-bot);
}

.cb-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cb-muted);
  animation: cb-dot 1.3s infinite ease-in-out;
}

.cb-typing span:nth-child(2) { animation-delay: .15s; }
.cb-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes cb-dot {
  0%, 60%, 100% { opacity: .35; transform: none; }
  30% { opacity: 1; transform: translateY(-5px); }
}

/* ── zadávanie ──────────────────────────────────────────────── */

.cb-form {
  display: flex;
  flex-shrink: 0;
  align-items: flex-end;
  gap: 8px;
  padding: 11px;
  border-top: 1px solid var(--cb-line);
  background: var(--cb-panel);
}

.cb-input {
  min-width: 0;
  height: 44px;
  max-height: 110px;
  flex: 1;
  padding: 11px 13px;
  border: 1px solid var(--cb-line);
  border-radius: 12px;
  background: var(--cb-panel);
  color: inherit;
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
  resize: none;
  overflow-y: auto;
  scrollbar-width: none;
}

.cb-input::-webkit-scrollbar { display: none; }
.cb-input:focus { border-color: var(--cb-primary); outline: none; }

.cb-send {
  display: flex;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  background: var(--cb-primary);
  color: var(--cb-on-primary);
  cursor: pointer;
  transition: background .15s ease;
}

.cb-send:hover:not(:disabled) { background: var(--cb-primary-dark); }
.cb-send:disabled { background: var(--cb-muted); cursor: default; }
.cb-send svg { width: 19px; height: 19px; }

.cb-foot {
  flex-shrink: 0;
  padding: 7px 12px;
  border-top: 1px solid var(--cb-line);
  color: var(--cb-muted);
  font-size: 11px;
  text-align: center;
}

.cb-error {
  padding: 9px 12px;
  border-radius: 10px;
  background: #fdecec;
  color: #9b2c2c;
  font-size: 14px;
}

/* ── mobil ──────────────────────────────────────────────────── */

@media (max-width: 640px) {
  .cb-panel:not(.cb-panel--inline) {
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .cb-panel.cb-vv { height: var(--cb-vv, 100dvh); max-height: var(--cb-vv, 100dvh); }
  .cb-panel:not(.cb-panel--inline) .cb-foot { display: none; }
  .cb-head { padding-top: max(13px, env(safe-area-inset-top)); }
  .cb-form { padding-bottom: max(11px, env(safe-area-inset-bottom)); }
  .cb-launcher { right: 16px; bottom: 16px; }
  .cb-teaser { right: 16px; bottom: 84px; }
  .cb-msg { max-width: 92%; }
}

/* ── tmavá téma (len okno vložené do našej stránky) ─────────── */

/* Stránka s prepínačom režimu (vizuály 2 až 4) zapisuje voľbu do
   `data-mode` na <html> - okno ide podľa nej, nie podľa systému. Inak by
   pri tmavom systéme a svetlej voľbe ostalo tmavé na svetlej stránke.
   Stránka bez prepínača (prvý vizuál) nemá `data-mode` a okno sa riadi
   systémom ako doteraz. */
:root[data-mode="dark"] .cb-root--auto {
  --cb-panel: #171b23;
  --cb-log: #12161d;
  --cb-text: #e8eaf0;
  --cb-muted: #98a1b3;
  --cb-line: #29303c;
  --cb-bot: #222834;
  --cb-shadow: 0 18px 48px rgba(0, 0, 0, .5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-mode]) .cb-root--auto {
    --cb-panel: #171b23;
    --cb-log: #12161d;
    --cb-text: #e8eaf0;
    --cb-muted: #98a1b3;
    --cb-line: #29303c;
    --cb-bot: #222834;
    --cb-shadow: 0 18px 48px rgba(0, 0, 0, .5);
  }
}

:root[data-mode="dark"] .cb-root--auto .cb-good-img { background: #fff; }
:root[data-mode="dark"] .cb-root--auto .cb-chip { background: transparent; }
:root[data-mode="dark"] .cb-root--auto .cb-error { background: #3a1f1f; color: #ffb4b4; }

@media (prefers-color-scheme: dark) {
  :root:not([data-mode]) .cb-root--auto .cb-good-img { background: #fff; }
  :root:not([data-mode]) .cb-root--auto .cb-chip { background: transparent; }
  :root:not([data-mode]) .cb-root--auto .cb-error { background: #3a1f1f; color: #ffb4b4; }
}

/* Odkaz na náhľad „na vašom webe“ - má ho len okno na našej ukážkovej
   stránke, na webe zákazníka nie. */
.cb-head-open {
  display: flex;
  padding: 7px;
  align-items: center;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}

.cb-head-open:hover { background: rgba(255, 255, 255, .18); }
.cb-head-open svg { width: 17px; height: 17px; }
