:root {
  --green: #2e6b30; --green-dark: #1f4d21; --green-light: #e8f1e4; --soil: #6b4f2e;
  --ink: #1f2421; --muted: #5f6b62; --line: #d9e0d8; --bg: #f6f7f3; --card: #fff;
  --red: #b3261e; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --green: #7fbf7f; --green-dark: #a8d8a8; --green-light: #203323; --ink: #e8ece6; --muted: #a6b0a6;
    --line: #34403a; --bg: #121714; --card: #1a211c; --red: #ff8a80;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--green); }
h1 { font-size: 1.5rem; margin: 0.6em 0 0.4em; }
h2 { font-size: 1.15rem; margin: 0.4em 0; }
h2.sub { margin-top: 1em; }
small, .muted { color: var(--muted); }
.center { text-align: center; }
main.narrow { max-width: 560px; margin: 0 auto; padding: 0 16px 40px; }
main.wide { max-width: 1100px; margin: 0 auto; padding: 0 16px 40px; }

.topnav { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--green); text-decoration: none; }
.navlinks { display: flex; align-items: center; gap: 12px; font-size: 0.92rem; }
@media (max-width: 480px) { .brand span { display: none; } .navlinks { gap: 10px; font-size: 0.88rem; } }
.navlinks a { text-decoration: none; }
form.inline, .inline { display: inline; margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.95rem; }
label small { font-weight: 400; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
input, select, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%; }
input[type=checkbox] { width: auto; }
button, .button { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 9px 18px; cursor: pointer; text-decoration: none; display: inline-block; }
button.primary, .button.primary { background: var(--green); color: #fff; border-color: var(--green); font-weight: 600; }
button.danger { color: var(--red); border-color: var(--red); background: transparent; }
button.small { padding: 5px 12px; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.linklike { background: none; border: none; color: var(--green); padding: 0; text-decoration: underline; cursor: pointer; border-radius: 0; }
.flash { padding: 10px 14px; border-radius: 8px; margin: 10px 0; }
.flash.ok { background: var(--green-light); }
.flash.err { background: #fbe9e7; color: #7a1b14; }
@media (prefers-color-scheme: dark) { .flash.err { background: #3a1f1c; color: #ffb4a9; } }

.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.plan .price { font-size: 2rem; font-weight: 700; margin: 4px 0; }
.plan .price span { font-size: 1rem; font-weight: 400; color: var(--muted); }

/* ---- Chat ---- */
body.chat-body main.wide { max-width: none; padding: 0; }
.chat { display: flex; flex-direction: column; height: calc(100dvh - 53px); max-width: 860px; margin: 0 auto; position: relative; }
.thread { flex: 1; overflow-y: auto; padding: 12px 16px 24px; }
.welcome { max-width: 640px; margin: 4vh auto 0; text-align: center; }
.examples { display: grid; gap: 8px; margin-top: 16px; }
.example { text-align: left; border-radius: var(--radius); background: var(--card); }
.msg { margin: 14px 0; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg .bubble { max-width: 92%; padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--green); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; width: 100%; max-width: 100%; }
.msg.assistant .bubble h3, .msg.assistant .bubble h4 { font-size: 1rem; margin: 0.8em 0 0.2em; }
.msg.assistant .bubble p { margin: 0.4em 0; }
.msg.assistant .bubble ul, .msg.assistant .bubble ol { margin: 0.3em 0; padding-left: 1.3em; }
.msg .bubble img.attached { max-width: 180px; border-radius: 8px; display: block; margin-bottom: 6px; }
.cite { font-size: 0.75em; vertical-align: super; color: var(--green); font-weight: 700; margin: 0 1px; }
.sources { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 0.85rem; color: var(--muted); }
.sources ol { margin: 4px 0 0; padding-left: 1.4em; }
.sources .web a { color: var(--muted); }
.msg-actions { display: flex; gap: 6px; margin-top: 6px; align-items: center; flex-wrap: wrap; }
.msg-actions button { padding: 3px 10px; font-size: 0.85rem; }
.msg-actions button.on { background: var(--green-light); border-color: var(--green); }
.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--green); }
@keyframes blink { 50% { opacity: 0; } }

.composer { border-top: 1px solid var(--line); background: var(--card); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
.composer-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.composer-tools .icon { font-size: 1.2rem; background: none; border: none; padding: 4px; cursor: pointer; display: inline-flex; }
.toggle { flex-direction: row; align-items: center; gap: 4px; font-weight: 400; font-size: 0.9rem; cursor: pointer; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; max-height: 40vh; min-height: 44px; border-radius: 22px; padding: 11px 16px; }
.send { width: 46px; height: 46px; padding: 0; flex: none; }
.disclaimer { font-size: 0.72rem; color: var(--muted); margin: 6px 0 0; text-align: center; }
.photo-preview { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.photo-preview img { height: 56px; border-radius: 6px; }
#mic.listening { color: var(--red); animation: blink 1s steps(1) infinite; }

.history { position: absolute; inset: 0 auto 0 0; width: min(320px, 88vw); background: var(--card); border-right: 1px solid var(--line); z-index: 4; overflow-y: auto; padding: 12px; box-shadow: 2px 0 12px rgba(0,0,0,.12); }
.history-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.history ul { list-style: none; margin: 0; padding: 0; }
.history li { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line); }
.history li a { flex: 1; padding: 10px 4px; text-decoration: none; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history li button { font-size: 0.8rem; }

/* ---- Admin ---- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 8px 0 12px; }
.tabs a { padding: 6px 12px; border-radius: 999px; text-decoration: none; border: 1px solid var(--line); background: var(--card); }
.tabs a.active { background: var(--green); color: #fff; border-color: var(--green); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; }
.stat b { font-size: 1.5rem; }
.stat.alert { border-color: var(--red); }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.urgent td { background: #fbe9e7; }
@media (prefers-color-scheme: dark) { tr.urgent td { background: #3a1f1c; } }
td.actions form { margin: 2px 0; }
.inline-form { display: flex; gap: 4px; align-items: center; }
.inline-form input, .inline-form select { padding: 4px 8px; font-size: 0.85rem; width: auto; min-width: 0; }
.tag { font-size: 0.72rem; border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; margin-left: 4px; }
.tag.red { color: var(--red); border-color: var(--red); }
.tag.green { color: var(--green); border-color: var(--green); }
.searchbar { display: flex; gap: 8px; margin-bottom: 10px; }
.transcript .msg .who { font-size: 0.8rem; color: var(--muted); }
.list li { margin: 6px 0; }
.report h2 { margin-top: 1em; }

.meter { height: 10px; background: var(--green-light); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.meter span { display: block; height: 100%; background: var(--green); }

/* Voice picker (Account page) */
.voice-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.voice-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.voice-list li:last-child { border-bottom: none; }
.voice-list li.chosen { background: var(--green-light); }
.voice-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.voice-name small { color: var(--muted); }

/* Login options */
p.small { font-size: 0.85rem; margin: 0; }
.button.google { display: flex; align-items: center; justify-content: center; gap: 10px; background: #fff; color: #1f1f1f; border: 1px solid #747775; font-weight: 600; text-decoration: none; }
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 12px; }
