:root {
  --paper:      #e7ebe3;
  --paper-deep: #dbe1d5;
  --card:       #ffffff;
  --ink:        #1b2420;
  --muted:      #6c7a6e;
  --line:       #d3dacc;
  --berry:      #8c2f39;
  --berry-dark: #6f242c;
  --berry-tint: #f7e9e7;
  --gold:       #a8762a;
  --radius:     14px;
  --shadow:     0 1px 2px rgba(27,36,32,.06), 0 8px 24px -12px rgba(27,36,32,.25);
  --sans: "Golos Text", "Segoe UI", system-ui, sans-serif;
  --serif: "PT Serif", Georgia, serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button, input, textarea, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--berry);
  outline-offset: 2px;
}

/* ---------------------------------------------------- вход и регистрация */

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px 48px;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}

.mark {
  text-align: center;
  margin-bottom: 26px;
}
.mark b {
  display: block;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -.02em;
}
.mark span {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

label.field {
  display: block;
  margin-bottom: 14px;
}
label.field > span {
  display: block;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type=text], input[type=password], input[type=date], textarea {
  width: 100%;
  padding: 10px 12px;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 10px;
}
input:focus, textarea:focus { border-color: var(--berry); background: #fff; }
textarea { resize: vertical; min-height: 80px; font-family: var(--serif); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--berry);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease;
}
.btn:hover { background: var(--berry-dark); }
.btn.wide { width: 100%; }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn.ghost:hover { background: var(--paper-deep); }

.note {
  margin-top: 18px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

.alert {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--berry-tint);
  border: 1px solid #e6cfcc;
  color: var(--berry-dark);
  font-size: 14px;
}
.alert.ok { background: #e8f0e5; border-color: #c9dcc3; color: #35543a; }
.alert[hidden] { display: none; }

/* ------------------------------------------------------------ аватарки */

.ava {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--paper-deep);
  display: grid;
  place-items: center;
  font-weight: 600;
  color: var(--muted);
  overflow: hidden;
}
.ava.lg { width: 96px; height: 96px; font-size: 30px; }

/* ---------------------------------------------------------------- чат */

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 272px 1fr;
}

