/**
 * CARNET Virtualni asistent (inc/chatbot.php, assets/js/chatbot.js).
 * Samo boje DOMENE.HR (tokeni iz domene.css). Purple je ovdje samo dekor (crta), nikad tekst na svijetlom.
 * Kontrasti: Off-Black na Off-White 50 ≈ 17:1, Black 75 na Off-White 50 7,4:1, Off-White 50 na Off-Black 16:1.
 */

.dm-bot {
  --bot-gap: 16px;
  --bot-lift: 0px;   /* podizanje iznad drugih plutajućih gumba */
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: var(--lh-md);
  font-weight: 400;
  color: var(--black-100);
}

/* OneTap (pristupačnost) stoji dolje desno s najvećim z-indexom: chatbot ide iznad njega. */
body:has(.onetap-toggle) .dm-bot { --bot-lift: 68px; }

.dm-bot .screen-reader-text {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

:where(.dm-bot), :where(.dm-bot) *, :where(.dm-bot) *::before { box-sizing: border-box; }
:where(.dm-bot) button { font: inherit; color: inherit; cursor: pointer; }
:where(.dm-bot) button:disabled { cursor: default; }
.dm-bot [hidden] { display: none !important; }
.dm-bot .dm-icon { width: 24px; height: 24px; }

/* ---------- gumb za otvaranje ---------- */
.dm-bot__launcher {
  position: fixed;
  right: var(--bot-gap);
  bottom: calc(var(--bot-gap) + var(--bot-lift));
  z-index: 99990;
  display: grid;
  place-items: center;
  width: 56px; height: 56px;
  padding: 0;
  border: 2px solid var(--white-50);
  border-radius: 50%;
  background: var(--black-100);
  color: var(--white-50);
  box-shadow: 0 4px 16px rgb(14 14 14 / .25);
  transition: transform .15s ease;
}
.dm-bot__launcher:hover { transform: scale(1.06); }
.dm-bot__launcher .dm-icon { width: 28px; height: 28px; }

/* ---------- poruka iznad gumba ---------- */
.dm-bot__hint {
  position: fixed;
  right: var(--bot-gap);
  bottom: calc(var(--bot-gap) + var(--bot-lift) + 68px);
  z-index: 99990;
  display: flex;
  align-items: stretch;
  max-width: calc(100vw - 2 * var(--bot-gap));
  border-radius: var(--radius);
  background: var(--black-100);
  color: var(--white-50);
  box-shadow: 0 4px 16px rgb(14 14 14 / .25);
}
.dm-bot__hint::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--purple);
}
.dm-bot__hint-text {
  padding: 12px 8px 12px 20px;
  border: 0;
  background: none;
  font-size: var(--fs-sm);
  font-weight: 600;
  text-align: left;
}
.dm-bot__hint-text:hover { text-decoration: underline; text-underline-offset: 3px; }
.dm-bot__hint-close {
  display: grid; place-items: center;
  width: 44px; min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
}
.dm-bot__hint-close .dm-icon { width: 20px; height: 20px; }
.dm-bot__hint :focus-visible { outline: 2px solid var(--blue); outline-offset: -4px; }

/* ---------- prozor ---------- */
.dm-bot__panel {
  position: fixed;
  right: var(--bot-gap);
  bottom: calc(var(--bot-gap) + var(--bot-lift));
  z-index: 110001;   /* iznad WP admin trake (Divi joj daje 110000) */
  display: flex;
  flex-direction: column;
  width: 400px;
  height: min(640px, calc(100vh - 2 * var(--bot-gap) - var(--bot-lift)));
  height: min(640px, calc(100dvh - 2 * var(--bot-gap) - var(--bot-lift)));
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--white-50);
  box-shadow: 0 8px 32px rgb(14 14 14 / .3);
}

