:root {
  --green-900: #103d14;
  --green-700: #1b5e20;
  --green-600: #2e7d32;
  --green-100: #e6f2e7;
  --wheat: #f7f1e1;
  --ink: #1c2420;
  --muted: #6b7a70;
  --bubble-user: #1b5e20;
  --bubble-agent: #ffffff;
  --bg: #f2f5f0;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  font-family: "Segoe UI", system-ui, -apple-system, "Noto Nastaliq Urdu", "Jameel Noori Nastaleeq", sans-serif;
  color: var(--ink);
}

svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- header ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: linear-gradient(135deg, var(--green-900), var(--green-700));
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 28px; height: 28px; color: var(--wheat); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 17px; }
.brand-text small { opacity: .75; font-size: 11px; }

.top-actions { display: flex; gap: 6px; }

.icon-btn {
  background: rgba(255,255,255,.14);
  border: none;
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.icon-btn svg { width: 19px; height: 19px; }
.lang-btn { width: auto; padding: 0 12px; font-size: 14px; font-weight: 600; }

/* speaker on/off swap */
#btn-speak .icon-off { display: none; }
#btn-speak.off .icon-on { display: none; }
#btn-speak.off .icon-off { display: block; }
#btn-speak.off { opacity: .55; }

/* ---------- chat ---------- */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: pop .18s ease-out;
}

@keyframes pop {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg.agent {
  align-self: flex-start;
  background: var(--bubble-agent);
  border: 1px solid #e2e8e2;
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.msg.error {
  align-self: center;
  background: #fdecea;
  color: #8c2f26;
  border: 1px solid #f5c6c0;
  font-size: 14px;
}

.msg.typing {
  align-self: flex-start;
  color: var(--muted);
  background: var(--bubble-agent);
  border: 1px solid #e2e8e2;
}
.msg.typing .dots::after {
  content: "…";
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: .2; } }

.welcome {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin: 24px 16px;
  line-height: 1.9;
}
.welcome .big { width: 44px; height: 44px; color: var(--green-600); margin-bottom: 6px; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}
.chip {
  background: var(--green-100);
  color: var(--green-700);
  border: 1px solid #cfe3d1;
  border-radius: 999px;
  padding: 8px 15px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.chip:active { background: #d3e8d5; }

/* ---------- composer ---------- */
#composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: #fff;
  border-top: 1px solid #e4e9e4;
}

#input {
  flex: 1;
  resize: none;
  border: 1px solid #d6ded6;
  border-radius: 22px;
  padding: 11px 16px;
  font-size: 16px;
  font-family: inherit;
  max-height: 120px;
  outline: none;
  background: var(--bg);
}
#input:focus { border-color: var(--green-600); }

.mic-btn, .send-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mic-btn svg, .send-btn svg { width: 21px; height: 21px; }

.mic-btn {
  background: var(--green-700);
  color: #fff;
  touch-action: none;               /* keep the hold gesture, no scroll/zoom */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: transform .12s ease;
}
.mic-btn.listening {
  background: #d32f2f;
  color: #fff;
  transform: scale(1.35);
  animation: pulse 1.1s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(211,47,47,.45); }
  100% { box-shadow: 0 0 0 16px rgba(211,47,47,0); }
}

.send-btn { background: var(--green-100); color: var(--green-700); }
.send-btn:disabled { opacity: .5; }

/* hold-to-talk hint / recording banner */
.rec-hint {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 76px);
  background: rgba(20, 30, 22, .88);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 40;
  pointer-events: none;
  transition: opacity .2s;
}
.rec-hint.hidden { opacity: 0; }
.rec-hint.recording { background: #d32f2f; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 40, 20, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(3px);
}
.overlay.hidden { display: none; }

.overlay-card {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  width: min(320px, 86vw);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}
.overlay-icon { width: 40px; height: 40px; color: var(--green-700); }

.primary-btn {
  background: var(--green-700);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
}
.ghost-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
