/* Text-Chat Widget — Allengerechtes Wohnen */
.aw-chat-root {
  --aw-green: #2f5d3a;
  --aw-green-dark: #23462c;
  --aw-bg: #f7f4ef;
  --aw-gold: #c4a35a;
  font-family: "Segoe UI", system-ui, sans-serif;
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* --- Auffälliger Launcher mit Avatar --- */
.aw-chat-toggle {
  border: 3px solid #fff;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--aw-green) 0%, var(--aw-green-dark) 100%);
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.45rem 1.15rem 0.45rem 0.45rem;
  box-shadow:
    0 0 0 3px rgba(47, 93, 58, 0.25),
    0 10px 32px rgba(35, 70, 44, 0.45);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  max-width: min(320px, calc(100vw - 2rem));
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  animation: aw-chat-pulse 2.8s ease-in-out infinite;
}
.aw-chat-toggle:hover {
  background: linear-gradient(135deg, #3a7348 0%, var(--aw-green-dark) 100%);
  transform: translateY(-2px) scale(1.03);
  box-shadow:
    0 0 0 4px rgba(196, 163, 90, 0.45),
    0 14px 36px rgba(35, 70, 44, 0.5);
  animation: none;
}
.aw-chat-toggle:focus-visible {
  outline: 3px solid var(--aw-gold);
  outline-offset: 3px;
}

.aw-chat-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  background: #e8f0ea;
}

.aw-chat-toggle-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  line-height: 1.2;
  padding-right: 0.35rem;
}
.aw-chat-toggle-text strong {
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}
.aw-chat-toggle-text small {
  font-size: 0.78rem;
  font-weight: 500;
  opacity: 0.92;
  margin-top: 0.15rem;
}

.aw-chat-status {
  font-size: 0.78rem;
  padding: 0.4rem 0.85rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  color: #5a655c;
  background: #f0ebe3;
}
.aw-chat-status.ok {
  color: #1e4d2b;
  background: #e4f0e7;
}
.aw-chat-status.warn {
  color: #6b4e12;
  background: #fff3cd;
}
.aw-chat-status.off {
  color: #555;
  background: #eeeae4;
}
.aw-chat-ki-on .aw-chat-online-dot {
  background: #3d9b55;
  box-shadow: 0 0 0 3px rgba(61, 155, 85, 0.35);
}

.aw-chat-online-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #5dce6a;
  border: 2px solid #fff;
  position: absolute;
  /* positioned via wrapper */
}

.aw-chat-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.aw-chat-avatar-wrap .aw-chat-online-dot {
  position: absolute;
  right: 2px;
  bottom: 2px;
}

@keyframes aw-chat-pulse {
  0%, 100% {
    box-shadow:
      0 0 0 3px rgba(47, 93, 58, 0.25),
      0 10px 32px rgba(35, 70, 44, 0.4);
  }
  50% {
    box-shadow:
      0 0 0 8px rgba(47, 93, 58, 0.12),
      0 10px 32px rgba(35, 70, 44, 0.45);
  }
}

/* Panel */
.aw-chat-panel {
  display: none;
  width: min(380px, calc(100vw - 2rem));
  height: min(520px, calc(100vh - 6rem));
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(28, 26, 23, 0.18);
  border: 1px solid #e2dcd2;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 0.65rem;
}
.aw-chat-root.open .aw-chat-panel { display: flex; }
.aw-chat-root.open .aw-chat-toggle { display: none; }

.aw-chat-head {
  background: var(--aw-green-dark);
  color: #fff;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.aw-chat-head-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}
.aw-chat-head-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.85);
}
.aw-chat-head strong { font-size: 1rem; display: block; }
.aw-chat-head span { display: block; font-size: 0.8rem; opacity: 0.85; font-weight: 400; }
.aw-chat-close {
  border: none;
  background: transparent;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  flex-shrink: 0;
}

.aw-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background: var(--aw-bg);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.aw-msg {
  max-width: 92%;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
}
.aw-msg.bot {
  background: #fff;
  border: 1px solid #e2dcd2;
  align-self: flex-start;
  color: #1c1a17;
}
.aw-msg.user {
  background: var(--aw-green);
  color: #fff;
  align-self: flex-end;
}
.aw-msg.error {
  background: #fdecea;
  border: 1px solid #f5c2c0;
  color: #7a1f1a;
  align-self: stretch;
  max-width: 100%;
  font-size: 0.88rem;
}

.aw-chat-form {
  display: flex;
  gap: 0.4rem;
  padding: 0.75rem;
  border-top: 1px solid #e2dcd2;
  background: #fff;
}
.aw-chat-form input {
  flex: 1;
  border: 1px solid #e2dcd2;
  border-radius: 999px;
  padding: 0.65rem 0.9rem;
  font: inherit;
  font-size: 0.95rem;
}
.aw-chat-form button {
  border: none;
  border-radius: 999px;
  background: var(--aw-green);
  color: #fff;
  font-weight: 600;
  padding: 0.65rem 1rem;
  cursor: pointer;
}
.aw-chat-form button:disabled {
  opacity: 0.55;
  cursor: wait;
}
.aw-chat-hint {
  font-size: 0.72rem;
  color: #6b655c;
  padding: 0 0.75rem 0.55rem;
  background: #fff;
}

.aw-chat-link {
  color: var(--aw-green);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.aw-msg.user .aw-chat-link { color: #fff; }
.aw-chat-link:hover { color: var(--aw-green-dark); }

.aw-chat-cta {
  padding: 0.45rem 0.75rem 0;
  background: #fff;
  border-top: 1px solid #e2dcd2;
}
.aw-chat-cta-btn {
  display: block;
  text-align: center;
  background: #e8f0ea;
  color: var(--aw-green-dark) !important;
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none !important;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid #c5d9cb;
}
.aw-chat-cta-btn:hover {
  background: var(--aw-green);
  color: #fff !important;
  border-color: var(--aw-green);
}

@media (max-width: 480px) {
  .aw-chat-root { right: 0.5rem; bottom: 0.5rem; }
  .aw-chat-panel {
    width: calc(100vw - 1rem);
    height: min(70vh, 560px);
  }
  .aw-chat-toggle {
    font-size: 0.95rem;
    padding-right: 0.9rem;
  }
  .aw-chat-avatar { width: 50px; height: 50px; }
  .aw-chat-toggle-text strong { font-size: 0.98rem; }
}

/* Startseite Desktop: sticky KI-Panel rechts (Demo-Übernahme) */
@media (min-width: 1100px) {
  body.page-home-clean .aw-chat-root {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(380px, 32vw);
    height: 100vh;
    margin: 0;
    padding: 0;
    align-items: stretch;
    z-index: 90;
    border-left: 1px solid #d5cfc4;
    background: #f7f4ef;
    box-shadow: -8px 0 28px rgba(28, 26, 23, 0.06);
  }
  body.page-home-clean .aw-chat-root .aw-chat-toggle {
    display: none !important;
  }
  body.page-home-clean .aw-chat-root .aw-chat-panel,
  body.page-home-clean .aw-chat-root.open .aw-chat-panel {
    display: flex !important;
    width: 100%;
    height: 100%;
    max-height: none;
    margin: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
}
