:root {
  --green: #1f6f43; --green-dark: #17553a; --bg: #f4f7f5; --card: #ffffff; --text: #17201b; --muted: #5b6b62;
  --border: #d9e2dc; --user: #1f6f43; --user-text: #ffffff; --chip: #e7f0ea; --err: #a32020; --errbg: #fdeaea;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1613; --card: #18211c; --text: #e8efe9; --muted: #9db0a4; --border: #2a3830; --chip: #223229; --errbg: #3a1c1c; --err: #ff9b9b; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
#app, .shell { height: 100%; }
.shell { display: flex; flex-direction: column; height: 100dvh; }
.column { width: 100%; max-width: 780px; margin: 0 auto; padding: 0 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

header { position: relative; background: var(--green); color: #fff; padding-top: env(safe-area-inset-top); flex: none; }
.bar { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.bar-actions { display: flex; gap: 8px; }
.menu { position: absolute; right: 12px; top: calc(100% - 4px); z-index: 5; background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 8px; min-width: 200px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.menu[hidden] { display: none; }
.menu .who { padding: 6px 10px; color: var(--muted); font-size: 14px; word-break: break-all; }
.linkbtn { display: block; width: 100%; text-align: left; background: none; border: 0; color: inherit; font: inherit; padding: 10px; border-radius: 8px; cursor: pointer; min-height: 44px; }
.linkbtn:hover, .linkbtn:focus-visible { background: var(--chip); }

.offline { background: #ffe9b5; color: #5b4300; text-align: center; padding: 6px 10px; font-size: 14px; flex: none; }
.offline[hidden] { display: none; }

.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 0 8px; }
.messages { display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; max-width: 100%; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }
.bubble { padding: 10px 14px; border-radius: var(--radius); max-width: 92%; overflow-wrap: anywhere; }
.user .bubble { background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.assistant .bubble { background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.assistant .bubble.error { background: var(--errbg); border-color: var(--err); color: var(--err); }
.bubble p { margin: 0 0 .6em; } .bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 .6em; padding-left: 1.3em; }
.bubble code { background: var(--chip); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.tablewrap { overflow-x: auto; margin: 0 0 .6em; }
table { border-collapse: collapse; font-size: 14px; } th, td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; } th { background: var(--chip); }

.sources { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; max-width: 92%; }
.sources-label { font-size: 12px; color: var(--muted); }
.chip { display: inline-block; max-width: 100%; background: var(--chip); color: var(--text); border: 0; border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 13px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; min-height: 30px; line-height: 22px; }
a.chip:hover, a.chip:focus-visible { outline: 2px solid var(--green); }
.chip[hidden] { display: none; }

.feedback { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.fb { background: none; border: 1px solid var(--border); border-radius: 10px; font-size: 18px; min-width: 44px; min-height: 36px; cursor: pointer; }
.fb:hover, .fb:focus-visible { background: var(--chip); }
.fbc { flex: 1 1 100%; font: inherit; font-size: 16px; padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text); }
.thanks { color: var(--green); }
.error-inline { color: var(--err); }

.typing { display: flex; gap: 5px; padding: 14px; }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; opacity: .6; } * { scroll-behavior: auto !important; } }

.empty { text-align: center; padding: 8vh 4px 0; } .empty h2 { margin: 0 0 6px; font-size: 20px; } .empty p { color: var(--muted); margin: 0 0 18px; }
.suggestions { display: grid; gap: 8px; }
.suggestion { text-align: left; background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 15px; cursor: pointer; min-height: 48px; }
.suggestion:hover, .suggestion:focus-visible { border-color: var(--green); }

.composer { flex: none; background: var(--bg); border-top: 1px solid var(--border); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.input { flex: 1; overflow-y: hidden; font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */ resize: none; padding: 10px 14px; border: 1px solid var(--border); border-radius: 22px; background: var(--card); color: var(--text); max-height: 160px; line-height: 1.4; }
.input:focus { outline: 2px solid var(--green); border-color: transparent; }
.send { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--green); color: #fff; display: grid; place-items: center; cursor: pointer; }
.send:hover, .send:focus-visible { background: var(--green-dark); }
.deep { display: block; font-size: 14px; color: var(--muted); margin: 0 4px 6px; }

.btn { background: var(--green); color: #fff; border: 0; border-radius: 12px; padding: 12px 22px; font: inherit; font-weight: 600; cursor: pointer; min-height: 46px; }
.btn:hover, .btn:focus-visible { background: var(--green-dark); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; border-radius: 10px; }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.55); color: inherit; }
.feedback .btn.ghost { border-color: var(--border); color: var(--text); }
header .btn.ghost:hover { background: rgba(255,255,255,.15); }

.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; gap: 8px; }
.login img { border-radius: 16px; } .login h1 { margin: 8px 0 0; font-size: 24px; } .login p { margin: 0 0 8px; color: var(--muted); max-width: 22rem; }
.login .hint { font-size: 13px; margin-top: 12px; }
button:focus-visible, a:focus-visible, textarea:focus-visible { outline: 2px solid #7fd1a3; outline-offset: 2px; }
