:root {
  --bg: #f6f1ea; --card: #fffdf9; --ink: #2b2420; --muted: #8a7d72; --line: #e6dcd0;
  --mine: #d9ecdf; --theirs: #fff; --ai: #ece6f7; --accent: #b4553a; --err: #b3261e;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1715; --card: #24201d; --ink: #efe7df; --muted: #a39486; --line: #3a332e;
          --mine: #23402f; --theirs: #2c2724; --ai: #342c45; --accent: #e08a6c; --err: #ff8a80; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
.langs a { text-decoration: none; color: var(--muted); }
.langs a.on { color: var(--accent); font-weight: 600; }

/* landing / setup */
.landing { display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; }
.card h1 { margin: 0 0 4px; font-family: Georgia, "Times New Roman", serif; font-weight: 600; font-size: 34px; letter-spacing: .5px; }
.sub { margin: 0 0 20px; color: var(--muted); }
label { display: block; margin: 0 0 14px; font-size: 14px; color: var(--muted); }
input, textarea { width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { font: inherit; font-weight: 600; color: #fff; background: var(--accent); border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer; }
.card button { width: 100%; margin-top: 4px; }
.err { color: var(--err); font-size: 14px; }
.card .langs { margin: 18px 0 0; text-align: center; font-size: 14px; }

/* chat */
.chat { display: flex; flex-direction: column; height: 100dvh; }
.chat header { display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.chat header strong { font-family: Georgia, serif; font-size: 20px; font-weight: 600; flex: 1; }
.chat header .out { font-size: 14px; color: var(--muted); }
#log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(560px, 85%); padding: 8px 12px; border-radius: 14px; background: var(--theirs); border: 1px solid var(--line); cursor: default; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg.ai { background: var(--ai); }
.msg.hasorig { cursor: pointer; }
.who { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.orig { display: none; font-size: 13px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.showorig .orig { display: block; }
#send { display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
#send textarea { margin: 0; resize: none; min-height: 44px; }

/* history */
.tools { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.tools input, .tools select { margin: 0; width: auto; font-size: 15px; padding: 8px 10px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.tools form { display: flex; gap: 8px; flex: 1; min-width: 220px; }
.tools #q { flex: 1; min-width: 0; }
.note { margin: 0; padding: 4px 16px; font-size: 12px; color: var(--muted); }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px; margin: 6px 0; text-align: center; }
.gap { align-self: center; font-size: 12px; color: var(--err); text-align: center; }
.sys { align-self: center; font-size: 12px; color: var(--muted); text-align: center; max-width: 85%; }
.media img, .media video { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: 4px 0; }
.media audio { width: 240px; max-width: 100%; margin: 4px 0; }
.msg .tr { font-size: 12px; color: var(--muted); }
.history .msg.showorig .orig { display: block; }
.history .msg .orig { color: var(--ink); opacity: .75; }
.more { align-self: center; background: var(--card); color: var(--accent); border: 1px solid var(--line); font-size: 14px; }
.msg.hit { outline: 2px solid var(--accent); }
.chat header a:not(.out) { font-size: 14px; }
.ok { color: #2e7d32; font-size: 14px; }

#members { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 16px; background: var(--card); border-bottom: 1px solid var(--line); font-size: 12px; }
.mem { padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.mem::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--line); margin-right: 5px; vertical-align: 1px; }
.mem.up::before { background: #43a047; }
.mem.ai { background: var(--ai); }

.mem.typing { color: var(--accent); }
#typing { min-height: 18px; padding: 0 16px; font-size: 12px; color: var(--accent); font-style: italic; background: var(--bg); }
.checks { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; margin-top: 3px; }
.ck { font-size: 10px; line-height: 1.4; padding: 0 4px; border-radius: 6px; color: var(--muted); opacity: .55; }
.ck.on { color: #2e7d32; opacity: 1; font-weight: 600; }
@media (prefers-color-scheme: dark) { .ck.on { color: #81c784; } }

.maillink { margin-top: 16px; font-size: 14px; }
.maillink summary { cursor: pointer; color: var(--accent); }
.maillink form { margin-top: 10px; }

.transcript { font-size: 13px; color: var(--muted); white-space: pre-wrap; margin-top: 4px; border-left: 2px solid var(--line); padding-left: 8px; }
.notes #log { display: block; }
.notes h3.cat { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 18px 0 6px; }
.notes .docl { font-size: 15px; line-height: 1.9; }
.notes .size { font-size: 12px; color: var(--muted); }
.notes h2 { font-family: Georgia, serif; font-weight: 600; margin: 4px 0; }
.docbody .txt { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.docbody img { max-width: 100%; border-radius: 10px; margin: 8px 0; display: block; }

/* location cards in History */
a.loc { display: block; width: 280px; max-width: 100%; margin: 4px 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--card); color: inherit; text-decoration: none; }
a.loc img { display: block; width: 100%; height: auto; aspect-ratio: 2 / 1; object-fit: cover; }
a.loc .locmap { position: relative; width: 280px; height: 140px; overflow: hidden; background: #e6e6e1; }
a.loc .locmap img { position: absolute; width: 256px; height: 256px; max-width: none; aspect-ratio: auto; }
a.loc .locdrop { position: absolute; left: 126px; top: 36px; width: 24px; height: 24px; background: #db4437; border: 2px solid #fff; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); box-shadow: 0 1px 3px rgba(0,0,0,.4); }
a.loc .locdrop::after { content: ''; position: absolute; left: 7px; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: #fff; }
a.loc .locpin { font-size: 40px; text-align: center; padding: 18px 0; }
a.loc .loctitle { padding: 6px 10px 0; font-weight: 600; }
a.loc .locsub { padding: 0 10px 6px; font-size: 12px; color: var(--muted); }
.body a { color: inherit; text-decoration: underline; overflow-wrap: anywhere; }

/* WhatsApp group page */
.quote { font-size: 13px; border-left: 3px solid var(--accent); padding: 2px 8px; margin: 2px 0 4px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
