:root {
  --glwc-navy: #162544;
  --glwc-orange: #f7933a;
  --glwc-green: #25d366;
  --glwc-text: #1f2937;
  --glwc-muted: #6b7280;
}

.glwc-widget,
.glwc-widget * {
  box-sizing: border-box;
}

.glwc-widget {
  font-family: Inter, Arial, Helvetica, sans-serif;
  position: relative;
  z-index: 999999;
}

.glwc-floating-wrap {
  position: fixed;
  right: 16px;
  bottom: 16px;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 999999;
}

.glwc-tooltip {
  position: absolute;
  right: calc(clamp(54px, 7vw, 64px) + 12px);
  top: 50%;
  transform: translateY(-50%);
  max-width: min(260px, calc(100vw - 110px));
  overflow: hidden;
  text-overflow: ellipsis;
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
}

.glwc-toggle {
  width: clamp(54px, 7vw, 64px);
  height: clamp(54px, 7vw, 64px);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--glwc-green);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 30px rgba(37, 211, 102, 0.35);
  cursor: pointer;
  position: relative;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}


.glwc-toggle:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 16px 34px rgba(37, 211, 102, 0.42);
}

.glwc-toggle:focus-visible,
.glwc-close:focus-visible,
.glwc-send:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.45);
  outline-offset: 3px;
}

.glwc-toggle svg {
  width: clamp(28px, 4vw, 34px);
  height: clamp(28px, 4vw, 34px);
  fill: #fff;
}

.glwc-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  border: 3px solid #fff;
  animation: glwc-pulse 1.6s infinite;
}

@keyframes glwc-pulse {
  0% { transform: scale(1); opacity: 1; }
  70% { transform: scale(1.35); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

.glwc-chat {
  position: fixed;
  right: 16px;
  bottom: 92px;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + clamp(66px, 8vw, 78px));
  width: 380px;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 118px);
  max-height: min(720px, calc(100dvh - 118px));
  max-height: min(720px, calc(var(--glwc-viewport-height, 100dvh) - 118px));
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: clamp(16px, 3vw, 22px);
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.28);
  transform: translateY(18px) scale(0.98);
  transform-origin: bottom right;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.28s ease, opacity 0.28s ease, visibility 0.28s ease;
  z-index: 999999;
}

.glwc-chat.is-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.glwc-header {
  flex: 0 0 auto;
  min-height: 76px;
  background: var(--glwc-navy);
  color: #fff;
  padding: clamp(14px, 2.5vw, 18px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.glwc-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.glwc-brand-copy {
  min-width: 0;
}

.glwc-avatar {
  flex: 0 0 auto;
  width: clamp(38px, 6vw, 44px);
  height: clamp(38px, 6vw, 44px);
  border-radius: 14px;
  background: var(--glwc-orange);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(247, 147, 58, 0.35);
}

.glwc-brand h3 {
  margin: 0;
  color: #fff;
  font-size: clamp(14px, 3.8vw, 16px);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.glwc-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #dbe7ff;
  font-size: clamp(11px, 3vw, 12px);
  line-height: 1.3;
  margin-top: 4px;
}

.glwc-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18);
}

.glwc-close {
  flex: 0 0 auto;
  -webkit-appearance: none;
  appearance: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.glwc-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: #f8fafc;
  padding: clamp(12px, 3vw, 18px);
  scrollbar-width: thin;
}

.glwc-message {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.glwc-bubble {
  width: 100%;
  background: #fff;
  color: var(--glwc-text);
  padding: clamp(12px, 3vw, 14px);
  border-radius: 16px 16px 16px 6px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  font-size: clamp(13px, 3.5vw, 14px);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.glwc-time {
  color: var(--glwc-muted);
  font-size: 11px;
  margin-top: 6px;
}

.glwc-form {
  margin: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  padding: clamp(12px, 3vw, 14px);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.glwc-field {
  margin-bottom: 12px;
}

.glwc-field input,
.glwc-field textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  color: var(--glwc-text);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.35;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  appearance: none;
}

.glwc-field input:focus,
.glwc-field textarea:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

.glwc-field textarea {
  min-height: clamp(76px, 14vh, 92px);
  max-height: 180px;
  resize: vertical;
}

.glwc-send {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
  border: 0;
  border-radius: 14px;
  padding: 13px 16px;
  background: linear-gradient(135deg, var(--glwc-orange), #ff8b2b);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(247, 147, 58, 0.35);
}

.glwc-send:hover {
  filter: brightness(1.03);
}

.glwc-footer {
  text-align: center;
  color: var(--glwc-muted);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 10px;
}

.glwc-credit {
  margin-top: 5px;
  text-align: center;
  color: #94a3b8;
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: 0.02em;
}

@media (max-width: 480px) {
  .glwc-floating-wrap {
    right: 12px;
    bottom: 12px;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .glwc-tooltip {
    display: none;
  }

  .glwc-chat {
    left: 10px;
    right: 10px;
    bottom: 78px;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 66px);
    width: auto;
    max-width: none;
    max-height: calc(100vh - 92px);
    max-height: calc(100dvh - 92px - env(safe-area-inset-top));
    max-height: calc(var(--glwc-viewport-height, 100dvh) - 92px - env(safe-area-inset-top));
    border-radius: 18px;
    transform-origin: bottom center;
  }

  .glwc-header {
    min-height: 68px;
    padding: 12px 14px;
  }

  .glwc-body {
    padding: 12px;
  }

  .glwc-form {
    padding: 12px;
  }

  .glwc-field {
    margin-bottom: 10px;
  }

  .glwc-field textarea {
    min-height: 72px;
  }

  .glwc-send {
    min-height: 46px;
  }
}

@media (max-width: 360px) {
  .glwc-chat {
    left: 6px;
    right: 6px;
  }

  .glwc-brand {
    gap: 9px;
  }

  .glwc-avatar {
    width: 36px;
    height: 36px;
    border-radius: 11px;
  }

  .glwc-brand h3 {
    font-size: 14px;
  }

  .glwc-status {
    font-size: 10px;
  }
}

@media (max-height: 700px) {
  .glwc-chat {
    max-height: calc(100vh - 92px);
    max-height: calc(100dvh - 92px);
    max-height: calc(var(--glwc-viewport-height, 100dvh) - 92px);
  }

  .glwc-header {
    min-height: 66px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .glwc-avatar {
    width: 38px;
    height: 38px;
  }

  .glwc-body {
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .glwc-bubble {
    line-height: 1.42;
  }

  .glwc-field {
    margin-bottom: 9px;
  }

  .glwc-field input,
  .glwc-field textarea {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .glwc-field textarea {
    min-height: 68px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .glwc-tooltip {
    display: none;
  }

  .glwc-chat {
    top: 8px;
    bottom: 8px;
    top: max(8px, env(safe-area-inset-top));
    bottom: max(8px, env(safe-area-inset-bottom));
    max-height: none;
    width: min(430px, calc(100vw - 90px));
  }

  .glwc-header {
    min-height: 58px;
  }

  .glwc-status,
  .glwc-message {
    display: none;
  }

  .glwc-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }

  .glwc-field {
    margin: 0;
  }

  .glwc-field:nth-child(3),
  .glwc-send,
  .glwc-footer {
    grid-column: 1 / -1;
  }

  .glwc-field textarea {
    min-height: 58px;
    max-height: 80px;
  }

  .glwc-footer {
    margin-top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .glwc-chat,
  .glwc-toggle,
  .glwc-field input,
  .glwc-field textarea {
    transition: none;
  }

  .glwc-badge {
    animation: none;
  }
}
