/* =========================================================================
   JP Facility Services — Chatbot (Chat-Fenster unten rechts)
   Nutzt die Farbvariablen aus style.css (Firmengrün #8D9D7A / #5F6D4E)
   ========================================================================= */

#jpchat, #jpchat * { box-sizing: border-box; }

#jpchat {
  --c-green: var(--green-dark, #5F6D4E);
  --c-green-2: var(--green, #8D9D7A);
  --c-beige: var(--cream, #F8F5EF);
  --c-ink: var(--ink, #24261F);
  --c-muted: var(--muted, #5F6252);
  --c-line: var(--line, #E7E2D7);
  font-family: var(--font, "Manrope", "Segoe UI", system-ui, sans-serif);
  color: var(--c-ink);
  line-height: 1.5;
  font-size: 15px;
}

/* ---------- Startknopf (Maskottchen) ---------- */
.jpc-launch {
  position: fixed; right: 16px; bottom: 14px; z-index: 90;
  width: 78px; height: 101px; padding: 0; border: 0; cursor: pointer;
  background: transparent; color: #fff; display: block;
  filter: drop-shadow(0 8px 14px rgba(30,36,20,.38));
  transition: transform .22s ease, filter .22s ease;
  -webkit-tap-highlight-color: transparent;
}
.jpc-launch:hover { transform: translateY(-4px) scale(1.04); filter: drop-shadow(0 12px 18px rgba(30,36,20,.45)); }
.jpc-launch:focus-visible, .jpc-close:focus-visible, .jpc-send:focus-visible,
.jpc-chip:focus-visible, .jpc-input:focus-visible, .jpc-form button:focus-visible {
  outline: 3px solid #E0A83B; outline-offset: 2px;
}
.jpc-avatar { display: block; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; pointer-events: none; user-select: none; }
.jpc-launch .jpc-ic-close { display: none; }
.jpc-launch .jpc-ic-close svg { width: 26px; height: 26px; }
/* Geöffnet: kleiner runder Schließen-Knopf statt Figur */
#jpchat.open .jpc-launch {
  width: 56px; height: 56px; border-radius: 50%; background: var(--c-green);
  display: grid; place-items: center;
  filter: drop-shadow(0 8px 16px rgba(30,36,20,.32));
  right: 18px; bottom: 18px;
}
#jpchat.open .jpc-launch .jpc-avatar { display: none; }
#jpchat.open .jpc-launch .jpc-ic-close { display: block; }
.jpc-dot {
  position: absolute; top: 4px; right: 4px; width: 16px; height: 16px; border-radius: 50%;
  background: #E0A83B; border: 2.5px solid #fff;
}
#jpchat.open .jpc-dot, #jpchat.seen .jpc-dot { display: none; }

/* ---------- Fenster ---------- */
.jpc-panel {
  position: fixed; right: 18px; bottom: 90px; z-index: 91;
  width: 372px; max-width: calc(100vw - 24px);
  height: min(560px, calc(100vh - 120px)); height: min(560px, calc(100dvh - 120px));
  background: #fff; border-radius: 22px; overflow: hidden;
  border: 1px solid var(--c-line);
  box-shadow: 0 26px 70px rgba(30,36,20,.28);
  display: none; flex-direction: column;
}
#jpchat.open .jpc-panel { display: flex; animation: jpc-in .22s ease; }
@keyframes jpc-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.jpc-head {
  background: var(--c-green); color: #fff; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; flex: 0 0 auto;
}
.jpc-logo { width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto; background: #F8F5EF; object-fit: cover; object-position: 50% 22%; border: 2px solid rgba(255,255,255,.75); }
.jpc-title { flex: 1; min-width: 0; }
.jpc-title b { display: block; font-family: var(--head, "Sora", "Manrope", sans-serif); font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.jpc-title span { display: block; font-size: 12px; opacity: .88; }
.jpc-close {
  width: 34px; height: 34px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(255,255,255,.16); color: #fff; display: grid; place-items: center;
}
.jpc-close:hover { background: rgba(255,255,255,.28); }
.jpc-close svg { width: 16px; height: 16px; }

.jpc-log {
  flex: 1 1 auto; overflow-y: auto; padding: 14px 14px 6px;
  background: var(--c-beige); display: flex; flex-direction: column; gap: 9px;
  scroll-behavior: smooth; overscroll-behavior: contain;
}
.jpc-msg {
  max-width: 86%; padding: 10px 13px; border-radius: 16px; font-size: 14.5px;
  overflow-wrap: anywhere; word-break: break-word;
}
.jpc-msg p + p { margin-top: 6px; }
.jpc-msg a { color: inherit; text-decoration: underline; font-weight: 600; }
.jpc-bot { align-self: flex-start; background: #fff; border: 1px solid var(--c-line); border-bottom-left-radius: 5px; }
.jpc-user { align-self: flex-end; background: var(--c-green); color: #fff; border-bottom-right-radius: 5px; }
.jpc-note {
  align-self: center; text-align: center; max-width: 94%;
  font-size: 12px; color: var(--c-muted); padding: 2px 6px;
}
.jpc-note a { color: var(--c-green); font-weight: 600; text-decoration: underline; }

.jpc-typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.jpc-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--c-green-2); animation: jpc-b 1.1s infinite ease-in-out; }
.jpc-typing i:nth-child(2) { animation-delay: .15s; }
.jpc-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes jpc-b { 0%,80%,100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }

.jpc-log > .jpc-chip { align-self: flex-start; }
.jpc-chips { display: flex; flex-wrap: wrap; gap: 7px; align-self: flex-start; max-width: 100%; }
.jpc-chip {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  background: #fff; color: var(--c-green); border: 1.5px solid var(--c-green-2);
  border-radius: 999px; padding: 7px 13px; transition: background .15s, color .15s;
}
.jpc-chip:hover { background: var(--c-green); color: #fff; border-color: var(--c-green); }

/* ---------- Anfrage-Formular im Chat ---------- */
.jpc-form {
  align-self: stretch; background: #fff; border: 1.5px solid var(--c-green-2);
  border-radius: 16px; padding: 13px; display: grid; gap: 8px;
}
.jpc-form h4 { font-family: var(--head, "Sora", sans-serif); font-size: 14px; margin: 0 0 1px; }
.jpc-form label { font-size: 12px; font-weight: 600; color: var(--c-muted); display: grid; gap: 3px; }
.jpc-form input[type=text], .jpc-form input[type=tel], .jpc-form input[type=email], .jpc-form textarea {
  font: inherit; font-size: 14px; width: 100%; padding: 9px 11px; color: var(--c-ink);
  border: 1.5px solid var(--c-line); border-radius: 10px; background: #fff;
}
.jpc-form textarea { resize: vertical; min-height: 58px; max-height: 120px; }
.jpc-form input:focus, .jpc-form textarea:focus { outline: none; border-color: var(--c-green); }
.jpc-form .jpc-check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; line-height: 1.4; }
.jpc-form .jpc-check input { margin-top: 3px; flex: 0 0 auto; accent-color: var(--c-green); }
.jpc-form .jpc-check a { color: var(--c-green); text-decoration: underline; font-weight: 600; }
.jpc-form button[type=submit] {
  font: inherit; font-weight: 700; cursor: pointer; border: 0; border-radius: 999px;
  background: var(--c-green); color: #fff; padding: 11px 16px;
}
.jpc-form button[type=submit]:hover { background: #4E5A40; }
.jpc-form button[disabled] { opacity: .6; cursor: default; }
.jpc-form .jpc-cancel { font: inherit; font-size: 12.5px; background: none; border: 0; color: var(--c-muted); text-decoration: underline; cursor: pointer; justify-self: center; }
.jpc-form .jpc-err { color: #A5432A; font-size: 12.5px; font-weight: 600; }
.jpc-form .jpc-hint { font-size: 12px; color: var(--c-muted); margin-top: -3px; }
.jpc-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }

/* ---------- Eingabe ---------- */
.jpc-foot { flex: 0 0 auto; border-top: 1px solid var(--c-line); background: #fff; padding: 10px 12px 8px; }
.jpc-row { display: flex; gap: 8px; align-items: flex-end; }
.jpc-input {
  flex: 1; font: inherit; font-size: 16px; /* 16px verhindert Zoom auf iPhones */
  resize: none; height: 42px; max-height: 96px; padding: 9px 13px; color: var(--c-ink);
  overflow: hidden; line-height: 22px;
  border: 1.5px solid var(--c-line); border-radius: 21px; background: var(--c-beige);
}
.jpc-input:focus { outline: none; border-color: var(--c-green); background: #fff; }
.jpc-send {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--c-green); color: #fff; display: grid; place-items: center;
}
.jpc-send:hover { background: #4E5A40; }
.jpc-send[disabled] { opacity: .5; cursor: default; }
.jpc-send svg { width: 19px; height: 19px; }
.jpc-legal { font-size: 11px; color: var(--c-muted); text-align: center; margin-top: 7px; line-height: 1.35; }
.jpc-legal a { color: var(--c-green); text-decoration: underline; }

/* ---------- Handy ---------- */
@media (max-width: 720px) {
  .jpc-launch { right: 12px; bottom: 84px; width: 64px; height: 83px; } /* über der Anruf-Leiste */
  .jpc-panel {
    right: 8px; left: 8px; width: auto; max-width: none; bottom: 8px;
    height: min(620px, calc(100vh - 16px)); height: min(620px, calc(100dvh - 16px));
    border-radius: 20px;
  }
  /* Bei geöffnetem Chat Anruf-Leiste unter dem Fenster nicht stören */
  #jpchat.open .jpc-launch { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .jpc-log { scroll-behavior: auto; }
  #jpchat.open .jpc-panel { animation: none; }
  .jpc-typing i { animation: none; }
}
@media print { #jpchat { display: none !important; } }
