/* ── DCR Live Chat Widget ─────────────────────────────────────────────────── */

/* ── Launcher wrapper (bubble + label) ─────────────────────────────────────── */

.dcr-chat-launcher {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.dcr-chat-launcher.chat-active {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.75) translateY(10px);
}

/* ── Bubble (trigger button) ───────────────────────────────────────────────── */

.dcr-chat-bubble {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: #F5870A;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(245, 135, 10, 0.40);
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
  outline: none;
}


.dcr-chat-bubble:hover {
  background: #E07500;
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(245, 135, 10, 0.55);
}

.dcr-chat-bubble:focus-visible {
  outline: 2px solid var(--blue-light);
  outline-offset: 3px;
}

.dcr-chat-bubble svg {
  width: 24px;
  height: 24px;
  color: var(--white);
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.dcr-chat-bubble .dcr-cb-icon-open { display: block; }

/* Unread badge */
.dcr-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--av-red);
  color: var(--white);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  line-height: 20px;
  text-align: center;
  display: none;
  border: 2px solid var(--white);
}

.dcr-chat-badge.visible { display: block; }

/* ── Window ────────────────────────────────────────────────────────────────── */

.dcr-chat-window {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  z-index: 9000;
  width: 360px;
  height: 520px;
  max-height: 80vh;
  background: var(--white);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-2xl);
  box-shadow: 0 8px 40px rgba(13, 71, 161, 0.14);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.88) translateY(16px);
  transform-origin: bottom right;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease, transform 0.24s ease;
}

.dcr-chat-window.is-open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ── Header ────────────────────────────────────────────────────────────────── */

.dcr-cw-header {
  background: var(--navy);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
}

.dcr-cw-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255,255,255,0.12);
  border-radius: 50%;
  color: var(--white);
  cursor: pointer;
  flex-shrink: 0;
  margin-left: auto;
  transition: background 0.15s;
}
.dcr-cw-close-btn:hover { background: rgba(255,255,255,0.22); }
.dcr-cw-close-btn svg   { width: 14px; height: 14px; }

.dcr-cw-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dcr-cw-avatar svg {
  width: 18px;
  height: 18px;
  color: var(--white);
}

.dcr-cw-info { flex: 1; min-width: 0; }

.dcr-cw-name {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  color: var(--white);
  line-height: var(--lh-tight);
}

.dcr-cw-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.dcr-cw-status-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--av-green);
  flex-shrink: 0;
}

.dcr-cw-status-dot.offline { background: var(--av-orange); }

.dcr-cw-status-text {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: rgba(255,255,255,0.75);
  line-height: 1;
}

/* ── Pre-chat form ─────────────────────────────────────────────────────────── */

.dcr-cw-prechat {
  flex: 1;
  padding: var(--sp-5);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.dcr-cw-prechat-title {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--fw-semibold);
  color: var(--text-dark);
  line-height: var(--lh-tight);
}

.dcr-cw-prechat-sub {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-mid);
  line-height: var(--lh-normal);
  margin-top: calc(var(--sp-1) * -1);
}

.dcr-cw-field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.dcr-cw-label {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--text-dark);
}
.dcr-cw-label span[aria-hidden="true"] { color: var(--av-red); }

.dcr-cw-input {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-dark);
  background: var(--white);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s;
}

.dcr-cw-input:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(13,71,161,0.08);
}
.dcr-cw-input.dcr-field-error {
  border-color: var(--av-red);
  box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.10);
}
select.dcr-cw-input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
  color: var(--text-dark);
}

.dcr-cw-start-btn {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  color: var(--white);
  background: var(--navy);
  border: none;
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-5);
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
  margin-top: var(--sp-2);
}

.dcr-cw-start-btn:hover { background: var(--blue); }
.dcr-cw-start-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Messages area ─────────────────────────────────────────────────────────── */

.dcr-cw-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  scroll-behavior: smooth;
}

.dcr-cw-messages::-webkit-scrollbar { width: 4px; }
.dcr-cw-messages::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 4px; }

/* System message */
.dcr-msg-system {
  text-align: center;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-muted);
  padding: var(--sp-1) 0;
}

/* Bubble row */
.dcr-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 80%;
}

.dcr-msg-row.from-visitor { align-self: flex-end; align-items: flex-end; }
.dcr-msg-row.from-admin   { align-self: flex-start; align-items: flex-start; }

.dcr-msg-bubble {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--lh-normal);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-xl);
  word-break: break-word;
}

.from-visitor .dcr-msg-bubble {
  background: var(--navy);
  color: var(--white);
  border-bottom-right-radius: var(--radius-sm);
}

.from-admin .dcr-msg-bubble {
  background: var(--page-bg);
  color: var(--text-dark);
  border: 1px solid var(--card-border);
  border-bottom-left-radius: var(--radius-sm);
}

.dcr-msg-time {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 3px;
}

/* Typing indicator */
.dcr-typing {
  display: none;
  align-self: flex-start;
  background: var(--page-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  border-bottom-left-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-4);
  gap: 4px;
  align-items: center;
}

.dcr-typing.visible { display: flex; }

.dcr-typing span {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--text-muted);
  animation: dcr-bounce 1.2s infinite ease-in-out;
}

.dcr-typing span:nth-child(2) { animation-delay: 0.2s; }
.dcr-typing span:nth-child(3) { animation-delay: 0.4s; }

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

/* ── Input bar ─────────────────────────────────────────────────────────────── */

.dcr-cw-inputbar {
  flex-shrink: 0;
  border-top: 1px solid var(--card-border);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  background: var(--white);
}

.dcr-cw-textarea {
  flex: 1;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-dark);
  background: var(--page-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--sp-2) var(--sp-3);
  resize: none;
  min-height: 38px;
  max-height: 100px;
  outline: none;
  line-height: var(--lh-normal);
  transition: border-color 0.15s;
  box-sizing: border-box;
}

.dcr-cw-textarea:focus {
  border-color: var(--navy);
  background: var(--white);
}

.dcr-cw-send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--navy);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  outline: none;
}

.dcr-cw-send-btn:hover  { background: var(--blue); }
.dcr-cw-send-btn:active { transform: scale(0.93); }
.dcr-cw-send-btn:focus-visible { outline: 2px solid var(--blue-light); }
.dcr-cw-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.dcr-cw-send-btn svg {
  width: 16px;
  height: 16px;
  color: var(--white);
}

/* ── Closed banner ─────────────────────────────────────────────────────────── */

.dcr-cw-closed-bar {
  flex-shrink: 0;
  background: var(--tint-warning);
  border-top: 1px solid var(--card-border);
  padding: var(--sp-3) var(--sp-5);
  text-align: center;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-warning-dark);
}

/* ── Error toast ───────────────────────────────────────────────────────────── */

.dcr-cw-error {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-danger-dark);
  padding: 0 var(--sp-5) var(--sp-2);
  text-align: center;
  display: none;
}

.dcr-cw-error.visible { display: block; }

/* ── Mobile ────────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .dcr-chat-launcher {
    right: var(--sp-4);
    bottom: var(--sp-4);
  }

  .dcr-chat-window {
    width: calc(100vw - var(--sp-8));
    right: var(--sp-4);
    bottom: var(--sp-4);
    height: auto;
    max-height: 80vh;
  }

  .dcr-chat-label { display: none; }
}
