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

:root {
  --bg-page: #E5DDD5;
  --bg-chat: #EFEAE2;
  --surface: #FFFFFF;
  --surface-soft: #F7F8FA;
  --bubble-user: #D9FDD3;
  --bubble-bot: #FFFFFF;
  --wa-header: #075E54;
  --wa-header-dark: #054C44;
  --wa-accent: #00A884;
  --wa-accent-hover: #008F6F;
  --wa-btn: #15803D;
  --wa-btn-hover: #166534;
  --text: #111B21;
  --text-secondary: #3B4A54;
  --text-muted: #667781;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --danger-bg: #FEF2F2;
  --danger-border: #FECACA;
  --danger-text: #991B1B;
  --warn-bg: #FFFBEB;
  --warn-border: #FDE68A;
  --warn-text: #92400E;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

html {
  height: 100%;
  height: -webkit-fill-available;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  background: var(--bg-page);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, a, input, textarea {
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

/* ================= AUTH GATE (MOBILE-FIRST & KEYBOARD SAFE) ================= */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 16px calc(24px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #075E54 0%, #075E54 148px, #F0F2F5 148px, #F0F2F5 100%);
  overflow-y: auto;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid rgba(17, 27, 33, 0.08);
  border-radius: 18px;
  padding: 24px 20px;
  box-shadow: 0 10px 30px rgba(17, 27, 33, 0.1);
  margin: auto 0;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.brand-sub {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.auth-desc {
  margin: 0 0 16px;
  font-size: 13.8px;
  color: var(--text-secondary);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.req {
  color: #DC2626;
}

/* 16px font-size prevents iOS Safari forced auto-zoom on focus */
input[type="text"],
input[type="tel"] {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="tel"]:focus {
  border-color: var(--wa-accent);
  box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.14);
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 18px 0;
}

/* ================= THUMB-FRIENDLY BUTTONS ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 42px;
  padding: 8px 13px;
  font-size: 13.5px;
  border-radius: 10px;
}

.btn-wa {
  background: var(--wa-btn);
  color: #FFFFFF;
}

.btn-wa:hover {
  background: var(--wa-btn-hover);
}

.btn-wa:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-dark {
  background: #111B21;
  color: #FFFFFF;
}

.btn-dark:hover {
  background: #202C33;
}

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-outline:hover {
  background: var(--surface-soft);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.alert {
  padding: 12px 14px;
  border-radius: 11px;
  font-size: 13.5px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
}

.alert-error {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

/* ================= APP SHELL (FULL-BLEED MOBILE NATIVE FEEL) ================= */
.app-shell {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  display: flex;
  flex-direction: column;
  background-color: var(--bg-chat);
  background-image: radial-gradient(rgba(17, 27, 33, 0.045) 1px, transparent 1px);
  background-size: 18px 18px;
  position: relative;
  overflow: hidden;
}

@media (min-width: 721px) {
  .app-shell {
    box-shadow: 0 0 32px rgba(0, 0, 0, 0.1);
  }
}

/* Top Header Bar (Notch & Dynamic Island Safe) */
.wa-topbar {
  background: var(--wa-header);
  color: #FFFFFF;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
  z-index: 20;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}

.wa-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hamburger-btn {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.hamburger-btn:active {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(0.96);
}

.wa-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.wa-title-wrap {
  min-width: 0;
}

.wa-title {
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-subtitle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.86);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.wa-subtitle.typing-status {
  color: #6EE7B7;
  font-weight: 600;
}

.wa-topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.topbar-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.14);
  color: #FFFFFF;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.topbar-pill-btn:active {
  background: rgba(255, 255, 255, 0.26);
}

/* Sub-Tabs with Icons for Menu 1 (Easy Thumb Tap >= 46px) */
.treatment-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--wa-header-dark);
  padding: 0 6px;
  flex-shrink: 0;
  z-index: 19;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.t-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 46px;
  padding: 10px 6px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.t-tab svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  opacity: 0.85;
}

.t-tab.active {
  color: #FFFFFF;
  border-bottom-color: #25D366;
}

.t-tab.active svg {
  opacity: 1;
  color: #6EE7B7;
}

/* ================= SIDEBAR DRAWER (SWIPEABLE MOBILE) ================= */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 27, 33, 0.56);
  backdrop-filter: blur(2px);
  z-index: 40;
}

.sidebar-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: 304px;
  max-width: 86vw;
  background: var(--surface);
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: 6px 0 28px rgba(0, 0, 0, 0.22);
  transform: translateX(-100%);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

.sidebar-drawer.open {
  transform: translateX(0);
}

.sidebar-head {
  background: var(--wa-header);
  color: #FFFFFF;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 16px 16px;
}

.sidebar-head-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sidebar-close {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sidebar-mitra-name {
  font-size: 16px;
  font-weight: 700;
}

.sidebar-mitra-id {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.88);
  margin-top: 2px;
}

.sidebar-mitra-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 12.5px;
  color: #A7F3D0;
  text-decoration: none;
  word-break: break-all;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  -webkit-overflow-scrolling: touch;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 6px 10px;
}

.sidebar-item {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 5px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.14s ease;
}

.sidebar-item:active {
  background: var(--surface-soft);
}