.dm-bot__top {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: 0 4px 0 16px;
  border-bottom: 4px solid var(--purple);
  background: var(--black-100);
  color: var(--white-50);
}
.dm-bot__top [data-bot-home]:not([hidden]) { margin-left: -12px; }
.dm-bot__title {
  flex: 1;
  margin: 0;
  padding: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: var(--lh-md);
  font-weight: 600;
  letter-spacing: 0;
  color: inherit;
}
.dm-bot__top :focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }

.dm-bot__icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px; height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
}
.dm-bot__icon-btn:hover:not(:disabled) { background: rgb(135 135 135 / .2); }
.dm-bot__icon-btn--line { border: 1px solid var(--black-100); border-radius: 50%; }
.dm-bot__icon-btn--line:disabled { border-color: var(--white-100); color: var(--black-50); }

/* ---------- tijelo ---------- */
.dm-bot__body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 16px;
}

.dm-bot__greeting {
  margin: 24px 0 16px;
  padding: 0;
  font-size: var(--fs-h6);
  line-height: var(--lh-h6);
  font-weight: 600;
}

.dm-bot__options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.dm-bot__option {
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--black-100);
  border-radius: 999px;
  background: transparent;
  font-size: var(--fs-sm);
  line-height: var(--lh-sm);
  font-weight: 600;
  text-align: left;
}
.dm-bot__option:hover:not(:disabled),
.dm-bot__option.is-chosen { background: var(--black-100); color: var(--white-50); }
.dm-bot__option:disabled:not(.is-chosen) { border-color: var(--white-100); color: var(--black-75); }

.dm-bot__link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-top: 24px;
  padding: 0;
  border: 0;
  background: none;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.dm-bot__link .dm-icon { width: 20px; height: 20px; }

/* poruke */
.dm-bot__log { display: flex; flex-direction: column; gap: 16px; }
.dm-bot__msg { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; max-width: 100%; }
.dm-bot__msg--user { align-items: flex-end; }
.dm-bot__bubble {
  max-width: 88%;
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--white-75);
  font-size: var(--fs-sm);
  line-height: var(--lh-sm);
  overflow-wrap: anywhere;
}
.dm-bot__msg--user .dm-bot__bubble { background: var(--black-100); color: var(--white-50); }
/* Oblačić je <p>, a Divijev p:not(.has-background):last-of-type mu briše donji padding (tekst je sjedao na rub) */
.dm-bot .dm-bot__log p.dm-bot__bubble { padding: 12px 16px; }
.dm-bot__bubble a,
.dm-bot__card a,
.dm-bot__related a,
.dm-bot__step a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.dm-bot__bubble p,
.dm-bot__step p { margin: 0 0 8px; padding: 0; }

.dm-bot__card,
.dm-bot__related {
  width: 100%;
  padding: 16px;
  border: 1px solid var(--white-100);
  border-left: 4px solid var(--purple);
  border-radius: var(--radius);
  background: var(--white-50);
  font-size: var(--fs-sm);
  line-height: var(--lh-sm);
}
.dm-bot__card-title { margin: 0 0 8px; padding: 0; font-weight: 600; }
.dm-bot__card-text { margin-bottom: 16px; }

.dm-bot__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--black-100);
  color: var(--white-50) !important;
  font-size: var(--fs-md);
  font-weight: 600;
  text-decoration: none !important;
}
.dm-bot__btn .dm-icon { width: 20px; height: 20px; }
.dm-bot__btn:disabled { background: var(--white-100); color: var(--black-75) !important; }

.dm-bot__img { max-width: 100%; height: auto; border-radius: var(--radius); }
.dm-bot__iframe { width: 100%; height: 200px; border: 0; border-radius: var(--radius); }

