:root {
  color-scheme: light dark;
  --bg: #f6f7f9; --panel: #ffffff; --line: #dfe3e8; --text: #1c2430; --muted: #6b7684;
  --accent: #2563eb; --accent-text: #ffffff; --user: #e8f0fe; --danger: #c62828; --ok: #1b7f3b; --warn: #b26a00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --panel: #1c2027; --line: #2e343d; --text: #e6e9ee; --muted: #98a2b0;
    --accent: #5b8def; --accent-text: #0e1116; --user: #25324a; --danger: #ef6b6b; --ok: #58c27d; --warn: #e0a84a;
  }
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
input, textarea { width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 9px 11px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
.hidden { display: none !important; }

/* вход и регистрация */
.auth { max-width: 380px; margin: 8vh auto; padding: 24px 16px; }
.auth h1 { font-size: 22px; margin: 0 0 16px; }
.auth label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.auth .actions { margin-top: 18px; display: flex; gap: 12px; align-items: center; }
.notice { margin-top: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; color: var(--muted); }

/* основная раскладка */
.layout { display: flex; height: 100%; }
.side { width: 270px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.side .top { padding: 12px; }
.side .top button { width: 100%; }
.chatlist { flex: 1; overflow-y: auto; padding: 0 6px; }
.chatitem { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.chatitem:hover { background: var(--bg); }
.chatitem.active { background: var(--user); }
.chatitem .title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatitem .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.side .bottom { padding: 12px; border-top: 1px solid var(--line); font-size: 13px; display: flex; flex-direction: column; gap: 8px; }
.side .bottom button.link { align-self: flex-start; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 12px; text-align: center; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.menu-button { display: none; }

/* чат */
.messages { flex: 1; overflow-y: auto; padding: 20px 16px; }
.messages .inner { max-width: 820px; margin: 0 auto; }
.msg { margin: 0 0 18px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--user); border-radius: 14px; padding: 9px 13px; max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.assistant .body { overflow-wrap: anywhere; }
.body p { margin: 0 0 10px; }
.body h3, .body h4 { margin: 14px 0 6px; font-size: 16px; }
.body ul, .body ol { margin: 0 0 10px; padding-left: 22px; }
.body pre { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; overflow-x: auto; font-size: 13px; }
.body code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.body pre code { border: 0; padding: 0; background: none; }
.body table { border-collapse: collapse; margin: 0 0 10px; display: block; overflow-x: auto; }
.body th, .body td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.live { white-space: pre-wrap; }
.tools { margin: 6px 0 8px; font-size: 13px; color: var(--muted); }
.tools summary { cursor: pointer; }
.tools li { overflow-wrap: anywhere; }
.status { color: var(--muted); font-size: 13px; margin: 4px 0; }
.meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.empty { color: var(--muted); text-align: center; margin-top: 18vh; }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 16px 14px; }
.composer .inner { max-width: 820px; margin: 0 auto; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 44px; max-height: 200px; }
.files { margin-bottom: 8px; font-size: 13px; }
.files summary { cursor: pointer; color: var(--muted); }
.files ul { margin: 6px 0 0; padding-left: 18px; }
.files li span { color: var(--muted); }

/* администратор */
.admin { flex: 1; overflow: auto; padding: 16px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.tabs button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.admin table { border-collapse: collapse; width: 100%; background: var(--panel); font-size: 14px; }
.admin th, .admin td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.admin th { color: var(--muted); font-weight: 500; white-space: nowrap; }
.admin td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.admin tr.clickable { cursor: pointer; }
.admin tr.clickable:hover td { background: var(--bg); }
.tablewrap { overflow-x: auto; }
.st { font-weight: 600; }
.st.pending { color: var(--warn); }
.st.active { color: var(--ok); }
.st.revoked, .st.rejected { color: var(--danger); }
.invite { margin: 0 0 14px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; font-size: 14px; overflow-wrap: anywhere; }
.rowbuttons { display: flex; gap: 6px; flex-wrap: wrap; }
.rowbuttons button { padding: 3px 8px; font-size: 13px; }
.transcript { max-width: 860px; }

@media (max-width: 760px) {
  .side { position: fixed; z-index: 5; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .15s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .menu-button { display: inline-block; margin: 8px 0 0 12px; align-self: flex-start; }
}
