/* ============================================================
   CHAT.CSS — WhatsApp-like chat interface for CPA Turnos
   Updated to align with unified design system
   ============================================================ */

/* ---- Layout: header fixed top, footer fixed bottom, body scrolls ---- */
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;          /* dynamic viewport height */
  overflow: hidden;
  background: var(--chat-bg, #eae6df);
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Theme tokens (extend from styles.css) ---------- */
:root {
  --chat-bg: #eae6df;
  --chat-header-bg: #075e54;
  --chat-header-fg: #ffffff;
  --bubble-bot-bg: #ffffff;
  --bubble-bot-fg: #303030;
  --bubble-user-bg: #dcf8c6;
  --bubble-user-fg: #303030;
  --chat-footer-bg: #f0f0f0;
  --chat-input-bg: #ffffff;
  --chat-send-bg: #075e54;
  --chat-send-fg: #ffffff;
  --chip-bg: #e0f2fe;
  --chip-fg: #0369a1;
  --chip-hover: #bae6fd;
  --chat-date-badge: rgba(0,0,0,.08);
  --chat-date-fg: #667085;
  --typing-dot: #9ca3af;
}

html.dark {
  --chat-bg: #0b141a;
  --chat-header-bg: #1f2c34;
  --chat-header-fg: #e5e7eb;
  --bubble-bot-bg: #1f2c34;
  --bubble-bot-fg: #e5e7eb;
  --bubble-user-bg: #005c4b;
  --bubble-user-fg: #e5e7eb;
  --chat-footer-bg: #1f2c34;
  --chat-input-bg: #2a3942;
  --chat-send-bg: #00a884;
  --chat-send-fg: #111b21;
  --chip-bg: #1e3a4d;
  --chip-fg: #7dd3fc;
  --chip-hover: #264d66;
  --chat-date-badge: rgba(255,255,255,.06);
  --chat-date-fg: #9ca3af;
  --typing-dot: #6b7280;
}

/* ============== Header ============== */
.chat-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--chat-header-bg);
  color: var(--chat-header-fg);
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}

.chat-back {
  color: var(--chat-header-fg);
  font-size: 18px;
  text-decoration: none;
  line-height: 1;
}

.chat-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  display: grid;
  place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.chat-header-name {
  font-weight: 600;
  font-size: 15px;
}

.chat-header-status {
  font-size: 12px;
  opacity: .8;
}

/* ============== Chat Body ============== */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  /* WhatsApp wallpaper subtle pattern */
  background:
    var(--chat-bg)
    url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M30 5 L35 15 L30 25 L25 15Z' fill='%23888' fill-opacity='0.03'/%3E%3C/svg%3E");
}

/* ============== Bubbles ============== */
.bubble {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14.5px;
  line-height: 1.45;
  position: relative;
  word-wrap: break-word;
  animation: bubbleIn .25s ease;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.bubble.bot {
  align-self: flex-start;
  background: var(--bubble-bot-bg);
  color: var(--bubble-bot-fg);
  border-bottom-left-radius: 2px;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}

.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user-bg);
  color: var(--bubble-user-fg);
  border-bottom-right-radius: 2px;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}

.bubble .time {
  display: block;
  text-align: right;
  font-size: 11px;
  opacity: .55;
  margin-top: 3px;
}

/* ============== Chips (quick-reply buttons) ============== */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border-radius: 20px;
  border: 1px solid var(--chip-fg);
  background: var(--chip-bg);
  color: var(--chip-fg);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .1s;
  user-select: none;
}

.chip:hover {
  background: var(--chip-hover);
}

.chip:active {
  transform: scale(.96);
}

.chip.selected {
  background: var(--chat-send-bg);
  color: var(--chat-send-fg);
  border-color: var(--chat-send-bg);
  pointer-events: none;
}

.chips-container.disabled .chip:not(.selected) {
  opacity: .4;
  pointer-events: none;
}

/* Date badge (separator) */
.date-badge {
  align-self: center;
  background: var(--chat-date-badge);
  color: var(--chat-date-fg);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 8px;
  margin: 8px 0;
}

/* ============== Typing indicator ============== */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 10px 16px;
  align-self: flex-start;
  background: var(--bubble-bot-bg);
  border-radius: 10px;
  border-bottom-left-radius: 2px;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}

.typing-indicator .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--typing-dot);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-indicator .dot:nth-child(2) { animation-delay: .15s; }
.typing-indicator .dot:nth-child(3) { animation-delay: .3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ============== Footer ============== */
.chat-footer {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--chat-footer-bg);
  border-top: 1px solid rgba(128,128,128,.15);
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 22px;
  border: none;
  outline: none;
  font-size: 16px;
  background: var(--chat-input-bg);
  color: var(--bubble-bot-fg);
  transition: box-shadow .15s;
}

.chat-input:focus {
  box-shadow: 0 0 0 2px rgba(0,168,132,.35);
}

.chat-input::placeholder {
  color: var(--typing-dot);
}

.chat-send {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--chat-send-bg);
  color: var(--chat-send-fg);
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity .15s, transform .1s;
  flex-shrink: 0;
}

.chat-send:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.chat-send:not(:disabled):active {
  transform: scale(.92);
}

/* ============== Summary card inside bubble ============== */
.summary-card {
  background: rgba(128,128,128,.08);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 6px;
  font-size: 13.5px;
  line-height: 1.6;
}

.summary-card strong {
  display: inline-block;
  min-width: 70px;
}

/* ============== Scrollbar ============== */
.chat-body::-webkit-scrollbar { width: 5px; }
.chat-body::-webkit-scrollbar-thumb { background: rgba(128,128,128,.3); border-radius: 4px; }
.chat-body::-webkit-scrollbar-track { background: transparent; }

/* ============== Responsive ============== */
@media (min-width: 600px) {
  body {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid rgba(128,128,128,.15);
    border-right: 1px solid rgba(128,128,128,.15);
  }
}

/* ============== Toggle override (inside dark header) ============== */
.chat-header .toggle {
  width: 40px; height: 22px;
  background: rgba(255,255,255,.2);
}

.chat-header .toggle::after {
  width: 16px; height: 16px;
}

.chat-header input.peer:checked + .toggle { background: var(--primary, #818cf8); }
.chat-header input.peer:checked + .toggle::after { transform: translateX(18px); }

/* ============== Warning banner animation ============== */
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
