/* AP Product AI Sales — Chat UI (v3) */
/* Minimal, production-ready styles */

/* =========================
   GLOBAL RESET & BASE
   ========================= */

.apais-overlay,
.apais-window,
.apais-support-launcher {
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.5;
}

.apais-overlay *,
.apais-window *,
.apais-support-launcher * {
  box-sizing: border-box;
}

/* =========================
   Z-INDEX (Above everything)
   ========================= */

.apais-overlay,
.apais-window,
.apais-support-launcher {
  z-index: 2147483000 !important; /* Max safe z-index */
}

/* =========================
   MODAL OVERLAY (Product Chat)
   ========================= */

.apais-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  background: rgba(0, 0, 0, 0.55);
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 16px !important;
}

/* =========================
   CHAT WINDOW
   ========================= */

.apais-window {
  position: relative;
  width: min(560px, 96vw);
  max-height: min(78vh, 720px);
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(0, 0, 0, 0.10);
}

/* Floating support window */
.apais-window--floating {
  position: fixed !important;
  right: 18px !important;
  bottom: 88px !important;
  width: min(420px, 94vw);
  max-height: min(70vh, 680px);
}

/* =========================
   HEADER
   ========================= */

.apais-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #111;
  color: #fff;
  flex-shrink: 0;
}

.apais-title {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.2px;
  line-height: 1.2;
  margin: 0;
}

.apais-close {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  width: 36px;
  height: 32px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  font-weight: 900;
  padding: 0;
  transition: background 0.2s;
}

.apais-close:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* =========================
   SUBHEADER (Product info)
   ========================= */

.apais-subheader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: #111;
  color: #fff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.apais-subheader a {
  color: #fff;
  text-decoration: underline;
  font-size: 13px;
  opacity: 0.95;
}

.apais-subheader a:hover {
  opacity: 1;
}

/* =========================
   BODY (Messages container)
   ========================= */

.apais-body {
  flex: 1;
  overflow: hidden;
  background: #f6f7f8;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.apais-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Scrollbar styling */
.apais-messages::-webkit-scrollbar {
  width: 8px;
}

.apais-messages::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.05);
}

.apais-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.apais-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* =========================
   TYPING INDICATOR
   ========================= */

.apais-typing {
  padding: 10px 14px;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.55);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: none; /* Controlled by JS */
  flex-shrink: 0;
}

/* =========================
   MESSAGE BUBBLES
   ========================= */

.apais-msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.apais-msg--user {
  align-items: flex-end;
}

.apais-msg--assistant,
.apais-msg--manager {
  align-items: flex-start;
}

.apais-bubble {
  max-width: 84%;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.35;
  font-size: 14px;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

/* User messages */
.apais-msg--user .apais-bubble {
  background: #111;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.10);
}

/* Assistant messages */
.apais-msg--assistant .apais-bubble {
  background: #f6f7f9;
  color: #111;
}

/* Manager takeover messages */
.apais-msg--manager .apais-bubble {
  background: #fff7e6;
  color: #111;
  border-color: rgba(0, 0, 0, 0.10);
}

/* Links in bubbles */
.apais-bubble a {
  color: inherit;
  text-decoration: underline;
}

.apais-bubble a:hover {
  opacity: 0.8;
}

/* Code blocks in bubbles */
.apais-bubble code {
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.06);
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
}

/* =========================
   FOOTER (Input area)
   ========================= */

.apais-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  flex-shrink: 0;
}

.apais-input {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  resize: none;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  outline: none;
  font-size: 14px;
  line-height: 1.25;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.2s;
}

.apais-input:focus {
  border-color: rgba(0, 0, 0, 0.28);
}

.apais-input::placeholder {
  color: rgba(0, 0, 0, 0.4);
}

/* Button row */
.apais-footer > div {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}

/* =========================
   BUTTONS
   ========================= */

.apais-send,
.apais-human {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: #111;
  color: #fff;
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  font-family: inherit;
  transition: filter 0.2s, opacity 0.2s;
}

.apais-human {
  background: #fff;
  color: #111;
}

.apais-send:hover {
  filter: brightness(1.06);
}

.apais-human:hover {
  background: #f3f4f6;
}

.apais-send:disabled,
.apais-human:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =========================
   CTA BUTTON (Product pages)
   ========================= */

.apais-talk-btn {
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  cursor: pointer;
  font-weight: 800;
  transition: transform 0.2s, box-shadow 0.2s;
}

