/* Реестр договорённостей — оформление.
   Mobile-first: базовые правила рассчитаны на телефон, десктоп добавляется
   одним медиазапросом внизу. Внешних библиотек нет. */

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-muted: #fafaf9;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e6e5e1;
  --accent: #2f6f8f;
  --accent-dark: #255a75;
  --danger: #a33a3a;

  --draft-bg: #f3f2f0;
  --draft-fg: #6f6663;
  --voting-bg: #fdf4e3;
  --voting-fg: #8a5a12;
  --agreed-bg: #e6f4ea;
  --agreed-fg: #1d6b3a;
  --rejected-bg: #fbecec;
  --rejected-fg: #9c3b3b;

  --radius: 12px;
  --tap: 44px; /* минимальная тап-зона */
  --gap: 12px;
}

* { box-sizing: border-box; }

/* Браузерное правило [hidden] { display: none } слабее любого селектора с
   классом, а у нас скрываемые элементы почти всегда с классом (.badge, .btn,
   .toolbar). Без этой строки панель ведущего показалась бы и участнику. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, 'Leelawadee UI', 'Noto Sans Thai', Thonburi, sans-serif;
  padding: 0 0 48px;
}

/* Тайский набор требует воздуха по вертикали: тоновые знаки ставятся над и под
   строкой и при line-height 1.5 задевают соседние строки. */
html[lang='th'] body { line-height: 1.75; }

.page {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}
.page--narrow { max-width: 520px; }

a { color: var(--accent); }

.muted { color: var(--muted); font-size: 14px; }

/* ── Шапка ─────────────────────────────────────────────────────────────── */

.topbar { padding: 8px 0 16px; }
.topbar__title { margin: 0; font-size: 22px; line-height: 1.25; font-weight: 650; }
.topbar__subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.topbar--room { position: sticky; top: 0; background: var(--bg); z-index: 5; padding-top: 12px; }
.topbar__row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar__row--meta { margin-top: 6px; justify-content: space-between; font-size: 13px; }

/* ── Переключатель языков ──────────────────────────────────────────────── */

.lang { display: flex; gap: 4px; margin-left: auto; flex: 0 0 auto; }

