:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --text: #17201a;
  --muted: #68716b;
  --border: #e3e7e2;
  --brand: #173f2b;
  --brand-soft: #eaf2ed;
  --user: #173f2b;
  --shadow: 0 12px 40px rgba(25, 42, 31, .08);
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { min-height: 100dvh; }
button, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100dvh; max-width: 820px; margin: 0 auto; background: var(--panel); display: grid; grid-template-rows: auto 1fr auto; box-shadow: var(--shadow); }
.topbar { min-height: 74px; padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(12px); z-index: 5; }
.brand-wrap { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 800; font-size: 22px; }
.brand { font-size: 17px; font-weight: 800; letter-spacing: -.2px; }
.status { margin-top: 3px; color: var(--muted); font-size: 11px; display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #2e9f5b; display: inline-block; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 40px; height: 40px; border: 1px solid var(--border); background: white; border-radius: 13px; font-size: 20px; color: var(--brand); }
.download-btn { min-height: 40px; border: 1px solid var(--border); background: #fff; color: var(--brand); border-radius: 13px; padding: 0 12px; font-size: 12px; font-weight: 800; }
.download-btn:hover { border-color: #b9cabe; background: #fafcfb; }
.download-btn:disabled { opacity: .55; cursor: wait; }

.chat { min-height: 0; overflow-y: auto; padding: 26px 16px 30px; scroll-behavior: smooth; }
.hero { max-width: 620px; margin: 3vh auto 0; text-align: center; }
.hero-badge { display: inline-flex; border: 1px solid #dbe7df; background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 7px 11px; font-size: 12px; font-weight: 750; }
.hero h1 { margin: 18px auto 10px; max-width: 520px; font-size: clamp(29px, 7vw, 46px); letter-spacing: -1.6px; line-height: 1.03; }
.hero > p { margin: 0 auto; max-width: 570px; color: var(--muted); line-height: 1.6; font-size: 15px; }
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 26px auto 0; max-width: 570px; }
.quick { text-align: left; padding: 14px; border: 1px solid var(--border); border-radius: 16px; background: #fff; color: #26332b; font-weight: 650; transition: .15s ease; }
.quick:hover { border-color: #b9cabe; background: #fafcfb; transform: translateY(-1px); }
.trust-note { margin: 20px auto 0; max-width: 570px; padding: 13px 14px; border-radius: 14px; background: #faf8f0; border: 1px solid #ece5cc; color: #6e6545; text-align: left; font-size: 12px; line-height: 1.45; }

.message-row { display: flex; margin: 0 auto 14px; max-width: 680px; }
.message-row.user { justify-content: flex-end; }
.message-row.assistant { justify-content: flex-start; }
.bubble { max-width: min(88%, 590px); padding: 13px 15px; border-radius: 18px; line-height: 1.52; font-size: 15px; overflow-wrap: anywhere; white-space: pre-wrap; }
.user .bubble { background: var(--user); color: white; border-bottom-right-radius: 6px; }
.assistant .bubble { background: #f4f6f3; border: 1px solid #e8ebe7; color: var(--text); border-bottom-left-radius: 6px; }
.assistant .bubble a { color: #0b5d37; font-weight: 700; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message-meta { max-width: 680px; margin: -7px auto 15px; padding-left: 2px; color: var(--muted); font-size: 11px; }
.sources { max-width: 680px; margin: -7px auto 18px; display: flex; gap: 7px; flex-wrap: wrap; }
.source-chip { display: inline-flex; max-width: 100%; align-items: center; gap: 6px; border: 1px solid #dae5dd; background: #fbfdfb; color: #26533b; border-radius: 999px; padding: 7px 10px; font-size: 11px; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.typing { display: inline-flex; gap: 4px; align-items: center; min-width: 54px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: #859087; animation: blink 1.2s infinite; }
.typing i:nth-child(2){ animation-delay: .15s; }.typing i:nth-child(3){ animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0);} 40% { opacity: 1; transform: translateY(-2px);} }

.composer-wrap { padding: 9px 12px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: rgba(255,255,255,.98); position: sticky; bottom: 0; z-index: 5; }
.composer { max-width: 680px; margin: 0 auto; display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 7px; padding: 7px; border: 1px solid #dfe4df; border-radius: 20px; background: #fff; box-shadow: 0 7px 24px rgba(26,44,32,.06); }
.composer:focus-within { border-color: #abc0b2; box-shadow: 0 0 0 3px rgba(46,106,70,.07); }
textarea { width: 100%; min-height: 39px; max-height: 140px; resize: none; border: 0; outline: 0; padding: 9px 5px 7px; color: var(--text); background: transparent; line-height: 1.35; }
textarea::placeholder { color: #9aa29c; }
.composer-icon, .send-btn { width: 42px; height: 42px; border-radius: 14px; border: 0; display: grid; place-items: center; }
.composer-icon { background: #f3f5f2; color: #425248; }
.send-btn { background: var(--brand); color: white; font-size: 19px; font-weight: 900; }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.footer-line { max-width: 680px; margin: 7px auto 0; text-align: center; color: #89918b; font-size: 10px; line-height: 1.35; }
.live-notice { max-width: 680px; margin: 0 auto 7px; padding: 9px 11px; border-radius: 12px; background: #fff5e6; border: 1px solid #eed9b6; color: #7f5a20; font-size: 12px; }

@media (max-width: 560px) {
  .app-shell { box-shadow: none; }
  .chat { padding: 18px 13px 22px; }
  .hero { margin-top: 1vh; }
  .hero h1 { font-size: 33px; }
  .quick-grid { grid-template-columns: 1fr; }
  .bubble { max-width: 92%; }
  .download-btn { width: 40px; padding: 0; font-size: 0; }
  .download-btn::before { content: "↓"; font-size: 18px; }
}

@media (min-width: 821px) {
  body { padding: 18px; }
  .app-shell { min-height: calc(100dvh - 36px); max-height: calc(100dvh - 36px); border-radius: 26px; overflow: hidden; border: 1px solid #e5e8e4; }
}


.pdf-export {
  width: 720px;
  padding: 34px;
  background: #fff;
  color: #17201a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.pdf-export h1 { margin: 0 0 5px; font-size: 24px; }
.pdf-export .pdf-meta { color: #68716b; font-size: 11px; margin-bottom: 22px; }
.pdf-export .pdf-message { margin: 0 0 15px; page-break-inside: avoid; }
.pdf-export .pdf-role { font-size: 11px; font-weight: 800; margin-bottom: 5px; color: #45604f; }
.pdf-export .pdf-body { white-space: pre-wrap; line-height: 1.5; font-size: 13px; padding: 11px 13px; border-radius: 12px; border: 1px solid #e3e7e2; background: #f8faf8; }
.pdf-export .pdf-message.user .pdf-body { background: #eef4f0; }
.pdf-export .pdf-sources { margin: 7px 0 0 13px; padding: 0; font-size: 10px; line-height: 1.45; }
.pdf-export .pdf-sources a { color: #174c32; overflow-wrap: anywhere; }
.pdf-export .pdf-disclaimer { margin-top: 24px; padding-top: 12px; border-top: 1px solid #e3e7e2; color: #68716b; font-size: 10px; line-height: 1.45; }


.pdf-stage {
  position: fixed;
  inset: 0;
  z-index: 9998;
  overflow: auto;
  background: #ffffff;
  padding: 18px;
}
.pdf-stage .pdf-export {
  margin: 0 auto;
}
.pdf-curtain {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: #ffffff;
}
.pdf-curtain-card {
  min-width: 220px;
  padding: 20px 22px;
  border: 1px solid #e3e7e2;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(25, 42, 31, .08);
  text-align: center;
  color: #173f2b;
  background: #ffffff;
}
.pdf-curtain-card strong,
.pdf-curtain-card span {
  display: block;
}
.pdf-curtain-card span {
  margin-top: 7px;
  color: #68716b;
  font-size: 12px;
}

.input-helper { max-width: 680px; margin: 0 auto 7px; padding: 0 2px; color: #5f6b63; font-size: 12px; line-height: 1.4; text-align: left; }


.attachment-preview { max-width: 680px; margin: 0 auto 7px; display: flex; align-items: center; gap: 9px; padding: 7px 9px; border: 1px solid #dfe4df; background: #fafcfb; border-radius: 14px; }
.attachment-preview[hidden] { display: none; }
.attachment-preview img { width: 42px; height: 42px; object-fit: cover; border-radius: 9px; border: 1px solid var(--border); background: #fff; }
.attachment-preview span { min-width: 0; flex: 1; font-size: 12px; color: #526057; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment-preview button { width: 30px; height: 30px; border: 0; border-radius: 9px; background: #eef1ee; color: #4d5a52; font-size: 20px; line-height: 1; }
.composer { grid-template-columns: auto auto 1fr auto; }
.composer-icon:disabled { opacity: .45; cursor: not-allowed; }