.apais-talk-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.apais-btn--small {
  font-size: 13px;
  padding: 10px 12px;
}

.apais-btn--large {
  font-size: 16px;
  padding: 14px 18px;
}

/* =========================
   SUPPORT LAUNCHER (Floating button)
   ========================= */

.apais-support-launcher {
  position: fixed !important;
  bottom: 20px !important;
  right: 20px !important;
  padding: 14px 18px;
  background: #111;
  color: #fff;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 50px;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-appearance: none;
}

.apais-support-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

/* =========================
   PRODUCT CARDS (Upsell/Crosssell)
   ========================= */

.apais-product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-width: 86%;
}

.apais-product-card {
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
  transition: box-shadow 0.2s;
}

.apais-product-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.apais-product-card img {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  object-fit: cover;
  background: #f2f2f2;
  flex: 0 0 auto;
}

.apais-product-card .info {
  flex: 1;
}

.apais-product-card .name {
  font-weight: 800;
  font-size: 13px;
  line-height: 1.2;
}

.apais-product-card .price {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 3px;
}

.apais-product-card .actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* =========================
   ACTION BUTTONS (Add to cart, etc)
   ========================= */

.apais-action-wrap {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-start;
  max-width: 86%;
}

.apais-action-btn {
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #111;
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
  transition: filter 0.2s, opacity 0.2s;
}

.apais-action-btn--light {
  background: #fff;
  color: #111;
}

.apais-action-btn:hover {
  filter: brightness(1.06);
}

.apais-action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =========================
   HUMAN REQUEST FORM (Inline)
   ========================= */

.apais-human-form {
  padding: 10px 12px;
  border: 1px solid rgba(0, 0, 0, 0.10);
  background: #fff;
  border-radius: 14px;
  max-width: 86%;
}

.apais-human-form input {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  font-size: 14px;
  width: 100%;
  margin-bottom: 8px;
  font-family: inherit;
}

.apais-human-form button {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  font-weight: 800;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background 0.2s;
}

.apais-human-form button[data-act="send"] {
  background: #111;
  color: #fff;
}

.apais-human-form button[data-act="cancel"] {
  background: #fff;
  color: #111;
}

.apais-human-form button:hover {
  opacity: 0.9;
}

/* =========================
   MOBILE RESPONSIVE
   ========================= */

@media (max-width: 768px) {
  
  .apais-window {
    width: 96vw !important;
    max-height: 85vh !important;
  }
  
  .apais-window--floating {
    bottom: 72px !important;
    right: 12px !important;
    width: calc(100vw - 24px) !important;
    max-height: 70vh !important;
  }
  
  .apais-support-launcher {
    bottom: 16px !important;
    right: 16px !important;
    padding: 12px 16px !important;
    font-size: 13px !important;
  }
  
  .apais-bubble {
    max-width: 90%;
  }
  
  .apais-product-grid {
    grid-template-columns: 1fr;
    max-width: 90%;
  }
  
  .apais-action-wrap {
    max-width: 90%;
  }
}

@media (max-width: 480px) {
  
  .apais-header {
    padding: 10px 12px;
  }
  
  .apais-title {
    font-size: 13px;
  }
  
  .apais-close {
    width: 32px;
    height: 28px;
    font-size: 14px;
  }
  
  .apais-messages {
    padding: 12px;
  }
  
  .apais-bubble {
    font-size: 13px;
    padding: 9px 11px;
  }
  
  .apais-footer {
    padding: 10px;
  }
  
  .apais-input {
    min-height: 38px;
    font-size: 13px;
  }
  
  .apais-send,
  .apais-human {
    font-size: 12px;
    padding: 9px 11px;
  }
}

/* =========================
   LOADING STATE
   ========================= */

.apais-loading {
  text-align: center;
  padding: 20px;
  color: rgba(0, 0, 0, 0.5);
  font-size: 14px;
}

/* =========================
   UTILITIES
   ========================= */

.apais-hidden {
  display: none !important;
}

.apais-visible {
  display: block !important;
}

/* Prevent text selection on buttons */
.apais-send,
.apais-human,
.apais-close,
.apais-talk-btn,
.apais-support-launcher,
.apais-action-btn {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* =========================
   PRINT STYLES (Hide chat)
   ========================= */

@media print {
  .apais-overlay,
  .apais-window,
  .apais-support-launcher,
  .apais-talk-btn {
    display: none !important;
  }
}