:root {
  --primary: #006fb9;
  --primary-dark: #3d80b4;
  --bg: #eef2f7;
  --surface: #ffffff;
  --text: #333333;
  --msg-bg: #f7f8fa;

  --btn-gradient: linear-gradient(135deg, #4c8cff, #006fb9);
  --btn-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);

  --header-h: 48px;
  --footer-h: auto;
  --container-max-w: 1200px;
}
@media (max-width: 520px) {
  :root {
    --header-h: 44px;
  }
}

/* ========= RESET ========= */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html,
body {
  height: 100%;
  overscroll-behavior: none;
  /* iframe-Einbettung: Touch-Scrolling aktivieren */
  -webkit-overflow-scrolling: touch;
}
body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100dvh;
  min-height: 100%;
  background: var(--bg);
  font-family: system-ui, sans-serif;
}

/* ========= HAUPTCONTAINER ========= */
.chat-window {
  width: 100%;
  max-width: var(--container-max-w);
  height: 100dvh;
  height: 100%;
  min-height: 0; /* wichtig für Flex-Scrolling im iframe */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border-radius: 16px;
}
@media (min-width: 1024px) {
  .chat-window {
    width: 95%;
    max-width: 1200px;
    margin: 1rem auto;
    height: 75vh;
    max-height: 75vh;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  }
}

@media (max-width: 520px) {
  .chat-window {
    border-radius: 0;
    display: block;
    height: auto;
    min-height: 100%;
    overflow-y: auto;
  }
}

/* ========= HEADER ========= */
.chat-header {
  flex: 0 0 var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0 2rem 0 4rem;
}
.back-btn {
  position: absolute;
  left: 1rem;
  width: 2.2rem;
  height: 2.2rem;
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  font-size: 1.4rem;
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.back-btn:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.1);
}
.chatbot-icon {
  display: none !important;
}
.chat-title {
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
}
@media (max-width: 520px) {
  .chat-header {
    padding: 0 1rem 0 3rem;
    height: var(--header-h);
  }
  .chat-title {
    font-size: 1rem;
  }
}

/* ========= MESSAGES ========= */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  background: var(--surface);
  scrollbar-width: thin;
}
@media (min-width: 1024px) {
  .messages {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}
@media (max-width: 520px) {
  .messages {
    padding: 0.75rem 0.75rem 1rem;
    overflow-y: visible;
    min-height: auto;
  }
}
@supports (scrollbar-gutter: stable) {
  .messages {
    scrollbar-gutter: stable both-edges;
  }
}

.message {
  max-width: 85%;
  margin: 0.4rem 0;
  padding: 0.5rem 0.9rem;
  border-radius: 16px;
  line-height: 1.4;
  font-size: 0.9rem;
  word-wrap: break-word;
  position: relative;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}
@media (min-width: 1024px) {
  .message {
    font-size: 1rem;
    padding: 0.6rem 1rem;
  }
}
.bot {
  align-self: flex-start;
  background: var(--msg-bg);
  color: var(--text);
  padding-left: 40px;
}
.user {
  align-self: flex-end;
  text-align: right;
  background: var(--btn-gradient);
  color: #fff;
  padding-right: 40px;
  box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.1),
    -4px -4px 8px rgba(255, 255, 255, 0.7);
}
.message.bot:not(.loading)::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  width: 28px;
  height: 28px;
  transform: translateY(-50%);
  background: url("chatbot-icon.png") center/cover no-repeat;
  border-radius: 50%;
}
.message.user::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  width: 28px;
  height: 28px;
  transform: translateY(-50%);
  background: url("anonym.png") center/cover no-repeat;
  border-radius: 50%;
}
.message.bot p + p {
  margin-top: 0.8rem;
}

/* ========= OVERLAY / SPINNER ========= */
.overlay {
  position: absolute;
  inset: var(--header-h) 0 var(--footer-h);
  background: rgba(255, 255, 255, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid transparent;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ========= FOOTER ========= */
.chat-footer {
  flex: 0 0 auto;
  background: var(--surface);
  padding: 0.6rem 0.5rem calc(env(safe-area-inset-bottom, 0px) + 0.6rem);
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.03);
  overflow: visible;
}
.options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 0.5rem 0;
  overflow: visible;
}

/* Ja/Nein Buttons: etwas grösser */
.options.yes-no-options {
  padding: 0.5rem 0;
}
.options.yes-no-options button {
  flex: 0 1 45%;
  max-width: 160px;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
}
.options button {
  flex: 1 1 calc(50% - 0.5rem);
  padding: 0.7rem 0.9rem;
  border: none;
  border-radius: 10px;
  background: var(--surface);
  color: var(--primary);
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.05),
    -3px -3px 6px rgba(255, 255, 255, 0.7);
  transition: transform 0.2s, background 0.2s, color 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
  /* Long-press auf Mobile verhindern (keine Texteingabe/Kontextmenü) */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
@media (hover: hover) {
  .options button:hover:not(:disabled) {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--btn-shadow);
    transform: translateY(-2px);
  }
}
.options button:active:not(:disabled) {
  background: var(--primary-dark);
  color: #fff;
  transform: scale(0.98);
}
.options button:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}
@media (max-width: 520px) {
  .options button {
    flex: 1 1 calc(50% - 0.4rem);
    font-size: 0.85rem;
    padding: 0.6rem 0.7rem;
  }
}

