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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111b21;
  color: #e9edef;
  height: 100vh;
  overflow: hidden;
}

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

/* ── Sidebar ── */
#sidebar {
  width: 360px;
  min-width: 280px;
  background: #111b21;
  border-right: 1px solid #2a3942;
  display: flex;
  flex-direction: column;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #202c33;
  border-bottom: 1px solid #2a3942;
  min-height: 60px;
}

#sidebar-brand {
  display: flex;
  align-items: center;
}

#brand-name {
  font-size: 20px;
  font-weight: 700;
  color: #e9edef;
  letter-spacing: -0.3px;
}

#sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#btn-new-chat {
  background: #00a884;
  color: #111b21;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}
#btn-new-chat:hover { background: #06cf9c; }

#btn-logout {
  background: transparent;
  border: none;
  color: #8696a0;
  font-size: 18px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#btn-logout:hover { background: #2a3942; color: #e9edef; }

#user-info {
  padding: 6px 16px;
  font-size: 12px;
  color: #8696a0;
  background: #0d1f27;
  border-bottom: 1px solid #2a3942;
}

/* Search bar */
#search-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #111b21;
  border-bottom: 1px solid #2a3942;
}

#search-input {
  flex: 1;
  background: #2a3942;
  border: none;
  border-radius: 8px;
  color: #e9edef;
  font-size: 14px;
  padding: 8px 14px;
  outline: none;
}
#search-input::placeholder { color: #8696a0; }

#conversation-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

#conversation-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 1px solid #1f2c34;
  transition: background 0.15s;
}
#conversation-list li:hover,
#conversation-list li.active { background: #2a3942; }

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #00a884;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #111b21;
  flex-shrink: 0;
}

.conv-info { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-last { font-size: 12px; color: #8696a0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.conv-badge {
  background: #00a884;
  color: #111b21;
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.conv-delete {
  background: transparent;
  border: none;
  font-size: 15px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
#conversation-list li:hover .conv-delete { opacity: 0.6; }
#conversation-list li:hover .conv-delete:hover { opacity: 1; background: #3b4a54; }

/* ── Chat area ── */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0b141a;
  position: relative;
}

#chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: #8696a0;
  font-size: 16px;
}

#placeholder-logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  opacity: 0.6;
}

#chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

#chat-header {
  padding: 10px 20px;
  background: #202c33;
  border-bottom: 1px solid #2a3942;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

#chat-header-logo {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}

#chat-header-logo img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  display: block;
}

#chat-header-info {}
#chat-contact-name { font-weight: 600; font-size: 16px; }
#chat-contact-phone { font-size: 12px; color: #8696a0; margin-top: 2px; }

#btn-edit-name {
  background: transparent;
  border: 1px solid #3b4a54;
  color: #8696a0;
  font-size: 13px;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
}
#btn-edit-name:hover { background: #2a3942; color: #e9edef; border-color: #8696a0; }

#messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 8%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
}
.msg.inbound {
  background: #202c33;
  align-self: flex-start;
  border-top-left-radius: 0;
}
.msg.outbound {
  background: #005c4b;
  align-self: flex-end;
  border-top-right-radius: 0;
}
.msg-time {
  font-size: 10px;
  color: #8696a0;
  margin-top: 4px;
  text-align: right;
}

/* Media messages */
.msg img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 6px;
  display: block;
  cursor: pointer;
  margin-bottom: 4px;
}

.audio-player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  margin-bottom: 4px;
  padding: 6px 4px;
}
.audio-play {
  background: #00a884;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 14px;
  cursor: pointer;
  color: #111b21;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.audio-play:hover { background: #06cf9c; }
.audio-track {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}
.audio-bar {
  height: 100%;
  background: #00a884;
  border-radius: 2px;
  width: 0%;
  transition: width 0.1s linear;
}
.audio-time {
  font-size: 11px;
  color: #8696a0;
  flex-shrink: 0;
  min-width: 32px;
  text-align: right;
}
.msg-file-link {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.07);
  border-radius: 6px;
  padding: 8px 10px;
  text-decoration: none;
  color: #e9edef;
  font-size: 13px;
  margin-bottom: 4px;
}
.msg-file-link:hover { background: rgba(255,255,255,0.12); }

