/* SAUH AI chat widget */
.sauh-ai {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(18px + var(--safe-bottom, 0px));
  z-index: 99960;
  font-family: Outfit, "Segoe UI", sans-serif;
}

.sauh-ai-launcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 999px;
  padding: 12px 16px 12px 14px;
  background: var(--sauh-blue, #009CDE);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 12px 28px rgba(0, 119, 179, 0.28);
  cursor: pointer;
  transition: transform .18s var(--ease, ease), background .18s ease;
}

.sauh-ai-launcher:hover {
  background: var(--sauh-blue-deep, #0077B3);
  transform: translateY(-1px);
}

.sauh-ai-launcher-icon {
  width: 18px;
  height: 18px;
  border-radius: 5px 5px 5px 2px;
  border: 2px solid #fff;
  position: relative;
  flex: 0 0 auto;
}

.sauh-ai-launcher-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 4px;
  height: 2px;
  background: #fff;
  box-shadow: 0 4px 0 #fff;
}

.sauh-ai[data-open="1"] .sauh-ai-launcher {
  display: none;
}

.sauh-ai-panel {
  position: relative;
  width: min(380px, calc(100vw - 28px));
  height: min(540px, calc(100dvh - 40px));
  display: none;
  flex-direction: column;
  background: #fff;
  border: 3px solid var(--sauh-blue, #009CDE);
  border-radius: 18px;
  box-shadow: 0 18px 44px rgba(0, 119, 179, 0.28);
  overflow: hidden;
}

.sauh-ai[data-open="1"] .sauh-ai-panel {
  display: flex;
}

.sauh-ai-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  background: linear-gradient(180deg, #f0f9ff 0%, #fff 100%);
  border-bottom: 1px solid rgba(0, 156, 222, 0.35);
}

.sauh-ai-head-text {
  min-width: 0;
}

.sauh-ai-head strong {
  display: block;
  font-size: 16px;
  color: var(--ink, #1a1d23);
}

.sauh-ai-head p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted, #6b7280);
  line-height: 1.35;
}

.sauh-ai-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.sauh-ai-min {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid rgba(0, 156, 222, 0.45);
  background: #fff;
  color: var(--sauh-blue, #009CDE);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 10px;
  min-height: 36px;
}

.sauh-ai-min span[aria-hidden="true"] {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  color: var(--sauh-blue, #009CDE);
}

.sauh-ai-min:hover {
  border-color: var(--sauh-blue, #009CDE);
  color: var(--sauh-blue-deep, #0077B3);
  background: #f0f9ff;
}

.sauh-ai-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  min-height: 36px;
  border: 1.5px solid rgba(220, 70, 70, 0.35);
  background: #fff;
  color: #dc4646;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  border-radius: 10px;
  padding: 0;
}

.sauh-ai-close:hover {
  border-color: #dc4646;
  color: #c62828;
  background: #fff;
}

.sauh-ai-confirm {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(26, 29, 35, 0.42);
}

.sauh-ai-confirm[hidden] {
  display: none !important;
}

.sauh-ai-confirm-card {
  width: min(280px, 100%);
  background: #fff;
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 12px 28px rgba(17, 24, 39, 0.18);
}

.sauh-ai-confirm-card p {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink, #1a1d23);
  line-height: 1.4;
}

.sauh-ai-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.sauh-ai-confirm-cancel,
.sauh-ai-confirm-ok {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  border-radius: 10px;
  min-height: 36px;
  padding: 8px 12px;
}

.sauh-ai-confirm-cancel {
  border: 1px solid var(--line, #e5e7eb);
  background: #fff;
  color: var(--ink, #1a1d23);
}

.sauh-ai-confirm-cancel:hover {
  border-color: var(--sauh-blue, #009CDE);
  color: var(--sauh-blue-deep, #0077B3);
}

.sauh-ai-confirm-ok {
  border: 0;
  background: var(--sauh-blue, #009CDE);
  color: #fff;
}

.sauh-ai-confirm-ok:hover {
  background: var(--sauh-blue-deep, #0077B3);
}

.sauh-ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px 4px;
  background: #fff;
  border-top: 1px solid rgba(0, 156, 222, 0.35);
}

.sauh-ai-suggestions[hidden] {
  display: none !important;
}

.sauh-ai-chip {
  border: 1.5px solid var(--sauh-blue, #009CDE);
  background: #f0f9ff;
  color: var(--sauh-blue-deep, #0077B3);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 999px;
  max-width: 100%;
}

.sauh-ai-chip:hover {
  background: #ffe7cc;
  border-color: var(--sauh-blue, #009CDE);
}

.sauh-ai-chip:disabled,
.sauh-ai-suggestions[aria-busy="true"] .sauh-ai-chip {
  opacity: 0.55;
  cursor: wait;
  pointer-events: none;
}

.sauh-ai-msgs {
  flex: 1;
  overflow: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fafafa;
}

.sauh-ai-bubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: normal;
  word-break: break-word;
}

.sauh-ai-bubble .sauh-ai-p {
  margin: 0 0 10px;
}

.sauh-ai-bubble .sauh-ai-p:last-child {
  margin-bottom: 0;
}

.sauh-ai-bubble strong {
  font-weight: 700;
}

.sauh-ai-bubble a.sauh-ai-link {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 6px 0 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: #f0f9ff;
  border: 1.5px solid var(--sauh-blue, #009CDE);
  color: var(--sauh-blue-deep, #0077B3) !important;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.35;
  text-decoration: none;
  word-break: break-word;
}

.sauh-ai-bubble a.sauh-ai-link:hover {
  background: #ffe7cc;
  border-color: var(--sauh-blue, #009CDE);
  color: #8a4200 !important;
}

.sauh-ai-product-cards {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.sauh-ai-product-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #d7eaf5;
  text-decoration: none !important;
  color: inherit !important;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.sauh-ai-product-card:hover {
  border-color: var(--sauh-blue, #009CDE);
  background: #f0f9ff;
}

.sauh-ai-product-card-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 6px;
  background: #f7fafc;
  flex-shrink: 0;
}

.sauh-ai-product-card-meta {
  min-width: 0;
  flex: 1;
}

.sauh-ai-product-card-title {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  color: #123;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sauh-ai-product-card-price {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--sauh-blue-deep, #0077B3);
}

.sauh-ai-product-card-cta {
  margin-top: 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--sauh-blue, #009CDE);
}

.sauh-ai-bubble.is-user a.sauh-ai-link {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff !important;
}

.sauh-ai-bubble.is-bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line, #e5e7eb);
  color: var(--ink, #1a1d23);
}

.sauh-ai-bubble.is-user {
  align-self: flex-end;
  background: var(--ink, #1a1d23);
  color: #fff;
}

.sauh-ai-bubble.is-sys {
  align-self: center;
  background: transparent;
  color: var(--muted, #6b7280);
  font-size: 12px;
  text-align: center;
}

.sauh-ai-bubble.is-loading {
  opacity: 1;
  padding: 12px 14px;
}

.sauh-ai-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 14px;
}

.sauh-ai-typing i {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sauh-blue, #009CDE);
  opacity: 0.35;
  animation: sauh-ai-bounce 1.1s infinite ease-in-out;
}

.sauh-ai-typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.sauh-ai-typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes sauh-ai-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.sauh-ai-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 9px;
  border-top: 1px solid rgba(0, 156, 222, 0.35);
  background: #fff;
  align-items: end;
}

.sauh-ai-form textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 11px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink, #1a1d23);
  min-height: 44px;
  max-height: 96px;
  field-sizing: content;
}

.sauh-ai-form textarea:focus {
  outline: 2px solid rgba(224, 120, 18, 0.35);
  border-color: var(--sauh-blue, #009CDE);
}

.sauh-ai-send {
  border: 0;
  border-radius: 11px;
  padding: 0 14px;
  min-height: 44px;
  background: var(--sauh-blue, #009CDE);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.sauh-ai-send:disabled {
  opacity: 0.55;
  cursor: wait;
}

@media (max-width: 767px) {
  /* Original Storefront bar size; no top divider line. */
  .storefront-handheld-footer-bar {
    border-top: 0 !important;
    box-shadow: none !important;
  }

  /* Identical absolute centering for search / cart / chat icons.
     Keep inherited font-size on <a> so height: N em does not collapse to 0. */
  .storefront-handheld-footer-bar ul li > a {
    height: 4.235801032em !important;
    position: relative !important;
    display: block !important;
    padding: 0 !important;
    overflow: hidden !important;
    text-indent: -9999px !important;
    text-decoration: none !important;
    line-height: 4.235801032em !important;
  }

  .storefront-handheld-footer-bar ul li > a::before {
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    right: auto !important;
    bottom: auto !important;
    width: auto !important;
    height: auto !important;
    margin: 0 !important;
    transform: translate(-50%, -50%) !important;
    line-height: 1 !important;
    font-size: 1.618em !important;
    display: block !important;
    text-indent: 0 !important;
  }

  .storefront-handheld-footer-bar ul li.cart .count {
    position: absolute !important;
    top: 0.7em !important;
    right: 50% !important;
    margin-right: -1.35em !important;
    text-indent: 0 !important;
    font-size: 0.75em !important;
    line-height: 1.4 !important;
    z-index: 2;
  }

  /* Hide floating add-to-cart while chat is open (phone only) */
  body.sauh-ai-open .sauh-stick,
  body.sauh-ai-open .sauh-stick.is-on {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }

  body.sauh-ai-open.single-product {
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Chat lives in Storefront handheld bar — hide floating pill */
  .sauh-ai > .sauh-ai-launcher {
    display: none !important;
  }

  .sauh-ai {
    right: 10px;
    left: 10px;
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
    width: auto;
  }

  .sauh-ai-panel {
    width: 100%;
    height: min(70dvh, calc(100dvh - 100px));
    border-radius: 16px;
  }

  body.single-product .sauh-ai {
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }

  /* Chat uses the same Font Awesome glyph metrics as search/cart (optical alignment). */
  .storefront-handheld-footer-bar ul li.sauh-ai-nav > a::before {
    content: "\f075" !important; /* FA comment */
    background: none !important;
    -webkit-mask: none !important;
    mask: none !important;
    width: auto !important;
    height: auto !important;
    /* Solid bubble reads high optically — nudge 1px down to match outline icons. */
    transform: translate(-50%, calc(-50% + 1px)) !important;
  }

  .storefront-handheld-footer-bar ul li.sauh-ai-nav > a.is-active {
    color: #009CDE;
  }

  /* Cart sticky "Mine maksma" — clear handheld search/cart/chat bar */
  .woocommerce-cart .wc-proceed-to-checkout {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

@media (max-width: 640px) {
  /* Mobile product sticky bar — lift chat so it doesn't cover buy actions */
  body.single-product .sauh-ai {
    bottom: calc(88px + var(--safe-bottom, 0px));
  }

  .sauh-ai-launcher-label {
    display: none;
  }
  .sauh-ai-launcher {
    width: 52px;
    height: 52px;
    padding: 0;
    justify-content: center;
  }
}
