/* TecBlitzWeb AI chat widget — scoped under #tbw-chat-widget */
#tbw-chat-widget {
  --tbw-chat-wa: #25d366;
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9998;
  font-family: 'Syne', sans-serif;
  color: #f5f5f0;
  box-sizing: border-box;
}

#tbw-chat-widget *,
#tbw-chat-widget *::before,
#tbw-chat-widget *::after {
  box-sizing: border-box;
}

/* Body scroll lock while chat is open (esp. mobile bottom sheet) */
html.tbw-chat-scroll-lock,
body.tbw-chat-scroll-lock {
  overflow: hidden !important;
  overflow-x: hidden !important;
  overscroll-behavior: none;
  max-width: 100%;
}

body.tbw-chat-scroll-lock {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 100vw;
  /* top set inline to -scrollY; avoid height:100% (iOS jump) */
}

#tbw-chat-widget .tbw-chat-messages,
#tbw-chat-widget .tbw-chat-input,
#tbw-chat-widget .tbw-chat-choices {
  touch-action: pan-y;
}

#tbw-chat-widget .tbw-chat-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9997;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
}

#tbw-chat-widget.is-open .tbw-chat-backdrop {
  display: block;
}

#tbw-chat-widget .tbw-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(0, 229, 255, 0.45);
  background: var(--panel, #111111);
  color: var(--accent, #00e5ff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 24px rgba(0, 229, 255, 0.22);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  padding: 0;
  position: relative;
  z-index: 9999;
}

#tbw-chat-widget .tbw-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 32px rgba(0, 229, 255, 0.35);
  background: #161616;
}

#tbw-chat-widget .tbw-chat-toggle:focus-visible {
  outline: 2px solid var(--accent, #00e5ff);
  outline-offset: 3px;
}

#tbw-chat-widget .tbw-chat-toggle svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
  display: block;
}

#tbw-chat-widget .tbw-chat-toggle[aria-expanded="true"] .tbw-chat-icon-open {
  display: none;
}

#tbw-chat-widget .tbw-chat-toggle[aria-expanded="false"] .tbw-chat-icon-close,
#tbw-chat-widget .tbw-chat-toggle:not([aria-expanded="true"]) .tbw-chat-icon-close {
  display: none;
}

#tbw-chat-widget .tbw-chat-toggle[aria-expanded="true"] .tbw-chat-icon-close {
  display: block;
}

#tbw-chat-widget .tbw-chat-panel {
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: 480px;
  margin-bottom: 14px;
  background: var(--panel, #111111);
  border: 1px solid rgba(0, 229, 255, 0.22);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 229, 255, 0.06);
  position: relative;
  z-index: 9999;
}

#tbw-chat-widget.is-open .tbw-chat-panel {
  display: flex;
}

#tbw-chat-widget .tbw-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--black, #080808);
  border-bottom: 1px solid rgba(0, 229, 255, 0.15);
  flex-shrink: 0;
}

#tbw-chat-widget .tbw-chat-header-title {
  font-family: 'Syne', sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #f5f5f0;
}

#tbw-chat-widget .tbw-chat-header-title span {
  color: var(--accent, #00e5ff);
}

#tbw-chat-widget .tbw-chat-header-sub {
  font-family: 'Syne Mono', monospace;
  font-size: 0.55rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(245, 245, 240, 0.45);
  margin-top: 3px;
}

#tbw-chat-widget .tbw-chat-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(245, 245, 240, 0.65);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}

#tbw-chat-widget .tbw-chat-close:hover {
  color: var(--accent, #00e5ff);
  background: rgba(0, 229, 255, 0.08);
}

#tbw-chat-widget .tbw-chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  background: linear-gradient(180deg, #0c0c0c 0%, var(--panel, #111111) 100%);
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 229, 255, 0.35) transparent;
}

#tbw-chat-widget .tbw-chat-msg {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

#tbw-chat-widget .tbw-chat-msg--bot {
  align-self: flex-start;
  background: #1a1a1a;
  border: 1px solid rgba(0, 229, 255, 0.12);
  color: #f5f5f0;
  border-bottom-left-radius: 4px;
}

#tbw-chat-widget .tbw-chat-msg--user {
  align-self: flex-end;
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid rgba(0, 229, 255, 0.35);
  color: #f5f5f0;
  border-bottom-right-radius: 4px;
}

#tbw-chat-widget .tbw-chat-choices {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 92%;
  width: 100%;
}

#tbw-chat-widget .tbw-chat-choice {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(0, 229, 255, 0.35);
  background: rgba(0, 229, 255, 0.08);
  color: #f5f5f0;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}

#tbw-chat-widget .tbw-chat-choice:hover {
  background: rgba(0, 229, 255, 0.16);
}

