* {
  box-sizing: border-box;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f0f2f5;
  color: #111b21;
}

#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.view {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---------- Contacts list ---------- */

#contacts-view {
  width: 100%;
  background: #ffffff;
  border-right: 1px solid #e9edef;
}

.contacts-header {
  background: #008069;
  color: #fff;
  padding: 18px 20px;
  flex: 0 0 auto;
}

.contacts-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.contacts-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1 1 auto;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  cursor: pointer;
  border-bottom: 1px solid #f0f2f5;
  transition: background 0.1s ease;
}

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

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

.contact-name {
  font-size: 16px;
  font-weight: 500;
  color: #111b21;
}

.contacts-list .loading,
.contacts-list .empty {
  padding: 20px;
  color: #667781;
  font-size: 14px;
}

.avatar {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #8696a0;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.5px;
}

/* ---------- Chat view ---------- */

#chat-view {
  width: 100%;
  flex: 1 1 auto;
  background: #efeae2;
  background-image:
    radial-gradient(circle at 25% 20%, rgba(0,0,0,0.02) 0, transparent 45%),
    radial-gradient(circle at 75% 75%, rgba(0,0,0,0.02) 0, transparent 45%);
}

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #008069;
  color: #fff;
  padding: 10px 16px;
}

.back-btn {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px 4px 0;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  font-size: 13px;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-contact-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-contact-phone {
  font-size: 12px;
  color: rgba(255,255,255,0.8);
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 6% 18px;
  display: flex;
  flex-direction: column;
}

.chat-placeholder,
.loading-messages {
  margin: auto;
  color: #667781;
  font-size: 15px;
}

.day-separator {
  display: flex;
  justify-content: center;
  margin: 14px 0;
}

.day-separator span {
  background: #ffffff;
  color: #54656f;
  font-size: 12.5px;
  padding: 5px 12px;
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.message-row {
  display: flex;
  margin: 2px 0;
}

.message-row.in {
  justify-content: flex-start;
}

.message-row.out {
  justify-content: flex-end;
}

.bubble {
  position: relative;
  max-width: 65%;
  padding: 6px 9px 20px 9px;
  border-radius: 8px;
  font-size: 14.5px;
  line-height: 1.4;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.13);
  word-wrap: break-word;
}

.message-row.in .bubble {
  background: #ffffff;
  border-top-left-radius: 0;
}

.message-row.out .bubble {
  background: #d9fdd3;
  border-top-right-radius: 0;
}

.bubble.bubble-email {
  max-width: 80%;
}

.bubble-line {
  margin: 4px 2px 2px;
  white-space: pre-wrap;
  color: #111b21;
}

.bubble-line.bubble-empty {
  color: #8696a0;
  font-style: italic;
}

.bubble-call {
  font-weight: 500;
}

.bubble-time {
  position: absolute;
  bottom: 4px;
  right: 9px;
  font-size: 11px;
  color: #667781;
}

.bubble-media {
  display: block;
  max-width: 100%;
  border-radius: 6px;
  margin: 2px 0;
}

.bubble-image {
  cursor: zoom-in;
  max-height: 320px;
  object-fit: cover;
}

audio.bubble-media {
  width: 260px;
  max-width: 100%;
  height: 40px;
}

video.bubble-media {
  max-height: 320px;
}

.bubble-document {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  margin: 2px 0;
  background: rgba(0,0,0,0.04);
  border-radius: 6px;
  text-decoration: none;
  color: #111b21;
}

.doc-icon {
  font-size: 22px;
}

.doc-name {
  font-size: 13.5px;
  word-break: break-word;
}

.email-block {
  margin: 4px 2px 2px;
}

.email-subject {
  font-weight: 600;
  color: #111b21;
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  z-index: 100;
}

.lightbox.hidden {
  display: none;
}

.lightbox img {
  max-width: 92%;
  max-height: 92%;
  border-radius: 4px;
}

/* ---------- Responsive: mobile single-pane ---------- */

@media (max-width: 768px) {
  #contacts-view,
  #chat-view {
    width: 100%;
  }

  body:not(.chat-open) #chat-view {
    display: none;
  }

  body.chat-open #contacts-view {
    display: none;
  }

  .back-btn {
    display: block;
  }

  .bubble {
    max-width: 82%;
  }
}

@media (min-width: 769px) {
  #contacts-view {
    width: 32%;
    min-width: 280px;
    max-width: 420px;
  }
}
