: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: 60px;
  --footer-h: 60px;
  --container-max-w: 1200px;
}
@media (max-width: 520px) {
  :root { --header-h: 54px; }
}

/* ========= RESET ========= */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html, body {
  height: 100%;
}
body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: var(--bg);
  font-family: system-ui, sans-serif;

  /* robuster Viewport auf Mobile */
  min-height: 100svh;
}
@supports (height: 100dvh) {
  body { min-height: 100dvh; }
}

/* ========= HAUPTCONTAINER ========= */
.chat-window {
  width: 100%;
  max-width: var(--container-max-w);
  display: flex;
  flex-direction: column;
  overflow: hidden;               /* verhindert Doppelscroll */
  background: var(--surface);
  border-radius: 16px;
  position: relative;

  /* auf Mobile vollflächig */
  min-height: 100svh;
  max-height: 100svh;
}
@supports (height: 100dvh) {
  .chat-window { min-height: 100dvh; max-height: 100dvh; }
}

@media (min-width: 1024px) {
  .chat-window {
    width: 90%;
    margin: 3.5rem 2rem;

    /* 20% weniger als vorher: (100dvh - 7rem) * 0.8 */
    min-height: 0; /* überschreibt 100dvh aus @supports */
    height: calc(0.8 * (100dvh - 7rem));
    max-height: calc(0.8 * (100dvh - 7rem));

    /* Alternative ohne Multiplikation: */
    /* height: calc(80dvh - 5.6rem); max-height: calc(80dvh - 5.6rem); */

    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  }
}

@media (max-width: 520px) {
  .chat-window { border-radius: 0; }
}

/* ========= 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.3rem; font-weight: 600; white-space: nowrap; }
@media (max-width: 520px) {
  .chat-header { padding: 0 1.5rem 0 4rem; }
  .chat-title { font-size: 1.2rem; }
}

/* ========= MESSAGES ========= */
.messages {
  flex: 1 1 auto;
  min-height: 0;                         /* wichtig für Safari/Flex */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;     /* iOS innerhalb von iframes */
  touch-action: pan-y;                   /* explizit vertikal scrollen */
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;

  /* Safe-Area unten einrechnen, sonst wird das Ende verdeckt */
  padding: calc(var(--header-h) + 1rem) 1.5rem
           calc(var(--footer-h) + 1.5rem + env(safe-area-inset-bottom));

  background: var(--surface);
  scrollbar-width: thin;
}
@media (min-width: 1024px) {
  .messages { padding-left: 3rem; padding-right: 3rem; }
}
@media (max-width: 520px) {
  .messages { padding-top: calc(var(--header-h) + 2rem); }
}
@supports (scrollbar-gutter: stable) {
  .messages { scrollbar-gutter: stable both-edges; }
}

/* zusätzlicher Spacer, falls Buttons ganz unten anstehen */
.messages::after {
  content: "";
  display: block;
  height: env(safe-area-inset-bottom);
}

.message {
  max-width: 80%;
  margin: 0.75rem 0;
  padding: 0.75rem 1.1rem;
  border-radius: 20px;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}
.bot {
  align-self: flex-start;
  background: var(--msg-bg);
  color: var(--text);
  padding-left: 52px;
}
.user {
  align-self: flex-end;
  text-align: right;
  background: var(--btn-gradient);
  color: #fff;
  padding-right: 52px;
  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: 12px;
  top: 50%;
  width: 36px;
  height: 36px;
  transform: translateY(-50%);
  background: url("chatbot-icon.png") center/cover no-repeat;
  border-radius: 50%;
}
.message.user::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 36px;
  height: 36px;
  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 calc(var(--footer-h) + env(safe-area-inset-bottom));
  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;     /* nicht starr – wächst bei Safe-Area */
  min-height: var(--footer-h);
  background: var(--surface);
  padding: 0.75rem 0.5rem env(safe-area-inset-bottom);
  border-top: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.03);
}
.options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 1rem;
  margin-bottom: 1rem;
}
.options button {
  flex: 1 1 calc(50% - 0.6rem);
  padding: 0.8rem;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--primary);
  font-size: 0.95rem;
  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;
  -webkit-tap-highlight-color: transparent;
}
@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;
}

/* ========= INPUT ========= */
.input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.4rem 0.2rem;
}
.input-wrapper input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.9rem 1rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  box-shadow:
    4px 4px 8px rgba(0, 0, 0, 0.05),
    -4px -4px 8px 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 90px;
  padding: 0.9rem;
  border: none;
  border-radius: 12px;
  background: var(--btn-gradient);
  color: #fff;
  font-size: 0.95rem;
  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 {
  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 lange Wörter */
}
.message.bot .prodline a {
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}
.message.bot .prodline a:hover { text-decoration: underline; }

/* ========= MOBILE: kompaktere Boxen ========= */
@media (max-width: 520px) {
  /* engerer Abstand zwischen den Boxen */
  .options {
    gap: 0.5rem;
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
  }
  /* Boxen niedriger + kleinere Schrift */
  .options button {
    flex: 1 1 100%;
    padding: 0.65rem 0.9rem;   /* vorher 0.8rem */
    font-size: 0.875rem;       /* ~14px, vorher 0.95/0.9rem */
    line-height: 1.2;
    border-radius: 10px;       /* etwas weniger rund */
    min-height: 44px;          /* bleibt gut klickbar */
  }
}
