/* ============================================
   CHAT WIDGET — OKC Mobile Auto
   Industrial-sleek, dark navy/red theme
   ============================================ */

.chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9000;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #d32f2f;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(211, 47, 47, 0.4);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  animation: chat-pulse 2.5s ease-in-out infinite;
}
.chat-launcher:hover {
  transform: scale(1.1);
  box-shadow: 0 8px 30px rgba(211, 47, 47, 0.5);
  animation: none;
}
.chat-launcher svg {
  width: 28px;
  height: 28px;
  fill: #fff;
  transition: transform 0.3s;
}
.chat-launcher.is-open svg {
  transform: rotate(90deg) scale(0.9);
}
@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(211, 47, 47, 0.4); }
  50% { box-shadow: 0 4px 20px rgba(211, 47, 47, 0.4), 0 0 0 10px rgba(211, 47, 47, 0); }
}

/* Badge */
.chat-launcher__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: #0d1321;
  border: 2px solid #d32f2f;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', sans-serif;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
}
.chat-launcher__badge.has-unread {
  display: flex;
  animation: badge-pop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes badge-pop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* ===== CHAT PANEL ===== */
.chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 9000;
  width: 370px;
  height: 520px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.8) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom right;
}
.chat-panel.is-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* Header */
.chat-panel__header {
  background: #0d1321;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-panel__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #1a1f3d;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #d32f2f;
  flex-shrink: 0;
}
.chat-panel__avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.chat-panel__header-text h4 {
  font-family: 'Teko', sans-serif;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1.2;
}
.chat-panel__header-text p {
  font-family: 'Outfit', sans-serif;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.45);
}
.chat-panel__status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  margin-left: auto;
  flex-shrink: 0;
  animation: status-blink 3s ease-in-out infinite;
}
@keyframes status-blink {
  0%, 90%, 100% { opacity: 1; }
  95% { opacity: 0.3; }
}

/* Close button */
.chat-panel__close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-size: 20px;
  cursor: pointer;
  padding: 0 0 0 8px;
  transition: color 0.2s;
}
.chat-panel__close:hover { color: #fff; }

/* ===== PRE-CHAT FORM ===== */
.chat-prechat {
  flex: 1;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
}
.chat-prechat__title {
  font-family: 'Teko', sans-serif;
  font-size: 22px;
  font-weight: 600;
  color: #0d1321;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.chat-prechat__sub {
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 20px;
  line-height: 1.5;
}
.chat-prechat input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #e8eaed;
  border-radius: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  color: #0d1321;
  background: #f4f5f7;
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.2s, background 0.2s;
}
.chat-prechat input::placeholder { color: #b0b3b8; }
.chat-prechat input:focus {
  border-color: #d32f2f;
  background: #fff;
}
.chat-prechat__btn {
  width: 100%;
  padding: 14px;
  background: #d32f2f;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: 'Teko', sans-serif;
  font-size: 18px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  margin-top: 6px;
  transition: background 0.2s, transform 0.2s;
}
.chat-prechat__btn:hover {
  background: #b71c1c;
  transform: translateY(-1px);
}

/* ===== CHAT BODY ===== */
.chat-body {
  flex: 1;
  padding: 16px 16px 8px;
  overflow-y: auto;
  display: none;
  flex-direction: column;
  gap: 8px;
  background: #f9fafb;
}
.chat-body.is-active { display: flex; }

.chat-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  animation: msg-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes msg-in {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}
.chat-msg--customer {
  background: #0d1321;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-msg--agent {
  background: #fff;
  color: #333;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid #e8eaed;
}
.chat-msg--system {
  align-self: center;
  background: none;
  color: #b0b3b8;
  font-size: 12px;
  text-align: center;
  padding: 4px 0;
}
.chat-typing {
  align-self: flex-start;
  padding: 10px 16px;
  display: none;
}
.chat-typing.is-visible { display: flex; }
.chat-typing span {
  width: 6px;
  height: 6px;
  background: #b0b3b8;
  border-radius: 50%;
  display: inline-block;
  margin: 0 2px;
  animation: typing-dot 1.4s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ===== CHAT INPUT ===== */
.chat-input {
  padding: 12px 16px;
  border-top: 1px solid #e8eaed;
  display: none;
  gap: 8px;
  align-items: center;
  background: #fff;
  flex-shrink: 0;
}
.chat-input.is-active { display: flex; }
.chat-input input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #e8eaed;
  border-radius: 20px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  color: #0d1321;
  outline: none;
  transition: border-color 0.2s;
}
.chat-input input::placeholder { color: #b0b3b8; }
.chat-input input:focus { border-color: #d32f2f; }
.chat-input button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #d32f2f;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
.chat-input button:hover { background: #b71c1c; }
.chat-input button svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* ===== END CHAT / TRANSCRIPT ===== */
.chat-end {
  padding: 20px;
  text-align: center;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex: 1;
  justify-content: center;
}
.chat-end.is-active { display: flex; }
.chat-end__icon { font-size: 36px; }
.chat-end h4 {
  font-family: 'Teko', sans-serif;
  font-size: 22px;
  font-weight: 600;
  color: #0d1321;
  text-transform: uppercase;
}
.chat-end p {
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  color: #6b7280;
}
.chat-end__btn {
  padding: 12px 24px;
  border-radius: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}
.chat-end__btn--yes {
  background: #d32f2f;
  color: #fff;
}
.chat-end__btn--yes:hover { background: #b71c1c; }
.chat-end__btn--no {
  background: #e8eaed;
  color: #333;
}
.chat-end__btn--no:hover { background: #d1d5db; }
.chat-end__sent {
  display: none;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  color: #4caf50;
  font-weight: 600;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    position: fixed;
    top: 0;
  }
  .chat-launcher {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
  }
  .chat-launcher svg {
    width: 24px;
    height: 24px;
  }
  .chat-body {
    padding: 12px 12px 8px;
  }
  .chat-input {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .chat-input input {
    font-size: 16px; /* prevents zoom on iOS */
  }
  .chat-prechat input {
    font-size: 16px;
  }
  .chat-panel__header {
    padding: 14px 16px;
    padding-top: max(14px, env(safe-area-inset-top));
  }
}
