/* WhatsApp-like styles for Trustway Chat */
:root {
  --wa-green-dark: #075E54;
  --wa-green: #128C7E;
  --wa-green-light: #25D366;
  --wa-teal: #34B7F1;
  --wa-bg: #ECE5DD;
  --wa-bubble-out: #DCF8C6;
  --wa-bubble-in: #FFFFFF;
  --wa-text: #303030;
  --wa-text-muted: #667781;
  --wa-divider: #E9EDEF;
  --wa-header-text: #FFFFFF;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin:0; padding:0; height:100%; overflow:hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--wa-bg);
  color: var(--wa-text);
  font-size: 15px;
  line-height: 1.4;
  overscroll-behavior: none;
}

#app { display: flex; flex-direction: column; height: 100dvh; height: 100vh; }

/* ============ Header ============ */
.header {
  background: var(--wa-green-dark);
  color: var(--wa-header-text);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding-top: max(10px, env(safe-area-inset-top));
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  z-index: 10;
}
.header-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #128C7E;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.header-info { flex: 1; min-width: 0; }
.header-name { font-weight: 500; font-size: 16px; }
.header-status { font-size: 12px; opacity: 0.85; }
.header-status.online::before {
  content: '';
  display: inline-block; width: 7px; height: 7px;
  background: #4ad04a; border-radius: 50%;
  margin-right: 5px; vertical-align: middle;
}

/* ============ Messages area ============ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  background-image:
    linear-gradient(rgba(236,229,221,0.92), rgba(236,229,221,0.92)),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='40'><circle cx='10' cy='10' r='1.2' fill='%23c6bdb3'/><circle cx='30' cy='30' r='1.2' fill='%23c6bdb3'/></svg>");
  background-color: var(--wa-bg);
  scroll-behavior: smooth;
}

/* Empty state */
.chat-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  max-width: 320px;
  margin: 24% auto 0;
  padding: 24px 20px;
  background: rgba(255,255,255,0.85);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.chat-empty-icon { font-size: 44px; margin-bottom: 8px; }
