/* SingDia simulator — WhatsApp-style chat UI. Vanilla CSS, offline, no CDNs. */

:root {
  --wa-header: #075e54;
  --wa-header-accent: #128c7e;
  --wa-bg: #e5ddd5;            /* classic WA wallpaper tint */
  --wa-out: #d9fdd3;           /* outgoing bubble (light green) */
  --wa-in: #ffffff;            /* incoming bubble (white) */
  --wa-text: #111b21;
  --wa-meta: #667781;          /* timestamp / secondary text */
  --wa-link: #027eb5;
  --wa-tick: #53bdeb;
  --wa-shadow: rgba(0, 0, 0, 0.13);
  --bubble-radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: #d2dbdf;
}

/* Phone frame: mobile-first, centered + bounded on desktop */
.phone {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--wa-bg);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.25);
}

/* ---------- Header ---------- */
.wa-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--wa-header);
  color: #fff;
  z-index: 5;
}
.wa-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #dfe5e7;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.wa-title-wrap { flex: 1 1 auto; min-width: 0; line-height: 1.2; }
.wa-title { font-size: 16px; font-weight: 600; }
.wa-subtitle { font-size: 12.5px; opacity: 0.85; }
.wa-reset {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  opacity: 0.92;
}
.wa-reset:hover { background: rgba(255, 255, 255, 0.12); }
.wa-reset:active { transform: rotate(-90deg); transition: transform 0.2s; }

/* ---------- Chat area ---------- */
.wa-chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* Subtle dotted wallpaper texture over the tint */
  background-image:
    radial-gradient(rgba(0, 0, 0, 0.035) 1px, transparent 1px);
  background-size: 22px 22px;
  scroll-behavior: smooth;
}

/* Row wrapper controls alignment */
.row { display: flex; width: 100%; }
.row.in { justify-content: flex-start; }
.row.out { justify-content: flex-end; }

/* ---------- Bubbles ---------- */
.bubble {
  position: relative;
  max-width: 80%;
  padding: 6px 9px 8px;
  border-radius: var(--bubble-radius);
  box-shadow: 0 1px 0.5px var(--wa-shadow);
  font-size: 14.5px;
  line-height: 1.32;
  color: var(--wa-text);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;        /* preserve line breaks from \n */
}
.bubble.in  { background: var(--wa-in);  border-top-left-radius: 0; }
.bubble.out { background: var(--wa-out); border-top-right-radius: 0; }

/* Bubble tails */
.bubble.in::before,
.bubble.out::before {
  content: "";
  position: absolute;
  top: 0;
  width: 8px;
  height: 13px;
}
.bubble.in::before {
  left: -8px;
  background: var(--wa-in);
  clip-path: polygon(100% 0, 0 0, 100% 100%);
}
.bubble.out::before {
  right: -8px;
  background: var(--wa-out);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.bubble b { font-weight: 700; }
.bubble i { font-style: italic; }
.bubble s { text-decoration: line-through; }

/* Timestamp / meta */
.meta {
  display: block;
  text-align: right;
  font-size: 11px;
  color: var(--wa-meta);
  margin-top: 2px;
  white-space: nowrap;
  user-select: none;
}
.meta .tick { color: var(--wa-tick); margin-left: 2px; font-size: 12px; }

/* ---------- Quick-reply buttons ---------- */
.qr-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 80%;
  margin-top: 1px;
}
.qr-btn {
  background: var(--wa-in);
  color: var(--wa-link);
  border: none;
  border-radius: var(--bubble-radius);
  padding: 10px 12px;
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 1px 0.5px var(--wa-shadow);
  text-align: center;
  width: 100%;
}
.qr-btn:hover { background: #f5f6f6; }
.qr-btn:active { background: #eceff1; }
.qr-group.disabled .qr-btn {
  color: var(--wa-meta);
  cursor: default;
  opacity: 0.6;
}

/* ---------- List opener button ---------- */
.list-opener {
  background: var(--wa-in);
  color: var(--wa-link);
  border: none;
  border-top: 1px solid #e9edef;
  border-radius: 0 0 var(--bubble-radius) var(--bubble-radius);
  padding: 11px 12px;
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  box-shadow: 0 1px 0.5px var(--wa-shadow);
}
.list-opener:hover { background: #f5f6f6; }
.list-opener:disabled { color: var(--wa-meta); cursor: default; opacity: 0.6; }
.list-opener svg { fill: currentColor; }
/* A list message renders bubble + opener stacked with no gap */
.list-wrap { display: flex; flex-direction: column; max-width: 80%; }
.list-wrap .bubble { border-bottom-left-radius: 0; box-shadow: none; max-width: 100%; }

/* ---------- Audio bubble ---------- */
.audio-cap { margin-bottom: 6px; }
.audio-row { display: flex; align-items: center; gap: 8px; min-width: 220px; }
.audio-mic {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--wa-header-accent);
  display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
.audio-row audio { flex: 1 1 auto; height: 36px; max-width: 100%; }
.audio-dl {
  flex: 0 0 auto;
  color: var(--wa-meta);
  display: flex;
  text-decoration: none;
  padding: 4px;
  border-radius: 50%;
}
.audio-dl:hover { background: #f0f2f3; }

/* ---------- Image ---------- */
.img-msg img {
  display: block;
  max-width: 100%;
  border-radius: 5px;
  margin-bottom: 4px;
}
.img-cap { font-size: 14px; }

/* ---------- Typing indicator ---------- */
.typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 10px 12px;
}
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #9aa6ac;
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- System note (errors etc.) ---------- */
.row.sys { justify-content: center; }
.sys-note {
  background: #fff4d6;
  color: #5b4b1d;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 8px;
  box-shadow: 0 1px 0.5px var(--wa-shadow);
  max-width: 85%;
  text-align: center;
}

/* ---------- Composer ---------- */
.wa-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  background: #f0f2f5;
}
.wa-input-pill {
  flex: 1 1 auto;
  background: #fff;
  border-radius: 22px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  min-height: 44px;
}
.wa-input-pill input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 15px;
  background: transparent;
  padding: 11px 0;
}
.wa-send {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--wa-header-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wa-send:hover { background: #0e7a6b; }
.wa-send:active { transform: scale(0.94); }

/* ---------- List bottom sheet ---------- */
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%;
  max-height: 70%;
  background: #fff;
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grip {
  width: 38px; height: 4px; border-radius: 2px;
  background: #ccd0d2;
  margin: 8px auto 4px;
}
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 15px;
  color: var(--wa-text);
  border-bottom: 1px solid #eef1f2;
}
.sheet-close {
  background: none; border: none;
  font-size: 26px; line-height: 1;
  color: var(--wa-meta);
  cursor: pointer;
}
.sheet-body { overflow-y: auto; padding: 4px 0 max(8px, env(safe-area-inset-bottom)); }
.sheet-section-title {
  padding: 12px 16px 4px;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--wa-header-accent);
}
.sheet-row {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid #f0f2f3;
  padding: 12px 16px;
  cursor: pointer;
}
.sheet-row:hover { background: #f5f6f6; }
.sheet-row:active { background: #eceff1; }
.sheet-row .r-title { font-size: 15px; color: var(--wa-text); }
.sheet-row .r-desc { font-size: 13px; color: var(--wa-meta); margin-top: 2px; }
