/* ==========================================================================
   Smart Agent, 24/7 Garage Door and Gate Services
   Brand: cream / green / gold. Self-contained chat widget styles.
   ========================================================================== */

/* ---- Launcher (bottom-right stack: agent above WhatsApp FAB) ---- */
.sa-fab {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(148px + env(safe-area-inset-bottom, 0px));
  z-index: 116;
  width: 56px;
  height: 56px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(247, 241, 227, 0.88);
  background: radial-gradient(circle at 32% 26%, var(--green, #4fa23c), var(--green-dd, #1a3f14));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow:
    0 14px 30px -10px rgba(20, 40, 16, 0.6),
    0 0 0 1px rgba(110, 84, 16, 0.22);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.sa-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px -10px rgba(20, 40, 16, 0.72);
}
.sa-fab:focus-visible {
  outline: 3px solid var(--gold, #c2912f);
  outline-offset: 2px;
}
.sa-fab svg {
  width: 26px;
  height: 26px;
}
.sa-fab .sa-pulse {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--gold, #c2912f);
  border: 2px solid var(--cream, #f7f1e3);
  box-shadow: 0 0 0 0 rgba(194, 145, 47, 0.55);
  animation: sa-pulse 2.4s infinite;
}
@keyframes sa-pulse {
  0% { box-shadow: 0 0 0 0 rgba(194, 145, 47, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(194, 145, 47, 0); }
  100% { box-shadow: 0 0 0 0 rgba(194, 145, 47, 0); }
}

@media (min-width: 761px) {
  .sa-fab {
    bottom: calc(148px + env(safe-area-inset-bottom, 0px));
  }
}

/* ---- Panel (desktop: 380px card; mobile: bottom sheet) ---- */
.sa-scrim {
  position: fixed;
  inset: 0;
  z-index: 128;
  background: rgba(19, 48, 15, 0.38);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}
.sa-scrim.open {
  opacity: 1;
  visibility: visible;
}

.sa-panel {
  position: fixed;
  z-index: 130;
  display: none;
  flex-direction: column;
  overflow: hidden;
  background: var(--white, #fffdf8);
  border: 1px solid var(--line, #ddd5c4);
  box-shadow: 0 30px 70px -28px rgba(20, 40, 16, 0.72);
  font-family: var(--sans, Inter, system-ui, sans-serif);
}

/* Desktop layout */
@media (min-width: 761px) {
  .sa-panel {
    right: 16px;
    left: auto;
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
    width: 380px;
    max-height: min(620px, calc(100vh - 120px));
    border-radius: 18px;
  }
}

/* Mobile bottom sheet */
@media (max-width: 760px) {
  .sa-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100vw;
    max-height: min(88vh, calc(100dvh - env(safe-area-inset-top, 0px) - 12px));
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sa-panel.sa-kb-open {
    max-height: min(88vh, calc(var(--sa-vv-h, 100dvh) - 8px));
  }
  .sa-panel::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: rgba(44, 106, 34, 0.22);
    margin: 10px auto 0;
    flex-shrink: 0;
  }
}

.sa-panel.open {
  display: flex;
  animation: sa-panel-in 0.24s cubic-bezier(0.4, 0, 0.2, 1) both;
}
@keyframes sa-panel-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 760px) {
  @keyframes sa-panel-in {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

/* ---- Header ---- */
.sa-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
  background: linear-gradient(160deg, var(--green-dd, #1a3f14), var(--green-ink, #13300f));
  color: #fff;
  flex-shrink: 0;
}
.sa-ava {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, var(--gold-l, #e2c079), var(--gold, #c2912f));
  color: #241a04;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sa-ava svg {
  width: 20px;
  height: 20px;
}
.sa-tt {
  flex: 1;
  line-height: 1.25;
  min-width: 0;
}
.sa-tt b {
  font-family: var(--serif, Fraunces, Georgia, serif);
  font-weight: 600;
  font-size: 1.02rem;
  display: block;
}
.sa-tt span {
  font-size: 0.74rem;
  color: #bfe6b0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sa-tt span::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #86e06a;
  flex-shrink: 0;
}
.sa-close {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.12);
  border: 0;
  color: #fff;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 9px;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sa-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* ---- Thread ---- */
.sa-thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  background: var(--cream, #f7f1e3);
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.sa-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.48;
  word-wrap: break-word;
}
.sa-msg.bot {
  align-self: flex-start;
  background: var(--paper, #efe6d2);
  color: var(--ink, #1c2418);
  border: 1px solid var(--line, #ddd5c4);
  border-bottom-left-radius: 5px;
}
.sa-msg.user {
  align-self: flex-end;
  background: var(--green-d, #2c6a22);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.sa-msg a {
  color: var(--gold-d, #6e5410);
  font-weight: 700;
}
.sa-msg.user a {
  color: #fff;
  text-decoration: underline;
}

/* ---- Typing indicator ---- */
.sa-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
  background: var(--paper, #efe6d2);
  border: 1px solid var(--line, #ddd5c4);
  border-radius: 14px;
  border-bottom-left-radius: 5px;
}
.sa-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green, #4fa23c);
  opacity: 0.35;
  animation: sa-dot 1.2s infinite ease-in-out;
}
.sa-typing span:nth-child(2) { animation-delay: 0.15s; }
.sa-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sa-dot {
  0%, 80%, 100% { opacity: 0.35; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.15); }
}

/* ---- Action buttons in messages ---- */
.sa-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}
.sa-actions a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.81rem;
  border-radius: 9px;
  padding: 10px 14px;
  min-height: 44px;
  border: 1px solid transparent;
  transition: background 0.14s ease, box-shadow 0.14s ease;
}
.sa-actions a svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.sa-actions a.sa-act-call {
  background: linear-gradient(180deg, var(--gold-l, #e2c079), var(--gold, #c2912f));
  color: #241a04;
}
.sa-actions a.sa-act-text {
  background: var(--green-d, #2c6a22);
  color: #fff;
}
.sa-actions a.sa-act-book {
  background: var(--white, #fffdf8);
  color: var(--green-dd, #1a3f14);
  border-color: rgba(44, 106, 34, 0.35);
}
.sa-actions a.sa-act-contact {
  background: transparent;
  color: var(--green-dd, #1a3f14);
  border-color: rgba(44, 106, 34, 0.35);
}
.sa-actions a:hover {
  box-shadow: 0 6px 16px -8px rgba(20, 40, 16, 0.45);
}

/* ---- Quick-reply chips ---- */
.sa-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 14px 6px;
  background: var(--cream, #f7f1e3);
  border-top: 1px solid var(--line, #ddd5c4);
  flex-shrink: 0;
}
.sa-chip {
  font-family: var(--sans, Inter, system-ui, sans-serif);
  font-weight: 600;
  font-size: 0.79rem;
  color: var(--green-dd, #1a3f14);
  background: var(--white, #fffdf8);
  border: 1px solid var(--line, #ddd5c4);
  border-radius: 999px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease;
}
.sa-chip:hover {
  background: var(--sage, #e8f0e2);
  border-color: var(--green, #4fa23c);
}
.sa-chip:focus-visible {
  outline: 3px solid var(--gold, #c2912f);
  outline-offset: 1px;
}

/* ---- Input row ---- */
.sa-form {
  display: flex;
  gap: 7px;
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom, 0px));
  background: var(--cream, #f7f1e3);
  flex-shrink: 0;
}
.sa-form input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line, #ddd5c4);
  border-radius: 11px;
  padding: 11px 13px;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--ink, #1c2418);
  background: var(--white, #fffdf8);
}
.sa-form input[type="text"]::placeholder {
  color: var(--muted, #5a6b52);
}
.sa-form input[type="text"]:focus {
  outline: none;
  border-color: var(--green, #4fa23c);
  box-shadow: 0 0 0 3px rgba(79, 162, 60, 0.15);
}
.sa-send {
  flex-shrink: 0;
  background: var(--green-d, #2c6a22);
  border: 0;
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sa-send:hover {
  background: var(--green-dd, #1a3f14);
}
.sa-send svg {
  width: 19px;
  height: 19px;
}

/* ---- Inline lead capture ---- */
.sa-lead {
  align-self: stretch;
  max-width: 100%;
  background: var(--white, #fffdf8);
  border: 1px solid var(--line, #ddd5c4);
  border-radius: 14px;
  padding: 14px;
  margin-top: 2px;
}
.sa-lead p {
  margin: 0 0 10px;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--ink, #1c2418);
}
.sa-lead label {
  display: block;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--green-dd, #1a3f14);
  margin-bottom: 4px;
}
.sa-lead input,
.sa-lead textarea {
  width: 100%;
  font: inherit;
  font-size: 0.86rem;
  border: 1px solid var(--line, #ddd5c4);
  border-radius: 9px;
  padding: 9px 11px;
  background: var(--cream, #f7f1e3);
  margin-bottom: 10px;
  box-sizing: border-box;
}
.sa-lead input:focus,
.sa-lead textarea:focus {
  outline: none;
  border-color: var(--green, #4fa23c);
  box-shadow: 0 0 0 3px rgba(79, 162, 60, 0.12);
  background: #fff;
}
.sa-lead textarea {
  min-height: 64px;
  resize: vertical;
}
.sa-lead-submit {
  width: 100%;
  font: inherit;
  font-weight: 700;
  font-size: 0.86rem;
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
  background: linear-gradient(180deg, var(--gold-l, #e2c079), var(--gold, #c2912f));
  color: #241a04;
}
.sa-lead-submit:disabled {
  opacity: 0.6;
  cursor: wait;
}
.sa-lead-skip {
  display: block;
  width: 100%;
  margin-top: 8px;
  background: none;
  border: 0;
  font: inherit;
  font-size: 0.78rem;
  color: var(--muted, #5a6b52);
  cursor: pointer;
  text-decoration: underline;
  padding: 4px;
}
.sa-lead-status {
  font-size: 0.8rem;
  margin: 8px 0 0;
}
.sa-lead-status.ok { color: var(--green-d, #2c6a22); }
.sa-lead-status.err { color: #a33; }

/* ---- Accessibility / contrast overrides ---- */
body.a11y-contrast .sa-panel {
  background: #111;
  color: #fff;
  border-color: #666;
}
body.a11y-contrast .sa-thread,
body.a11y-contrast .sa-chips,
body.a11y-contrast .sa-form {
  background: #000;
}
body.a11y-contrast .sa-msg.bot,
body.a11y-contrast .sa-typing {
  background: #1a1a1a;
  color: #fff;
  border-color: #666;
}
body.a11y-contrast .sa-lead {
  background: #1a1a1a;
  border-color: #666;
  color: #fff;
}

@media (max-width: 760px) {
  .sa-form input[type="text"],
  .sa-lead input,
  .sa-lead textarea {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sa-fab .sa-pulse,
  .sa-typing span {
    animation: none;
  }
  .sa-panel.open,
  .sa-fab:hover,
  .sa-scrim {
    animation: none;
    transition: none;
  }
}
