/* ───────────────────────── основа ───────────────────────── */
:root {
  --font: "Inter", "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
  --radius: 12px;
  --accent: #3390ec;
  --accent-2: #64b3e5;
  --danger: #e05b5b;
  --green: #4dcd5e;
  --sidebar-w: 366px;
}

html[data-theme="dark"] {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #1d2836;
  --panel-3: #202b36;
  --hover: #202b36;
  --active: #2b5278;
  --border: #101a23;
  --text: #e9edf2;
  --text-dim: #9aa8b5;
  --muted: #708499;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --bubble-out-text: #ffffff;
  --pattern: rgba(255, 255, 255, .018);
  --shadow: 0 16px 40px rgba(0, 0, 0, .45);
  --input-bg: #242f3d;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f4f4f5;
  --panel-3: #e9edf0;
  --hover: #f1f4f7;
  --active: #3390ec;
  --border: #e3e7ea;
  --text: #17212b;
  --text-dim: #707579;
  --muted: #8b959e;
  --bubble-in: #ffffff;
  --bubble-out: #eeffde;
  --bubble-out-text: #17212b;
  --pattern: rgba(0, 0, 0, .022);
  --shadow: 0 16px 40px rgba(16, 35, 60, .16);
  --input-bg: #f1f4f7;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(140, 160, 180, .35); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(140, 160, 180, .6); }

.ico {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  flex: 0 0 auto;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(.94); }

/* ───────────────────────── вход ───────────────────────── */
.auth-screen {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  background: radial-gradient(900px 500px at 12% 18%, #1c3f5e 0%, transparent 60%),
              radial-gradient(700px 500px at 88% 88%, #22303f 0%, transparent 65%),
              #0d141d;
  overflow: auto;
}

.auth-brand {
  color: #fff;
  padding: 8vh 7vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
}

.auth-logo {
  width: 84px;
  height: 84px;
  border-radius: 26px;
  background: linear-gradient(150deg, #37aee2, #1e96c8);
  display: grid;
  place-items: center;
  box-shadow: 0 18px 44px rgba(30, 150, 200, .45);
  margin-bottom: 8px;
}
.auth-logo svg { width: 48px; height: 48px; fill: #fff; }

.auth-brand h1 {
  font-size: 40px;
  margin: 0;
  letter-spacing: -.6px;
}
.auth-brand > p {
  margin: 0;
  color: #a9bcca;
  font-size: 17px;
  line-height: 1.55;
  max-width: 420px;
}
.auth-features { margin-top: 26px; display: grid; gap: 12px; color: #c2d3df; font-size: 14px; }
.auth-features span { color: var(--accent); margin-right: 8px; }

.auth-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6vh 4vw;
}

.auth-card {
  width: 100%;
  max-width: 396px;
  background: var(--panel);
  color: var(--text);
  border-radius: 18px;
  padding: 26px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, .04);
}

.auth-tabs {
  display: flex;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 22px;
}
.auth-tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 0;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.auth-tab.active { background: var(--active); color: #fff; box-shadow: 0 4px 14px rgba(43, 82, 120, .5); }

.auth-form { display: grid; gap: 14px; }
.auth-form label { display: grid; gap: 6px; }
.auth-form label > span { font-size: 12.5px; color: var(--text-dim); font-weight: 600; letter-spacing: .2px; }
.auth-form input {
  border: 1.5px solid transparent;
  background: var(--input-bg);
  border-radius: 10px;
  padding: 12px 13px;
  outline: none;
  color: var(--text);
  transition: border-color .15s, background .15s;
  width: 100%;
}
.auth-form input::placeholder { color: var(--muted); }
.auth-form input:focus { border-color: var(--accent); }

.btn-primary {
  border: 0;
  border-radius: 10px;
  padding: 13px 18px;
  background: linear-gradient(180deg, #43a1f5, var(--accent));
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  margin-top: 4px;
  transition: filter .15s, transform .05s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.auth-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 0;
}
.auth-error:not(:empty) { min-height: 18px; }

.auth-note {
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

/* ───────────────────────── каркас ───────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ───────────────────────── сайдбар ───────────────────────── */
.sidebar {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
  position: relative;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 12px;
}

.search-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}
.search-ico {
  position: absolute;
  left: 10px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}
#search {
  width: 100%;
  border: 0;
  border-radius: 20px;
  background: var(--input-bg);
  padding: 9px 34px 9px 34px;
  outline: none;
  font-size: 14px;
}
#search::-webkit-search-cancel-button { display: none; }
#search::placeholder { color: var(--muted); }
.clear-search {
  position: absolute;
  right: 6px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.clear-search:hover { background: var(--hover); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 6px;
}

.chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 9px 12px;
  color: inherit;
  position: relative;
  transition: background .12s;
}
.chat-row:hover { background: var(--hover); }
.chat-row.active { background: var(--active); }
.chat-row.active .chat-title,
.chat-row.active .chat-preview,
.chat-row.active .chat-time { color: #fff; }
.chat-row.active .chat-preview { color: rgba(255, 255, 255, .78); }
.chat-row.active .badge { background: #fff; color: var(--active); }

.chat-row-body { flex: 1; min-width: 0; }
.chat-row-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.chat-title {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.chat-time { font-size: 11.5px; color: var(--muted); flex: 0 0 auto; }
.chat-row-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}
.chat-preview {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-preview .you { color: var(--muted); }
.chat-preview .draft { color: var(--accent); }
.chat-row.active .chat-preview .you { color: rgba(255, 255, 255, .68); }

.badge {
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--active);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  flex: 0 0 auto;
}
.badge.muted { background: #7b8fa4; }

.chat-empty {
  padding: 30px 20px;
  color: var(--muted);
  text-align: center;
  font-size: 13.5px;
  line-height: 1.6;
}

/* аватары */
.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 18px;
  flex: 0 0 auto;
  user-select: none;
  letter-spacing: .3px;
  overflow: hidden;
}
.avatar.sm { width: 42px; height: 42px; font-size: 15px; }
.avatar.lg { width: 76px; height: 76px; font-size: 26px; }
.avatar.tiny { width: 34px; height: 34px; font-size: 13px; }
.avatar svg { width: 46%; height: 46%; fill: #fff; }

/* результаты поиска */
.search-results {
  position: absolute;
  top: 60px;
  left: 8px;
  right: 8px;
  bottom: 64px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow-y: auto;
  z-index: 20;
  padding: 6px;
}
.section-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 10px 6px;
}
.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
}
.user-row:hover { background: var(--hover); }
.user-row .u-name { font-weight: 600; font-size: 14.5px; }
.user-row .u-sub { font-size: 12.5px; color: var(--muted); }

.me-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.me-info { flex: 1; min-width: 0; }
.me-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.me-username {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ───────────────────────── чат ───────────────────────── */
.chat-pane {
  position: relative;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 25% 25%, var(--pattern) 0 2px, transparent 2px),
    radial-gradient(circle at 75% 75%, var(--pattern) 0 2px, transparent 2px);
  background-size: 46px 46px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 30px;
  text-align: center;
}
.empty-badge {
  width: 92px;
  height: 92px;
  border-radius: 30px;
  background: var(--panel-2);
  display: grid;
  place-items: center;
  margin-bottom: 6px;
}
.empty-badge svg { width: 46px; height: 46px; fill: var(--text-dim); }
.empty-state h2 { margin: 0; font-size: 19px; font-weight: 600; }
.empty-state p { margin: 0; color: var(--muted); font-size: 14px; max-width: 340px; line-height: 1.6; }

.conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 5;
  flex: 0 0 auto;
}
.chat-head .avatar { width: 42px; height: 42px; font-size: 15px; }
.peer-info { flex: 1; min-width: 0; }
.peer-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.peer-status {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.peer-status.online { color: var(--accent); }
.peer-status.typing { color: var(--accent); }
.back-btn { display: none; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px clamp(12px, 5vw, 60px) 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.day-sep {
  align-self: center;
  background: rgba(20, 30, 42, .55);
  color: #dfe9f3;
  border-radius: 12px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  margin: 10px 0 8px;
}
html[data-theme="light"] .day-sep { background: rgba(255, 255, 255, .85); color: #5c7183; }

.msg {
  display: flex;
  max-width: min(72%, 660px);
  align-self: flex-start;
  animation: pop .16s ease-out;
}
.msg.out { align-self: flex-end; justify-content: flex-end; }
@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.bubble {
  position: relative;
  background: var(--bubble-in);
  color: var(--text);
  border-radius: 12px;
  padding: 7px 11px 7px 12px;
  font-size: 14.5px;
  line-height: 1.35;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .18);
  word-break: break-word;
}
.msg.out .bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
}
.msg.out .bubble { border-bottom-right-radius: 5px; }
.msg.in .bubble { border-bottom-left-radius: 5px; }

.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }

.msg-meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
  flex: 0 0 auto;
  transform: translateY(2px);
}
.msg.out .msg-meta { color: rgba(255, 255, 255, .68); }
html[data-theme="light"] .msg.out .msg-meta { color: #6f9b62; }
.msg.out .msg-meta .ticks.read { color: #fff; }
html[data-theme="light"] .msg.out .msg-meta .ticks.read { color: #3aa1f0; }
.ticks { font-size: 12px; letter-spacing: -2px; padding-right: 2px; }

.typing-row {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  background: var(--bubble-in);
  border-radius: 12px;
  padding: 11px 14px;
  margin-top: 4px;
}
.typing-row span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.3s infinite;
}
.typing-row span:nth-child(2) { animation-delay: .2s; }
.typing-row span:nth-child(3) { animation-delay: .4s; }
@keyframes blink {
  0%, 60%, 100% { opacity: .25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.composer {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px clamp(10px, 4vw, 46px) 14px;
  flex: 0 0 auto;
}
#input {
  flex: 1;
  resize: none;
  border: 0;
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  padding: 11px 14px;
  outline: none;
  max-height: 140px;
  line-height: 1.4;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
}
#input::placeholder { color: var(--muted); }

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  transition: filter .15s, transform .06s;
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn:active { transform: scale(.94); }
.send-btn svg { width: 24px; height: 24px; }

.emoji-panel {
  position: absolute;
  bottom: 68px;
  left: clamp(10px, 4vw, 46px);
  right: clamp(10px, 4vw, 46px);
  max-width: 320px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  z-index: 30;
}
.emoji-panel button {
  border: 0;
  background: transparent;
  font-size: 21px;
  line-height: 1;
  padding: 5px 0;
  border-radius: 8px;
}
.emoji-panel button:hover { background: var(--hover); }

/* ───────────────────────── модалка ───────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 12, 18, .62);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px 22px 22px;
  border: 1px solid var(--border);
}
.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal h3 { margin: 0; font-size: 17px; }
.modal .icon-btn { font-size: 24px; }
.profile-top { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.profile-name { font-weight: 600; font-size: 17px; }
.profile-username { color: var(--muted); font-size: 13.5px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--panel-3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  z-index: 200;
  animation: pop .18s ease-out;
}

/* ───────────────────────── адаптив ───────────────────────── */
@media (max-width: 860px) {
  .auth-screen { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-form-wrap { padding: 20px; }
  .auth-card { max-width: 440px; }

  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .chat-pane {
    position: fixed;
    inset: 0;
    z-index: 40;
    transform: translateX(100%);
    transition: transform .22s ease;
  }
  .app.chat-open .chat-pane { transform: none; }
  .back-btn { display: inline-flex; }
  .msg { max-width: 86%; }
  .messages { padding-inline: 10px; }
}

/* ------------------------- ãðóïïû ------------------------- */

.field { display: grid; gap: 6px; }
.field-label { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--input-bg);
  border-radius: 14px;
  padding: 5px 6px 5px 11px;
  font-size: 13px;
}
.chip button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  padding: 0 3px;
}
.chip button:hover { color: var(--danger); }

.member-input-row { display: flex; gap: 8px; margin-top: 8px; }
.member-input-row input { flex: 1; min-width: 0; }
.btn-ghost {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 0 14px;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  transition: background .15s;
}
.btn-ghost:hover { background: var(--hover); }
.hint { font-size: 12.5px; color: var(--muted); }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px;
  font-size: 14px;
}
.switch-row input { width: 20px; height: 20px; accent-color: var(--accent); }

.author {
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 2px;
  line-height: 1.2;
}

.avatar.group { border-radius: 16px; }
.msg.in .msg-body { min-width: 0; }
