/*
 * Caldi customer chat widget — styling.
 *
 * Two mount modes share one panel (history + input):
 *   .cw-floating  — fixed bottom-right launcher that swaps to the dialog on
 *                   click (every public page except the contact page).
 *   .cw-inline    — dialog rendered straight into the contact page's
 *                   #chat-container placeholder; no launcher, no close.
 *
 * Palette per CLAUDE.md: primary #F9583A (dialog bg + accents), content areas
 * white (message bubbles), text dark charcoal. Body type inherits Roboto from
 * main.css; headings/labels use Comfortaa to match the site chrome.
 */

/* ---------- shared tokens ---------- */
.cw-root {
  --cw-orange: #f9583a;
  --cw-orange-dark: #d94425;
  --cw-cream: #fff0e6;
  --cw-charcoal: #2c2a28;
  box-sizing: border-box;
}
.cw-root *,
.cw-root *::before,
.cw-root *::after { box-sizing: border-box; }

/* ---------- floating launcher ---------- */
.cw-floating {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 9999;
}

.cw-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--cw-orange);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  /* Subtle ~3.5s glow pulse — soft, not constant. */
  animation: cw-pulse 3.5s ease-in-out infinite;
  transition: transform 0.15s ease;
}
.cw-launcher:hover { transform: scale(1.06); }
.cw-launcher:active { transform: scale(0.97); }
.cw-launcher svg {
  width: 30px;
  height: 30px;
  stroke: var(--cw-orange);
  fill: none;
}

@keyframes cw-pulse {
  0%, 70%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18), 0 0 0 0 rgba(249, 88, 58, 0.0); }
  82%          { box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18), 0 0 0 8px rgba(249, 88, 58, 0.22); }
}
@media (prefers-reduced-motion: reduce) {
  .cw-launcher { animation: none; }
}

/* ---------- dialog (open state) ---------- */
.cw-dialog {
  display: flex;
  flex-direction: column;
  background: var(--cw-orange);
  overflow: hidden;
}

/* Floating dialog: fixed card bottom-right, replacing the launcher. */
.cw-floating .cw-dialog {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 370px;
  max-width: calc(100vw - 2rem);
  height: 540px;
  max-height: calc(100vh - 2.5rem);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28);
}

/* Inline dialog: sits in the page flow inside #chat-container. */
.cw-inline {
  max-width: 480px;
  margin: 0 auto;
}
.cw-inline .cw-dialog {
  height: 520px;
  border-radius: 14px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
}

.cw-dialog[hidden] { display: none; }

/* ---------- header ---------- */
.cw-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  color: #fff;
  flex: 0 0 auto;
}
.cw-header__icon {
  width: 22px;
  height: 22px;
  stroke: #fff;
  fill: none;
  flex: 0 0 auto;
}
.cw-header__title {
  font-family: 'Comfortaa', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  margin: 0;
}
.cw-close {
  margin-left: auto;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  transition: background-color 0.15s;
}
.cw-close:hover { background: rgba(255, 255, 255, 0.18); }

/* ---------- history ---------- */
.cw-history {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.cw-msg {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--cw-charcoal);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.cw-msg--bot {
  align-self: flex-start;
  background: #fff;
  border-bottom-left-radius: 4px;
}
.cw-msg--user {
  align-self: flex-end;
  background: var(--cw-cream);
  border-bottom-right-radius: 4px;
}

/* Markdown subset inside a message. */
.cw-msg p { margin: 0 0 0.5rem; }
.cw-msg p:last-child { margin-bottom: 0; }
.cw-msg ul { margin: 0.25rem 0 0.5rem; padding-left: 1.2rem; }
.cw-msg li { margin-bottom: 0.2rem; }
.cw-msg strong { font-weight: 700; }
.cw-msg a { color: var(--cw-orange-dark); text-decoration: underline; }
.cw-img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 0.4rem 0;
}

/* ---------- typing indicator ---------- */
.cw-typing {
  align-self: flex-start;
  background: #fff;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  padding: 0.7rem 0.85rem;
  display: flex;
  gap: 4px;
}
.cw-typing[hidden] { display: none; }
.cw-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cw-orange);
  opacity: 0.5;
  animation: cw-bounce 1.2s infinite ease-in-out;
}
.cw-typing span:nth-child(2) { animation-delay: 0.18s; }
.cw-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes cw-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-4px); opacity: 0.9; }
}
@media (prefers-reduced-motion: reduce) {
  .cw-typing span { animation: none; }
}

/* ---------- input bar ---------- */
.cw-inputbar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.6rem;
  background: #fff;
}
.cw-input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid #e2d6cc;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-family: 'Roboto', sans-serif;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--cw-charcoal);
  max-height: 96px;
  outline: none;
}
.cw-input:focus { border-color: var(--cw-orange); }
.cw-input:disabled { background: #f4f0ec; color: #999; cursor: not-allowed; }

.cw-send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--cw-orange);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, transform 0.1s;
}
.cw-send:hover:not(:disabled) { background: var(--cw-orange-dark); }
.cw-send:active:not(:disabled) { transform: scale(0.94); }
.cw-send:disabled { background: #d9c9bd; cursor: not-allowed; }
.cw-send svg { width: 20px; height: 20px; stroke: #fff; fill: none; }

/* ---------- mobile: near-fullscreen dialog ---------- */
@media (max-width: 599px) {
  .cw-floating .cw-dialog {
    right: 0;
    bottom: 0;
    top: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
}
