:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e3e5e8;
  --text: #1d2129;
  --muted: #6b7280;
  --accent: #2f6fed;
  --accent-soft: #e8efff;
  --out: #dbe7ff;
  --in: #ffffff;
  --danger: #d93a3a;
  --warn-bg: #fff4e0;
  --warn-text: #8a5a00;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border); background: var(--panel);
  border-radius: 8px; padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: #c9ccd1; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.icon { border: none; background: none; font-size: 18px; padding: 4px 8px; }
input, select, textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
  background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1em; }

/* ---------- вход ---------- */
.auth { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; width: 100%; max-width: 380px; display: grid; gap: 14px;
}
.card h1 { margin: 0; font-size: 22px; }
.card p { margin: 0; }
.card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

/* ---------- основной экран ---------- */
.app {
  display: grid; grid-template-columns: 340px 1fr; height: 100vh; height: 100dvh;
  /* вырезы и закругления экрана телефона в режиме приложения */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.sidebar { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.me span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .actions { display: flex; align-items: center; flex: none; }
.topbar .actions button.icon { padding: 4px 6px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  background: var(--accent-soft); color: var(--accent);
}
.banner { margin: 10px 14px 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; }
.banner button { margin-top: 6px; }
.banner.info { background: var(--accent-soft); color: var(--text); }
.banner .row { gap: 10px; }
#push-menu { right: -70px; width: 290px; }
.folder-strip {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px 0;
}
.folder-strip button {
  flex: none; border: 1px solid var(--border); background: #fff; border-radius: 16px;
  padding: 4px 12px; font-size: 13px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.folder-strip button.tg::before { content: "✈"; font-size: 11px; color: #1b7bb3; }
.folder-strip button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.folder-strip button.active .badge { background: #fff; color: var(--accent); }
.folder-strip button.active.tg::before { color: #fff; }
.folder-strip button.bx::before { content: "Б24"; font-size: 10px; font-weight: 700; color: #1ea7d6; }
.folder-strip button.active.bx::before { color: #fff; }
.ok { color: #22a559; }
.howto { margin-bottom: 14px; background: var(--accent-soft); border-radius: 8px; padding: 10px 14px; }
.howto summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.howto .steps { margin: 10px 0 6px; }
code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.menu-wrap { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; min-width: 240px;
  background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(20, 24, 32, .12); display: grid; gap: 8px;
}
.popover-title { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.plain-list { margin: 0; padding-left: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 6px;
  border: 1px solid var(--border); border-radius: 14px; font-size: 13px; cursor: pointer; background: #fff;
}
.chip input { width: auto; margin: 0; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.small { font-size: 12px; max-width: 280px; }
#assign-menu { min-width: 280px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
  background: #1d2129; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}
.filters {padding: 10px 14px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: none; background: none; padding: 5px 10px; border-radius: 6px; color: var(--muted); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-list li {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 14px; cursor: pointer; border-bottom: 1px solid #f0f1f3;
}
.chat-list li:hover { background: #f8f9fb; }
.chat-list li.active { background: var(--accent-soft); }
.chat-list .avatar { width: 40px; height: 40px; }
.chat-list .body { min-width: 0; }
.chat-list .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .owner { font-size: 12px; color: var(--accent); }
.chat-list .side { display: grid; justify-items: end; gap: 4px; font-size: 12px; color: var(--muted); }
.badge { background: var(--accent); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.channel-tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #e7f4fb; color: #1b7bb3; }
.list-empty { padding: 24px 14px; color: var(--muted); text-align: center; }

/* ---------- переписка ---------- */
.conversation { min-width: 0; min-height: 0; display: flex; }
.empty { margin: auto; color: var(--muted); }
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.chat-title { display: grid; flex: 1; min-width: 160px; }
.chat-title strong { font-size: 16px; }
.chat-title .muted { font-size: 12px; }
.assign { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.assign select { width: auto; min-width: 160px; }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: #e9ebef; padding: 2px 10px; border-radius: 10px; margin: 8px 0; }
.msg { max-width: min(640px, 80%); padding: 8px 12px; border-radius: var(--radius); background: var(--in); border: 1px solid var(--border); word-wrap: break-word; }
.msg .text { white-space: pre-wrap; }
.msg.out { align-self: flex-end; background: var(--out); border-color: #c8d8fb; }
.msg .who { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.msg.out .who { color: #2553b8; }
.msg .time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.messages .loading { margin: auto; color: var(--muted); }

.composer { display: grid; grid-template-columns: 1fr auto; gap: 8px;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); }
.composer textarea { resize: none; }
.composer .hint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }

/* ---------- настройки ---------- */
dialog { border: none; border-radius: 14px; padding: 0; width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(20, 24, 32, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.dialog-body { padding: 18px 20px 22px; overflow-y: auto; }
.dialog-body h3 { margin: 0 0 8px; font-size: 15px; }
.steps { margin: 0 0 16px; padding-left: 20px; }
.steps li { margin-bottom: 4px; }
.stack { display: grid; gap: 10px; max-width: 420px; }
.stack label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.status-line { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #c2c6cc; }
.dot.on { background: #22a559; }
.dot.err { background: var(--danger); }
.qr-wrap { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.qr { width: 240px; height: 240px; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
.qr-wrap .steps { flex: 1; min-width: 240px; }
.code-hint { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; max-width: 560px; }
.row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.link {background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; }

table.users { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
table.users th, table.users td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 13px; }
table.users th { color: var(--muted); font-weight: 500; }
table.users td:last-child { text-align: right; white-space: nowrap; }
table.users td button { padding: 4px 8px; font-size: 12px; }
.inline-form { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; align-items: center; }
.inline-form h3, .inline-form .error { grid-column: 1 / -1; }
.check { display: flex; gap: 6px; align-items: center; }
.check input { width: auto; }

/* ---------- узкие экраны ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .conversation { display: none; }
  .back { display: inline-block; }
  .inline-form { grid-template-columns: 1fr; }
  .msg { max-width: 90%; }
  .chat-list { padding-bottom: env(safe-area-inset-bottom); }
  .chat-head { padding: 8px 10px; gap: 8px; }
  .chat-head .menu-wrap .popover { right: auto; left: 0; }
  #push-menu { right: -60px; width: min(290px, calc(100vw - 32px)); }
  /* на телефоне 16px в полях ввода — иначе iPhone приближает страницу при вводе */
  input, select, textarea { font-size: 16px; }
}
