/* ==========================================================
   UNIVERSAL EARTHING SOLUTIONS - CHATBOT STYLES
   All class names start with "uni-ear"
   ========================================================== */

.uni-ear-widget {
  /* ---- Change these to match your brand ---- */
  --uni-ear-primary: #1f2b35;        /* header / dark steel */
  --uni-ear-accent: #b87333;         /* copper rule + highlights */
  --uni-ear-accent-dark: #032289;    /* buttons, user bubble, chips (AA contrast with white) */
  --uni-ear-accent-darker: #6f3e15;
  --uni-ear-bg: #f3f4f5;
  --uni-ear-bot: #ffffff;
  --uni-ear-text: #1b2229;
  --uni-ear-muted: #5b6670;
  --uni-ear-line: #dadfe3;
  --uni-ear-error: #b3261e;

  /* Distance from the right edge / bottom of the screen */
  --uni-ear-offset-right: 15px;
  --uni-ear-offset-bottom: 15px;

  font-family: inherit, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--uni-ear-text);
}

.uni-ear-widget *,
.uni-ear-widget *::before,
.uni-ear-widget *::after {
  box-sizing: border-box;
}

.uni-ear-widget button,
.uni-ear-widget input,
.uni-ear-widget select,
.uni-ear-widget textarea {
  font-family: inherit;
  margin: 0;
}


/* ----------------------------------------------------------
   FLOATING TOGGLE (right side, 15px from the edge)
   ---------------------------------------------------------- */

.uni-ear-toggle {
  position: fixed;
  right: var(--uni-ear-offset-right);
  bottom: 188px;
  z-index: 99998;
  width: 43px;
  height: 43px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--uni-ear-accent-dark);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(31, 43, 53, 0.35);
  transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease, visibility 0s;
}

.uni-ear-toggle:hover {
  background: var(--uni-ear-accent-darker);
  transform: scale(1.06);
}

.uni-ear-toggle:focus-visible,
.uni-ear-close:focus-visible,
.uni-ear-send:focus-visible,
.uni-ear-quick-btn:focus-visible,
.uni-ear-submit:focus-visible,
.uni-ear-link-btn:focus-visible {
  outline: 3px solid var(--uni-ear-accent);
  outline-offset: 2px;
}

.uni-ear-toggle::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--uni-ear-accent);
  opacity: 0;
  animation: uni-ear-pulse 2.2s ease-out 1s 3;
  pointer-events: none;
}

.uni-ear-toggle-icon {
  width: 28px;
  height: 28px;
  display: block;
}

.uni-ear-toggle-hidden {
  opacity: 0;
  visibility: hidden;
  transform: scale(0.6);
  pointer-events: none;
}

.uni-ear-tip {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) translateX(6px);
  background: #fff;
  color: var(--uni-ear-text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(31, 43, 53, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.uni-ear-tip-show {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}


/* ----------------------------------------------------------
   CHAT WINDOW
   ---------------------------------------------------------- */

.uni-ear-window {
  position: fixed;
  right: var(--uni-ear-offset-right);
  bottom: calc(var(--uni-ear-offset-bottom) + 68px + env(safe-area-inset-bottom, 0px));
  z-index: 99999;
  width: 380px;
  max-width: calc(100vw - 25px);
  height: min(600px, calc(100vh - 110px));
  height: min(600px, calc(100dvh - 110px));
  display: flex;
  flex-direction: column;
  background: var(--uni-ear-bg);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(31, 43, 53, 0.35);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
  outline: none;
}

.uni-ear-window.uni-ear-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition-delay: 0s;
}


/* Header */

.uni-ear-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: var(--uni-ear-primary);
  border-bottom: 3px solid var(--uni-ear-accent);
  color: #fff;
}

.uni-ear-avatar {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--uni-ear-accent-dark);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.uni-ear-head-text {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.uni-ear-head-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.uni-ear-head-status {
  font-size: 12.5px;
  line-height: 1.2;
  color: rgba(255, 255, 255, 0.82);
  display: flex;
  align-items: center;
  gap: 6px;
}

.uni-ear-head-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3ddc84;
  flex: 0 0 auto;
}

.uni-ear-close {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.uni-ear-close:hover {
  background: rgba(255, 255, 255, 0.14);
}


/* Messages */

.uni-ear-body {
  position: relative;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px;
  background: var(--uni-ear-bg);
}

.uni-ear-msg {
  display: flex;
  margin-bottom: 8px;
}

.uni-ear-msg-bot {
  justify-content: flex-start;
}

.uni-ear-msg-user {
  justify-content: flex-end;
}

.uni-ear-bubble {
  max-width: 86%;
  padding: 10px 13px;
  font-size: 14.5px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  border-radius: 14px;
}

.uni-ear-msg-bot .uni-ear-bubble {
  background: var(--uni-ear-bot);
  border: 1px solid var(--uni-ear-line);
  border-bottom-left-radius: 4px;
}

.uni-ear-msg-user .uni-ear-bubble {
  background: var(--uni-ear-accent-dark);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.uni-ear-bubble a {
  color: var(--uni-ear-accent-dark);
  font-weight: 600;
  text-decoration: underline;
}

.uni-ear-link-btn,
.uni-ear-bubble a.uni-ear-link-btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--uni-ear-primary);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
}

.uni-ear-link-btn:hover {
  background: #2c3b47;
}

/* Typing indicator */

.uni-ear-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 13px 14px;
}

.uni-ear-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--uni-ear-muted);
  animation: uni-ear-blink 1.1s infinite ease-in-out;
}

