/* Loudoun Online: chat-first PWA shell. Mobile-first, no framework. */
:root {
  --cream: #fbf6ee;
  --paper: #ffffff;
  --sand: #f1e7d6;
  --ink: #2a2620;
  --muted: #5d554a;
  --green: #2f4a3a;
  --green-soft: #e6ede6;
  --clay: #a8452a;
  --clay-soft: #f7e3d9;
  --gold: #e3b34f;
  --line: #e4d9c7;
  --focus: #1f5fbf;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; background: var(--cream); }
body { margin: 0; overflow: hidden; overscroll-behavior: none; color: var(--ink); font: 16px/1.5 var(--sans); -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
a { color: var(--clay); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* App frame: fills the visual viewport so the composer sits above the keyboard. */
.app {
  position: fixed; left: 0; right: 0; top: var(--vv-top, 0px);
  height: 100vh; height: 100dvh; height: var(--vv-height, 100dvh);
  display: flex; flex-direction: column;
  max-width: 720px; margin: 0 auto;
}

.bar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 6px) calc(var(--sar) + 8px) 6px calc(var(--sal) + 16px);
  border-bottom: 1px solid transparent; transition: border-color .2s;
}
.app.has-chat .bar { border-bottom-color: var(--line); }
.wordmark { font-family: var(--serif); font-weight: 600; font-size: 1.12rem; color: var(--green); letter-spacing: -.01em; }
.bar-actions { display: flex; gap: 0; flex: 0 0 auto; }
.wordmark { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; background: transparent; color: var(--green); border-radius: 50%; cursor: pointer; }
.icon-btn:hover { background: var(--green-soft); }

.thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 8px calc(var(--sar) + 14px) 12px calc(var(--sal) + 14px); display: flex; flex-direction: column; }

/* Empty state */
.empty { margin: auto 0; padding: 12px 2px 8px; }
.empty h1 { font-family: var(--serif); font-weight: 600; font-size: 1.85rem; line-height: 1.12; letter-spacing: -.015em; color: var(--green); margin: 0 0 8px; }
.empty p { margin: 0 0 18px; color: var(--muted); }
.chips { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.chip { text-align: left; font-size: .94rem; color: var(--green); background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; cursor: pointer; }
.chip:hover { border-color: #b9c9bb; background: var(--green-soft); }
.app.has-chat .empty { display: none; }

/* Messages */
.messages { display: flex; flex-direction: column; gap: 12px; }
.messages:empty { display: none; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 18px; }
.msg p { margin: 0 0 .55em; } .msg p:last-child { margin-bottom: 0; }
.msg.user { align-self: flex-end; background: var(--green); color: #fff; border-bottom-right-radius: 6px; }
.msg.bot { align-self: flex-start; background: var(--sand); border-bottom-left-radius: 6px; }
.msg.bot.unknown { background: transparent; border: 1px dashed #cdbfa8; }
.msg.error { align-self: flex-start; background: var(--clay-soft); color: #6e2a17; }
.msg.error.busy { background: var(--sand); color: var(--ink); }
.msg .retry[disabled] { opacity: .7; cursor: default; color: var(--muted); border-color: var(--line); }
.msg .retry { margin-top: 8px; font-size: .88rem; font-weight: 600; background: var(--paper); color: var(--clay); border: 1px solid #e0b8a6; border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.msg .sources { margin: 8px 0 0 !important; font-size: .82rem; color: var(--muted); }
.msg .sources a { color: var(--muted); }
.demo-note { font-size: .75rem; color: var(--muted); font-style: italic; margin-top: 6px !important; }


.typing { display: inline-flex; gap: 5px; align-items: center; height: 20px; }
.typing span { width: 7px; height: 7px; background: var(--muted); border-radius: 50%; animation: bob 1s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* Composer */
.composer { flex: 0 0 auto; padding: 8px calc(var(--sar) + 12px) calc(var(--sab) + 12px) calc(var(--sal) + 12px); background: var(--cream); }
.ask { display: flex; align-items: center; gap: 6px; background: var(--paper); border: 1.5px solid #d5c8b3; border-radius: 999px; padding: 4px 4px 4px 16px; }
.ask:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(47,74,58,.15); }
.ask input { flex: 1; min-width: 0; font: inherit; font-size: 16px; /* 16px stops iOS zoom */ color: var(--ink); background: transparent; border: 0; padding: 9px 0; }
.ask input:focus, .ask input:focus-visible { outline: none; }
.ask input::placeholder { color: #776d60; }
.send { flex: 0 0 auto; display: grid; place-items: center; width: 42px; height: 42px; color: #fff; background: var(--clay); border: 0; border-radius: 50%; cursor: pointer; }
.send:hover { background: #8f3a22; }
.send[disabled] { opacity: .55; cursor: progress; }
.turnstile { margin-top: 8px; }
.turnstile:empty { display: none; }

/* Info sheet */
.sheet { border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 85dvh; background: var(--paper); color: var(--ink); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 40px rgba(42,38,32,.18); }
.sheet[open] { animation: up .22s ease-out; }
.sheet::backdrop { background: rgba(30,28,24,.45); }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-inner { padding: 8px 20px calc(var(--sab) + 20px); overflow-y: auto; max-height: 85dvh; font-size: .95rem; }
.sheet-inner::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 6px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-right: -10px; }
.sheet h2 { font-family: var(--serif); font-weight: 600; font-size: 1.3rem; color: var(--green); margin: 0; }
.sheet h3 { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; color: var(--green); margin: 18px 0 6px; }
.sheet p { margin: 0 0 10px; }
.tip .tip-text { margin: 4px 0 6px; }
.share-glyph { vertical-align: -3px; color: var(--green); }
.contact { color: var(--muted); }
.contact a { color: var(--green); }
.legal { font-size: .8rem; color: var(--muted); margin-top: 14px !important; }

@media (min-width: 721px) {
  .sheet { margin: auto; border-radius: 20px; }
  .empty h1 { font-size: 2.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  .typing span { animation: none; opacity: .7; }
  .sheet[open] { animation: none; }
}
[hidden] { display: none !important; }
.sheet:focus, .sheet:focus-visible { outline: none; }
