/* ================================================================
   MR GIWU — Live Chat Widget
   GIWU Construction and Trading Co. Ltd
   ================================================================ */

#giwu-chat {
  --gc-green:      #173b22;
  --gc-green-dark: #0f2818;
  --gc-green-mid:  #245231;
  --gc-gold:       #d1aa5d;
  --gc-gold-light: #e8c87a;
  --gc-ink:        #18221b;
  --gc-muted:      #5a6b5e;
  --gc-bg:         #f7f9f7;
  --gc-border:     #dde8de;
  --gc-radius:     20px;
  font-family: "Manrope", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

#giwu-chat *,
#giwu-chat *::before,
#giwu-chat *::after { box-sizing: border-box; }

/* ── Shared avatar SVG ──────────────────────────────────────── */
.mr-giwu-avatar-svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── LAUNCHER BUTTON ────────────────────────────────────────── */
.giwu-chat-launch {
  position: fixed;
  right: 24px;
  bottom: 96px;   /* clears the 56px WhatsApp button (bottom:24px) + gap */
  z-index: 10001;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 10px 10px;
  border: none;
  border-radius: 50px;
  background: var(--gc-green);
  box-shadow: 0 6px 24px rgba(11,26,15,.35), 0 2px 8px rgba(11,26,15,.2);
  color: #fff;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s, background .2s;
  text-align: left;
}

.giwu-chat-launch:hover {
  background: var(--gc-green-mid);
  transform: translateY(-3px);
  box-shadow: 0 10px 32px rgba(11,26,15,.4);
}

.giwu-chat-launch--open {
  background: var(--gc-green-dark);
}

/* avatar container in launcher */
.giwu-launch-avatar {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: visible;
}

.giwu-launch-avatar .mr-giwu-avatar-svg {
  border-radius: 50%;
  border: 2px solid rgba(209,170,93,.5);
}

/* online dot on launcher */
.giwu-launch-dot {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #3ecf69;
  border: 2px solid var(--gc-green);
}

/* text block in launcher */
.giwu-launch-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.2;
}

.giwu-launch-text strong {
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  letter-spacing: .2px;
}

.giwu-launch-text span {
  font-size: 11px;
  color: rgba(255,255,255,.72);
  font-weight: 500;
}

/* chevron */
.giwu-launch-chevron {
  font-size: 18px;
  line-height: 1;
  color: rgba(255,255,255,.55);
  margin-left: 2px;
}

/* ── PANEL ───────────────────────────────────────────────────── */
.giwu-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 168px;  /* above launcher (96px) + launcher height (~62px) + 10px gap */
  z-index: 10002;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  height: min(590px, calc(100dvh - 120px));
  min-height: 380px;
  border-radius: var(--gc-radius);
  background: #fff;
  box-shadow: 0 20px 60px rgba(11,26,15,.28), 0 4px 16px rgba(11,26,15,.12);
  overflow: hidden;
  animation: gc-slide-up .22s ease;
}

.giwu-chat-panel[hidden] { display: none; }

@keyframes gc-slide-up {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── HEADER ──────────────────────────────────────────────────── */
.giwu-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--gc-green) 0%, var(--gc-green-mid) 100%);
  flex-shrink: 0;
}

.giwu-chat-header-avatar {
  position: relative;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid rgba(209,170,93,.4);
  overflow: visible;
}

.giwu-chat-header-avatar .mr-giwu-avatar-svg {
  border-radius: 50%;
}

.giwu-header-dot {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #3ecf69;
  border: 2px solid var(--gc-green);
  animation: gc-pulse 2s infinite;
}

@keyframes gc-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(62,207,105,.5); }
  50%       { box-shadow: 0 0 0 5px rgba(62,207,105,0); }
}

.giwu-chat-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.giwu-chat-header-info strong {
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  letter-spacing: .3px;
}

.giwu-chat-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: rgba(255,255,255,.75);
}

.giwu-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3ecf69;
  flex-shrink: 0;
}

.giwu-chat-header-actions {
  display: flex;
  gap: 6px;
}

.giwu-chat-close {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
  color: #fff;
  cursor: pointer;
  transition: background .15s;
}

.giwu-chat-close:hover { background: rgba(255,255,255,.22); }

.giwu-chat-close svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ── MESSAGES AREA ───────────────────────────────────────────── */
.giwu-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--gc-bg);
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

/* scrollbar */
.giwu-chat-messages::-webkit-scrollbar { width: 5px; }
.giwu-chat-messages::-webkit-scrollbar-track { background: transparent; }
.giwu-chat-messages::-webkit-scrollbar-thumb { background: #c8d4c9; border-radius: 4px; }

/* ── MESSAGE WRAP ────────────────────────────────────────────── */
.giwu-msg-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 92%;
}

.giwu-msg-wrap--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.giwu-msg-wrap--assistant {
  align-self: flex-start;
}

/* avatar in messages */
.giwu-msg-avatar {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 1.5px solid var(--gc-border);
}

