* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #dadbd3; height: 100vh; overflow: hidden; }
#app { display: flex; height: 100vh; max-width: 1600px; margin: 0 auto; box-shadow: 0 2px 10px rgba(0,0,0,.15); }

.sidebar { width: 380px; min-width: 380px; background: #fff; display: flex; flex-direction: column; border-right: 1px solid #e0e0e0; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: #f0f2f5; height: 60px; }
.user-avatar { width: 40px; height: 40px; border-radius: 50%; overflow: hidden; }
.user-avatar svg { width: 100%; height: 100%; }
.header-actions { display: flex; gap: 8px; }
.btn-icon { background: none; border: none; cursor: pointer; color: #54656f; padding: 8px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; line-height: 1; }
.btn-icon:hover { background: #e0e0e0; }
.btn-send { color: #00a884; }

.search-box { padding: 8px 12px; background: #fff; border-bottom: 1px solid #e0e0e0; }
.search-box input { width: 100%; padding: 8px 12px; border: none; background: #f0f2f5; border-radius: 8px; font-size: 14px; outline: none; }

.contacts-list { flex: 1; overflow-y: auto; }
.contact-item { display: flex; align-items: center; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #f0f2f5; transition: background .15s; }
.contact-item:hover { background: #f5f6f6; }
.contact-item.active { background: #f0f2f5; }
.contact-avatar { width: 50px; height: 50px; border-radius: 50%; background: #dfe5e7; display: flex; align-items: center; justify-content: center; font-size: 20px; color: #667781; flex-shrink: 0; }
.contact-info { flex: 1; margin-left: 12px; min-width: 0; }
.contact-name { font-size: 16px; font-weight: 500; color: #111b21; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-last-msg { font-size: 13px; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-meta { text-align: right; margin-left: 8px; flex-shrink: 0; }
.contact-time { font-size: 12px; color: #667781; }
.contact-unread { background: #00a884; color: #fff; border-radius: 50%; width: 20px; height: 20px; font-size: 11px; display: flex; align-items: center; justify-content: center; margin-top: 4px; margin-left: auto; }
.empty-list { padding: 40px 16px; text-align: center; color: #667781; }

.chat-area { flex: 1; display: flex; flex-direction: column; background: #efeae2; min-width: 0; position: relative; }
.chat-area::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: url('data:image/svg+xml,<svg xmlns= http://www.w3.org/2000/svg viewBox=0 0 400 400 opacity=0.06><path fill=%23555 d=M0 0h400v400H0z/><path fill=%23ddd d=M0 0h200v200H0z/><path fill=%23eee d=M200 200h200v200H200z/></svg>'); background-size: 400px; pointer-events: none; }
.chat-header { display: flex; align-items: center; padding: 10px 16px; background: #f0f2f5; height: 60px; border-bottom: 1px solid #e0e0e0; gap: 12px; position: relative; z-index: 1; }
.chat-info { display: flex; align-items: center; gap: 12px; }
.chat-avatar { width: 40px; height: 40px; border-radius: 50%; background: #dfe5e7; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }
.chat-details { display: flex; flex-direction: column; }
.chat-name { font-size: 16px; font-weight: 500; color: #111b21; }
.chat-status { font-size: 12px; color: #667781; }

.messages-container { flex: 1; overflow-y: auto; padding: 20px 60px; display: flex; flex-direction: column; position: relative; z-index: 1; }
.loading { text-align: center; color: #667781; padding: 40px; }

.empty-chat { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: #667781; text-align: center; position: relative; z-index: 1; }
.empty-chat h2 { color: #41525d; margin-bottom: 8px; margin-top: 12px; }
.empty-chat p { font-size: 14px; }

.message { max-width: 65%; margin-bottom: 4px; display: flex; clear: both; }
.message.sent { float: none; justify-content: flex-end; }
.message.received { float: none; justify-content: flex-start; }
.message-bubble { padding: 6px 8px 2px; border-radius: 8px; word-wrap: break-word; position: relative; }
.message.sent .message-bubble { background: #d9fdd3; border-top-right-radius: 0; }
.message.received .message-bubble { background: #fff; border-top-left-radius: 0; }
.message-text { font-size: 14.2px; color: #111b21; line-height: 1.4; white-space: pre-wrap; }
.message-reaction { font-size: 28px; text-align: center; padding: 4px 0; }
.message-time { font-size: 11px; color: #667781; text-align: right; margin-top: 2px; display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.message.sent .message-time { color: #53bdeb; }
.message-time .status-icon { font-size: 14px; }

.message-input-area { display: flex; align-items: center; padding: 8px 16px; background: #f0f2f5; gap: 8px; position: relative; z-index: 1; }
.message-input-wrapper { flex: 1; }
.message-input-wrapper input { width: 100%; padding: 10px 16px; border: none; border-radius: 8px; font-size: 15px; outline: none; background: #fff; }

.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: #fff; border-radius: 12px; width: 90%; max-width: 400px; overflow: hidden; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; background: #00a884; color: #fff; }
.modal-header h3 { font-size: 18px; }
.btn-close { background: none; border: none; color: #fff; font-size: 24px; cursor: pointer; line-height: 1; }
.modal-body { padding: 20px; }
.modal-body input { width: 100%; padding: 12px; border: 1px solid #e0e0e0; border-radius: 8px; font-size: 15px; margin-bottom: 12px; outline: none; }
.modal-body input:focus { border-color: #00a884; }
.btn-primary { width: 100%; padding: 12px; background: #00a884; color: #fff; border: none; border-radius: 8px; font-size: 15px; cursor: pointer; font-weight: 500; }
.btn-primary:hover { background: #008f72; }
.btn-secondary { background: #e0e0e0; color: #333; }

.notification-banner { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #00a884; color: #fff; padding: 12px 20px; border-radius: 8px; display: flex; align-items: center; gap: 12px; z-index: 999; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.btn-small { padding: 6px 16px; border: none; border-radius: 4px; cursor: pointer; font-size: 13px; background: #fff; color: #00a884; font-weight: 500; }

.search-results { display: none; flex-direction: column; background: #fff; border-top: 2px solid #00a884; max-height: 50%; overflow-y: auto; position: absolute; bottom: 0; left: 0; right: 0; z-index: 50; box-shadow: 0 -4px 12px rgba(0,0,0,.1); }
.sidebar { position: relative; }
.search-results-header { padding: 8px 16px; font-size: 13px; color: #00a884; font-weight: 500; background: #f0f2f5; }
.search-results .contact-item { padding: 8px 16px; }
.search-results .contact-avatar { width: 36px; height: 36px; font-size: 14px; }
.search-results .contact-name { font-size: 14px; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #cccccc; border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }
.message-media { margin: -2px -8px 2px; }
.message-media img { display: block; max-width: 100%; border-radius: 8px 8px 4px 4px; }
.message-media video { display: block; max-width: 100%; border-radius: 8px 8px 4px 4px; }
.message-media audio { display: block; width: 100%; border-radius: 8px; }
.message-document { padding: 12px; background: #f0f2f5; border-radius: 8px; margin: 0 0 4px; }
.doc-link { color: #00a884; text-decoration: none; font-weight: 500; font-size: 14px; display: block; }
.doc-link:hover { text-decoration: underline; }
.loc-link { color: #00a884; text-decoration: none; font-weight: 500; }
.loc-link:hover { text-decoration: underline; }

.message-media { margin: -2px -8px 2px; }
.message-media img { display: block; max-width: 100%; border-radius: 8px 8px 4px 4px; }
.message-media video { display: block; max-width: 100%; border-radius: 8px 8px 4px 4px; }
.message-media audio { display: block; width: 100%; border-radius: 8px; }
.message-document { padding: 12px 8px; background: #f0f2f5; border-radius: 8px; margin: 0 0 4px; }
.doc-link { color: #00a884; text-decoration: none; font-weight: 500; font-size: 14px; display: block; }
.doc-link:hover { text-decoration: underline; }
.loc-link { color: #00a884; text-decoration: none; font-weight: 500; }
.loc-link:hover { text-decoration: underline; }
.msg-delete { color: #e53935; font-size: 13px; cursor: pointer; margin-left: 6px; opacity: 0; transition: opacity .2s; font-weight: bold; line-height: 1; user-select: none; }
.msg-delete:hover { opacity: 1; color: #c62828; }
.message-bubble:hover .msg-delete { opacity: 1; }
.mobile-only { display: none !important; }

@media (max-width: 768px) {
  .message-input-area { position: sticky; bottom: 0; z-index: 10; }
  #app { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: 100%; }
  .sidebar.hidden { display: none; }
  .chat-area { width: 100%; height: 100%; display: none; }
  .chat-area.show { display: flex; }
  .messages-container { padding: 12px 8px; }
  .message { max-width: 90%; }
  .mobile-only { display: flex !important; }
  .message-input-area { padding: 6px 8px; }
  .message-input-wrapper input { font-size: 16px; }
  .empty-chat h2 { font-size: 18px; }
  .search-results { max-height: 60%; }
}

@media (max-width: 480px) {
  .sidebar-header { padding: 8px 12px; height: 50px; }
  .contact-item { padding: 10px 12px; }
  .contact-avatar { width: 42px; height: 42px; font-size: 16px; }
  .contact-name { font-size: 15px; }
  .chat-header { padding: 8px 12px; height: 50px; }
  .chat-avatar { width: 36px; height: 36px; }
  .chat-name { font-size: 15px; }
  .message { max-width: 95%; }
  .message-bubble { padding: 5px 6px 2px; }
  .message-text { font-size: 13.5px; }
  .header-actions .btn-icon { padding: 6px; font-size: 18px; }
}

@media (hover: none) and (pointer: coarse) {
  .msg-delete { opacity: 1 !important; }
  .msg-delete:hover { opacity: 1 !important; }
}
/* Mobile viewport fix */
@supports (height: 100dvh) {
  body, #app { height: 100dvh; }
}
@media (max-width: 768px) {
  #message-input-area { flex-shrink: 0; }
  .messages-container { flex: 1; min-height: 0; }
  .chat-area { min-height: 0; }
}

.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #f0f2f5;
  border-radius: 12px;
  min-width: 220px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.audio-play-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: #00a884;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform .1s, background .2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.audio-play-btn:active {
  transform: scale(0.92);
  background: #008f72;
}
.audio-progress {
  flex: 1;
  height: 6px;
  background: #ddd;
  border-radius: 3px;
  overflow: hidden;
  min-width: 60px;
}
.audio-progress-bar {
  height: 100%;
  background: #00a884;
  width: 0%;
  border-radius: 3px;
  transition: width .3s linear;
}
.audio-time {
  font-size: 13px;
  color: #667781;
  min-width: 36px;
  text-align: right;
  font-family: monospace;
}
@media (max-width: 768px) {
  .audio-player { padding: 14px 16px; min-width: 180px; }
  .audio-play-btn { width: 52px; height: 52px; font-size: 24px; }
}
@media (max-width: 480px) {
  .audio-player { padding: 12px 14px; min-width: 160px; }
  .audio-play-btn { width: 48px; height: 48px; font-size: 22px; }
}
