/* ============================================================
   SHAWO KI-Web-Chat Widget — Design-System v2 konsistent
   Tokens: --c-ink #0B3D4F, --c-cyan #0891B2, --c-cream #FFFBF5
   ============================================================ */

.shawo-chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 61, 79, 0.45);
  backdrop-filter: blur(2px);
  z-index: 99998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.shawo-chat-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.shawo-chat-fab {
  position: fixed;
  right: calc(1rem + env(safe-area-inset-right, 0px));
  bottom: calc(8rem + env(safe-area-inset-bottom, 0px));
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #0891B2, #0B3D4F);
  color: #FFFFFF;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(8, 145, 178, 0.35);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.shawo-chat-fab:hover { transform: scale(1.06); }
.shawo-chat-fab svg { width: 1.5rem; height: 1.5rem; }

.shawo-chat-panel {
  position: fixed;
  right: 1rem;
  bottom: calc(8rem + env(safe-area-inset-bottom, 0px));
  width: min(24rem, calc(100vw - 2rem));
  height: min(34rem, calc(100vh - 10rem));
  background: #FFFBF5;
  border-radius: 1rem;
  box-shadow: 0 24px 64px rgba(11, 61, 79, 0.25);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(1rem) scale(0.98);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.shawo-chat-panel.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.shawo-chat-header {
  background: #0891B2;
  color: #FFFFFF;
  padding: 0.875rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}
.shawo-chat-header-logo {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: 0.02em;
}
.shawo-chat-header-text { flex: 1; min-width: 0; }
.shawo-chat-header-title {
  font-weight: 700;
  font-size: 0.9375rem;
  display: block;
}
.shawo-chat-header-sub {
  font-size: 0.75rem;
  opacity: 0.85;
  display: block;
  margin-top: 0.125rem;
}
.shawo-chat-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #FFFFFF;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.shawo-chat-close:hover { background: rgba(255, 255, 255, 0.25); }

.shawo-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  -webkit-overflow-scrolling: touch;
}
.shawo-chat-body[hidden] { display: none !important; }

.shawo-chat-msg {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 0.875rem;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.shawo-chat-msg.bot {
  background: #FFFFFF;
  color: #334155;
  border-start-start-radius: 0.25rem;
  align-self: flex-start;
  box-shadow: 0 1px 4px rgba(11, 61, 79, 0.08);
}
.shawo-chat-msg.user {
  background: #0891B2;
  color: #FFFFFF;
  border-end-end-radius: 0.25rem;
  align-self: flex-end;
}
.shawo-chat-msg b { font-weight: 700; }
.shawo-chat-msg i { font-style: italic; }
.shawo-chat-msg code {
  background: rgba(11, 61, 79, 0.08);
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  font-size: 0.8125rem;
}
.shawo-chat-msg a {
  color: #0891B2;
  text-decoration: underline;
}
.shawo-chat-msg.admin {
  background: #FFFBF5;
  border: 1px solid rgba(8, 145, 178, 0.3);
  color: #0B3D4F;
  align-self: flex-start;
}

.shawo-chat-typing {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  padding: 0.625rem 0.875rem;
  background: #FFFFFF;
  border-radius: 0.875rem;
  border-start-start-radius: 0.25rem;
  align-self: flex-start;
  box-shadow: 0 1px 4px rgba(11, 61, 79, 0.08);
}
.shawo-chat-typing span {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: #0891B2;
  opacity: 0.4;
  animation: shawoChatBounce 1.2s infinite;
}
.shawo-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.shawo-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes shawoChatBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-0.25rem); opacity: 1; }
}

