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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f1115;
  color: #e8e8ec;
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- AUTH ---------- */
.auth-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #1b1f2b, #0f1115 60%);
}
.auth-card {
  width: 360px;
  background: #171a21;
  border: 1px solid #262a35;
  border-radius: 16px;
  padding: 28px;
}
.brand { font-size: 22px; font-weight: 700; text-align: center; }
.brand-sub { font-size: 12.5px; color: #9297a8; text-align: center; margin: 8px 0 20px; line-height: 1.4; }
.tabs { display: flex; gap: 6px; background: #10131a; border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tab-btn { flex: 1; padding: 8px; border: none; background: transparent; color: #9297a8; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.tab-btn.active { background: #6C5CE7; color: white; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input, .auth-form textarea { background: #10131a; border: 1px solid #262a35; color: #e8e8ec; padding: 11px 12px; border-radius: 10px; font-size: 14px; outline: none; }
.auth-form input:focus, .auth-form textarea:focus { border-color: #6C5CE7; }
.auth-form button[type="submit"] { background: #6C5CE7; color: white; border: none; padding: 11px; border-radius: 10px; cursor: pointer; font-weight: 600; margin-top: 4px; }
.auth-form button[type="submit"]:hover { background: #5b4bd6; }
.auth-error { color: #ff6b6b; font-size: 12.5px; min-height: 14px; }
.auth-hint { color: #6c7280; font-size: 11.5px; margin-top: 10px; line-height: 1.5; }

/* ---------- APP LAYOUT ---------- */
.app-screen { display: flex; height: 100vh; }
.sidebar { width: 280px; background: #14161c; border-right: 1px solid #22252e; display: flex; flex-direction: column; }
.me-panel { display: flex; align-items: center; gap: 10px; padding: 14px; border-bottom: 1px solid #22252e; }
.me-info { flex: 1; min-width: 0; }
.me-name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-username { font-size: 12px; color: #8b8f9c; }
.icon-btn { background: transparent; border: none; color: #c3c6d0; cursor: pointer; font-size: 15px; padding: 6px; border-radius: 8px; }
.icon-btn:hover { background: #22252e; }

.contacts-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: #6c7280; }
.new-chat-btn { background: #6C5CE7; color: white; border: none; padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 11.5px; font-weight: 600; text-transform: none; letter-spacing: normal; }
.new-chat-btn:hover { background: #5b4bd6; }
.contacts-list { flex: 1; overflow-y: auto; }
.contacts-empty { padding: 24px 18px; text-align: center; font-size: 12.5px; color: #6c7280; line-height: 1.6; }
.contact-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; }
.contact-item:hover { background: #1b1e26; }
.contact-item.active { background: #22263380; border-right: 3px solid #6C5CE7; }
.contact-name { font-size: 13.5px; font-weight: 500; }
.contact-sub { font-size: 11.5px; color: #7c8090; }

.avatar { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; position: relative; }
.avatar.small { width: 34px; height: 34px; font-size: 16px; }
.dot { position: absolute; bottom: -1px; right: -1px; width: 10px; height: 10px; border-radius: 50%; background: #3a3d47; border: 2px solid #14161c; }
.dot.online { background: #2ecc71; }

.chat-area { flex: 1; display: flex; flex-direction: column; background: #0f1115; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: #5c606c; font-size: 14px; }
.chat-window { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid #22252e; }
.chat-title { font-weight: 600; font-size: 14.5px; }
.chat-status { font-size: 11.5px; color: #7c8090; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.bubble { max-width: 62%; padding: 9px 13px; border-radius: 14px; font-size: 13.8px; line-height: 1.45; word-wrap: break-word; }
.msg-row:not(.mine) .bubble { background: #1e2129; border-bottom-left-radius: 4px; }
.msg-row.mine .bubble { background: #6C5CE7; color: white; border-bottom-right-radius: 4px; }
.bubble .meta { display: block; font-size: 10px; opacity: .6; margin-top: 4px; }
.bubble.broken { color: #ff8787; font-style: italic; }

.send-form { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid #22252e; }
.send-form input { flex: 1; background: #171a21; border: 1px solid #262a35; color: #e8e8ec; padding: 11px 14px; border-radius: 22px; outline: none; font-size: 14px; }
.send-form input:focus { border-color: #6C5CE7; }
.send-form button { background: #6C5CE7; color: white; border: none; width: 42px; border-radius: 50%; cursor: pointer; font-size: 15px; }

/* ---------- MODAL ---------- */
.modal { position: fixed; inset: 0; background: #000000b3; display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { width: 340px; background: #171a21; border: 1px solid #262a35; border-radius: 16px; padding: 22px; display: flex; flex-direction: column; gap: 8px; }
.modal-card h3 { margin-bottom: 8px; }
.modal-card label { font-size: 12px; color: #9297a8; margin-top: 6px; }
.modal-card input, .modal-card textarea { background: #10131a; border: 1px solid #262a35; color: #e8e8ec; padding: 9px 11px; border-radius: 8px; font-size: 13.5px; outline: none; resize: none; }
.modal-card input[type="color"] { padding: 2px; height: 36px; }
.search-results { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.search-result-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; cursor: pointer; }
.search-result-item:hover { background: #1e2129; }
.search-hint { font-size: 12px; color: #6c7280; padding: 6px 2px; }
.modal-actions { display: flex; gap: 10px; margin-top: 12px; }
.modal-actions button { flex: 1; padding: 10px; border-radius: 10px; border: none; cursor: pointer; font-weight: 600; }
#saveProfileBtn { background: #6C5CE7; color: white; }
.secondary { background: #262a35; color: #e8e8ec; }

.back-btn { display: none; font-size: 18px; }

/* ---------- MOBILE ---------- */
@media (max-width: 768px) {
  .auth-card { width: 90vw; max-width: 360px; }

  .app-screen { position: relative; overflow: hidden; }
  .sidebar { width: 100%; position: absolute; inset: 0; z-index: 2; transition: transform .2s ease; }
  .chat-area { width: 100%; position: absolute; inset: 0; z-index: 1; transform: translateX(100%); transition: transform .2s ease; }
  .app-screen.chat-open .sidebar { transform: translateX(-100%); }
  .app-screen.chat-open .chat-area { transform: translateX(0); }

  .back-btn { display: inline-block; }
  .bubble { max-width: 82%; }
  .modal-card { width: 88vw; max-width: 360px; }
  .send-form input { font-size: 16px; } /* iOS не зумит поле при 16px+ */
}