.uni-ear-typing span:nth-child(2) { animation-delay: 0.15s; }
.uni-ear-typing span:nth-child(3) { animation-delay: 0.3s; }

/* Quick reply chips */

.uni-ear-quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 12px;
}

.uni-ear-quick-btn {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 13px;
  border: 1.5px solid var(--uni-ear-accent-dark);
  border-radius: 999px;
  background: #fff;
  color: var(--uni-ear-accent-dark);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.uni-ear-quick-btn:hover {
  background: var(--uni-ear-accent-dark);
  color: #fff;
}


/* ----------------------------------------------------------
   ENQUIRY FORM (inside a bot bubble)
   ---------------------------------------------------------- */

.uni-ear-bubble.uni-ear-form-bubble {
  width: 100%;
  max-width: 100%;
  padding: 14px;
}

.uni-ear-form-title {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
}

.uni-ear-field {
  margin-bottom: 11px;
}

.uni-ear-label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--uni-ear-text);
}

.uni-ear-input,
.uni-ear-select,
.uni-ear-textarea {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--uni-ear-line);
  border-radius: 10px;
  background: #fff;
  color: var(--uni-ear-text);
  font-size: 15px;
  line-height: 1.35;
  appearance: none;
  -webkit-appearance: none;
}

.uni-ear-select {
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235b6670' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.uni-ear-textarea {
  resize: vertical;
  min-height: 92px;
}

.uni-ear-input:focus,
.uni-ear-select:focus,
.uni-ear-textarea:focus {
  border-color: var(--uni-ear-accent-dark);
  outline: 2px solid rgba(138, 79, 31, 0.25);
  outline-offset: 0;
}

.uni-ear-input[aria-invalid="true"],
.uni-ear-select[aria-invalid="true"],
.uni-ear-textarea[aria-invalid="true"] {
  border-color: var(--uni-ear-error);
}

.uni-ear-err {
  display: block;
  margin-top: 3px;
  font-size: 12.5px;
  line-height: 1.3;
  color: var(--uni-ear-error);
}

.uni-ear-err:empty {
  display: none;
}

.uni-ear-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  overflow: hidden !important;
}

.uni-ear-captcha {
  margin-bottom: 8px;
  overflow-x: auto;
}

.uni-ear-submit {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--uni-ear-accent-dark);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.uni-ear-submit:hover {
  background: var(--uni-ear-accent-darker);
}

.uni-ear-submit:disabled {
  opacity: 0.75;
  cursor: not-allowed;
}

.uni-ear-submit.uni-ear-loading::after {
  content: "";
  width: 15px;
  height: 15px;
  margin-left: 10px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: uni-ear-spin 0.7s linear infinite;
}

.uni-ear-status {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--uni-ear-error);
}

.uni-ear-status:empty {
  display: none;
}

.uni-ear-privacy {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--uni-ear-muted);
}


/* ----------------------------------------------------------
   COMPOSER + FOOTER
   ---------------------------------------------------------- */

.uni-ear-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid var(--uni-ear-line);
}

.uni-ear-text-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 11px 15px;
  border: 1.5px solid var(--uni-ear-line);
  border-radius: 999px;
  background: #fff;
  color: var(--uni-ear-text);
  font-size: 15px;
}

.uni-ear-text-input:focus {
  border-color: var(--uni-ear-accent-dark);
  outline: 2px solid rgba(138, 79, 31, 0.25);
}

.uni-ear-send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--uni-ear-accent-dark);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.uni-ear-send:hover {
  background: var(--uni-ear-accent-darker);
}

.uni-ear-send svg {
  width: 20px;
  height: 20px;
}

.uni-ear-foot {
  flex: 0 0 auto;
  padding: 0 12px 9px;
  background: #fff;
  text-align: center;
  font-size: 11.5px;
  color: var(--uni-ear-muted);
}


/* ----------------------------------------------------------
   MOBILE
   ---------------------------------------------------------- */

@media (max-width: 600px) {

  .uni-ear-toggle {
    width: 43px;
    height: 43px;
    right: 6px;
  }

  .uni-ear-tip {
    display: none;
  }

  .uni-ear-window {
    left: 10px;
    right: var(--uni-ear-offset-right);
    width: auto;
    max-width: none;
    bottom: calc(var(--uni-ear-offset-bottom) + 62px + env(safe-area-inset-bottom, 0px));
    height: min(600px, calc(100vh - 100px));
    height: min(600px, calc(100dvh - 100px));
    border-radius: 14px;
  }

  .uni-ear-quick-btn {
    min-height: 44px;
  }

  /* 16px stops iOS from zooming into inputs */
  .uni-ear-text-input,
  .uni-ear-input,
  .uni-ear-select,
  .uni-ear-textarea {
    font-size: 16px;
  }

  .uni-ear-bubble {
    max-width: 90%;
  }
}

@media (max-height: 520px) {
  .uni-ear-foot {
    display: none;
  }
}


/* ----------------------------------------------------------
   KEYFRAMES + REDUCED MOTION
   ---------------------------------------------------------- */

@keyframes uni-ear-pulse {
  0%   { opacity: 0.7; transform: scale(1); }
  100% { opacity: 0;   transform: scale(1.6); }
}

@keyframes uni-ear-blink {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40%           { opacity: 1;   transform: translateY(-3px); }
}

@keyframes uni-ear-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .uni-ear-widget *,
  .uni-ear-widget *::before,
  .uni-ear-widget *::after {
    animation: none !important;
    transition: none !important;
  }
}
