/* ─── Brand tokens ─────────────────────────────────────────────────────────── */
:root {
  --green:       #004634;
  --green-light: #006B50;
  --green-dark:  #003326;
  --orange:      #FF5B2E;
  --orange-light:#FF7A54;
  --white:       #FFFFFF;
  --gray-50:     #F9FAFB;
  --gray-100:    #F3F4F6;
  --gray-200:    #E5E7EB;
  --gray-500:    #6B7280;
  --gray-800:    #1F2937;
  --radius:      8px;
  --topbar-h:    52px;
  --doc-bar-h:   48px;
  --input-bar-h: 68px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ─── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--gray-50);
  color: var(--gray-800);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

/* ─── Top bar ──────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--green);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.topbar-title { line-height: 1.1; text-align: center; }

.topbar-logo {
  height: 28px;
  width: auto;
  display: block;
}

.topbar-guy  { color: var(--orange); }
.topbar-rest { color: var(--white); }
.topbar-beta {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0.5px;
  margin-top: -2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-link {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: color 0.15s;
}
.topbar-link:hover { color: var(--white); }

/* ─── Language toggle ──────────────────────────────────────────────────────── */
.lang-toggle {
  background: rgba(255,255,255,0.15);
  color: var(--white);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Document buttons ─────────────────────────────────────────────────────── */
.doc-buttons {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.doc-buttons::-webkit-scrollbar { display: none; }

.doc-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--green);
  background: var(--white);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  touch-action: manipulation;
}
/* Hover only with a real mouse */
.can-hover .doc-btn:hover {
  background: var(--green);
  color: var(--white);
}
.can-hover .doc-btn:active { transform: scale(0.95); }
.can-hover .lang-toggle:hover { background: rgba(255,255,255,0.25); }

/* Active generator button stays green */
.doc-btn-active {
  background: var(--green) !important;
  color: var(--white) !important;
  font-weight: 700;
}

/* ─── Chat panel ───────────────────────────────────────────────────────────── */
.chat-panel {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  background: var(--white);
  z-index: 50;
}

/* Messages scroll area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Individual message bubble wrapper */
.msg {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 480px);
  gap: 6px;
  animation: msgIn 0.18s ease;
}

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

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

.bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.guy  .bubble {
  background: var(--green);
  color: var(--white);
  border-bottom-left-radius: 4px;
}

.msg.user .bubble {
  background: var(--gray-100);
  color: var(--gray-800);
  border-bottom-right-radius: 4px;
}

/* Action buttons below a message */
.msg-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-action.payment {
  background: var(--orange);
  color: var(--white);
  box-shadow: 0 3px 10px rgba(255,91,46,0.3);
}
.btn-action.payment:hover { background: var(--orange-light); }
.btn-action.payment:active { transform: scale(0.97); }

.btn-action.download {
  background: var(--green);
  color: var(--white);
  box-shadow: 0 3px 10px rgba(0,70,52,0.25);
}
.btn-action.download:hover { background: var(--green-light); }
.btn-action.download:active { transform: scale(0.97); }

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 15px;
  background: var(--green);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255,255,255,0.7);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ─── Input bar ────────────────────────────────────────────────────────────── */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  min-height: var(--input-bar-h);
}

.chat-input {
  flex: 1;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 22px;
  background: var(--gray-50);
  color: var(--gray-800);
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  -webkit-appearance: none;
  transition: border-color 0.15s ease;
}

.chat-input:focus { border-color: var(--green-light); }
.chat-input::placeholder { color: var(--gray-500); }

