:root {
  --bg: #f5f6f8; --panel: #ffffff; --ink: #1d2433; --muted: #5d6677; --line: #dfe3ea;
  --accent: #1d2433; --accent-ink: #ffffff; --gold: #a07c26; --agent: #eef3ff; --mine: #1d2433; --mine-ink: #ffffff;
  --notice: #fff6dc; --danger: #b3261e; --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151d; --panel: #181e29; --ink: #e8ecf4; --muted: #9aa3b5; --line: #2a3242; --accent: #c9a24b; --accent-ink: #11151d;
    --gold: #c9a24b; --agent: #1f2840; --mine: #c9a24b; --mine-ink: #11151d; --notice: #3a3218; --danger: #ff8a80; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { overflow: hidden; }
#root { height: 100dvh; }
button { font: inherit; border: 0; border-radius: 999px; padding: .55em 1.1em; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
button.secondary { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
button.link { background: none; color: var(--gold); padding: .2em .4em; border-radius: 6px; }
button.link.danger { color: var(--danger); }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
input[type=text], textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .6em .8em; width: 100%; }
.loading { padding: 2rem; color: var(--muted); }
.fine { color: var(--muted); font-size: .85rem; }
.welcome { max-width: 32rem; margin: 10vh auto; padding: 0 16px; }
.welcome form { display: grid; gap: .8rem; margin: 1.5rem 0; }
.welcome label { display: grid; gap: .4rem; }

.layout { display: grid; grid-template-columns: 300px 1fr; height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); }
.sidebar .actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sidebar .actions button { font-size: .85rem; padding: .45em .9em; }
.threads { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.threads button { width: 100%; text-align: left; background: none; color: var(--ink); border-radius: 10px; display: grid; grid-template-columns: 1fr auto; gap: 0 8px; padding: .6em .8em; }
.threads li.current button { background: var(--bg); }
.threads .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads .kind { grid-column: 1; color: var(--muted); font-size: .8rem; }
.threads .badge { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.badge { background: var(--gold); color: #fff; border-radius: 999px; font-size: .75rem; padding: .1em .55em; margin-left: .4em; }

.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.main .back { display: none; }
.thread, .approvals, .empty { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.empty, .approvals { padding: 24px; overflow-y: auto; }
.thread > header { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.thread h2 { margin: 0; font-size: 1.15rem; }
.members { margin: .2em 0 0; color: var(--muted); font-size: .85rem; }
.modes { display: inline-flex; background: var(--bg); border-radius: 999px; padding: 3px; }
.modes button { background: none; color: var(--muted); padding: .35em .9em; font-size: .85rem; }
.modes button.on { background: var(--accent); color: var(--accent-ink); }
.tools { display: flex; flex-wrap: wrap; gap: 4px; }
.entries { list-style: none; margin: 0; padding: 16px 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.entry { max-width: min(42rem, 85%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .55em .8em; }
.entry.agent { background: var(--agent); }
.entry.mine { align-self: flex-end; background: var(--mine); color: var(--mine-ink); border-color: transparent; }
.entry.notice { align-self: center; background: var(--notice); font-size: .85rem; }
.entry .who { font-size: .78rem; font-weight: 600; display: flex; gap: .5em; align-items: center; margin-bottom: .2em; }
.entry .who time { font-weight: 400; opacity: .7; }
.tag { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--gold); }
.entry .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { display: flex; gap: 8px; padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { resize: none; }

.approvals ul { list-style: none; padding: 0; display: grid; gap: 12px; }
.approval { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.approval .who { font-weight: 600; display: flex; justify-content: space-between; }
.approval pre, .approval blockquote { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); padding: .6em .8em; border-radius: 8px; margin: .5em 0; font-size: .9rem; max-height: 20rem; overflow: auto; }
.approval pre.full { max-height: 60vh; resize: vertical; }
.approval .buttons, .dialog .buttons { display: flex; gap: 8px; margin-top: .6em; }
.approval.granted, .approval.denied { opacity: .7; }
.reason { color: var(--muted); }

.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.dialog { background: var(--panel); border-radius: 16px; padding: 20px; width: min(30rem, 100%); max-height: 90dvh; overflow-y: auto; display: grid; gap: 12px; }
.dialog header { display: flex; justify-content: space-between; align-items: center; }
.dialog h2 { margin: 0; font-size: 1.1rem; }
.dialog form { display: grid; gap: 12px; }
.dialog label { display: grid; gap: .4rem; }
.dialog fieldset { border: 1px solid var(--line); border-radius: 10px; display: grid; gap: .4rem; }
.dialog label.check { display: flex; gap: .5em; align-items: center; }
.qr { width: min(16rem, 100%); justify-self: center; image-rendering: pixelated; border-radius: 8px; }
.words { font-size: 1.1rem; font-weight: 600; line-height: 1.6; word-spacing: .3em; }
.error { position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; background: var(--danger); color: #fff; padding: .6em 1em; border-radius: 10px; max-width: calc(100% - 32px); z-index: 20; }
.error button { color: #fff; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .layout.open .sidebar { display: none; }
  .layout.home .main { display: none; }
  .main .back { display: block; align-self: flex-start; margin: 8px 12px 0; }
  .thread > header, .entries, .composer { padding-left: 16px; padding-right: 16px; }
  .entry { max-width: 92%; }
}
