/* =========================================================
   Chat asistent vpravo dole (js/chat.js) – farby a písma z tokenov v style.css
   ========================================================= */

.chat {
  --chat-gap: 20px;
  position: fixed;
  right: max(var(--chat-gap), env(safe-area-inset-right));
  bottom: max(var(--chat-gap), env(safe-area-inset-bottom));
  z-index: 120;
  font-family: var(--font-body);
}

.chat__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- tlačidlo ---------- */

.chat__launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font: 800 1rem/1 var(--font-body);
  box-shadow: 0 12px 30px var(--accent-glow), var(--shadow);
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.chat__launcher:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
}

.chat__launcher:focus-visible,
.chat__close:focus-visible,
.chat__send:focus-visible,
.chat__chip:focus-visible,
.chat__link:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.chat__launcher svg {
  width: 26px;
  height: 26px;
  flex: none;
}

/* ---------- okno ---------- */

.chat__panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 2 * var(--chat-gap)));
  height: min(600px, calc(100dvh - 120px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow), 0 2px 8px rgba(42, 24, 16, 0.08);
  animation: chat-in 0.22s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.chat__panel[hidden] {
  display: none;
}

@keyframes chat-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
}

.chat__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 18px;
  background: var(--ink);
  color: var(--on-ink);
}

.chat__avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font: 800 1.35rem/1 var(--font-display);
}

.chat__who {
  display: grid;
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.chat__who strong {
  font-family: var(--font-display);
  font-size: 1.08rem;
}

.chat__who small {
  color: var(--on-ink-muted);
  font-size: 0.82rem;
}

.chat__close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--on-ink-soft);
  color: var(--on-ink);
  cursor: pointer;
}

.chat__close:hover {
  background: var(--on-ink-line);
}

.chat__close svg {
  width: 20px;
  height: 20px;
}

/* ---------- správy ---------- */

.chat__log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  padding: 18px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--paper);
}

.chat__msg {
  display: grid;
  gap: 8px;
  max-width: 88%;
}

.chat__msg--bot {
  align-self: flex-start;
}

.chat__msg--user {
  align-self: flex-end;
}

.chat__bubble {
  padding: 10px 14px;
  border-radius: 18px 18px 18px 6px;
  background: var(--white);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(42, 24, 16, 0.06);
}

.chat__msg--user .chat__bubble {
  border-radius: 18px 18px 6px 18px;
  background: var(--ink);
  color: var(--on-ink);
}

.chat__bubble a {
  color: var(--accent-text);
  font-weight: 700;
}

.chat__msg--user .chat__bubble a {
  color: var(--accent);
}

.chat__links,
.chat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat__link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--on-ink);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
}

.chat__link::after {
  content: "→";
}

.chat__link:hover {
  background: var(--ink-3);
}

.chat__chip {
  padding: 7px 12px;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  background: var(--white);
  color: var(--text);
  font: 700 0.85rem/1.3 var(--font-body);
  text-align: left;
  cursor: pointer;
}

.chat__chip:hover {
  background: var(--accent);
  color: var(--on-accent);
}

/* „asistent píše“ */
.chat__typing .chat__bubble {
  display: flex;
  gap: 5px;
  padding: 14px 16px;
}

.chat__typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-dot 1.1s infinite ease-in-out;
}

.chat__typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.chat__typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-dot {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: none;
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ---------- písanie ---------- */

.chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 12px 6px;
  border-top: 1px solid var(--line);
  background: var(--white);
}

.chat__form textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  color: var(--text);
  font: 500 1rem/1.4 var(--font-body);
  resize: none;
  overflow-y: hidden; /* posuvník až pri dlhom texte – zapína ho js/chat.js */
}

.chat__form textarea:focus {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.chat__send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

.chat__send:hover {
  background: var(--accent-hover);
}

.chat__send:disabled,
.chat__form textarea:read-only {
  opacity: 0.55;
  cursor: wait;
}

.chat__send svg {
  width: 20px;
  height: 20px;
}

.chat__note {
  margin: 0;
  padding: 0 14px 10px;
  background: var(--white);
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.4;
}

/* ---------- mobil: okno cez celú šírku zdola, tlačidlo len ikona ---------- */

@media (max-width: 560px) {
  .chat {
    --chat-gap: 16px;
  }

  .chat__launcher {
    padding: 0 18px 0 16px;
  }

  .chat.is-open .chat__launcher {
    display: none;
  }

  .chat__panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    height: min(88dvh, 640px);
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (max-width: 380px) {
  .chat__launcher-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .chat__launcher {
    width: 56px;
    padding: 0;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat__panel,
  .chat__typing i {
    animation: none;
  }

  .chat__launcher {
    transition: none;
  }

  .chat__launcher:hover {
    transform: none;
  }
}

@media print {
  .chat {
    display: none;
  }
}