/* ========= INPUT ========= */
.input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.3rem 0.2rem;
}
.input-wrapper input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.6rem 0.8rem;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.05),
    -3px -3px 6px rgba(255, 255, 255, 0.7);
  transition: box-shadow 0.25s, background 0.25s;
}
.input-wrapper input:focus {
  outline: none;
  background: #fefefe;
  box-shadow: var(--btn-shadow);
}
.input-wrapper button {
  flex: 0 0 70px;
  padding: 0.6rem;
  border: none;
  border-radius: 10px;
  background: var(--btn-gradient);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--btn-shadow);
  transition: transform 0.2s, background 0.2s;
}
@media (hover: hover) {
  .input-wrapper button:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-2px);
  }
}
.input-wrapper button:active:not(:disabled) {
  transform: scale(0.96);
}
.input-wrapper button:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

/* ========= WAITING-LOADER ========= */
.waiting-loader {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.waiting-loader-text {
  margin-bottom: 0.4rem;
  font-weight: 500;
  color: var(--text);
}
.waiting-loader-animation {
  display: inline-flex;
  gap: 0.35rem;
}
.waiting-loader-animation span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.4;
  animation: waitingBounce 0.8s infinite ease-in-out;
}
.waiting-loader-animation span:nth-child(2) {
  animation-delay: 0.16s;
}
.waiting-loader-animation span:nth-child(3) {
  animation-delay: 0.32s;
}
@keyframes waitingBounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ========== Variante A: Einzeilige Produktzeile mit Ellipsis ========== */
.message.bot .prodline {
  /* nur Produkt-Zeilen! */
  display: flex;
  gap: 0.4rem;
  margin: 0.8rem 0;
  line-height: 1.45;
}
.message.bot .prodline strong {
  flex: 0 0 auto;
  font-weight: 600;
  white-space: nowrap;
}
.message.bot .prodline a,
.message.bot .prodline span.prodnum {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal; /* Link darf umbrechen */
  overflow-wrap: anywhere; /* bricht auch in langen Wörtern */
}
.message.bot .prodline a {
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}
.message.bot .prodline a:hover {
  text-decoration: underline;
}

/* ========= PRODUKTKACHELN (Schuhe) ========= */
.product-message {
  max-width: 100% !important;
  padding: 0.5rem !important;
  background: transparent !important;
  box-shadow: none !important;
}

.product-message::before {
  display: none !important;
}

.product-cards-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  width: 100%;
}

@media (max-width: 900px) {
  .product-cards-container {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 520px) {
  .product-cards-container {
    grid-template-columns: 1fr;
  }
}

.product-card {
  background: var(--surface);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.product-card-image {
  width: 100%;
  height: 180px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.product-card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0.5rem;
}

.product-card-image .no-image {
  color: #999;
  font-size: 0.9rem;
  text-align: center;
  padding: 1rem;
}

.product-card-content {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.product-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-card-number {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 0.5rem;
}

.product-card-price {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.product-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.5rem 0;
}

.product-filter label {
  font-size: 0.9rem;
  color: #666;
}

.product-filter select {
  padding: 0.5rem 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fff;
  cursor: pointer;
  outline: none;
}

.product-filter select:focus {
  border-color: var(--primary);
}

.product-card-desc {
  font-size: 0.85rem;
  color: #555;
  line-height: 1.4;
  margin-bottom: 0.75rem;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-card-link {
  display: inline-block;
  padding: 0.6rem 1rem;
  background: var(--btn-gradient);
  color: #fff;
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  transition: transform 0.2s, background 0.2s;
  margin-top: auto;
}

.product-card-link:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
}

/* Kategorie-Badge (z.B. S3) */
.product-card-category {
  display: inline-block;
  padding: 0.3rem 0.6rem;
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Erfüllungsgrad */
.product-card-fulfillment {
  font-size: 0.8rem;
  color: #2e7d32;
  font-weight: 500;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.product-card-fulfillment::before {
  content: "✓";
  font-weight: bold;
}

/* ========= PRODUKTE ERGEBNIS ========= */
.products-result {
  width: 100%;
}

.products-count {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1rem;
}

.no-products-message {
  padding: 2rem;
  text-align: center;
  color: #666;
  font-size: 1rem;
  background: var(--surface);
  border-radius: 12px;
}

/* ========= MEHR LADEN BUTTON ========= */
.load-more-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  margin-top: 1rem;
  padding: 0.9rem 1.5rem;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--primary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.05),
    -4px -4px 8px rgba(255, 255, 255, 0.7);
  transition: transform 0.2s, background 0.2s, color 0.2s, box-shadow 0.2s;
}

.load-more-btn:hover {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--btn-shadow);
  transform: translateY(-2px);
}

.load-more-btn:active {
  background: var(--primary-dark);
  color: #fff;
  transform: scale(0.98);
}

/* Hidden cards container */
.product-cards-hidden {
  display: contents;
}

/* ========= IFRAME-EINBETTUNG FIXES ========= */
/* Scrolling im iframe sicherstellen */
.messages {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Mobile: Footer-Bereich mit etwas Abstand */
@media (max-width: 520px) {
  .chat-footer {
    padding: 0.6rem 0.5rem calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
    margin-top: 0.5rem;
  }

  .options {
    gap: 0.4rem;
    margin: 0.4rem 0;
  }
}

/* Long-press auf allen interaktiven Elementen verhindern */
button,
input,
a {
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Spezifisch für Buttons: alle Long-press Aktionen blockieren */
button {
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  -webkit-user-modify: read-only !important;
  -webkit-text-size-adjust: none;
  touch-action: manipulation;
}

/* Verhindere contenteditable bei Long-press auf Buttons */
.options button {
  -webkit-user-modify: read-only !important;
  -moz-user-modify: read-only !important;
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
  pointer-events: auto;
}

/* Kein Text-Cursor auf Buttons */
.options button,
.input-wrapper button {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