/* timestamp */
.giwu-msg-time {
  font-size: 10px;
  color: #9aaa9c;
  align-self: flex-end;
  flex-shrink: 0;
  margin-bottom: 2px;
}

/* ── BUBBLES ─────────────────────────────────────────────────── */
.giwu-msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.giwu-msg-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.giwu-msg-bubble--assistant {
  background: #fff;
  color: var(--gc-ink);
  border: 1px solid var(--gc-border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.giwu-msg-bubble--user {
  background: var(--gc-green);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(23,59,34,.2);
}

.giwu-msg-bubble--user a { color: var(--gc-gold-light); }

.giwu-msg-bubble--error {
  background: #fff5f2;
  border-color: #f0c8bc;
  color: #7a3020;
}

/* ── TYPING INDICATOR ────────────────────────────────────────── */
.giwu-typing-dots {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  min-width: 56px;
}

.giwu-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aaa9c;
  animation: gc-bounce .9s infinite ease-in-out;
}

.giwu-typing-dots span:nth-child(2) { animation-delay: .15s; }
.giwu-typing-dots span:nth-child(3) { animation-delay: .30s; }

@keyframes gc-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-6px); }
}

/* ── QUICK REPLY CHIPS ───────────────────────────────────────── */
.giwu-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 6px 14px 2px;
  background: var(--gc-bg);
  flex-shrink: 0;
}

.giwu-chip {
  padding: 6px 13px;
  border: 1.5px solid var(--gc-green);
  border-radius: 999px;
  background: #fff;
  color: var(--gc-green);
  font: 600 12px/1.3 "Manrope", Arial, sans-serif;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}

.giwu-chip:hover {
  background: var(--gc-green);
  color: #fff;
}

/* ── NOTICE ──────────────────────────────────────────────────── */
.giwu-chat-notice {
  margin: 0;
  padding: 5px 14px 6px;
  font-size: 10.5px;
  color: var(--gc-muted);
  background: var(--gc-bg);
  text-align: center;
  flex-shrink: 0;
  border-top: 1px solid var(--gc-border);
}

.giwu-chat-notice a {
  color: var(--gc-green);
  font-weight: 700;
  text-decoration: none;
}

/* ── INPUT FORM ──────────────────────────────────────────────── */
.giwu-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  background: #fff;
  border-top: 1px solid var(--gc-border);
  flex-shrink: 0;
}

.giwu-chat-form textarea {
  flex: 1 1 auto;
  min-height: 42px;
  max-height: 110px;
  resize: none;
  padding: 11px 13px;
  border: 1.5px solid var(--gc-border);
  border-radius: 14px;
  background: var(--gc-bg);
  color: var(--gc-ink);
  font: 400 13.5px/1.45 "Manrope", Arial, sans-serif;
  outline: none;
  transition: border-color .15s;
}

.giwu-chat-form textarea:focus {
  border-color: var(--gc-green);
  background: #fff;
}

.giwu-send-btn {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: none;
  border-radius: 14px;
  background: var(--gc-gold);
  color: var(--gc-green);
  cursor: pointer;
  transition: background .15s, transform .15s;
}

.giwu-send-btn:hover:not(:disabled) {
  background: var(--gc-gold-light);
  transform: scale(1.05);
}

.giwu-send-btn:disabled { opacity: .45; cursor: wait; }

.giwu-send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── ACCESSIBILITY ───────────────────────────────────────────── */
.giwu-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  clip-path: inset(50%);
}

/* ── MOBILE ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* On phones the launcher is a round avatar button the same size as the
     WhatsApp button, stacked directly above it, so it covers less text. */
  .giwu-chat-launch {
    right: 14px;
    bottom: 76px;  /* 52px WhatsApp button at bottom:14px + 10px gap */
    width: 52px;
    height: 52px;
    padding: 4px;
    gap: 0;
    justify-content: center;
  }

  .giwu-launch-avatar { width: 44px; height: 44px; }
  .giwu-launch-text,
  .giwu-launch-chevron { display: none; }

  /* Pages with the fixed Call / Quote bar lift both buttons above it. */
  body:has(.mobile-contact-bar) .giwu-chat-launch { bottom: 124px; }
  /* Home page: its Call / Quote bar is .action-bar; WhatsApp sits at 60px, so the chat goes above it. */
  body:has(.action-bar) .giwu-chat-launch { bottom: 122px; }

  .giwu-chat-panel {
    /* On mobile: almost full screen, anchored bottom */
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: min(85dvh, 560px);
    border-radius: 20px 20px 0 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  /* Mobile slide-up from bottom */
  .giwu-chat-panel:not([hidden]) {
    animation: gc-sheet-up .25s ease;
  }

  @keyframes gc-sheet-up {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
}

@media (prefers-reduced-motion: reduce) {
  .giwu-chat-launch,
  .giwu-send-btn,
  .giwu-chip { transition: none; }
  .giwu-chat-panel { animation: none; }
  .giwu-header-dot { animation: none; }
  .giwu-typing-dots span { animation: none; }
}
