* { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #app { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: #fff;
  color: #1a1a1a;
  -webkit-tap-highlight-color: transparent;
}

.app { display: flex; height: 100%; }

/* ---------- Панель чатов ---------- */
.panel {
  width: 340px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 1px solid #e5e7eb;
}

.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
}

.panel-title { font-size: 20px; font-weight: 700; }

.icon-btn {
  border: 0;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #5b6472;
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: #eef1f5; }

.chats { flex: 1; overflow-y: auto; }

.chat {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f2f4f7;
}
.chat:hover { background: #f5f7fa; }
.chat.on { background: #e9f2ff; }
.chat.on:hover { background: #dfeaff; }

.avatar {
  position: relative;
  height: 48px;
  border-radius: 50%;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 17px;
}

.chat .dot {
  position: absolute;
  left: 47px; bottom: 7px;
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  background: #aab2bd;
  z-index: 1;
}
.dot.online { background: #34c759; }

.chat-body { flex: 1; min-width: 0; }

.row1 { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.row2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }

.cname {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px;
}

.ctime {
  flex: none;
  font-size: 12px;
  color: #8a94a3;
}

.csub {
  font-size: 13.5px;
  color: #6b7280;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.members {
  flex: none;
  font-size: 11px;
  color: #8a94a3;
  border: 1px solid #d7dce3;
  padding: 0 6px;
  border-radius: 20px;
  font-weight: 500;
}
.members.pin { color: #4f81ff; border-color: #b9d1ff; background: #eef4ff; }

.unread {
  flex: none;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  background: #4f81ff;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

.divider {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  color: #8a94a3;
  background: #f8fafc;
  border-bottom: 1px solid #f2f4f7;
}

/* ---------- Беседа ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #f7f9fc; }

.chat-empty {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  color: #9aa3af;
  font-size: 15px;
}

.chat-view { display: flex; flex-direction: column; height: 100%; }

.head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
}

.back-btn { display: none; }

.head-titles { flex: 1; min-width: 0; }
.head-title {
  font-weight: 650; font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 8px;
}
.head-status { font-size: 12.5px; color: #8a94a3; }

.head .avatar { width: 40px; height: 40px; font-size: 15px; }

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day {
  align-self: center;
  font-size: 12px;
  color: #8a94a3;
  background: #eef1f5;
  border-radius: 14px;
  padding: 3px 12px;
  margin: 8px 0;
}

.msg { max-width: 66%; display: flex; align-items: flex-end; gap: 8px; animation: pop .12s ease-out; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.theirs { align-self: flex-start; }

@keyframes pop { from { transform: translateY(4px); opacity: .55; } to { transform: none; opacity: 1; } }

.bubble {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 8px 12px 6px;
  max-width: 100%;
  box-shadow: 0 1px 1px rgba(16,24,40,.04);
}
.msg.mine .bubble { background: #d3ecff; border-color: #c0e1ff; }

.msg-name { font-size: 13px; font-weight: 600; margin-bottom: 2px; }

.msg-text { font-size: 14.5px; line-height: 1.35; word-wrap: break-word; }

.msg-ts {
  font-size: 11px;
  color: #8a94a3;
  text-align: right;
  margin-top: 2px;
}
.msg.mine .msg-ts { color: #5f8fc7; }

.photo { border-radius: 12px; overflow: hidden; max-width: 260px; cursor: pointer; }
.photo img { display: block; width: 100%; height: auto; }

/* ---------- Комposer ---------- */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
}

.composer textarea {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  padding: 9px 16px;
  font-size: 14.5px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.35;
}
.composer textarea:focus { border-color: #4f81ff; }

.send-btn {
  border: 0;
  background: #4f81ff;
  color: #fff;
  border-radius: 50%;
  width: 40px; height: 40px;
  font-size: 17px;
  cursor: pointer;
  flex: none;
}
.send-btn:hover { background: #3f6fff; }

/* ---------- Лайтбокс ---------- */
.lightbox[hidden] { display: none; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  cursor: zoom-out;
}
.lightbox img { max-width: 92%; max-height: 92%; border-radius: 8px; }

/* ---------- Мобильная версия ---------- */
@media (max-width: 767px) {
  .panel {
    width: 100%;
    min-width: 0;
    position: fixed;
    inset: 0;
    z-index: 10;
    border-right: 0;
  }
  .app.chat-open .panel { display: none; }
  .main { width: 100%; height: 100%; }
  .app:not(.chat-open) .main { display: none; }
  .app.chat-open .main { display: flex; }
  .back-btn { display: inline-flex; }
}

/* ---------- Онбординг / модалка / меню / тост ---------- */
.dimmed #main, .dimmed .panel { filter: blur(3px); pointer-events: none; }

.overlay, .onboard, .modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 24, 33, .38);
  z-index: 200;
}
.onboard, .modal { background: rgba(20, 24, 33, .45); }
.onboard[hidden], .modal[hidden], .toast[hidden], .menu[hidden] { display: none; }

.card {
  background: #fff;
  border-radius: 16px;
  padding: 22px 24px;
  width: 320px;
  max-width: 92vw;
  box-shadow: 0 18px 50px rgba(0,0,0,.18);
}
.card h2 { font-size: 19px; margin-bottom: 6px; }
.card .mnote {
  font-size: 13px;
  color: #8a94a3;
  text-align: left;
  margin: 4px 0 12px;
  background: #fff4e5;
  color: #b26a00;
  border-radius: 10px;
  padding: 9px 12px;
}
.card h3 { font-size: 16px; margin-bottom: 12px; }
.card .hint { font-size: 12.5px; color: #8a94a3; margin-bottom: 12px; line-height: 1.4; }
.card input, .card select {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 12px;
  outline: none;
}
.card input:focus, .card select:focus { border-color: #4f81ff; }

.colors { display: flex; gap: 10px; justify-content: center; margin-bottom: 14px; }
.col {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  padding: 0;
}
.col.on { border-color: #1a1a1a; }

.mrow { display: flex; gap: 10px; justify-content: flex-end; }
.mrow button {
  border: 0;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  background: #eef1f5;
  color: #1a1a1a;
}
.mrow button.primary, .card button.primary {
  background: #4f81ff;
  color: #fff;
}
.card button.primary { display: block; width: 100%; margin-top: 2px; }
.mrow button:hover, .card button.primary:hover { filter: brightness(.96); }

.menu {
  position: fixed;
  z-index: 150;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.12);
  min-width: 200px;
  padding: 6px;
}
.menu-item {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.menu-item:hover { background: #f2f4f7; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: #fff;
  font-size: 13.5px;
  border-radius: 20px;
  padding: 9px 18px;
  z-index: 300;
  opacity: 1;
  transition: opacity .3s;
}

.offline-banner {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: #f08c00;
  color: #fff;
  font-size: 13px;
  border-radius: 0 0 10px 10px;
  padding: 6px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.offline-banner[hidden] { display: none; }

/* ---------- Профиль ---------- */
.linky { cursor: pointer; }
.ava-wrap { display: inline-flex; }

.profile[hidden] { display: none; }
.profile {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 24, 33, .45);
  z-index: 210;
}
.profile .card { width: 380px; position: relative; text-align: center; padding: 26px 24px 20px; max-height: 88vh; overflow-y: auto; }

.fio { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.fio label { min-width: 0; }

.close {
  position: absolute;
  top: 10px; right: 12px;
  border: 0;
  background: #eef1f5;
  width: 30px; height: 30px;
  border-radius: 50%;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  color: #5b6472;
}
.close:hover { background: #e2e6ec; }

.ph { display: flex; justify-content: center; margin-bottom: 12px; }
.p-name { font-size: 19px; margin: 4px 0 2px; }
.nick { color: #8a94a3; font-weight: 500; font-size: 15px; margin-left: 6px; }

.p-online { font-size: 12.5px; color: #aab2bd; margin-bottom: 12px; }
.p-online.on { color: #2f9e44; }

.p-info { text-align: left; margin: 6px 0 16px; }
.p-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 2px;
  border-bottom: 1px solid #f2f4f7;
  font-size: 14px;
}
.p-row span { color: #8a94a3; }
.p-row b { font-weight: 600; }

.profile .card h3 { margin-bottom: 16px; }
.profile .card label {
  display: block;
  text-align: left;
  font-size: 12.5px;
  color: #6b7280;
  margin: 10px 0 2px;
}
.profile .card input { margin-bottom: 0; }
.profile .card .mrow { margin-top: 16px; }

.ghost {
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: #5b6472;
  margin-bottom: 6px;
}
.ghost:hover { background: #f5f7fa; }