.chat-empty-title { font-size: 18px; font-weight: 600; color: #111b21; margin-bottom: 6px; }
.chat-empty-desc { font-size: 14px; color: #54656f; line-height: 1.45; }

.day-divider {
  text-align: center;
  margin: 10px 0;
}
.day-divider span {
  background: rgba(225, 245, 254, 0.92);
  color: #54656f;
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 12px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}

.bubble-row { display: flex; margin: 2px 0; }
.bubble-row.out { justify-content: flex-end; }
.bubble-row.in { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 6px 9px 8px 9px;
  border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 14.6px;
  line-height: 1.35;
}
.bubble-row.out .bubble {
  background: var(--wa-bubble-out);
  border-top-right-radius: 0;
}
.bubble-row.in .bubble {
  background: var(--wa-bubble-in);
  border-top-left-radius: 0;
}
.bubble.has-tail::before {
  content: '';
  position: absolute; top: 0;
  width: 8px; height: 13px;
}
.bubble-row.out .bubble.has-tail::before {
  right: -7px;
  background: linear-gradient(135deg, var(--wa-bubble-out) 0%, var(--wa-bubble-out) 50%, transparent 50%);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}
.bubble-row.in .bubble.has-tail::before {
  left: -7px;
  background: linear-gradient(225deg, var(--wa-bubble-in) 0%, var(--wa-bubble-in) 50%, transparent 50%);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.bubble .meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 8px;
  float: right;
  font-size: 11px;
  color: var(--wa-text-muted);
  line-height: 1;
  padding-top: 6px;
  user-select: none;
}
.bubble .meta .ticks { display: inline-flex; }
.bubble .meta .ticks svg { width: 16px; height: 11px; }
.tick { fill: var(--wa-text-muted); }
.tick.read { fill: var(--wa-teal); }

.bubble .media img {
  max-width: 100%;
  border-radius: 6px;
  display: block;
  margin-bottom: 4px;
}
.bubble .media a {
  display: inline-block;
  padding: 8px 12px;
  background: rgba(0,0,0,0.05);
  border-radius: 6px;
  color: var(--wa-green-dark);
  text-decoration: none;
  margin-bottom: 4px;
}
.bubble .media audio { width: 240px; max-width: 100%; display: block; margin-bottom: 4px; }

/* ===== Voice player (WhatsApp-style) ===== */
.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  max-width: 280px;
  padding: 4px 2px 2px;
  user-select: none;
}
.voice-btn {
  width: 36px; height: 36px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--wa-green);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.bubble-row.in .voice-btn { background: var(--wa-green-dark); }
.voice-btn:hover { filter: brightness(1.08); }
.voice-btn svg { width: 16px; height: 16px; fill: #fff; }
.voice-wave {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 28px;
  cursor: pointer;
  min-width: 90px;
}
.voice-wave .bar {
  flex: 1;
  min-width: 2px;
  background: #b3c2c8;
  border-radius: 1px;
  transition: background 0.1s linear;
}
.bubble-row.out .voice-wave .bar { background: #a9c9a4; }
.voice-wave .bar.played { background: #54656F; }
.bubble-row.out .voice-wave .bar.played { background: var(--wa-green-dark); }
.voice-time {
  font-size: 11px;
  color: var(--wa-text-muted);
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.bubble .quote {
  border-left: 3px solid var(--wa-green);
  background: rgba(0,0,0,0.04);
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 13px;
  cursor: pointer;
}
.bubble .quote .quote-author { color: var(--wa-green-dark); font-weight: 500; font-size: 12px; }
.bubble .quote .quote-text { color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.bubble-row.in .bubble .quote { border-left-color: #4caf50; }

/* Reply preview above composer */
.reply-preview {
  display: none;
  background: #F0F2F5;
  padding: 8px 14px;
  border-top: 1px solid var(--wa-divider);
  border-left: 3px solid var(--wa-green);
  align-items: center;
  gap: 8px;
}
.reply-preview.show { display: flex; }
.reply-preview .content { flex: 1; min-width: 0; }
.reply-preview .author { font-size: 12px; color: var(--wa-green-dark); font-weight: 500; }
.reply-preview .text { font-size: 13px; color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-preview button {
  background: transparent; border: 0; color: #54656F; font-size: 20px; cursor: pointer;
  padding: 4px 8px;
}

/* Long-press context menu */
.msg-menu {
  position: fixed;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  padding: 4px 0;
  z-index: 1000;
  font-size: 14px;
  min-width: 160px;
  display: none;
}
.msg-menu.show { display: block; }
.msg-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 10px 16px;
  cursor: pointer;
  color: var(--wa-text);
}
.msg-menu button:hover { background: #f5f6f7; }

.bubble.highlighted { animation: pulse 0.8s; }
@keyframes pulse {
  0%, 100% { background: var(--wa-bubble-out); }
  50% { background: #FFE082; }
}
.bubble-row.in .bubble.highlighted { animation: pulseIn 0.8s; }
@keyframes pulseIn {
  0%, 100% { background: var(--wa-bubble-in); }
  50% { background: #FFE082; }
}

/* Notification toast offset when reply-preview is shown */
.scroll-bottom {
  position: absolute;
  right: 16px;
  bottom: 80px;
  width: 40px; height: 40px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  border: 0;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: #54656F;
}
.scroll-bottom.show { display: flex; }
.scroll-bottom .badge {
  position: absolute;
  top: -6px; right: -6px;
  background: var(--wa-green-light);
  color: #fff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ============ Typing indicator ============ */
.typing-row {
  display: none;
  padding: 0 8px 6px;
}
.typing-row.show { display: flex; }
.typing-row .bubble {
  background: var(--wa-bubble-in);
  padding: 10px 14px;
}
.typing-dots { display: inline-flex; gap: 3px; align-items: center; height: 12px; }
.typing-dots span {
  width: 6px; height: 6px;
  background: #8696a0; border-radius: 50%;
  animation: typing 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ============ Composer ============ */
.composer {
  background: #F0F2F5;
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.composer button.icon {
  width: 40px; height: 40px;
  border: 0; background: transparent;
  color: #54656F;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.composer button.icon:hover { background: rgba(0,0,0,0.05); }
.composer button.icon svg { width: 24px; height: 24px; }
.composer .input-wrap {
  flex: 1;
  background: #FFF;
  border-radius: 22px;
  padding: 9px 14px;
  min-height: 40px;
  max-height: 120px;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}
.composer textarea {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  font-size: 15px;
  font-family: inherit;
  background: transparent;
  max-height: 100px;
  line-height: 1.4;
}
.composer .send-btn {
  width: 44px; height: 44px;
  background: var(--wa-green-light);
  color: white;
  border: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.composer .send-btn:hover { background: var(--wa-green); }
.composer .send-btn svg { width: 22px; height: 22px; }
.composer input[type="file"] { display: none; }
/* iOS Safari fix: [hidden] doesn't suppress display:flex without !important */
.composer .send-btn[hidden],
.composer .mic-btn[hidden] { display: none !important; }

/* ====== Mic / voice recording ====== */
.composer .mic-btn {
  width: 44px; height: 44px;
  background: var(--wa-green-light);
  color: white;
  border: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.composer .mic-btn:hover { background: var(--wa-green); }
.composer .mic-btn:active { transform: scale(0.96); }
.composer .mic-btn svg { width: 22px; height: 22px; }
.composer.recording .mic-btn { background: #d94343; }
.composer.recording .mic-btn:hover { background: #c33; }

.rec-ui {
  display: flex; align-items: center; gap: 8px;
  flex: 1;
  color: #d94343;
  font-variant-numeric: tabular-nums;
}
.rec-ui[hidden] { display: none; }
.rec-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #d94343;
  animation: rec-pulse 1s ease-in-out infinite;
}
.rec-cancel {
  margin-left: auto;
  background: transparent;
  border: 0;
  color: #54656F;
  font-size: 18px;
  cursor: pointer;
  width: 28px; height: 28px;
  border-radius: 50%;
}
.rec-cancel:hover { background: rgba(0,0,0,0.05); }
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.composer.recording textarea { display: none; }

/* ============ Onboarding ============ */
.onboarding {
  position: absolute;
  inset: 0;
  background: var(--wa-green-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  z-index: 100;
}
.onboarding.hidden { display: none; }
.lang-switch {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 14px;
  display: flex;
  background: rgba(0,0,0,0.18);
  border-radius: 14px;
  padding: 3px;
}
.lang-switch button {
  background: transparent;
  color: #fff;
  border: 0;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 11px;
  cursor: pointer;
  opacity: 0.65;
  letter-spacing: 0.5px;
}
.lang-switch button.active {
  background: rgba(255,255,255,0.18);
  opacity: 1;
}
.onboarding .logo {
  width: 96px; height: 96px;
  background: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 48px;
  margin-bottom: 24px;
  color: var(--wa-green-dark);
  font-weight: 600;
}
.onboarding h1 { font-size: 24px; margin: 0 0 12px; font-weight: 500; }
.onboarding p { font-size: 15px; opacity: 0.9; max-width: 320px; margin: 0 0 24px; line-height: 1.5; }
.onboarding .step {
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 6px 0;
  max-width: 320px;
  text-align: left;
  font-size: 14px;
}
.onboarding .step strong { display: block; margin-bottom: 4px; }
.onboarding .cta {
  background: var(--wa-green-light);
  color: #fff;
  border: 0;
  padding: 14px 32px;
  border-radius: 24px;
  font-size: 16px;
  font-weight: 500;
  margin-top: 24px;
  cursor: pointer;
}
.onboarding .cta:disabled { opacity: 0.5; }
.onboarding small { display: block; margin-top: 12px; opacity: 0.7; font-size: 12px; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 80px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.8); color: #fff;
  padding: 10px 16px; border-radius: 20px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ============ Banner ============ */
.banner {
  background: #FFF3CD;
  color: #856404;
  padding: 10px 14px;
  font-size: 13px;
  text-align: center;
  border-bottom: 1px solid #ffeaa7;
}
.banner button {
  margin-left: 8px;
  background: var(--wa-green-dark);
  color: white; border: 0;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
}
