:root {
  --bg: #ffffff; --panel: #f6f7f9; --border: #e2e5ea; --text: #1b1f24;
  --muted: #6b7280; --accent: #2d6cdf; --accent-soft: #eaf1fd;
  --user: #eef2f7; --error: #b42318; --error-bg: #fef3f2;
  --code-bg: #f2f4f7; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --panel: #1b1f26; --border: #2b313a; --text: #e6e9ee;
    --muted: #9aa3b0; --accent: #6ea0ff; --accent-soft: #1e2a3f;
    --user: #222833; --error: #ff9a90; --error-bg: #3a1f1d; --code-bg: #222833;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, textarea, select { font: inherit; color: inherit; }

/* вход */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg); }
.login-card button { width: 100%; margin-top: 18px; padding: 11px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; cursor: pointer; }
.err { margin-top: 12px; color: var(--error); font-size: 13px; min-height: 18px; }

/* приложение */
.layout { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--border); display: flex;
  flex-direction: column; min-width: 0; }
.side header { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.side header h2 { margin: 0; font-size: 15px; }
.side header .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.proj { display: flex; gap: 6px; padding: 12px 16px; }
.proj button { flex: 1; padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); cursor: pointer; font-size: 13px; }
.proj button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.newchat { margin: 0 16px 10px; padding: 9px; border: 1px dashed var(--border); border-radius: 8px;
  background: transparent; cursor: pointer; color: var(--muted); }
.chats { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.chats div { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.chats div:hover { background: var(--bg); }
.chats div.on { background: var(--accent-soft); color: var(--text); }
.side footer { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 12px;
  color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.side footer button { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }

.main { display: flex; flex-direction: column; min-width: 0; }
.feed { flex: 1; overflow-y: auto; padding: 24px; }
.feed-inner { max-width: 820px; margin: 0 auto; }
.msg { margin-bottom: 22px; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.msg.user .body { background: var(--user); border-radius: 10px; padding: 10px 14px; display: inline-block; }
.msg.error .body { background: var(--error-bg); color: var(--error); border-radius: 10px; padding: 10px 14px; }
.body p { margin: 0 0 10px; }
.body ul, .body ol { margin: 0 0 10px; padding-left: 22px; }
.body code { font-family: var(--mono); font-size: 13px; background: var(--code-bg);
  padding: 1px 5px; border-radius: 4px; }
.body pre { background: var(--code-bg); padding: 12px 14px; border-radius: 8px; overflow-x: auto; }
.body pre code { background: none; padding: 0; }
.body h2, .body h3 { font-size: 15px; margin: 16px 0 8px; }
.body table { border-collapse: collapse; margin-bottom: 10px; display: block; overflow-x: auto; }
.body td, .body th { border: 1px solid var(--border); padding: 5px 9px; font-size: 13px; }
a.fileref { color: var(--accent); text-decoration: none; border-bottom: 1px dashed var(--accent);
  font-family: var(--mono); font-size: 13px; cursor: pointer; }
.status { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.hint { color: var(--muted); font-size: 13px; }

.composer { border-top: 1px solid var(--border); padding: 14px 24px 18px; }
.composer .icon { padding: 12px 12px; background: var(--panel); color: var(--muted);
  border: 1px solid var(--border); }
.composer .icon:hover { color: var(--accent); border-color: var(--accent); }
.composer-inner { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; min-height: 46px; max-height: 180px; padding: 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--panel); }
.composer button { padding: 12px 18px; border: 0; border-radius: 10px; background: var(--accent);
  color: #fff; cursor: pointer; }
.composer button:disabled { opacity: .5; cursor: default; }
.quota { max-width: 820px; margin: 8px auto 0; font-size: 12px; color: var(--muted); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer;
  font-size: 12px; text-decoration: none; border-bottom: 1px dotted var(--accent); }

/* приложенные файлы */
.files { max-width: 820px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.uperr { max-width: 820px; margin: 0 auto; font-size: 12px; color: var(--error);
  overflow-wrap: anywhere; }
.uperr.ok { color: var(--accent); }
.saved { max-height: 70vh; overflow: auto; padding: 8px; }
.saved-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px;
  border-radius: 8px; cursor: pointer; font-size: 13px; }
.saved-row:hover { background: var(--panel); }
.saved-row span:first-child { font-family: var(--mono); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 320px; padding: 5px 9px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--panel); font-size: 12px;
  color: var(--text); text-decoration: none; overflow: hidden; white-space: nowrap; }
.chip:hover { border-color: var(--accent); }
.chip .chip-ic { color: var(--accent); }
.chip .chip-sz { color: var(--muted); }
.chip.pending { background: var(--accent-soft); }
.chip-x { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 15px;
  line-height: 1; padding: 0 0 0 2px; }
.chip-x:hover { color: var(--error); }
.acts { margin-top: 6px; opacity: 0; transition: opacity .12s; }
.msg:hover .acts { opacity: 1; }

/* перетаскивание файла */
.main { position: relative; }
.drop { position: absolute; inset: 12px; display: none; place-items: center; z-index: 5;
  border: 2px dashed var(--accent); border-radius: 12px; background: var(--accent-soft);
  color: var(--accent); font-size: 15px; pointer-events: none; }
.drop.on { display: grid; }

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: var(--text);
  max-width: min(900px, 92vw); width: 900px; padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog header { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-family: var(--mono); font-size: 13px; }
dialog header button { background: none; border: 0; cursor: pointer; font-size: 18px; }
dialog pre { margin: 0; max-height: 70vh; overflow: auto; padding: 14px 16px; font-size: 13px; }
dialog pre .ln { color: var(--muted); user-select: none; }
dialog pre mark { background: var(--accent-soft); color: inherit; }
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .side { display: none; }
}
