:root {
  --bg: #f6f4ef; --surface: #fff; --ink: #1d2124; --muted: #5d656b; --line: #dcd8cf;
  --accent: #9a5b00; --accent-ink: #fff; --accent-soft: #f6e8d0; --user: #e9e5db; --danger: #a3271c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181a; --surface: #1e2225; --ink: #eceae4; --muted: #a2a9ae; --line: #33393d;
    --accent: #e0a040; --accent-ink: #1b1305; --accent-soft: #3a2c15; --user: #2a2f33; --danger: #f08a7e;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column; height: 100dvh; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.muted { color: var(--muted); }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand div { display: flex; flex-direction: column; line-height: 1.2; }
.brand span:not(.mark) { color: var(--muted); font-size: 13px; }
.mark { width: 26px; height: 32px; border: 3px solid var(--accent); border-radius: 5px; position: relative; }
.mark::before, .mark::after { content: ""; position: absolute; left: -3px; right: -3px; height: 3px; background: var(--accent); }
.mark::before { top: 7px; } .mark::after { bottom: 7px; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: none; border: 0; padding: 8px 12px; border-radius: 6px; color: var(--muted); min-height: 40px; }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }

.account { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
#lang { min-height: 34px; padding: 0 4px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }
.login .brand { position: relative; }
.login #lang { position: absolute; right: 0; top: 0; }

.login-page { align-items: center; justify-content: center; padding: 16px; }
.login { flex: none; display: block; width: 100%; max-width: 360px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.login h1 { font-size: 22px; margin: 20px 0 12px; }
.login label { display: block; margin: 12px 0 4px; font-weight: 600; font-size: 15px; }
.login input { width: 100%; min-height: 44px; padding: 0 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.login .send { width: 100%; margin-top: 16px; }
.login .error { margin: 12px 0 0; }
.login .muted { margin: 16px 0 0; font-size: 14px; }

main { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-width: 0; display: flex; flex-direction: column; width: 100%; max-width: 860px; margin: 0 auto; }
.view[hidden] { display: none; }
.banner { margin: 12px 16px 0; padding: 10px 12px; background: var(--accent-soft); border-radius: 8px; font-size: 15px; }

.log { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.intro { margin: auto 0; }
.intro h1 { font-size: 24px; line-height: 1.25; margin: 0 0 6px; }
.intro p { color: var(--muted); margin: 0 0 16px; }
.examples { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; }
.examples button {
  text-align: left; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.examples button:hover { border-color: var(--accent); }

.msg { max-width: 100%; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; max-width: 85%; background: var(--user); padding: 8px 12px; border-radius: 12px 12px 2px 12px; white-space: pre-wrap; }
.msg.user img { display: block; max-width: 220px; max-height: 220px; border-radius: 6px; margin-bottom: 6px; }
.msg.bot > :first-child { margin-top: 0; } .msg.bot > :last-child { margin-bottom: 0; }
.msg.bot h2, .msg.bot h3, .msg.bot h4 { font-size: 17px; margin: 16px 0 4px; }
.msg.bot p { margin: 8px 0; } .msg.bot ul, .msg.bot ol { margin: 8px 0; padding-left: 22px; }
.msg.bot li { margin: 4px 0; }
.msg.bot code { background: var(--user); padding: 1px 4px; border-radius: 4px; font-size: 0.92em; }
.msg.bot hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.table-wrap { overflow-x: auto; margin: 8px 0; }
.msg.bot table { border-collapse: collapse; font-size: 15px; }
.msg.bot th, .msg.bot td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.msg.bot th { background: var(--surface); }
.cite {
  border: 0; background: var(--accent-soft); color: inherit; padding: 0 6px; border-radius: 5px;
  font-size: 0.86em; white-space: nowrap; text-decoration: underline; text-underline-offset: 2px;
}
.steps { color: var(--muted); font-size: 14px; margin: 0 0 8px; padding: 0; list-style: none; }
.steps li::before { content: "› "; color: var(--accent); }
.error { color: var(--danger); }

.composer { padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.row { display: flex; gap: 8px; align-items: flex-end; }
textarea {
  flex: 1; min-width: 0; resize: none; max-height: 160px; padding: 9px 11px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px;
}
.icon-btn {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.icon-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.send { flex: none; min-height: 44px; padding: 0 16px; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; font-weight: 600; }
.send:disabled, textarea:disabled { opacity: 0.55; cursor: not-allowed; }
.foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; white-space: nowrap; }
.preview { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.preview[hidden] { display: none; }
.preview img { height: 56px; border-radius: 6px; }
.preview button { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 14px; }

.search { display: flex; gap: 8px; padding: 16px 16px 0; }
.search input { flex: 1; min-width: 0; min-height: 44px; padding: 0 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
#search-info { margin: 8px 16px; font-size: 14px; }
.results { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 0 16px 16px; }
.results button {
  display: block; width: 100%; text-align: left; margin-top: 8px; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px;
}
.results button:hover { border-color: var(--accent); }
.results b { display: block; } .results small { color: var(--muted); display: block; font-size: 13px; }
.results span { display: block; font-size: 15px; margin-top: 2px; overflow-wrap: anywhere; }

dialog { width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; padding: 0; border: 0; background: var(--bg); color: var(--ink); }
dialog[open] { display: flex; flex-direction: column; }
.viewer-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.viewer-bar div { display: flex; flex-wrap: wrap; gap: 6px; }
.viewer-bar button { min-height: 40px; padding: 0 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }
.viewer-body { flex: 1; min-height: 0; overflow: auto; text-align: center; padding: 8px; }
.viewer-body img { max-width: min(100%, 1100px); background: #fff; }

@media (max-width: 560px) {
  .foot span { display: none; } .foot { justify-content: flex-end; }
  .intro h1 { font-size: 21px; }
}
