:root {
  --ink: #1F2A22;
  --deep-green: #163C2C;
  --deep-green-light: #1F5138;
  --paper: #FAF7F0;
  --bubble-ai: #FFFFFF;
  --bubble-user: #FFE9C2;
  --gold: #E3982E;
  --gold-dark: #C97F1C;
  --line: #E7E1D3;
  --muted: #7C8A7F;
  --danger: #C0392B;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--deep-green);
  color: var(--ink);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--paper);
  position: relative;
}

/* ---------- Header ---------- */
#chat-header {
  background: var(--deep-green);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  flex: 0 0 auto;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
  z-index: 5;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--deep-green);
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.header-name {
  font-weight: 600;
  font-size: 16px;
  line-height: 1.2;
}

.header-status {
  font-size: 12px;
  color: #CFE3D6;
}

/* ---------- Chat window ---------- */
#chat-window {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px 8px;
  background-image: radial-gradient(circle at 20px 20px, rgba(22,60,44,0.035) 1px, transparent 0);
  background-size: 22px 22px;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble-row {
  display: flex;
  width: 100%;
}
.bubble-row.from-ai { justify-content: flex-start; }
.bubble-row.from-user { justify-content: flex-end; }

.bubble {
  max-width: 78%;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.42;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,0.05);
  animation: pop-in 120ms ease-out;
}

.from-ai .bubble {
  background: var(--bubble-ai);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--line);
}

.from-user .bubble {
  background: var(--bubble-user);
  border-bottom-right-radius: 4px;
}

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

.msg-time {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 2px;
  padding: 0 4px;
}
.from-user .msg-time { text-align: right; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  width: fit-content;
  background: var(--bubble-ai);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  margin: 6px 0 0 0;
}
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}
.hidden { display: none !important; }

/* ---------- Action cards (sample / pay) ---------- */
.action-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  max-width: 78%;
  margin-top: 2px;
}
.action-card .action-title {
  font-weight: 600;
  font-size: 13.5px;
  margin-bottom: 6px;
}
.action-card a.sample-link {
  display: inline-block;
  color: var(--deep-green-light);
  font-size: 13.5px;
  text-decoration: underline;
}

.pay-btn {
  display: block;
  width: 100%;
  background: var(--gold);
  color: var(--deep-green);
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}
.pay-btn:active { background: var(--gold-dark); }
.pay-btn:disabled { opacity: .6; cursor: default; }

.download-btn {
  display: block;
  width: 100%;
  text-align: center;
  background: var(--deep-green);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  margin-top: 6px;
}

/* ---------- Suggestions ---------- */
.suggestions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px;
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.suggestions::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--deep-green-light);
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.chip:active { background: var(--bubble-user); }

/* ---------- Composer ---------- */
#composer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
}

#message-input {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 15px;
  outline: none;
  background: #fff;
}
#message-input:focus { border-color: var(--gold); }

#send-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--deep-green);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
}
#send-btn:disabled { opacity: .5; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(22,60,44,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.modal-box {
  background: #fff;
  width: 100%;
  max-width: 560px;
  border-radius: 18px 18px 0 0;
  padding: 20px;
}
.modal-box h3 { margin: 0 0 6px; font-size: 17px; }
.modal-box p { margin: 0 0 12px; font-size: 13.5px; color: var(--muted); }
#email-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  margin-bottom: 12px;
}
.modal-actions { display: flex; gap: 10px; }
.btn-secondary, .btn-primary {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary { background: #F0EEE6; color: var(--ink); }
.btn-primary { background: var(--gold); color: var(--deep-green); }

@media (min-width: 561px) {
  body { padding: 20px 0; }
  #app { height: calc(100dvh - 40px); border-radius: 18px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
}
