:root {
  --bg: #f6f5f1; --card: #ffffff; --ink: #1d1d1b; --muted: #6b6a65; --line: #e3e1da;
  --accent: #2f5d50; --accent-ink: #ffffff; --mine: #e8f0ec; --err: #a4282a;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151614; --card: #1f201d; --ink: #ecebe6; --muted: #a09f98; --line: #34352f;
          --accent: #7fb8a4; --accent-ink: #10201a; --mine: #243029; --err: #ff8a80; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
[hidden] { display: none !important; }
button { font: inherit; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
button.link { background: none; color: var(--accent); padding: 4px; }
button.danger { background: none; color: var(--err); padding: 4px 8px; }
input, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; }
label { display: block; margin: 10px 0; }
code.code { font-size: 1.05em; user-select: all; word-break: break-all; }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 1.2em; margin: 6px 0; }
.topbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar nav { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.tab { background: none; color: var(--ink); }
.tab.active { background: var(--mine); }
main { padding: 16px; max-width: 1100px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.narrow { max-width: 440px; margin: 40px auto; }
.row { display: flex; gap: 8px; align-items: flex-start; }
.row > :first-child { flex: 1; }
.list { list-style: none; margin: 12px 0 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); padding: 10px 0; }
.chat { display: grid; grid-template-columns: 240px 1fr; gap: 16px; height: calc(100vh - 110px); }
.sidebar { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; overflow-y: auto; }
.sidebar .list > li { display: flex; align-items: center; gap: 4px; padding: 4px 0; }
.sidebar .conv { flex: 1; text-align: left; background: none; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .conv.active { background: var(--mine); }
.thread { display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.msg { white-space: pre-wrap; overflow-wrap: anywhere; padding: 10px 12px; border-radius: 10px; margin: 0 0 10px; max-width: 85%; }
.msg.user { background: var(--mine); margin-left: auto; }
.msg.assistant { border: 1px solid var(--line); }
.composer { display: flex; gap: 8px; margin-top: 10px; }
.composer textarea { flex: 1; }
.mem-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.mem-actions { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: 6px; font-size: .92em; }
.mem-actions label { display: inline-flex; gap: 4px; margin: 0; align-items: center; }
.mem-actions input[type=checkbox] { width: auto; }
.group { border-top: 1px solid var(--line); padding: 14px 0; }
.group h3 { margin: 0 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { background: var(--mine); border-radius: 999px; padding: 2px 4px 2px 10px; display: inline-flex; align-items: center; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 14px; }
.shot { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg); display: flex; flex-direction: column; }
.shot img { width: 100%; height: auto; display: block; aspect-ratio: auto; }
.shot .placeholder { aspect-ratio: 1 / 1; display: grid; place-items: center; color: var(--muted); padding: 12px; text-align: center; }
.shot .meta { padding: 8px 10px; font-size: .9em; }
.shot .meta p { margin: 0 0 6px; overflow-wrap: anywhere; }
.shot .actions { display: flex; gap: 10px; align-items: center; }
.image-controls { align-items: center; margin-top: 8px; }
.image-controls > :first-child { flex: 0 1 auto; }
label.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; }
select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }

@media (max-width: 720px) {
  .chat { grid-template-columns: 1fr; height: auto; }
  .sidebar { max-height: 160px; }
  .messages { min-height: 50vh; }
  .row { flex-direction: column; } .row > * { width: 100%; }
}