#tbw-chat-widget .tbw-chat-msg a.tbw-chat-wa-link {
  color: var(--tbw-chat-wa);
  font-weight: 600;
  text-decoration: underline;
}

#tbw-chat-widget .tbw-chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
  background: #1a1a1a;
  border: 1px solid rgba(0, 229, 255, 0.12);
  border-radius: 10px;
  border-bottom-left-radius: 4px;
}

#tbw-chat-widget .tbw-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent, #00e5ff);
  opacity: 0.45;
  animation: tbw-chat-dot 1.2s ease-in-out infinite;
}

#tbw-chat-widget .tbw-chat-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

#tbw-chat-widget .tbw-chat-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes tbw-chat-dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

#tbw-chat-widget .tbw-chat-input-row {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  height: auto !important;
  min-height: 52px;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(0, 229, 255, 0.12);
  background: var(--black, #080808);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

#tbw-chat-widget.is-open .tbw-chat-input-row {
  display: flex !important;
}

#tbw-chat-widget .tbw-chat-input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(0, 229, 255, 0.2);
  border-radius: 8px;
  background: #111;
  color: #f5f5f0;
  font-family: 'Syne', sans-serif;
  font-size: 0.82rem;
  padding: 10px 12px;
  outline: none;
}

#tbw-chat-widget .tbw-chat-input::placeholder {
  color: rgba(245, 245, 240, 0.35);
}

#tbw-chat-widget .tbw-chat-input:focus {
  border-color: var(--accent, #00e5ff);
}

#tbw-chat-widget .tbw-chat-send {
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: var(--accent, #00e5ff);
  color: var(--black, #080808);
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  padding: 0 14px;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#tbw-chat-widget .tbw-chat-send:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

#tbw-chat-widget .tbw-chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#tbw-chat-widget .tbw-chat-launcher {
  display: flex;
  justify-content: flex-end;
  position: relative;
  z-index: 9999;
}

#tbw-chat-widget .tbw-chat-teaser {
  position: absolute;
  right: 64px;
  bottom: 14px;
  max-width: min(260px, calc(100vw - 100px));
  background: #111111;
  color: #f5f5f0;
  border: 1px solid rgba(0, 229, 255, 0.35);
  border-radius: 10px;
  padding: 10px 14px;
  font-family: 'Syne', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  white-space: normal;
}

#tbw-chat-widget .tbw-chat-teaser.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#tbw-chat-widget .tbw-chat-teaser.is-visible.is-fading {
  opacity: 0;
  transition: opacity 200ms ease;
}

@media (max-width: 480px) {
  #tbw-chat-widget {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    padding: 0;
    overflow-x: hidden;
  }

  #tbw-chat-widget .tbw-chat-launcher {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 9999;
  }

  #tbw-chat-widget .tbw-chat-panel {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh; /* fallback */
    height: 100dvh;
    max-height: 100vh; /* fallback */
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    border-top: none;
    z-index: 9999;
    overflow-x: hidden;
  }

  #tbw-chat-widget .tbw-chat-messages {
    min-height: 0;
    overflow-x: hidden;
    max-width: 100%;
  }

  #tbw-chat-widget .tbw-chat-header,
  #tbw-chat-widget .tbw-chat-header > div,
  #tbw-chat-widget .tbw-chat-msg,
  #tbw-chat-widget .tbw-chat-choices,
  #tbw-chat-widget .tbw-chat-choice,
  #tbw-chat-widget .tbw-chat-input-row {
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
  }

  #tbw-chat-widget .tbw-chat-header-title,
  #tbw-chat-widget .tbw-chat-header-sub {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  #tbw-chat-widget .tbw-chat-choices {
    max-width: 100%;
  }

  #tbw-chat-widget .tbw-chat-input {
    font-size: 16px; /* prevent iOS focus zoom */
  }

  #tbw-chat-widget .tbw-chat-input-row {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  #tbw-chat-widget.is-open .tbw-chat-launcher {
    display: none;
  }

  /* Teaser above launcher — avoids right-edge overflow / button overlap */
  #tbw-chat-widget .tbw-chat-teaser {
    right: 0;
    left: auto;
    bottom: calc(100% + 10px);
    max-width: min(200px, calc(100vw - 88px));
    font-size: 0.75rem;
    padding: 9px 12px;
  }
}

@media (max-width: 380px) {
  #tbw-chat-widget .tbw-chat-launcher {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  #tbw-chat-widget .tbw-chat-teaser {
    max-width: min(160px, calc(100vw - 72px));
    font-size: 0.7rem;
    padding: 8px 10px;
  }

  #tbw-chat-widget .tbw-chat-choice {
    font-size: 0.76rem;
    padding: 10px 11px;
  }
}