.side {
  background: var(--paper-deep);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-head {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.side-head b { font-size: 19px; font-weight: 600; letter-spacing: -.01em; }
.side-head span { display: block; font-size: 12px; color: var(--muted); }

.side-scroll { overflow-y: auto; padding: 14px 10px; flex: 1; min-height: 0; }

.side-title {
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 6px 8px 8px;
}

.member {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.member:hover { background: rgba(255,255,255,.7); }
.member .nm { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .dot {
  margin-left: auto;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--line);
}
.member.on .dot { background: #5c8a4e; border-color: #5c8a4e; }

/* дни рождения — витрина, ради которой в профиле есть дата */
.bdays { margin-top: 22px; }
.bday {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 8px;
  font-size: 14px;
}
.bday .when { margin-left: auto; font-size: 12px; color: var(--gold); white-space: nowrap; }
.bday.today { background: #fff6e6; border-radius: 8px; }
.bday.today .when { font-weight: 600; }

.side-foot {
  border-top: 1px solid var(--line);
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.side-foot .nm { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 9px;
  padding: 6px 9px;
  font-size: 13px;
  cursor: pointer;
}
.icon-btn:hover { background: #fff; }

/* --------------------------------------------------------- лента чата */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.topbar b { font-size: 16px; font-weight: 600; }
.topbar .sub { font-size: 12px; color: var(--muted); }
.burger { display: none; }

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px 8px;
  min-height: 0;
}
.feed-inner { max-width: 780px; margin: 0 auto; }

.day-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 22px 0 14px;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.day-sep::before, .day-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.msg { display: flex; gap: 12px; padding: 3px 0; }
.msg .slot { width: 40px; flex: none; }
.msg .body { min-width: 0; flex: 1; }
.msg .who {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}
.msg .who b { font-size: 14px; font-weight: 600; cursor: pointer; }
.msg .who time { font-size: 11px; color: var(--muted); }

.bubble {
  display: inline-block;
  max-width: 100%;
  padding: 9px 13px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px 12px 12px 12px;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--berry-tint); border-color: #ecd7d3; }
.msg.cont .bubble { border-radius: 12px; }

.del {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  opacity: 0;
  padding: 2px 4px;
}
.msg:hover .del { opacity: 1; }
.del:hover { color: var(--berry); }

.typing {
  height: 18px;
  padding: 0 20px 4px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.composer {
  border-top: 1px solid var(--line);
  background: var(--paper);
  padding: 12px 20px 16px;
}
.composer-inner {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  min-height: 46px;
  max-height: 180px;
  border-radius: 12px;
  background: #fff;
}

/* ------------------------------------------------------------- модалка */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(27,36,32,.45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
}
.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 420px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
  text-align: center;
}

/* фото как карточка из альбома — единственное украшение на сайте */
.frame {
  display: inline-block;
  padding: 8px 8px 22px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transform: rotate(-2deg);
  margin-bottom: 14px;
}
.frame .ava { border-radius: 2px; width: 150px; height: 150px; }

.sheet h2 { margin: 4px 0 2px; font-size: 22px; font-weight: 600; }
.sheet .role { font-size: 13px; color: var(--muted); }
.sheet .about {
  font-family: var(--serif);
  margin: 14px 0 0;
  text-align: left;
  color: #2c3a32;
}

.rows { margin-top: 18px; text-align: left; }
.rows div {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.rows dt, .rows .k { color: var(--muted); flex: none; width: 42%; }
.rows .v { overflow-wrap: anywhere; }

/* -------------------------------------------------------------- профиль */

.page {
  max-width: 620px;
  margin: 0 auto;
  padding: 28px 16px 64px;
}
.page h1 { font-size: 26px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 4px; }
.page .lede { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
}
.block h2 {
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 16px;
}

.photo-row { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }

.extra-row { display: flex; gap: 8px; margin-bottom: 8px; }
.extra-row input { flex: 1; }
.extra-row input.k { max-width: 38%; }
.extra-row button {
  flex: none;
  border: 1px solid var(--line);
  background: none;
  border-radius: 9px;
  width: 38px;
  cursor: pointer;
  color: var(--muted);
}
.extra-row button:hover { color: var(--berry); border-color: var(--berry); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------ мобильные */

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: fixed;
    inset: 0 auto 0 0;
    width: 84%;
    max-width: 300px;
    z-index: 30;
    transform: translateX(-102%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .side.open { transform: none; }
  .burger { display: inline-flex; }
  .feed { padding: 16px 12px 4px; }
  .composer { padding: 10px 12px 14px; }
  .bubble { font-size: 16px; }
}

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

/* ------------------------------------------------------------ вложения */

.composer-inner .clip {
  flex: none;
  height: 46px;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 0 12px;
  background: #fff;
}
.composer-inner .clip:hover { color: var(--berry); border-color: var(--berry); }

.attach-bar {
  max-width: 780px;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.attach-bar[hidden] { display: none; }
.attach-preview {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 8px;
  background: var(--paper-deep);
  display: grid;
  place-items: center;
  overflow: hidden;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
}
.attach-preview img, .attach-preview video { width: 100%; height: 100%; object-fit: cover; }
.attach-info { flex: 1; min-width: 0; }
.attach-info .nm { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-info .sz { font-size: 12px; color: var(--muted); }
.attach-info .bar {
  height: 4px;
  margin-top: 6px;
  background: var(--paper-deep);
  border-radius: 3px;
  overflow: hidden;
}
.attach-info .bar i { display: block; height: 100%; width: 0; background: var(--berry); transition: width .15s linear; }

.att { margin-top: 6px; }
.att img, .att video {
  display: block;
  max-width: min(360px, 100%);
  max-height: 420px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--paper-deep);
}
.att img { cursor: zoom-in; }
.att audio { width: min(360px, 100%); }

.file-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: var(--ink);
}
.file-card:hover { border-color: var(--berry); }
.file-card .ext {
  flex: none;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--berry);
  background: var(--berry-tint);
  border-radius: 6px;
  padding: 6px 7px;
  text-transform: uppercase;
}
.file-card .nm { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .sz { font-size: 12px; color: var(--muted); }

.dropping { outline: 2px dashed var(--berry); outline-offset: -12px; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(27,36,32,.85);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* --------------------------------------------------- требования к паролю */

.pw-hint {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 12px;
  color: var(--muted);
}
.pw-hint li::before {
  content: "○ ";
  color: var(--line);
}
.pw-hint li.ok {
  color: #4a7040;
  text-decoration: line-through;
  text-decoration-color: rgba(74,112,64,.4);
}
.pw-hint li.ok::before {
  content: "● ";
  color: #5c8a4e;
  text-decoration: none;
}

/* ------------------------------------------- комнаты, значки, навигация */

.member.active { background: #fff; box-shadow: inset 3px 0 0 var(--berry); }
.member .ava.tile {
  border-radius: 9px;
  font-size: 11px;
  letter-spacing: .04em;
  background: var(--ink);
  color: var(--paper);
}
.member .badge {
  margin-left: auto;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--berry);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}
.member .badge[hidden] { display: none; }
.member .badge + .dot { margin-left: 6px; }

.me-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  cursor: pointer;
  text-align: left;
}
.me-btn:hover { background: #fff; }
.me-btn .nm { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar #roomAva { display: flex; }
.topbar #roomProfile { margin-left: auto; }

/* профиль поверх чата, без ухода со страницы */
.panel {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}
.panel[hidden] { display: none; }
.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}
.panel-head b { font-size: 18px; font-weight: 600; }
.panel-head .icon-btn { margin-left: auto; }
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 60px;
}
.panel-body > * { max-width: 620px; margin-left: auto; margin-right: auto; }

/* -------------------------------------------- чаты, участники, права */

.side-title.with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.mini {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  cursor: pointer;
}
.mini:hover { background: #fff; border-color: var(--berry); color: var(--berry); }

.side-empty {
  margin: 0 8px 6px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.member .ava.tile.general { background: var(--ink); color: var(--paper); }
.member .ava.tile.group { background: var(--berry); color: #fff; font-size: 16px; }

.watch-mark {
  margin-left: auto;
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--gold);
  border: 1px solid rgba(168,118,42,.35);
  border-radius: 6px;
  padding: 1px 5px;
  white-space: nowrap;
}
.member.watch .nm { color: var(--muted); }

.topbar-text { min-width: 0; }
.topbar-text b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar #roomProfile, .topbar #roomMembers { margin-left: auto; }
.topbar #roomProfile + #roomMembers { margin-left: 8px; }

.observe-note {
  border-top: 1px solid var(--line);
  background: #fbf6ec;
  color: #6f5220;
  font-size: 13px;
  padding: 14px 20px;
  text-align: center;
}
.observe-note[hidden] { display: none; }

.empty-state {
  display: grid;
  place-items: center;
  padding: 40px 24px;
  text-align: center;
}
.empty-state[hidden] { display: none; }
.empty-state h2 { font-size: 22px; font-weight: 600; margin: 0 0 8px; }
.empty-state p { color: var(--muted); max-width: 420px; margin: 0 auto; }

.main[hidden] { display: none; }

/* выбор людей в чат */
.picker {
  margin: 12px 0 4px;
  max-height: 46vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: left;
}
.pick {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.pick:last-child { border-bottom: 0; }
.pick:hover { background: var(--paper); }
.pick input { width: 18px; height: 18px; accent-color: var(--berry); }
.pick .ava { width: 30px; height: 30px; font-size: 13px; }
.pick .nm { font-size: 14px; }

.actions.center { justify-content: center; margin-top: 18px; }
.btn.ghost.danger { color: var(--berry); border-color: #e3c9c6; }
.btn.ghost.danger:hover { background: var(--berry-tint); }

.sheet .lede { font-size: 13px; color: var(--muted); margin: 6px 0 0; }

.empty-state { grid-column: 2; }
@media (max-width: 760px) { .empty-state { grid-column: 1; } }

/* кнопка удаления — у каждого сообщения, а не только у первого в группе */

.msg .del {
  flex: none;
  align-self: center;
  width: 26px;
  height: 26px;
  line-height: 1;
  font-size: 18px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease;
}
.msg:hover .del, .msg .del:focus-visible { opacity: 1; }
.msg .del:hover { background: var(--berry-tint); color: var(--berry); }

/* на телефоне наведения нет — держим кнопку видимой, но негромкой */
@media (hover: none) {
  .msg .del { opacity: .45; }
}