/* ── Message form ── */
#message-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: #202c33;
  border-top: 1px solid #2a3942;
  align-items: flex-end;
}

#btn-attach {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  flex-shrink: 0;
  opacity: 0.7;
}
#btn-attach:hover { opacity: 1; background: #2a3942; }

#message-input {
  flex: 1;
  background: #2a3942;
  border: none;
  border-radius: 8px;
  color: #e9edef;
  font-size: 15px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}
#message-input::placeholder { color: #8696a0; }

#btn-send {
  background: #00a884;
  color: #111b21;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
#btn-send:hover { background: #06cf9c; }
#btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Upload preview bar */
#upload-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #2a3942;
  border-top: 1px solid #1f2c34;
  font-size: 13px;
  color: #e9edef;
}

#btn-cancel-upload {
  background: transparent;
  border: none;
  color: #8696a0;
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
#btn-cancel-upload:hover { color: #e9edef; }

/* ── Mic button ── */
#btn-mic {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.15s, transform 0.1s;
  user-select: none;
  -webkit-user-select: none;
}
#btn-mic:hover { opacity: 1; background: #2a3942; }
#btn-mic.recording {
  opacity: 1;
  transform: scale(1.15);
  animation: mic-pulse 1s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); }
  50%       { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* ── Recording bar ── */
#recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #202c33;
  border-top: 1px solid #2a3942;
}
#btn-cancel-recording {
  background: transparent;
  border: none;
  color: #8696a0;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  flex-shrink: 0;
}
#btn-cancel-recording:hover { color: #ef4444; }

#recording-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  animation: dot-blink 1s step-start infinite;
}
@keyframes dot-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}
#recording-timer {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: #e9edef;
  min-width: 36px;
}
#recording-hint {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: #8696a0;
}
#btn-send-recording {
  background: #00a884;
  color: #111b21;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#btn-send-recording:hover { background: #06cf9c; }

/* ── Responsive — mobile ── */
@media (max-width: 768px) {
  #sidebar {
    width: 100%;
    min-width: unset;
    position: absolute;
    inset: 0;
    z-index: 10;
    transition: transform 0.25s ease;
  }
  #sidebar.hidden-mobile {
    transform: translateX(-100%);
    pointer-events: none;
  }
  #chat-area {
    width: 100%;
  }
  #btn-back-mobile {
    display: flex;
    align-items: center;
    background: transparent;
    border: none;
    color: #00a884;
    font-size: 22px;
    cursor: pointer;
    padding: 6px 8px 6px 0;
    flex-shrink: 0;
  }
  #messages-container {
    padding: 12px 4%;
  }
  #message-form {
    padding: 10px 10px;
    gap: 6px;
  }
  #btn-send {
    padding: 10px 14px;
    font-size: 13px;
  }
  #recording-hint { display: none; }
}

/* Back button hidden on desktop */
#btn-back-mobile { display: none; }

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#modal {
  background: #202c33;
  border-radius: 12px;
  padding: 28px 32px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#modal h2 { font-size: 18px; }

#modal label {
  font-size: 13px;
  color: #8696a0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#modal input {
  background: #2a3942;
  border: none;
  border-radius: 6px;
  color: #e9edef;
  font-size: 15px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}

#modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 4px;
}
#modal-cancel {
  background: transparent;
  border: 1px solid #8696a0;
  color: #8696a0;
  border-radius: 6px;
  padding: 8px 18px;
  cursor: pointer;
}
#modal-confirm {
  background: #00a884;
  color: #111b21;
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  font-weight: 600;
  cursor: pointer;
}
#modal-confirm:hover { background: #06cf9c; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3b4a54; border-radius: 4px; }

.date-separator {
  text-align: center;
  color: #8696a0;
  font-size: 12px;
  margin: 12px 0;
  background: rgba(11,20,26,0.8);
  padding: 4px 12px;
  border-radius: 8px;
  align-self: center;
}
