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

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

#app {
  height: 100vh;
  max-width: 600px;
  margin: 0 auto;
  background: white;
  position: relative;
}

.screen {
  display: none;
  height: 100vh;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* === ЭКРАНЫ ВХОДА === */

.login-box {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 30px;
  text-align: center;
}

.login-box h1 {
  font-size: 28px;
  margin-bottom: 10px;
  color: #333;
}

.login-box .subtitle {
  font-size: 18px;
  color: #666;
  margin-bottom: 30px;
}

.login-box input {
  width: 100%;
  max-width: 350px;
  padding: 18px 20px;
  font-size: 22px;
  border: 3px solid #ddd;
  border-radius: 15px;
  text-align: center;
  outline: none;
  margin-bottom: 20px;
}

.login-box input:focus {
  border-color: #4a90d9;
}

.login-box button {
  width: 100%;
  max-width: 350px;
  padding: 18px;
  font-size: 22px;
  font-weight: bold;
  background: #4a90d9;
  color: white;
  border: none;
  border-radius: 15px;
  cursor: pointer;
  transition: background 0.2s;
}

.login-box button:hover {
  background: #357abd;
}

.login-box button:active {
  background: #2a5f9e;
  transform: scale(0.98);
}

.error {
  color: #e74c3c;
  font-size: 18px;
  margin-top: 15px;
  min-height: 25px;
}

/* === КОНТАКТЫ === */

.header {
  padding: 20px;
  background: #4a90d9;
  color: white;
}

.header h2 {
  font-size: 24px;
}

.contacts-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.contact-item {
  display: flex;
  align-items: center;
  padding: 20px 15px;
  border-bottom: 2px solid #f0f2f5;
  cursor: pointer;
  border-radius: 12px;
  margin-bottom: 5px;
  transition: background 0.2s;
}

.contact-item:hover {
  background: #f0f7ff;
}

.contact-item:active {
  background: #dceafa;
}

.contact-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #4a90d9;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: bold;
  margin-right: 15px;
  flex-shrink: 0;
}

.contact-info {
  flex: 1;
}

.contact-name {
  font-size: 22px;
  font-weight: 600;
  color: #333;
}

.contact-status {
  font-size: 16px;
  color: #999;
  margin-top: 3px;
}

.contact-status.online {
  color: #27ae60;
}

.contact-unread {
  background: #e74c3c;
  color: white;
  font-size: 18px;
  font-weight: bold;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading {
  text-align: center;
  padding: 40px;
  font-size: 20px;
  color: #999;
}

/* === ЧАТ === */

.chat-header {
  display: flex;
  align-items: center;
  padding: 15px;
  background: #4a90d9;
  color: white;
}

.back-btn {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 5px 10px;
  margin-right: 10px;
}

#chat-name {
  flex: 1;
  font-size: 22px;
  font-weight: 600;
}

.online-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 10px;
  display: none;
}

.online-dot.active {
  display: block;
  background: #2ecc71;
}

.chat-actions {
  display: flex;
  gap: 5px;
}

.call-btn {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  padding: 5px 8px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  background: #f0f2f5;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  margin-bottom: 10px;
  word-wrap: break-word;
  font-size: 20px;
  line-height: 1.4;
}

.message.sent {
  background: #4a90d9;
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.message.received {
  background: white;
  color: #333;
  border-bottom-left-radius: 4px;
}

.message .msg-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.8;
}

.message .msg-time {
  font-size: 13px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

.message img {
  max-width: 100%;
  border-radius: 12px;
  margin-top: 5px;
  cursor: pointer;
}

.typing-hidden {
  display: none;
}

.typing-visible {
  display: block;
  padding: 5px 15px;
  font-size: 16px;
  color: #999;
  font-style: italic;
}

.input-area {
  display: flex;
  align-items: center;
  padding: 10px;
  background: white;
  border-top: 2px solid #f0f2f5;
}

.attach-btn {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  padding: 5px 10px;
}

#message-input {
  flex: 1;
  padding: 14px 18px;
  font-size: 20px;
  border: 2px solid #ddd;
  border-radius: 25px;
  outline: none;
  margin: 0 8px;
}

#message-input:focus {
  border-color: #4a90d9;
}

.send-btn {
  background: #4a90d9;
  border: none;
  color: white;
  font-size: 24px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn:active {
  background: #357abd;
}

/* === ЗВОНОК === */

.call-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.call-modal.hidden {
  display: none;
}

.call-content {
  text-align: center;
  color: white;
}

#call-status {
  font-size: 24px;
  margin-bottom: 10px;
}

#call-name {
  font-size: 32px;
  font-weight: bold;
  margin-bottom: 30px;
}

.video-container {
  position: relative;
  width: 100vw;
  max-width: 600px;
  margin-bottom: 20px;
}

.video-container.hidden {
  display: none;
}

#remote-video {
  width: 100%;
  max-height: 60vh;
  background: #000;
  border-radius: 12px;
}

#local-video {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 120px;
  border-radius: 8px;
  border: 2px solid white;
}

.call-buttons {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.call-end-btn {
  padding: 18px 40px;
  font-size: 22px;
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: 50px;
  cursor: pointer;
}

.call-answer-btn {
  padding: 18px 40px;
  font-size: 22px;
  background: #27ae60;
  color: white;
  border: none;
  border-radius: 50px;
  cursor: pointer;
}

.call-answer-btn.hidden {
  display: none;
}

/* === АДАПТИВ === */

@media (max-width: 600px) {
  #app {
    max-width: 100%;
  }

  .login-box h1 {
    font-size: 24px;
  }

  .login-box input {
    font-size: 20px;
    padding: 16px;
  }

  .login-box button {
    font-size: 20px;
    padding: 16px;
  }

  .message {
    font-size: 18px;
  }

  #message-input {
    font-size: 18px;
  }
}
