/* Live chat widget — styled from the shipped design tokens (tokens/colors.css,
   typography.css, spacing.css, radius.css). No box-shadow anywhere, per the
   brand's flat/hairline depth system (tokens/elevation.css) — the floating
   read comes from fixed positioning + a hairline border, not a shadow. */

#tcc-chat-widget {
  position: fixed;
  right: var(--space-sm);
  bottom: var(--space-sm);
  z-index: 999999;
  font-family: var(--font-body);
}

#tcc-chat-widget * { box-sizing: border-box; }

/* ---- Launcher ---- */
.tcc-chat-launcher {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  border: 2px solid var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background var(--transition-base), border-color var(--transition-base);
  position: relative;
}
.tcc-chat-launcher:hover {
  background: var(--surface-canvas);
}
.tcc-chat-launcher svg { width: 26px; height: 26px; }
.tcc-chat-launcher .tcc-chat-icon-open { stroke: var(--tcc-navy); }
.tcc-chat-launcher .tcc-chat-icon-close { stroke: var(--tcc-navy); display: none; }
.tcc-chat-launcher:hover .tcc-chat-icon-open,
.tcc-chat-launcher:hover .tcc-chat-icon-close { stroke: var(--color-primary); }
#tcc-chat-widget.is-open .tcc-chat-icon-open { display: none; }
#tcc-chat-widget.is-open .tcc-chat-icon-close { display: block; }

/* First-visit attention ring — plays once, then removed by JS. */
.tcc-chat-launcher.tcc-chat-pulse::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: var(--radius-full);
  border: 2px solid var(--color-primary);
  animation: tcc-chat-pulse 1.8s ease-out 3;
}
@keyframes tcc-chat-pulse {
  0%   { transform: scale(0.9); opacity: 0.8; }
  100% { transform: scale(1.35); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .tcc-chat-launcher.tcc-chat-pulse::before { animation: none; display: none; }
}

/* ---- Panel ---- */
.tcc-chat-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 380px;
  max-width: calc(100vw - 2 * var(--space-sm));
  height: min(600px, calc(100vh - 140px));
  background: var(--surface-canvas);
  border: var(--elevation-hairline);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transform-origin: bottom right;
  transition: opacity var(--transition-base), transform var(--transition-base);
}
#tcc-chat-widget.is-open .tcc-chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
@media (prefers-reduced-motion: reduce) {
  .tcc-chat-panel { transition: opacity 0.15s linear; transform: none; }
}

/* ---- Header ---- */
.tcc-chat-header {
  background: var(--color-hero-bg);
  color: var(--text-on-dark);
  padding: var(--space-xs) var(--space-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2xs);
  flex: none;
}
.tcc-chat-header-text { min-width: 0; }
.tcc-chat-title {
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  font-size: 17px;
  line-height: 125%;
  color: var(--text-on-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tcc-chat-subtitle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--text-on-dark-muted);
  font-size: 11px;
  line-height: var(--text-label-lh);
  font-weight: var(--weight-medium);
  letter-spacing: var(--text-label-tracking);
  text-transform: uppercase;
}
.tcc-chat-status-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--tcc-green);
  flex: none;
}
.tcc-chat-close {
  background: transparent;
  border: none;
  padding: 6px;
  margin: -6px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  flex: none;
}
.tcc-chat-close svg { width: 20px; height: 20px; stroke: var(--text-on-dark); }
.tcc-chat-close:hover { background: rgba(255, 255, 255, 0.12); }

/* ---- Messages ---- */
.tcc-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-sm);
  background: var(--surface-muted);
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
}
.tcc-chat-messages::-webkit-scrollbar { width: 6px; }
.tcc-chat-messages::-webkit-scrollbar-thumb { background: var(--border-hairline); border-radius: var(--radius-full); }

.tcc-chat-row { display: flex; }
.tcc-chat-row.is-user { justify-content: flex-end; }
.tcc-chat-row.is-bot { justify-content: flex-start; }

.tcc-chat-bubble {
  max-width: 82%;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  border-radius: var(--radius-md);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.tcc-chat-row.is-bot .tcc-chat-bubble {
  background: var(--tcc-white);
  border: var(--elevation-hairline);
  color: var(--text-strong);
  border-bottom-left-radius: var(--radius-sm);
}
.tcc-chat-row.is-user .tcc-chat-bubble {
  background: var(--color-hero-bg);
  color: var(--text-on-dark);
  border-bottom-right-radius: var(--radius-sm);
}

.tcc-chat-typing .tcc-chat-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}
.tcc-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--tcc-ink-600);
  opacity: 0.4;
  animation: tcc-chat-typing 1s infinite ease-in-out;
}
.tcc-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.tcc-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes tcc-chat-typing {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---- Footer / input ---- */
.tcc-chat-footer { flex: none; border-top: var(--elevation-hairline); background: var(--tcc-white); }
.tcc-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2xs);
  padding: var(--space-2xs) var(--space-sm);
}
.tcc-chat-input {
  flex: 1 1 auto;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-input);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 16px; /* keeps iOS Safari from auto-zooming on focus */
  line-height: 1.4;
  color: var(--text-strong);
  background: var(--tcc-white);
  resize: none;
  max-height: 96px;
  overflow-y: auto;
}
.tcc-chat-input:focus { outline: none; border-color: var(--tcc-navy); }
.tcc-chat-send {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity var(--transition-base);
}
.tcc-chat-send svg { width: 18px; height: 18px; stroke: var(--tcc-navy); }
.tcc-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

.tcc-chat-whatsapp-fallback {
  padding: 0 var(--space-sm) var(--space-2xs);
  text-align: center;
}
.tcc-chat-whatsapp-fallback a {
  font-size: 12px;
  font-weight: var(--weight-medium);
  letter-spacing: var(--text-label-tracking);
  text-transform: uppercase;
  color: var(--text-body);
}
.tcc-chat-whatsapp-fallback a:hover { color: var(--color-primary); }

/* ---- Mobile: full-screen panel ---- */
@media (max-width: 640px) {
  #tcc-chat-widget { right: var(--space-2xs); bottom: var(--space-2xs); }
  .tcc-chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    border-radius: 0;
    border: none;
    bottom: 0;
    right: 0;
  }
  .tcc-chat-header { padding-top: max(var(--space-xs), env(safe-area-inset-top)); }
  .tcc-chat-input-row { padding-bottom: max(var(--space-2xs), env(safe-area-inset-bottom)); }
  #tcc-chat-widget.is-open .tcc-chat-launcher { display: none; }
}
