:root {
  /* WhatsApp palette */
  --wa-teal-green: #128C7E;
  --wa-teal-dark: #075E54;
  --wa-green: #25D366;
  --wa-light-green: #DCF8C6;
  --wa-header: #075E54;
  --wa-chat-bg: #ECE5DD;
  --wa-panel: #F0F0F0;
  --wa-white: #FFFFFF;
  --wa-text: #111B21;
  --wa-muted: #667781;
  --wa-tick-blue: #53BDEB;
  --wa-in-bubble: #FFFFFF;
  --wa-out-bubble: #DCF8C6;
  --wa-compose-bg: #F0F0F0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--wa-chat-bg);
  color: var(--wa-text);
  height: 100%;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------------- App shell ---------------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--wa-chat-bg);
  position: relative;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--wa-header);
  color: #fff;
  flex: 0 0 auto;
  min-height: 58px;
}
.chat-header .back { font-size: 22px; color: #fff; opacity: 0.9; }
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: #128C7E;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 18px;
  flex: 0 0 auto;
  overflow: hidden;
}
.header-info { flex: 1; min-width: 0; }
.chat-title { font-weight: 600; font-size: 16px; line-height: 1.2; }
.chat-sub { font-size: 12.5px; color: #cfe9e4; }
.header-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.15); }
.icon-btn svg { width: 22px; height: 22px; fill: #fff; }

/* Messages area with WhatsApp doodle background */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background-color: #ECE5DD;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cg fill='%23000000' fill-opacity='0.03'%3E%3Cpath d='M30 5c2 0 3 1 3 3s-1 3-3 3-3-1-3-3 1-3 3-3zm15 10c1.5 0 2.5 1 2.5 2.5S46.5 20 45 20s-2.5-1-2.5-2.5S43.5 15 45 15zM15 15c1.5 0 2.5 1 2.5 2.5S16.5 20 15 20s-2.5-1-2.5-2.5S13.5 15 15 15zm35 20c1 0 2 1 2 2s-1 2-2 2-2-1-2-2 1-2 2-2zM10 35c1 0 2 1 2 2s-1 2-2 2-2-1-2-2 1-2 2-2zm20 8c2 0 3 1 3 3s-1 3-3 3-3-1-3-3 1-3 3-3z'/%3E%3C/g%3E%3C/svg%3E");
}

.date-chip {
  align-self: center;
  background: #E1F2FB;
  color: #54656F;
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 8px;
  margin: 8px 0;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}

/* Chat bubbles */
.msg {
  position: relative;
  max-width: 80%;
  padding: 6px 9px 8px;
  border-radius: 8px;
  line-height: 1.35;
  font-size: 14.5px;
  word-wrap: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  margin-bottom: 2px;
  animation: pop 0.12s ease;
}
@keyframes pop { from { transform: translateY(4px); opacity: 0; } to { transform: none; opacity: 1; } }

.msg.user {
  align-self: flex-end;
  background: var(--wa-out-bubble);
  border-top-right-radius: 0;
}
.msg.bot, .msg.admin {
  align-self: flex-start;
  background: var(--wa-in-bubble);
  border-top-left-radius: 0;
}
/* bubble tails */
.msg.user::after {
  content: '';
  position: absolute; top: 0; right: -8px;
  border: 8px solid transparent;
  border-top-color: var(--wa-out-bubble);
  border-right: 0;
}
.msg.bot::after, .msg.admin::after {
  content: '';
  position: absolute; top: 0; left: -8px;
  border: 8px solid transparent;
  border-top-color: var(--wa-in-bubble);
  border-left: 0;
}
.msg .who { font-size: 12.5px; color: var(--wa-teal-green); font-weight: 600; display: block; margin-bottom: 2px; }
.msg .meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  float: right;
  margin: 4px 0 -2px 8px;
  font-size: 11px;
  color: var(--wa-muted);
}
.msg .ticks { color: var(--wa-tick-blue); font-size: 13px; line-height: 1; }

