* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; height: 100dvh; overflow: hidden; }
body { font-family: system-ui, sans-serif; background: #e5ddd5; }
.hidden { display: none !important; }
.mobile-only { display: none; }

/* Экран входа */
.screen { display: flex; align-items: center; justify-content: center; height: 100%; }
.auth-box { background: #fff; padding: 32px; border-radius: 12px; width: 340px; max-width: 90%; box-shadow: 0 4px 20px rgba(0,0,0,.15); }
.auth-box h1 { text-align: center; margin-bottom: 20px; color: #128c7e; }
.tabs { display: flex; margin-bottom: 16px; gap: 4px; }
.tab { flex: 1; padding: 8px; border: none; background: #eee; cursor: pointer; border-radius: 6px; }
.tab.active { background: #128c7e; color: #fff; }
#authForm { display: flex; flex-direction: column; gap: 10px; }
#authForm input { padding: 10px 12px; border: 1px solid #ccc; border-radius: 6px; font-size: 16px; }
#authForm button { padding: 10px; border: none; background: #128c7e; color: #fff; border-radius: 6px; cursor: pointer; font-size: 16px; }
.error { color: #c00; font-size: 13px; margin-top: 10px; min-height: 18px; }

/* Основное приложение */
#appScreen { display: flex; height: 100%; width: 100%; align-items: stretch; }
#sidebar { width: 320px; background: #fff; border-right: 1px solid #ddd; display: flex; flex-direction: column; flex-shrink: 0; }
#meBar { padding: 12px; background: #128c7e; color: #fff; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
#meBar button { background: transparent; border: none; color: #fff; font-size: 18px; cursor: pointer; }
#searchWrap { padding: 8px; border-bottom: 1px solid #eee; position: relative; flex-shrink: 0; }
#searchInput { width: 100%; padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 16px; }
#searchResults { position: absolute; top: 100%; left: 8px; right: 8px; background: #fff; border: 1px solid #ddd; border-radius: 6px; max-height: 300px; overflow-y: auto; z-index: 10; }
#searchResults:empty { display: none; }
.search-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #f0f0f0; }
.search-item:hover { background: #f5f5f5; }
.search-item small { color: #888; }

#chatList { flex: 1; overflow-y: auto; min-height: 0; }
.chat-item { padding: 12px; border-bottom: 1px solid #f0f0f0; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.chat-item:hover { background: #f9f9f9; }
.chat-item.active { background: #e8f5e9; }
.chat-item .info { flex: 1; min-width: 0; }
.chat-item .name { font-weight: 600; margin-bottom: 2px; }
.chat-item .preview { font-size: 12px; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge { background: #128c7e; color: #fff; font-size: 11px; font-weight: bold; padding: 2px 6px; border-radius: 10px; margin-left: 8px; }

#chatPane { flex: 1; display: flex; flex-direction: column; background: #e5ddd5; min-width: 0; min-height: 0; overflow: hidden; }
#chatHeader { padding: 12px 16px; background: #f0f0f0; border-bottom: 1px solid #ddd; font-weight: 600; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
#backBtn { background: transparent; border: none; font-size: 22px; cursor: pointer; padding: 0 10px 0 0; color: #333; line-height: 1; }

#messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.date-divider { text-align: center; font-size: 12px; color: #666; margin: 12px 0 8px; background: rgba(255,255,255,0.7); padding: 4px 12px; border-radius: 10px; align-self: center; }

.msg { max-width: 70%; padding: 8px 12px; border-radius: 10px; background: #fff; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.msg.me { background: #dcf8c6; align-self: flex-end; }
.msg .sender { font-size: 11px; color: #128c7e; font-weight: 600; margin-bottom: 2px; }
.msg .time { font-size: 10px; color: #999; float: right; margin-left: 8px; margin-top: 4px; }

.msg-img { max-width: 100%; max-height: 300px; border-radius: 8px; cursor: pointer; display: block; margin-top: 4px; object-fit: cover; }

/* Плеер для голосовых */
.msg audio { max-width: 100%; height: 40px; outline: none; margin-top: 4px; border-radius: 20px; }

#composer { display: flex; padding: 8px; gap: 8px; background: #f0f0f0; align-items: center; flex-shrink: 0; }
#msgInput { flex: 1; padding: 10px 14px; border: none; border-radius: 20px; outline: none; font-size: 16px; min-width: 0; }
#composer button { padding: 0 20px; border: none; border-radius: 20px; background: #128c7e; color: #fff; cursor: pointer; font-size: 18px; flex-shrink: 0; }

#attachBtn, #recordBtn { background: transparent !important; color: #555 !important; font-size: 24px !important; padding: 0 4px !important; box-shadow: none !important; line-height: 1; cursor: pointer; }
#attachBtn:hover, #recordBtn:hover { color: #128c7e !important; }

/* Анимация записи */
#recordBtn.recording {
  color: #c00 !important;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.4; }
  100% { opacity: 1; }
}

#emptyHint { flex: 1; display: flex; align-items: center; justify-content: center; color: #888; font-size: 14px; }

@media (max-width: 768px) {
  .mobile-only { display: block; }
  #sidebar { width: 100%; border-right: none; }
  #chatPane { display: none; width: 100%; }
  #appScreen.chat-open #sidebar { display: none; }
  #appScreen.chat-open #chatPane { display: flex; }
  .msg { max-width: 85%; }
}