.lang__btn {
  min-width: 44px;
  min-height: 44px;
  padding: 4px 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.lang__btn--active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.who { color: var(--muted); }
.who--clickable { cursor: pointer; text-decoration: underline dotted; }

/* Индикатор соединения */
.conn { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.conn__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); flex: 0 0 auto;
}
.conn[data-state='ok'] .conn__dot { background: #3f9e5f; }
.conn[data-state='cache'] .conn__dot { background: #c9a227; }
.conn[data-state='pending'] .conn__dot { background: #c9a227; }
.conn[data-state='offline'] .conn__dot { background: #b45454; }

/* ── Карточки и формы ──────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card__title { margin: 0 0 8px; font-size: 18px; font-weight: 640; }
.card__hint { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.card__hint--spaced { margin-top: 20px; margin-bottom: 0; }

.field { display: block; margin-bottom: 16px; font-size: 14px; color: var(--muted); }
.field--inline { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.field__hint { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }

.input {
  display: block;
  width: 100%;
  min-height: var(--tap);
  margin-top: 6px;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input--area { min-height: 72px; resize: vertical; line-height: 1.45; }
.input--mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.input--pin { letter-spacing: 0.3em; font-size: 20px; }
.input--search { margin-top: 0; }
.input--select { width: auto; min-width: 160px; margin-top: 0; }

.form-error, .dialog__error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fdeceb;
  color: var(--danger);
  font-size: 14px;
}

/* ── Кнопки ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 16px;
  font: inherit;
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:active { background: var(--accent-dark); }
.btn--ghost { background: var(--surface); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--wide { width: 100%; }
.btn--small { min-height: 36px; padding: 6px 12px; font-size: 14px; font-weight: 500; }
.btn--add { margin-top: 10px; }
.btn--busy { opacity: 0.7; }

.btn--link {
  min-height: 36px;
  padding: 6px 0;
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 500;
}
.btn--danger-link { color: var(--danger); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  font-size: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-muted); }

.row { display: flex; gap: var(--gap); flex-wrap: wrap; }

/* ── Ссылка на комнату ─────────────────────────────────────────────────── */

.linkbox { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

.notice {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.5;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}
.notice--warn { background: #fdf4e3; border-color: #f0e0bd; color: #6b4d12; }

.pin-reminder { margin: 16px 0; font-size: 15px; color: var(--muted); }
.pin-reminder__value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 20px;
  letter-spacing: 0.2em;
  color: var(--text);
}

.rooms { list-style: none; margin: 0; padding: 0; }
.rooms__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.rooms__link { font-weight: 550; text-decoration: none; }

/* ── Панель инструментов ───────────────────────────────────────────────── */

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.toolbar--admin { background: var(--surface-muted); }
.toolbar__row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* Поиск ужимается, чтобы переключатель языков встал с ним в одну строку
   даже на экране в 375 px. min-width: 0 обязателен: у флекс-элемента
   минимальная ширина по умолчанию равна собственной ширине поля ввода
   (около 200 px), и без сброса строка переносилась бы. */
.toolbar__row--search .input--search { flex: 1 1 160px; width: auto; min-width: 0; }
.toolbar__row:last-child { justify-content: space-between; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips--status { flex-wrap: wrap; overflow: visible; }

.chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.chip--active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip--status.chip--active { background: var(--text); border-color: var(--text); }

.counter { font-size: 14px; color: var(--muted); font-weight: 550; }

/* ── Разделы и пункты ──────────────────────────────────────────────────── */

.content { display: flex; flex-direction: column; gap: 16px; }

.empty, .section__empty {
  margin: 0;
  padding: 16px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.section--deleted { opacity: 0.6; }
.section__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.section__title { flex: 1 1 100%; margin: 0; font-size: 17px; font-weight: 640; }
.section__tools { display: flex; gap: 4px; }

.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.item {
  padding: 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 10px;
}
.item--draft { border-left-color: var(--draft-fg); }
.item--voting { border-left-color: var(--voting-fg); }
.item--agreed { border-left-color: var(--agreed-fg); }
.item--rejected { border-left-color: var(--rejected-fg); }
.item--deleted { opacity: 0.55; }
/* Согласованный пункт — единственное, что в этой комнате нельзя переписать.
   Пусть это будет видно и глазом, а не только по отсутствию кнопок. */
.item--agreed { background: var(--surface); border-left-width: 4px; }
.item__frozen { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.item__admin-row--wide { flex-wrap: wrap; }

.item__head { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.item__text { margin: 0 0 8px; line-height: 1.5; overflow-wrap: anywhere; }
.item__meta, .item__status-meta { font-size: 13px; color: var(--muted); }
.item__status-meta { margin-top: 4px; }
.item__actions { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 4px; }
/* Второстепенные действия помельче — иначе на 375 px они не встают в строку */
.item__actions .btn--link { font-size: 14px; }
.item__admin { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.item__admin-row { display: flex; gap: 6px; margin-top: 8px; }
.item-editor { margin-bottom: 8px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
}
.badge--draft { background: var(--draft-bg); color: var(--draft-fg); }
.badge--voting { background: var(--voting-bg); color: var(--voting-fg); }
.badge--agreed { background: var(--agreed-bg); color: var(--agreed-fg); }
.badge--rejected { background: var(--rejected-bg); color: var(--rejected-fg); }
.badge--edition { background: #eef3f7; color: var(--accent-dark); }
.badge--deleted, .badge--locked { background: #f3f0ef; color: var(--muted); }

/* ── Голосование ───────────────────────────────────────────────────────── */

.poll {
  margin: 10px 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--voting-fg);
  border-radius: 10px;
}
.poll__head { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.poll__roster { list-style: none; margin: 0 0 8px; padding: 0; display: flex;
  flex-direction: column; gap: 4px; }
.poll__voter { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  font-size: 14px; }
.poll__name { font-weight: 600; }
.poll__choice { font-size: 13px; padding: 2px 8px; border-radius: 999px; }
.poll__choice--for { background: var(--agreed-bg); color: var(--agreed-fg); }
.poll__choice--against { background: var(--rejected-bg); color: var(--rejected-fg); }
.poll__choice--pending { background: var(--draft-bg); color: var(--muted); }
.poll__tally, .poll__waiting { font-size: 13px; color: var(--muted); }
.poll__waiting { margin: 4px 0 0; }
.poll__actions { display: flex; gap: 8px; margin-top: 10px; }
.poll__actions .btn { flex: 1 1 auto; }
.poll__mine { margin: 10px 0 0; font-size: 14px; font-weight: 600; }

/* Принятое решение — под пунктом, коротко */
.decision {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
}
.decision--agreed { background: var(--agreed-bg); color: var(--agreed-fg); }
.decision--rejected { background: var(--rejected-bg); color: var(--rejected-fg); }
.decision__voices { margin-top: 4px; opacity: 0.85; }

/* ── Предыдущие редакции ───────────────────────────────────────────────── */

.editions { list-style: none; margin: 10px 0 0; padding: 0; display: flex;
  flex-direction: column; gap: 10px; }
.edition {
  padding: 10px 12px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
}
.edition__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.edition__text { margin: 0; line-height: 1.45; overflow-wrap: anywhere;
  text-decoration: line-through; text-decoration-color: var(--border); }

/* ── Отметки времени ───────────────────────────────────────────────────── */

.ts { cursor: pointer; border-bottom: 1px dotted var(--border); }
.ts--expanded { border-bottom-style: solid; }
.ts__rel { color: var(--muted); }

/* ── Комментарии ───────────────────────────────────────────────────────── */

.comments-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.comments { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.comment {
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.comment--mine { background: #f2f7fa; }
.comment--empty, .comment--removed { background: none; border: none; padding: 0; color: var(--muted); font-size: 14px; }
.comment__head { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.comment__author { color: var(--text); font-weight: 600; margin-right: 6px; }
.comment__text { margin: 0; line-height: 1.45; overflow-wrap: anywhere; }
.comment__tools { display: flex; gap: 16px; margin-top: 4px; }

.comment-form { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.comment-form .btn { align-self: flex-end; }
.comment-editor { display: flex; flex-direction: column; gap: 8px; margin: 4px 0; }

/* ── Общий чат ─────────────────────────────────────────────────────────── */

.chat {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.chat__hint { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.chat__list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 2px;
}
.chat__empty { text-align: center; padding: 12px 0; }
.chat__msg {
  padding: 8px 12px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.chat__msg--mine { background: #f2f7fa; }
.chat__msg--removed { background: none; border: none; padding: 2px 0; font-size: 14px; }
.chat__head { font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.chat__author { color: var(--text); font-weight: 600; margin-right: 6px; }
.chat__text { margin: 0; line-height: 1.45; overflow-wrap: anywhere; }
.chat__tools { display: flex; gap: 16px; margin-top: 2px; flex-wrap: wrap; }
.chat__form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; align-items: flex-start; }
.chat__form .btn { align-self: flex-end; }
.chat-editor { display: flex; flex-direction: column; gap: 8px; margin: 4px 0; }

/* ── История изменений ─────────────────────────────────────────────────── */

.history {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.history__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.history__row { padding-left: 10px; border-left: 2px solid var(--border); }
.history__head { font-size: 13px; color: var(--muted); }
.history__title { margin: 12px 0 8px; font-size: 14px; font-weight: 640; }
.history__voices { margin-top: 4px; font-size: 13px; color: var(--muted); }
.history__diff { margin-top: 4px; font-size: 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.history__before { color: var(--muted); text-decoration: line-through; }
.history__after { color: var(--text); }
.history__arrow { color: var(--muted); }

/* ── Диалоги ───────────────────────────────────────────────────────────── */

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
.dialog::backdrop { background: rgba(20, 22, 25, 0.35); }
.dialog__form { padding: 20px; }
.dialog__title { margin: 0 0 8px; font-size: 18px; }
.dialog__text { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.dialog__actions { display: flex; gap: var(--gap); margin-top: 20px; }
.dialog__actions .btn { flex: 1; }

.members { list-style: none; margin: 0; padding: 0; }
.members__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

/* ── Всплывающие сообщения ─────────────────────────────────────────────── */

.toasts {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  z-index: 50;
  pointer-events: none;
}
.toast {
  padding: 12px 14px;
  border-radius: 10px;
  background: #23282d;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  opacity: 1;
  transition: opacity 0.25s ease;
}
.toast--success { background: #1d6b3a; }
.toast--error { background: #8f3030; }
.toast--leaving { opacity: 0; }

/* ── Подвал ────────────────────────────────────────────────────────────── */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 16px 0 0;
}
.footer--room { padding: 24px 16px 0; max-width: 900px; margin: 0 auto; }

/* ── Десктоп ───────────────────────────────────────────────────────────── */

@media (min-width: 720px) {
  .page { padding: 24px; }
  .topbar__title { font-size: 26px; }
  .linkbox { flex-direction: row; align-items: center; }
  .linkbox .btn { flex: 0 0 auto; }
  .toolbar { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .toolbar .input--search { max-width: 260px; }
  .section__title { flex: 1 1 auto; }
  .toolbar__row:last-child { margin-left: auto; justify-content: flex-end; gap: 16px; }
  .comment-form { flex-direction: row; align-items: flex-start; }
  .comment-form .input--area { flex: 1; }
  .comment-form .btn { align-self: center; }
  .chat__form { flex-direction: row; align-items: flex-start; }
  .chat__form .input--area { flex: 1; }
  .chat__form .btn { align-self: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
