:root {
  --bg: #f4f5f2; --panel: #ffffff; --side: #eceee9; --text: #1d2420; --muted: #66706a; --line: #dde1db;
  --accent: #1f6f5c; --accent-text: #ffffff; --accent-soft: #e2efe9; --mine: #dcefe6; --warn: #fff4d6; --warn-text: #6b5300;
  --err: #b3261e; --code: #f0f2ee; --shadow: 0 1px 2px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816; --panel: #1b201d; --side: #171b19; --text: #e4e9e5; --muted: #98a39c; --line: #2b322e;
    --accent: #4fb495; --accent-text: #0d1512; --accent-soft: #1f3129; --mine: #22372e; --warn: #3a3218; --warn-text: #f1d98a;
    --err: #ff8a80; --code: #222925; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; } .err { color: var(--err); min-height: 1em; }
button { font: inherit; color: inherit; cursor: pointer; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; text-decoration: none; display: inline-block; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: calc(100% - 24px); margin: 0 12px 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon { border: none; background: transparent; font-size: 20px; padding: 6px 8px; border-radius: 8px; }
.icon:hover { background: var(--accent-soft); }

/* вход */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: 100%; max-width: 380px; text-align: center; box-shadow: var(--shadow); }
.logo { font-size: 34px; font-weight: 700; color: var(--accent); letter-spacing: .5px; }
.dev-users { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 14px; }
.dev-users button { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px; }

/* раскладка */
.app { display: grid; grid-template-columns: 300px minmax(0, 1fr); height: 100%; height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 14px 16px 10px; }
.brand { font-weight: 700; font-size: 20px; color: var(--accent); }
.net { font-size: 12px; vertical-align: middle; color: var(--muted); }
.net.on { color: #2e9d6a; } .net.off { color: var(--err); }
.me { color: var(--muted); font-size: 13px; }
.me-row { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.link { border: none; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
.login-msg { min-height: 1em; margin: 12px 0 0; font-size: 14px; }
.topics { display: flex; flex-direction: column; overflow-y: auto; padding: 0 8px; }
.side > .topics { flex: 1; min-height: 0; }
.topic { text-align: left; border: none; background: transparent; border-radius: 10px; padding: 9px 10px; display: flex; flex-direction: column; gap: 2px; }
.topic:hover { background: var(--accent-soft); }
.topic.active { background: var(--panel); box-shadow: var(--shadow); }
.topic .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic .s { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); display: inline-block; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.closed-box { padding: 4px 8px 12px; border-top: 1px solid var(--line); max-height: 40%; overflow-y: auto; }
.closed-box summary { padding: 8px 10px; color: var(--muted); cursor: pointer; font-size: 13px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.main-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.title-wrap { flex: 1; min-width: 0; }
.topic-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }
.banner { display: flex; align-items: center; gap: 10px; padding: 8px 16px; font-size: 14px; flex-wrap: wrap; }
.banner.warn { background: var(--warn); color: var(--warn-text); }
.banner.ok { background: var(--accent-soft); }

.feed { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 420px; }
.msg { max-width: min(820px, 100%); min-width: 0; width: fit-content; padding: 10px 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--mine); border-color: transparent; white-space: pre-wrap; }
.msg.system { align-self: center; background: transparent; border-style: dashed; color: var(--muted); font-size: 14px; }
.msg .time { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.msg.pending .time::after { content: " · ждёт"; }
.msg .files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.msg details.steps { margin-top: 6px; font-size: 12px; color: var(--muted); }
.msg details.steps summary { cursor: pointer; }
.msg details.steps li { margin: 2px 0; }

.md p { margin: 0 0 8px; } .md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { font-size: 16px; margin: 10px 0 6px; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 22px; }
.md code { overflow-wrap: anywhere; background: var(--code); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md pre { background: var(--code); padding: 10px; border-radius: 8px; overflow-x: auto; }
.md pre code { padding: 0; background: none; }
.md .tbl { max-width: 100%; overflow-x: auto; margin: 6px 0 8px; }
.md table { border-collapse: collapse; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--code); }
.md a { color: var(--accent); }

.live { align-self: flex-start; max-width: 820px; width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: 14px; padding: 10px 14px; }
.live-head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.live-head .grow { flex: 1; color: var(--muted); }
.live ol { margin: 6px 0 0; padding-left: 20px; font-size: 13px; color: var(--muted); }
.live ol li.last { color: var(--text); }
.live ol li .d { display: block; font-size: 12px; opacity: .8; overflow-wrap: anywhere; }
.live .draft { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--panel); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; font: inherit; color: var(--text); background: var(--bg); max-height: 40vh; }
.composer textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
#mic.rec { background: var(--err); color: #fff; }

@media (max-width: 800px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app .main { display: none; }
  .app.in-topic .side { display: none; }
  .app.in-topic .main { display: flex; }
  .back { display: inline-block; }
  .feed { padding: 12px; }
  .msg { max-width: 100%; }
  .btn.ghost#close-topic { padding: 6px 10px; font-size: 13px; }
}

/* внутри доски задач (вкладка «Чаты») — без своего «Выйти»; непрочитанные темы; коды задач — ссылки на карточки */
.embed #logout { display: none; }
.topic.unread .t { font-weight: 700; }
.topic.unread .t::before { content: "● "; color: var(--accent); }
.md a.task { color: var(--accent); font-weight: 600; text-decoration: none; border-bottom: 1px dashed currentColor; }
#mic { white-space: nowrap; }
#mic.rec { font-size: 14px; padding: 6px 10px; }
#mic.busy { opacity: .6; cursor: progress; }
/* внутри доски — светлая тема и цвета доски (синий акцент), чтобы вкладка «Чаты» не выглядела чужой */
body.embed { --accent: #2f6fdf; --accent-text: #ffffff; --accent-soft: #e8f0fd; --mine: #e8f0fd; --bg: #eef2f4; --side: #f6f8f9;
  --panel: #ffffff; --text: #1d2a33; --muted: #6b7a86; --line: #dfe5e9; --code: #f0f3f5; }
