/* ============================================================
   chat.css — "Chat s podrškom" widget (učitava se na SVIM stranicama).
   Launcher + panel žive na z-index 130: iznad zaglavlja (100) i mobilne
   tab trake (120), ispod bottom sheeta (150/160) i pretrage (200).
   Boje isključivo preko design tokena iz main.css → radi u obje teme.
   ============================================================ */

/* ---------- Launcher ---------- */
.chat-launcher {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 130;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--at-orange-600), var(--at-orange-500));
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}

.chat-launcher:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: var(--shadow-3);
}

.chat-launcher:active { transform: scale(0.94); }

.chat-launcher svg {
  width: 26px;
  height: 26px;
}

/* iznad mobilne tab trake + sigurnosna zona (notch) */
@media (max-width: 768px) {
  .chat-launcher {
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 1rem);
  }
}

/* ---------- Panel ---------- */
.chat-panel {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + 54px + 0.75rem);
  z-index: 130;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 2rem));
  height: min(560px, calc(100dvh - var(--header-h) - 2rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity 240ms var(--ease-out), transform 240ms var(--ease-out);
}

.chat-panel.is-open {
  opacity: 1;
  transform: none;
}

/* mobitel: sheet preko cijelog ekrana (i preko tab trake — z 130 > 120) */
@media (max-width: 768px) {
  .chat-panel {
    inset: 0;
    width: auto;
    height: auto;
    border: 0;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(4%);
  }
  .chat-panel.is-open { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel {
    transition: none;
    transform: none;
  }
}

/* ---------- Zaglavlje panela ---------- */
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: linear-gradient(135deg, var(--at-navy-900), var(--at-navy-700));
  color: #e8f0f7;
  flex: none;
}

.chat-head-title {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 800;
  font-size: 1rem;
  color: #fff;
}

.chat-head-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--at-sky-400);
  box-shadow: 0 0 0 3px rgba(51, 204, 255, 0.25);
}

.chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  transition: background-color var(--t-fast);
}

.chat-close:hover { background: rgba(255, 255, 255, 0.22); }

/* ---------- Razgovor ---------- */
.chat-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-log {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: 86%;
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  font-size: 0.94rem;
  line-height: 1.5;
  overflow-wrap: break-word;
}

.chat-msg p { margin: 0 0 0.45em; }
.chat-msg p:last-child { margin-bottom: 0; }
.chat-msg ul { margin: 0.2em 0 0.45em; padding-left: 1.15em; }
.chat-msg ul:last-child { margin-bottom: 0; }
.chat-msg a { text-decoration: underline; }

.chat-msg--user {
  align-self: flex-end;
  background: var(--at-navy-800);
  color: #fff;
  border-bottom-right-radius: 4px;
}

:root[data-theme='dark'] .chat-msg--user {
  background: var(--at-orange-500);
  color: var(--at-navy-950);
}

.chat-msg--bot {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-msg--bot a { color: var(--link); }
.chat-msg--bot a:hover { color: var(--link-hover); }

.chat-msg--error {
  background: var(--danger-soft);
  color: var(--danger);
}

/* izvori ispod odgovora */
.chat-sources {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.55rem;
  max-width: 86%;
  margin-top: -0.2rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.chat-sources-label { font-weight: 700; }

.chat-source {
  padding: 0.12rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--at-sky-ink);
  text-decoration: none;
}

.chat-source:hover {
  border-color: var(--at-sky);
  color: var(--at-sky-ink);
  background: var(--at-sky-soft);
}

/* indikator tipkanja */
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 2.1em;
}

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

.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-typing-bounce {
  0%, 60%, 100% { transform: none; opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-typing-dot { animation: none; }
}

/* prijedlozi (chipovi) */
.chat-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.75rem;
  flex: none;
}

.chat-chip { font-size: 0.82rem; }

/* traka za eskalaciju */
.chat-escalate-bar {
  padding: 0 1rem 0.55rem;
  flex: none;
}

.chat-escalate-btn {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast), background-color var(--t-fast);
}

.chat-escalate-btn:hover,
.chat-escalate-btn.is-suggested {
  border-color: var(--at-orange);
  border-style: solid;
  color: var(--at-orange-ink);
  background: var(--at-orange-soft);
}

/* ---------- Forma za poruku ---------- */
.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}

.chat-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.6rem 0.9rem;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-pill);
  font: inherit;
  font-size: 0.94rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.chat-input::placeholder { color: var(--text-muted); opacity: 0.8; }

.chat-input:focus-visible {
  outline: none;
  border-color: var(--at-orange);
  box-shadow: 0 0 0 4px var(--at-orange-soft);
}

.chat-send {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--at-orange-600), var(--at-orange-500));
  color: #fff;
  cursor: pointer;
  transition: transform var(--t-fast), filter var(--t-fast);
}

.chat-send:hover { transform: translateY(-1px); filter: saturate(1.08); }
.chat-send:disabled { opacity: 0.55; cursor: default; transform: none; }

/* ---------- Eskalacija ---------- */
.chat-escalation {
  flex: 1 1 auto;
  padding: 1rem;
  overflow-y: auto;
}

.chat-esc-title {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.chat-esc-intro {
  margin: 0 0 0.9rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.chat-esc-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.chat-esc-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.86rem;
  font-weight: 600;
}

.chat-esc-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.chat-esc-status {
  margin: 0;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.86rem;
}

.chat-esc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ---------- Uspjeh ---------- */
.chat-done {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem;
  text-align: center;
}

.chat-done-icon { color: var(--live); }
.chat-done h2 { margin: 0; font-size: 1.15rem; }
.chat-done p { margin: 0 0 0.6rem; color: var(--text-muted); font-size: 0.94rem; }

/* honeypot — dijele ga chat i /podrska forma */
.hp-field {
  position: absolute !important;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ispis: widget nema smisla na papiru */
@media print {
  .chat-launcher,
  .chat-panel { display: none !important; }
}