/* Attachments in bubbles */
.msg img.att-image {
  display: block;
  max-width: 240px;
  width: 100%;
  border-radius: 6px;
  margin-bottom: 3px;
  cursor: pointer;
}
.att-doc {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 3px;
  text-decoration: none;
  color: var(--wa-text);
  min-width: 200px;
}
.att-doc .doc-icon {
  width: 36px; height: 36px;
  background: var(--wa-teal-green);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; flex: 0 0 auto;
}
.att-doc .doc-name { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-doc .doc-sub { font-size: 11px; color: var(--wa-muted); }

.att-audio {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
}
.att-audio audio { width: 100%; height: 34px; }

/* Composer */
.composer-wrap {
  flex: 0 0 auto;
  padding: 6px 8px 8px;
  background: transparent;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.composer {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border-radius: 24px;
  padding: 4px 6px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}
.composer input.text-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  padding: 8px 4px;
  background: transparent;
  color: var(--wa-text);
}
.composer .comp-icon {
  background: transparent; border: none; cursor: pointer;
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--wa-muted); padding: 0;
}
.composer .comp-icon svg { width: 22px; height: 22px; fill: #54656F; }
.composer .comp-icon.attach svg { transform: rotate(0deg); }

.send-btn {
  flex: 0 0 auto;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--wa-green);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.send-btn svg { width: 24px; height: 24px; fill: #fff; }
.send-btn:active { transform: scale(0.95); }

/* Attach menu popup */
.attach-menu {
  position: absolute;
  bottom: 70px;
  left: 12px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px 24px;
  z-index: 50;
}
.attach-item { display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; background: none; border: none; }
.attach-item .circle {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px;
}
.attach-item .circle.doc { background: #5157AE; }
.attach-item .circle.img { background: #BF59CF; }
.attach-item .circle.cam { background: #D3396D; }
.attach-item .circle.audio { background: #E67E22; }
.attach-item span { font-size: 12px; color: var(--wa-muted); }

/* Voice recording bar */
.recording-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border-radius: 24px;
  padding: 8px 16px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}
.recording-bar .rec-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: #f00;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
.recording-bar .rec-time { font-variant-numeric: tabular-nums; color: var(--wa-text); font-size: 15px; }
.recording-bar .rec-hint { color: var(--wa-muted); font-size: 13px; margin-left: auto; }
.rec-cancel { background: none; border: none; color: #f00; cursor: pointer; font-size: 14px; font-weight: 600; }

/* Call overlay */
.call-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #075E54 0%, #0b141a 100%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 60px 24px 48px;
  color: #fff;
  text-align: center;
}
.call-overlay .call-avatar {
  width: 110px; height: 110px; border-radius: 50%;
  background: #128C7E; display: flex; align-items: center; justify-content: center;
  font-size: 44px; font-weight: 700; margin-bottom: 16px;
}
.call-overlay .call-name { font-size: 26px; font-weight: 600; }
.call-overlay .call-status { font-size: 15px; color: #cfe9e4; margin-top: 8px; }
.call-top { margin-top: 30px; display: flex; flex-direction: column; align-items: center; }
.call-actions { display: flex; gap: 28px; }
.call-action {
  width: 64px; height: 64px; border-radius: 50%;
  border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.call-action.end { background: #f4433 6; background: #f44336; }
.call-action.mute { background: rgba(255,255,255,0.2); }
.call-action svg { width: 28px; height: 28px; fill: #fff; }

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

/* Lightbox for images */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 3500; padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; }


/* App is visible but non-interactive until notifications are enabled */
.app.locked { pointer-events: none; user-select: none; filter: saturate(0.85); }

/* ---------------- Popups (permission, install, contact) ---------------- */
.popup-backdrop {
  position: fixed; inset: 0;
  background: rgba(11, 20, 26, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 3200;
  animation: fade-in 0.2s ease;
}
.popup {
  position: relative;
  background: #fff;
  width: 100%; max-width: 480px;
  max-height: 92dvh; overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 10px 22px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,0.25);
  text-align: center;
  animation: slide-up 0.28s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 600px) {
  .popup-backdrop { align-items: center; }
  .popup { border-radius: 20px; padding-bottom: 24px; }
  .popup-handle { display: none; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.popup-handle { width: 40px; height: 4px; border-radius: 2px; background: #d1d7db; margin: 0 auto 14px; }
.popup h1 { margin: 6px 0; font-size: 21px; font-weight: 600; color: var(--wa-text); }
.popup h2 { margin: 0 0 4px; font-size: 19px; color: var(--wa-text); text-align: left; }
.popup-text { margin: 0 0 14px; color: var(--wa-muted); font-size: 15px; line-height: 1.45; }
.popup-fine { margin: 10px 0 0; color: var(--wa-muted); font-size: 12.5px; }

.popup-hero { position: relative; width: 84px; height: 84px; margin: 8px auto 10px; }
.popup-app-icon { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 4px 14px rgba(0,0,0,0.18); display: block; }
.popup-badge {
  position: absolute; right: -8px; bottom: -6px;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--wa-green); border: 3px solid #fff;
  display: flex; align-items: center; justify-content: center;
  animation: ring 1.6s ease-in-out 0.4s infinite;
}
.popup-badge svg { width: 18px; height: 18px; fill: #fff; }
@keyframes ring {
  0%, 60%, 100% { transform: rotate(0); }
  10%, 30% { transform: rotate(-14deg); }
  20%, 40% { transform: rotate(14deg); }
}
.popup-hero-icon {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--wa-light-green);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
}
.popup-hero-icon.blocked { background: #fde8e8; }

.popup-points, .install-perks { list-style: none; margin: 0 0 6px; padding: 0; text-align: left; }
.popup-points li {
  position: relative; padding: 9px 0 9px 32px;
  font-size: 14.5px; color: var(--wa-text);
  border-top: 1px solid #f0f2f5;
}
.popup-points li::before {
  content: ''; position: absolute; left: 4px; top: 50%;
  width: 18px; height: 18px; margin-top: -9px; border-radius: 50%;
  background: var(--wa-green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23fff' d='M9 16.2 4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z'/%3E%3C/svg%3E") center / 13px no-repeat;
}
.popup-steps { text-align: left; margin: 0 0 8px; padding: 0; list-style: none; counter-reset: step; }
.popup-steps li {
  counter-increment: step; position: relative;
  padding: 10px 0 10px 40px; font-size: 14.5px; color: var(--wa-text); line-height: 1.4;
}
.popup-steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: 8px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--wa-light-green); color: var(--wa-teal-dark);
  font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.ios-share { display: inline-block; color: #007aff; font-weight: 700; }

/* Gate shows exactly one view, chosen by data-state */
.gate-view { display: none; }
#gate[data-state="ask"] [data-view="ask"],
#gate[data-state="blocked"] [data-view="blocked"],
#gate[data-state="inapp"] [data-view="inapp"],
#gate[data-state="ios"] [data-view="ios"],
#gate[data-state="unsupported"] [data-view="unsupported"] { display: block; }

.gate-status { min-height: 18px; font-size: 13.5px; margin: 8px 0 0; }
.gate-status.error { color: #d32f2f; }
.gate-status.ok { color: var(--wa-teal-green); }

/* Buttons */
.btn-primary {
  margin-top: 16px;
  background: var(--wa-green);
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 2px 6px rgba(37, 211, 102, 0.4);
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
  margin-top: 10px; width: 100%;
  background: #fff; color: var(--wa-teal-green);
  border: 1px solid #d1d7db; border-radius: 24px;
  padding: 12px 24px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-text { background: none; border: none; color: var(--wa-teal-green); font-size: 15px; font-weight: 600; padding: 10px 8px; cursor: pointer; }
.btn-text.danger { color: #d32f2f; }
.btn-inline { width: auto; margin-top: 0; padding: 12px 30px; }

/* Install popup */
.install-head { display: flex; align-items: center; gap: 14px; text-align: left; margin: 4px 0 14px; }
.install-icon { width: 60px; height: 60px; border-radius: 16px; box-shadow: 0 3px 10px rgba(0,0,0,0.15); }
.install-name { font-size: 18px; font-weight: 600; color: var(--wa-text); }
.install-host { font-size: 13px; color: var(--wa-muted); }
.install-perks li { display: flex; align-items: center; gap: 12px; padding: 9px 0; font-size: 14.5px; color: var(--wa-text); border-top: 1px solid #f0f2f5; }
.install-perks li span { width: 32px; height: 32px; border-radius: 50%; background: #f0f2f5; display: flex; align-items: center; justify-content: center; font-size: 16px; flex: 0 0 auto; }
.install-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 16px; }

/* Contact form */
.sheet-sub { margin: 0 0 14px; color: var(--wa-muted); font-size: 13px; line-height: 1.4; text-align: left; }
.field { display: block; font-size: 13px; color: var(--wa-muted); margin-bottom: 12px; text-align: left; }
.field input {
  display: block; width: 100%;
  margin-top: 4px; padding: 12px;
  font-size: 16px; color: var(--wa-text);
  border: 1px solid #d1d7db; border-radius: 8px;
}
.field input:focus { outline: none; border-color: var(--wa-teal-green); }
.sheet-actions { display: flex; justify-content: space-between; margin-top: 8px; }

/* Header dropdown menu */
.menu-dropdown {
  position: absolute; top: 52px; right: 8px;
  background: #fff; border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  padding: 6px 0; min-width: 200px;
  z-index: 60;
  transform-origin: top right;
  animation: menu-in 0.15s ease;
}
@keyframes menu-in { from { transform: scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }
.menu-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  padding: 12px 20px; font-size: 15px; color: var(--wa-text);
}
.menu-item:active, .menu-item:hover { background: #f5f6f6; }

/* Emoji panel */
.emoji-panel {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 2px; padding: 8px;
  max-height: 220px; overflow-y: auto;
  background: var(--wa-panel);
  border-top: 1px solid #e0e0e0;
}
.emoji-panel button { background: none; border: none; font-size: 26px; padding: 6px 0; cursor: pointer; border-radius: 8px; }
.emoji-panel button:active { background: #e2e2e2; }

/* System notice chip (top of chat) */
.sys-chip {
  align-self: center; max-width: 88%;
  background: #FFF3C4; color: #54656F;
  font-size: 12.5px; line-height: 1.4; text-align: center;
  padding: 6px 12px; border-radius: 8px; margin: 6px 0 10px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
}

/* Grey single tick while a message is sending */
.msg .ticks.pending { color: var(--wa-muted); }

/* Bot reply buttons (WhatsApp Business style) */
.msg.has-buttons { padding-bottom: 0; min-width: 230px; }
.msg-buttons { clear: both; margin: 8px -9px 0; }
.msg-button {
  display: block; width: 100%;
  background: none; border: 0; border-top: 1px solid #e9edef;
  padding: 11px 10px; font-size: 14.5px; font-weight: 500;
  color: #027eb5; cursor: pointer; text-align: center;
  font-family: inherit;
}
.msg-button:active { background: #f5f6f6; }
.msg-button:disabled { cursor: default; color: #8696a0; }
.msg.failed { opacity: 0.6; }
.msg.failed .ticks { color: #d32f2f; }

/* Profile photo inside round avatars (chat header, call screen, admin) */
.avatar img, .call-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.call-avatar { overflow: hidden; }