/* piše… */
.dm-bot__typing { display: flex; gap: 4px; padding: 12px 16px; }
.dm-bot__typing span:not(.screen-reader-text) {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--black-75);
  animation: dm-bot-dot 1s infinite ease-in-out;
}
.dm-bot__typing span:nth-child(2) { animation-delay: .15s; }
.dm-bot__typing span:nth-child(3) { animation-delay: .3s; }
@keyframes dm-bot-dot { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* obrazac iz razgovora */
.dm-bot__field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.dm-bot__field label { font-size: var(--fs-sm); font-weight: 600; }
.dm-bot__field input:not([type=checkbox]),
.dm-bot__field select {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--black-75);
  border-radius: var(--radius);
  background: var(--white-50);
  color: var(--black-100);
  font: inherit;
}
.dm-bot__field--check { flex-direction: row; align-items: flex-start; gap: 8px; }
.dm-bot__field--check input { width: 24px; height: 24px; margin: 0; accent-color: var(--black-100); }
.dm-bot__field--check label { font-weight: 400; }
.dm-bot__field [aria-invalid=true] { border-width: 2px; border-color: var(--black-100); }
.dm-bot__error:not(:empty) {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-left: 4px solid var(--black-100);
  background: var(--white-75);
  font-weight: 600;
}

/* ---------- unos ---------- */
.dm-bot__form {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  margin: 0;
  padding: 8px 8px 8px 16px;
  border-top: 1px solid var(--white-100);
  background: var(--white-50);
}
.dm-bot__input {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 12px;
  border: 1px solid var(--black-75);
  border-radius: var(--radius);
  background: var(--white-50);
  color: var(--black-100);
  font: inherit;
  font-size: var(--fs-md);
  resize: none;
}
.dm-bot__input::placeholder { color: var(--black-75); opacity: 1; }
.dm-bot__send { background: var(--black-100); color: var(--white-50); border-radius: 50%; }
.dm-bot__send:hover:not(:disabled) { background: var(--black-75); }
.dm-bot__send:disabled { background: var(--white-100); color: var(--black-75); }

/* ---------- ploča (koraci, prijedlozi) ---------- */
.dm-bot__sheet {
  position: absolute;
  inset: 60px 0 0;
  display: flex;
  flex-direction: column;
  background: var(--white-50);
}
.dm-bot__sheet-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px 8px 16px;
  border-bottom: 1px solid var(--white-100);
}
.dm-bot__sheet-title {
  flex: 1;
  margin: 0;
  padding: 0;
  font-family: var(--font);
  font-size: var(--fs-h6);
  line-height: var(--lh-h6);
  font-weight: 600;
  color: var(--black-100);
}
.dm-bot__sheet-title:focus { outline: none; }
.dm-bot__sheet-body { flex: 1; overflow-y: auto; padding: 16px; font-size: var(--fs-sm); line-height: var(--lh-sm); }
.dm-bot__sheet-sec + .dm-bot__sheet-sec { margin-top: 24px; }
.dm-bot__sheet-sec .dm-bot__related + .dm-bot__related { margin-top: 8px; }
.dm-bot__sheet-h {
  margin: 0 0 8px;
  padding: 0;
  font-family: var(--font);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--black-75);
}
.dm-bot__muted { margin: 0; padding: 0; color: var(--black-75); }
.dm-bot__step-count { margin: 0 0 8px; padding: 0; color: var(--black-75); font-weight: 600; }
.dm-bot__step-title { margin: 0 0 8px; padding: 0; font-size: var(--fs-md); font-weight: 600; }
.dm-bot__step-nav { display: flex; gap: 8px; margin-top: 16px; }

/* ---------- mobitel: preko cijelog zaslona ---------- */
@media (max-width: 479px) {
  .dm-bot__panel { inset: 0; width: auto; height: auto; border-radius: 0; }
  /* prozor je preko cijelog zaslona; OneTap i CookieYes bi prekrili unos i gumb „Pošalji" */
  html.dm-bot-open .onetap-toggle { visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .dm-bot__launcher { transition: none; }
  .dm-bot__launcher:hover { transform: none; }
  .dm-bot__typing span:not(.screen-reader-text) { animation: none; opacity: .6; }
}
