/* POLY Assistant widget — all rules namespaced under .poly-* */
.poly-widget-root,
.poly-widget-root *,
.poly-widget-root *::before,
.poly-widget-root *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.poly-widget-root {
  position: fixed;
  z-index: 2147483000;
  bottom: 24px;
  right: 24px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: #1a202c;
}

.poly-widget__launcher {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  background: #0f6e3c;
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  transition: transform 0.15s ease;
}

.poly-widget__launcher:hover {
  transform: scale(1.06);
}

.poly-widget {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.24);
  overflow: hidden;
}

.poly-widget[aria-hidden='true'] {
  display: none;
}

.poly-widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #0f6e3c;
  color: #fff;
  font-weight: 600;
}

.poly-widget__close {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.poly-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  background: #f4f6f8;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.poly-message {
  display: flex;
}

.poly-message--user {
  justify-content: flex-end;
}

.poly-message--assistant {
  justify-content: flex-start;
}

.poly-message__bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.poly-message--user .poly-message__bubble {
  background: #0f6e3c;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.poly-message--assistant .poly-message__bubble {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.poly-message--card {
  justify-content: flex-start;
}

.poly-product-card {
  width: 82%;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.poly-product-card__name {
  font-weight: 600;
  font-size: 13px;
}

.poly-product-card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.poly-product-card__price {
  color: #0f6e3c;
  font-weight: 700;
}

.poly-product-card__stock {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
}

.poly-product-card__stock--in {
  background: #e6f7ee;
  color: #0f6e3c;
}

.poly-product-card__stock--out {
  background: #fdeaea;
  color: #b23b3b;
}

.poly-product-card__link {
  color: #0f6e3c;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.poly-product-card__link:hover {
  text-decoration: underline;
}

.poly-calc-card {
  width: 82%;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.poly-calc-card__sheets {
  font-weight: 600;
}

.poly-calc-card__cost {
  color: #0f6e3c;
  font-weight: 700;
}

.poly-widget__footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}


.poly-widget__input {
  flex: 1;
  resize: none;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  color: inherit;
}

.poly-widget__input:focus {
  outline: 2px solid #0f6e3c;
  border-color: transparent;
}

.poly-widget__send {
  border: 0;
  border-radius: 8px;
  background: #0f6e3c;
  color: #fff;
  font-weight: 600;
  padding: 0 14px;
  cursor: pointer;
}

.poly-widget__send:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Phase 7 — human handoff link (rendered only when handoffPhone is
   configured). Full-width row under the input row; click-to-call (tel:). */
.poly-widget__handoff {
  flex: 1 0 100%;
  text-align: center;
  color: #0f6e3c;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  border-top: 1px solid #eef2f5;
  padding-top: 8px;
}

.poly-widget__handoff:hover {
  text-decoration: underline;
}


@media (max-width: 480px) {
  /* Phase 8 — mobile-first. The open chat becomes an edge-to-edge,
     full-height overlay (100dvh) with safe-area insets. The fixed root is
     stretched over the whole viewport but is pointer-transparent, so it never
     blocks taps on the page behind the launcher (closed) or the panel (open). */
  .poly-widget-root {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    pointer-events: none;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
  }

  .poly-widget__launcher {
    pointer-events: auto;
    width: 60px;
    height: 60px;
    margin: 0 calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .poly-widget {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100vh; /* fallback for browsers without dvh */
    height: 100dvh; /* full dynamic viewport height (mobile browsers) */
    max-height: none;
    border-radius: 0;
    pointer-events: auto;
  }

  /* Phase 8 — notch / home-indicator clearance */
  .poly-widget__header {
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  .poly-widget__footer {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  /* Phase 8 — prevent iOS auto-zoom on input focus (>= 16px) */
  .poly-widget__input {
    font-size: 16px;
  }

  /* Phase 8 — touch targets >= 44px */
  .poly-widget__send {
    min-width: 52px;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .poly-widget__close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .poly-product-card__link,
  .poly-widget__handoff {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
}
