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

body {
  font-family: system-ui, sans-serif;
  background: #f0f0f0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
}

#app {
  width: 100%;
  max-width: min(960px, 100%);
  min-height: 100vh;
  background: #fff;
  display: flex;
  flex-direction: column;
}

/* ── Экраны ── */
.screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Шапка ── */
.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #4a90d9;
  color: #fff;
}
.header h2 { flex: 1; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header button {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 1rem;
}
.header button:hover { background: rgba(255,255,255,0.2); }

/* ── Логин ── */
.login-screen {
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 32px;
}
.login-screen h1 { font-size: 1.6rem; margin-bottom: 8px; }
.login-screen input, .login-screen button {
  width: 100%;
  max-width: 320px;
}

/* ── Список чатов ── */
.chat-list { flex: 1; overflow-y: auto; }
.chat-row {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}
.chat-row:hover { background: #f7f7f7; }
.chat-row-top { display: flex; align-items: baseline; gap: 8px; }
.chat-name { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 0.78rem; color: #aaa; flex-shrink: 0; }
.chat-preview { font-size: 0.85rem; color: #888; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 24px 16px; color: #aaa; text-align: center; }

/* ── Чат ── */
.chat-screen { display: flex; flex-direction: column; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.message {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.message.has-img {
  width: fit-content;
  max-width: min(75%, 304px); /* 280px картинка + 24px padding */
}
.msg-text {
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}
.message.mine    { align-self: flex-end; background: #4a90d9; color: #fff; border-bottom-right-radius: 2px; }
.message.theirs  { align-self: flex-start; background: #e8e8e8; color: #111; border-bottom-left-radius: 2px; }
.msg-sender { font-size: 0.65rem; font-weight: 700; opacity: 0.7; letter-spacing: 0.02em; }
.msg-meta { font-size: 0.72rem; opacity: 0.65; align-self: flex-end; }

.input-row {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid #eee;
  align-items: flex-end;
}
.input-row textarea {
  flex: 1;
  resize: none;
  border-radius: 8px;
  border: 1px solid #ccc;
  padding: 8px 10px;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.4;
  max-height: 120px;
}
.hidden { display: none; }
.btn-clip {
  background: transparent;
  color: #666;
  border: 1px solid #ccc;
  padding: 8px 10px;
  font-size: 1rem;
}
.btn-clip:hover { background: #f0f0f0; color: #333; }

.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 6px;
  min-height: 0;
}
.file-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #e8f0fe;
  color: #3a7bc8;
  border-radius: 12px;
  padding: 2px 6px 2px 10px;
  font-size: 0.8rem;
  max-width: 220px;
}
.file-chip span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-chip-remove {
  flex-shrink: 0;
  background: transparent;
  color: #3a7bc8;
  border: none;
  padding: 0 2px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.file-chip-remove:hover { background: #c5d8f8; }

.msg-img {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  flex-shrink: 0;
  align-self: flex-start;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
}
.msg-file {
  display: inline-block;
  margin-top: 4px;
  color: inherit;
  text-decoration: underline;
  font-size: 0.9rem;
  word-break: break-all;
}

/* ── Лайтбокс ── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
}
.lightbox-img {
  max-width: calc(100vw - 120px);
  max-height: calc(100vh - 80px);
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
}
.lightbox-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  font-size: 2.5rem;
  line-height: 1;
  padding: 12px 18px;
  cursor: pointer;
  border-radius: 8px;
}
.lightbox-btn:hover { background: rgba(255,255,255,0.3); }
.lightbox-prev { left: 12px; }
.lightbox-next { right: 12px; }
.lightbox-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  font-size: 1.2rem;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 8px;
}
.lightbox-close:hover { background: rgba(255,255,255,0.3); }
.lightbox-counter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  pointer-events: none;
}

/* ── Общие элементы ── */
input, button, textarea {
  font-family: inherit;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid #ccc;
  padding: 8px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: #4a90d9; }
button {
  background: #4a90d9;
  color: #fff;
  border: none;
  cursor: pointer;
  padding: 8px 18px;
}
button:hover { background: #3a7bc8; }
.btn-danger { background: #d94a4a; }
.btn-danger:hover { background: #c03a3a; }
.btn-secondary { background: #888; }
.btn-secondary:hover { background: #666; }
.dialog hr { border: none; border-top: 1px solid #eee; margin: 4px 0; }
.btn-close {
  position: absolute;
  top: 12px; right: 12px;
  background: transparent;
  color: #666;
  border: none;
  font-size: 1.1rem;
  padding: 4px 8px;
}
.error { color: #d94a4a; font-size: 0.85rem; min-height: 1.2em; }

/* ── Диалог / оверлей ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}
.dialog {
  position: relative;
  background: #fff;
  border-radius: 12px;
  padding: 24px 20px 20px;
  width: 90%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dialog h3 { font-size: 1.1rem; }
.user-pick-list { display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; }
.user-pick-list label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.user-pick-list input[type=checkbox] { width: 16px; height: 16px; }

/* ── Админка ── */
.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.admin-section { display: flex; flex-direction: column; gap: 8px; }
.admin-section h4 { font-size: 0.85rem; color: #888; text-transform: uppercase; letter-spacing: 0.04em; }
.admin-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 0;
  user-select: none;
}
.admin-arrow { font-size: 0.75rem; color: #888; width: 12px; }
.admin-group-members { padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.admin-member-row { font-size: 0.88rem; color: #444; padding: 2px 0; }