.shawo-chat-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0 1rem 0.5rem;
  flex-shrink: 0;
}
.shawo-chat-suggest[hidden] { display: none !important; }
.shawo-chat-suggest button {
  background: #FFFFFF;
  color: #0B3D4F;
  border: 1px solid rgba(8, 145, 178, 0.35);
  border-radius: 999px;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.shawo-chat-suggest button:hover {
  background: #0891B2;
  color: #FFFFFF;
  border-color: #0891B2;
}

.shawo-chat-footer {
  padding: 0.75rem 1rem;
  background: #FFFFFF;
  border-top: 1px solid rgba(11, 61, 79, 0.08);
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-shrink: 0;
}
.shawo-chat-footer[hidden] { display: none !important; }
.shawo-chat-input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 1px solid rgba(11, 61, 79, 0.15);
  border-radius: 0.75rem;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.4;
  max-height: 7rem;
  background: #FFFBF5;
  color: #0B3D4F;
  outline: none;
  transition: border-color 0.15s ease;
}
.shawo-chat-input:focus { border-color: #0891B2; }
.shawo-chat-send {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: #0891B2;
  color: #FFFFFF;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.shawo-chat-send:hover { background: #0B3D4F; }
.shawo-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Lead gate (Name + Kontakt) */
.shawo-chat-lead {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.125rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}
.shawo-chat-lead[hidden] { display: none; }

/* Gate view: lead fills the panel, header + gate footer only */
.shawo-chat-gate-foot {
  flex-shrink: 0;
  padding: 0.625rem 1.125rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(11, 61, 79, 0.08);
  background: #FFFFFF;
  font-size: 0.6875rem;
  color: #64748B;
  text-align: center;
}
.shawo-chat-gate-foot[hidden] { display: none !important; }
.shawo-chat-lead h3 {
  margin: 0;
  font-size: 1rem;
  color: #0B3D4F;
  font-weight: 700;
  line-height: 1.4;
}
.shawo-chat-lead p {
  margin: 0;
  font-size: 0.8125rem;
  color: #334155;
  line-height: 1.5;
}
.shawo-chat-lead input[type="text"],
.shawo-chat-lead input[type="tel"],
.shawo-chat-lead input[type="email"] {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(11, 61, 79, 0.2);
  border-radius: 0.625rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  background: #FFFFFF;
  color: #0B3D4F;
  outline: none;
}
.shawo-chat-lead input:focus { border-color: #0891B2; }
.shawo-chat-lead label.shawo-chat-consent {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-size: 0.75rem;
  color: #334155;
  line-height: 1.45;
  cursor: pointer;
}
.shawo-chat-lead label.shawo-chat-consent input { margin-top: 0.125rem; accent-color: #0891B2; }
.shawo-chat-lead button {
  background: #0891B2;
  color: #FFFFFF;
  border: none;
  border-radius: 0.625rem;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s ease;
}
.shawo-chat-lead button:hover { background: #0B3D4F; }
.shawo-chat-lead button:disabled { opacity: 0.6; cursor: not-allowed; }
.shawo-chat-lead .shawo-chat-lead-error {
  color: #DC2626;
  font-size: 0.75rem;
  display: none;
}
.shawo-chat-lead .shawo-chat-lead-error.is-visible { display: block; }
.shawo-chat-lead a { color: #0891B2; }

/* Mobile: Fullscreen panel */
@media (max-width: 640px) {
  .shawo-chat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
  }
  .shawo-chat-overlay { display: none; }
  .shawo-chat-gate-foot { padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)); }
}

/* RTL (Arabic pages) */
[dir="rtl"] .shawo-chat-fab { right: auto; left: calc(1rem + env(safe-area-inset-right, 0px)); }
[dir="rtl"] .shawo-chat-panel { right: auto; left: 1rem; }
[dir="rtl"] .shawo-chat-msg.bot,
[dir="rtl"] .shawo-chat-msg.admin { align-self: flex-end; border-start-start-radius: 0.875rem; border-start-end-radius: 0.25rem; }
[dir="rtl"] .shawo-chat-msg.user { align-self: flex-start; border-end-end-radius: 0.875rem; border-end-start-radius: 0.25rem; }
[dir="rtl"] .shawo-chat-gate-foot { text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .shawo-chat-panel,
  .shawo-chat-overlay,
  .shawo-chat-fab { transition: none; }
  .shawo-chat-typing span { animation: none; }
}
