:root {
  --bg: #F6F8FC; --card: #ffffff; --ink: #22263A; --muted: #5F6680; --line: #DCE4F0;
  --accent: #1F3A93; --accent-ink: #ffffff; --accent-soft: #EAF0FF;
  --me: #e9f6ef; --me-line: #bfe3cd; --mt: #ffffff; --ok: #1f7a4d; --err: #b3261e;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #141824; --card: #1C2232; --ink: #EEF0F7; --muted: #A2A8BD; --line: #313A52;
    --accent: #9DB5FF; --accent-ink: #141824; --accent-soft: #232C47; --me: #1f3329; --me-line: #2f5040; --mt: #22212a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: "Atkinson Hyperlegible", system-ui, sans-serif; font-size: 18px; line-height: 1.55; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; } h2 { font-size: 1.2rem; margin: 1.2rem 0 .6rem; } h3 { font-size: 1.05rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
code { font-size: .9em; background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-size: .85rem; }
.top nav { display: flex; align-items: center; gap: 14px; font-size: .9rem; flex-wrap: wrap; justify-content: flex-end; }
.who { color: var(--muted); }

.page { max-width: 900px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0 0 16px; }
.narrow { max-width: 440px; margin: 8vh auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.row { display: flex; gap: 8px; align-items: flex-end; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .95rem; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
textarea { resize: none; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-block; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.ghost { background: transparent; }
.small, button.small, .btn.small { font-size: .82rem; padding: 5px 10px; }
button:disabled { opacity: .5; cursor: default; }
.alert { padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); }
.alert.error { color: var(--err); } .alert.ok { color: var(--ok); }
.list { padding-left: 1.1rem; } .list li { margin: 4px 0; }
.inline { display: inline-block; margin: 0; }
details.inline > summary { list-style: none; } details.inline > summary::-webkit-details-marker { display: none; }
details.inline[open] form { margin-top: 6px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.off td { opacity: .5; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-start; }
.radios, .checks { display: flex; flex-wrap: wrap; gap: 10px 18px; }
label.radio, label.check { flex-direction: row; align-items: center; gap: 8px; }
label.radio input, label.check input { width: auto; }

/* chat */
body.chatbody { height: 100dvh; display: flex; flex-direction: column; }
main.chat { flex: 1; display: flex; flex-direction: column; max-width: 820px; width: 100%; margin: 0 auto; min-height: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 14px; font-size: .9rem; }
.toolbar select { width: auto; padding: 6px 10px; }
.switch { flex-direction: row; align-items: center; gap: 6px; }
.switch input { width: auto; }
.log { flex: 1; overflow-y: auto; padding: 8px 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.log.readonly { overflow: visible; padding: 0; }
.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.mt { align-self: flex-start; }
.bubble { padding: 10px 14px; border-radius: 16px; border: 1px solid var(--line); background: var(--mt); overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--me); border-color: var(--me-line); border-bottom-right-radius: 4px; }
.msg.mt .bubble { border-bottom-left-radius: 4px; }
.msg.reading .bubble { outline: 3px solid var(--accent); }
.bubble p { margin: .3em 0; } .bubble ul, .bubble ol { margin: .3em 0; padding-left: 1.3em; }
.bubble img.sent { display: block; max-width: 240px; max-height: 240px; border-radius: 10px; margin-bottom: 6px; }
.time { font-size: .75rem; color: var(--muted); margin-top: 4px; }
.actions { margin-top: 4px; }
.typing { color: var(--muted); font-style: italic; }
.composer { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--card); }
.composer textarea { min-height: 46px; max-height: 160px; }
.attach { display: grid; place-items: center; width: 46px; height: 46px; flex: none; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-size: 1.3rem; }
.send { width: 52px; height: 46px; flex: none; padding: 0; font-size: 1.2rem; }
.preview { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.preview img { height: 64px; border-radius: 8px; }
@media (max-width: 600px) {
  body { font-size: 17px; } .who { display: none; } .msg { max-width: 94%; }
  .page { padding: 12px; } .card { padding: 14px; border-radius: 12px; } .narrow { margin: 4vh auto; }
  h1 { font-size: 1.35rem; }
  .top { padding: 8px 12px; } .top nav { gap: 10px; }
  .grid { grid-template-columns: 1fr; }
  .row { flex-wrap: wrap; }
  .memlist li { flex-direction: column; gap: 6px; }
  table { font-size: .85rem; } th, td { padding: 6px 4px; }
  .actions-cell { min-width: 150px; }
  details.inline[open] form { flex-wrap: wrap; }
}
.memlist { list-style: none; padding: 0; margin: 0; }
.memlist li { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.memlist li:last-child { border-bottom: 0; }
