:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #e2e1dc;
  --accent: #c8102e;
  --accent-text: #ffffff;
  --user: #fdf1e7;
  --code: #f1f0ec;
  --active: #efeee9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a;
    --panel: #242422;
    --text: #ecebe6;
    --muted: #9a9993;
    --line: #3a3a37;
    --accent: #e0455f;
    --user: #3a2f28;
    --code: #2f2f2c;
    --active: #30302d;
  }
}
* { box-sizing: border-box; }
html, body { 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: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { border: none; background: none; padding: 0; color: var(--muted); text-decoration: underline; }
button:disabled { opacity: .5; cursor: default; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--accent); min-height: 1.5em; margin: 0; }

.login { display: flex; align-items: center; justify-content: center; height: 100%; padding: 16px; }
.login-box { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box p { margin: 0 0 8px; }
.login-box input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }

.app { display: flex; height: 100%; }
.sidebar { width: 280px; flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
.sidebar-head { padding: 12px; }
.sidebar-head button { width: 100%; }
.projects { flex: 1; overflow-y: auto; padding: 0 8px; }
.project { display: block; width: 100%; text-align: left; border: none; background: none; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.project:hover { background: var(--active); }
.project.active { background: var(--active); font-weight: 600; }
.project small { display: block; color: var(--muted); font-weight: normal; font-size: 12px; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.topbar h2 { margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.menu { display: none; padding: 4px 10px; }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.empty { margin: auto; text-align: center; max-width: 420px; }
/* flex: none — иначе сообщения сжимаются по высоте и наезжают друг на друга. */
.msg { max-width: 820px; width: 100%; margin: 0 auto; flex: none; }
.msg .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg .body { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; overflow-wrap: anywhere; }
.msg.user .body { background: var(--user); white-space: pre-wrap; }
.msg .status { font-size: 13px; color: var(--muted); margin-top: 6px; }
.msg .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.msg .warn { font-size: 13px; color: var(--accent); margin-top: 4px; }
.msg.error .body { border-color: var(--accent); color: var(--accent); }
.msg.error .body.partial { color: var(--text); border-style: dashed; margin-top: 4px; }
.msg .retry { margin-top: 8px; }
.empty .primary { margin-top: 14px; }
.notice { max-width: 820px; width: calc(100% - 40px); margin: 0 auto 6px; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--accent); color: var(--accent); font-size: 14px; }
.body p { margin: 0 0 .7em; }
.body p:last-child { margin-bottom: 0; }
.body h3, .body h4 { margin: .8em 0 .4em; }
.body ul, .body ol { margin: 0 0 .7em; padding-left: 1.4em; }
.body code { background: var(--code); border-radius: 4px; padding: 1px 5px; font: 13px/1.4 Consolas, Menlo, monospace; }
.body pre { background: var(--code); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 0 0 .7em; }
.body pre code { padding: 0; background: none; }
/* Таблица шире сообщения прокручивается, а числа в ячейках не рвутся. */
.body table { border-collapse: collapse; margin: 0 0 .7em; display: block; overflow-x: auto; max-width: 100%; }
.body th, .body td { border: 1px solid var(--line); padding: 4px 8px; text-align: left;
  white-space: nowrap; overflow-wrap: normal; }
.body th.right, .body td.right { text-align: right; }

.composer { display: flex; gap: 10px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 220px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }

.backdrop { display: none; }

@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 10; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s; }
  .backdrop { display: block; position: fixed; inset: 0; z-index: 9; background: rgba(0,0,0,.35); }
  .backdrop.hidden { display: none; }
  /* iOS увеличивает страницу при фокусе на поле со шрифтом меньше 16px. */
  .composer textarea { font-size: 16px; }
  .notice { width: calc(100% - 32px); }
  .sidebar.open { transform: none; box-shadow: 0 0 24px rgba(0,0,0,.25); }
  .menu { display: inline-block; }
  .messages, .composer { padding-left: 16px; padding-right: 16px; }
}