.sidebar-item.active {
  background: #ECFDF5;
  color: var(--wa-header);
}

.sidebar-item-left {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.sidebar-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.sidebar-icon svg {
  width: 16px;
  height: 16px;
}

.sidebar-item.active .sidebar-icon {
  background: var(--wa-header);
  border-color: var(--wa-header);
  color: #FFFFFF;
}

.sidebar-badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text-muted);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-badge.live {
  background: #DCFCE7;
  color: #166534;
  border-color: #BBF7D0;
}

.sidebar-badge.wa {
  background: #ECFDF5;
  color: #047857;
  border-color: #A7F3D0;
}

.sidebar-foot {
  padding: 12px 12px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

/* ================= CHAT STREAM (SMOOTH MOBILE SCROLL) ================= */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-feed {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 12px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 94%;
}

@media (min-width: 560px) {
  .chat-feed {
    padding: 14px 16px 18px;
  }
  .msg-row {
    max-width: 84%;
  }
}

.msg-row.user {
  align-self: flex-end;
}

.msg-row.bot {
  align-self: flex-start;
}

.bubble {
  padding: 10px 12px;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(17, 27, 33, 0.12);
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-row.user .bubble {
  background: var(--bubble-user);
  border-top-right-radius: 4px;
  color: var(--text);
}

.msg-row.bot .bubble {
  background: var(--bubble-bot);
  border-top-left-radius: 4px;
  color: var(--text);
}

.bubble-sender {
  font-size: 12px;
  font-weight: 700;
  color: var(--wa-header);
  margin-bottom: 5px;
  line-height: 1.3;
}

.bubble-text {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-line;
  color: var(--text);
}

.bubble-time {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

/* Thinking & Typing Animation */
.typing-indicator-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 2px;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wa-accent);
  animation: waBounce 1.2s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes waBounce {
  0%, 80%, 100% {
    transform: scale(0.65);
    opacity: 0.45;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.typing-label {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}

/* Profile Summary Pills inside Bot Reply */
.profile-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.p-pill {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: #F0FDF4;
  color: #166534;
  border: 1px solid #BBF7D0;
}

/* Markdown Wrapper Box (Optimized for Mobile Reading & 1-Tap Copy) */
.md-box {
  margin-top: 6px;
  border: 1px solid #CBD5E1;
  border-radius: 12px;
  background: #F8FAFC;
  overflow: hidden;
}

.md-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: #E2E8F0;
  font-size: 11px;
  font-weight: 700;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.md-code {
  margin: 0;
  padding: 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.58;
  color: #0F172A;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: all;
  -webkit-user-select: all;
}

.cursor-blink {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--wa-accent);
  vertical-align: middle;
  margin-left: 2px;
  animation: cursorFade 0.7s infinite;
}

@keyframes cursorFade {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.bubble-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
  animation: fadeUpIn 0.25s ease forwards;
}

.bubble-actions .btn-full-span {
  grid-column: 1 / -1;
}

@media (max-width: 360px) {
  .bubble-actions {
    grid-template-columns: 1fr;
  }
}

@keyframes fadeUpIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ================= BOTTOM WHATSAPP COMPOSER (THUMB ZONE) ================= */
.composer-wrap {
  background: #F0F2F5;
  border-top: 1px solid #D1D7DB;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
  z-index: 20;
}

.quick-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.quick-strip::-webkit-scrollbar {
  display: none;
}

.q-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid #CBD5E1;
  background: #FFFFFF;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
}

.q-chip svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.q-chip:active {
  transform: scale(0.97);
  border-color: var(--wa-accent);
}

.q-chip.accent {
  background: #ECFDF5;
  border-color: #86EFAC;
  color: #065F46;
}

.q-chip.primary-chip {
  background: #075E54;
  border-color: #075E54;
  color: #FFFFFF;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

/* 16px prevents iOS Safari zoom when typing/pasting */
.composer-input {
  flex: 1;
  min-height: 46px;
  max-height: 140px;
  padding: 11px 15px;
  border-radius: 23px;
  border: 1.5px solid #D1D7DB;
  background: #FFFFFF;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.38;
  resize: none;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.composer-input:focus {
  border-color: var(--wa-accent);
}

.send-circle-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--wa-accent);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 168, 132, 0.36);
  transition: background 0.15s ease, transform 0.08s ease;
}

.send-circle-btn:hover:not(:disabled) {
  background: var(--wa-accent-hover);
}

.send-circle-btn:active:not(:disabled) {
  transform: scale(0.93);
}

.send-circle-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-circle-btn svg {
  width: 21px;
  height: 21px;
  margin-left: 2px;
}

/* ================= LOCKED STAGE PLACEHOLDER ================= */
.locked-stage-view {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.locked-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 20px;
  text-align: center;
  box-shadow: 0 6px 24px rgba(17, 27, 33, 0.08);
}

.locked-title {
  margin: 10px 0 6px;
  font-size: 17.5px;
  font-weight: 700;
}

.locked-desc {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* Toast (Safe above notch/header) */
.toast {
  position: fixed;
  left: 50%;
  top: calc(68px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  z-index: 70;
  max-width: calc(100vw - 28px);
  background: #111B21;
  color: #FFFFFF;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