.btn-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--orange);
  color: var(--white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-send:hover  { background: var(--orange-light); }
.btn-send:active { transform: scale(0.93); }
.btn-send:disabled { background: var(--gray-200); cursor: not-allowed; }

/* ─── Info capture card ────────────────────────────────────────────────────── */
.info-card {
  background: var(--green);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}

.info-prompt {
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
  line-height: 1.4;
}

.info-input {
  font-family: var(--font);
  font-size: 14px;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.9);
  color: var(--gray-800);
  outline: none;
}
.info-input:focus { background: var(--white); }
.info-input::placeholder { color: var(--gray-500); }
.info-input-error { border: 2px solid #e53e3e; background: #fff5f5; }
.info-input-error:focus { border-color: #e53e3e; }

.info-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.info-btn {
  flex: 1;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.info-btn.save {
  background: var(--orange);
  color: var(--white);
}
.info-btn.save:hover { background: var(--orange-light); }

.info-btn.skip {
  background: rgba(255,255,255,0.2);
  color: var(--white);
}
.info-btn.skip:hover { background: rgba(255,255,255,0.3); }

/* ─── Stripe inline payment ────────────────────────────────────────────────── */
.payment-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--gray-200);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

#payment-element {
  margin-bottom: 12px;
}

.payment-submit {
  width: 100%;
  padding: 12px;
  background: var(--orange);
  color: var(--white);
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.payment-submit:hover { background: var(--orange-light); }
.payment-submit:disabled { background: var(--gray-200); cursor: not-allowed; }

.payment-error {
  color: #e53e3e;
  font-size: 13px;
  margin-top: 8px;
  min-height: 18px;
}

/* ─── Revision tag ─────────────────────────────────────────────────────────── */
.rev-tag {
  position: fixed;
  bottom: calc(var(--input-bar-h) + 2px);
  right: 8px;
  font-size: 10px;
  color: var(--gray-200);
  font-family: monospace;
  z-index: 200;
  user-select: none;
  cursor: default;
  transition: color 0.2s ease;
  padding: 12px 16px;
  margin: -12px -16px;
}
.rev-tag:hover, .rev-tag:active {
  color: var(--gray-800);
  transition: color 0.1s ease;
}

/* ─── Responsive: small phones (≤ 380px) ──────────────────────────────────── */
@media (max-width: 380px) {
  :root { --topbar-h: 46px; }
  .topbar { padding: 0 10px; }
  .topbar-left { font-size: 14px; gap: 5px; }
  .topbar-logo { height: 20px; }
  .topbar-rest { display: none; }
  .topbar-link { font-size: 12px; }
  .lang-toggle { padding: 3px 8px; font-size: 11px; }

  .doc-buttons { padding: 5px 8px; gap: 5px; }
  .doc-btn { padding: 4px 8px; font-size: 11px; }

  .chat-messages { padding: 10px 10px 6px; gap: 8px; }
  .msg { max-width: 92%; }
  .bubble { font-size: 13px; padding: 8px 10px; }

  .chat-input-bar { padding: 8px 8px; gap: 8px; }
  .chat-input { font-size: 16px; padding: 8px 10px; }
  .btn-send { width: 38px; height: 38px; }

  .info-card, .payment-card { max-width: 100%; }
}

/* ─── Responsive: phones (381px – 600px) ──────────────────────────────────── */
@media (min-width: 381px) and (max-width: 600px) {
  .topbar-left { font-size: 16px; gap: 7px; }
  .topbar-logo { height: 24px; }
  .topbar-rest { display: none; }

  .doc-buttons { padding: 6px 10px; gap: 6px; }
  .doc-btn { padding: 5px 11px; font-size: 12px; }

  .msg { max-width: 88%; }
  .bubble { font-size: 14px; }

  .chat-input { font-size: 16px; } /* 16px prevents iOS zoom */

  .info-card, .payment-card { max-width: 100%; }
}

/* ─── Responsive: tablets (601px – 1024px) ────────────────────────────────── */
@media (min-width: 601px) and (max-width: 1024px) {
  .chat-panel {
    max-width: 640px;
    margin: 0 auto;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    border-left: 1px solid var(--gray-200);
    border-right: 1px solid var(--gray-200);
  }

  .doc-buttons { justify-content: center; }
  .msg { max-width: min(82%, 500px); }
}

/* ─── Responsive: desktop (1025px+) ───────────────────────────────────────── */
@media (min-width: 1025px) {
  .chat-panel {
    max-width: 720px;
    margin: 0 auto;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    border-left: 1px solid var(--gray-200);
    border-right: 1px solid var(--gray-200);
    box-shadow: 0 0 24px rgba(0,0,0,0.07);
  }

  .doc-buttons { justify-content: center; }
}
