* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-app: #efeae2;
  --bg-sidebar: #ffffff;
  --bg-chat: #efeae2;
  --bg-header: #f0f2f5;
  --bg-out: #d9fdd3;
  --bg-in: #ffffff;
  --bg-hover: #f5f6f6;
  --bg-active: #f0f2f5;
  --text-primary: #111b21;
  --text-secondary: #667781;
  --text-time: #667781;
  --green: #00a884;
  --green-dark: #008069;
  --blue-check: #53bdeb;
  --border: #e9edef;
  --shadow: 0 1px 3px rgba(11, 20, 26, 0.08);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  background: #d1d7db;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Top bar */
.top-bar {
  height: 126px;
  background: var(--green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  flex-shrink: 0;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
}

.top-bar .icon {
  color: #fff;
}

/* Main container */
.main-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  background: var(--bg-app);
  box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
}

/* Sidebar */
.sidebar {
  width: 30%;
  min-width: 320px;
  max-width: 420px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  height: 60px;
  background: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}

.sidebar-header-icons {
  display: flex;
  gap: 20px;
  color: #54656f;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 500;
  flex-shrink: 0;
}

.avatar.small {
  width: 40px;
  height: 40px;
  font-size: 15px;
}

.icon-btn {
  cursor: pointer;
  color: #54656f;
  transition: opacity 0.2s;
}

.icon-btn:hover {
  opacity: 0.6;
}

/* Search */
.search-bar {
  padding: 8px 12px;
  background: var(--bg-sidebar);
  flex-shrink: 0;
}

.search-input {
  background: var(--bg-hover);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-icon {
  color: var(--text-secondary);
}

.search-input input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 14px;
  color: var(--text-primary);
}

/* Chat list */
.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  gap: 14px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.chat-item:hover {
  background: var(--bg-hover);
}

.chat-item.active {
  background: var(--bg-active);
}

.chat-avatar {
  width: 49px;
  height: 49px;
  border-radius: 50%;
  background: #00af8f;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 500;
  flex-shrink: 0;
}

.chat-info {
  flex: 1;
  min-width: 0;
}

.chat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chat-name {
  font-size: 16px;
  font-weight: 400;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  font-size: 12px;
  color: var(--text-time);
  flex-shrink: 0;
}

.chat-preview {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

/* Chat main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cpath fill='%23e5ddd5' fill-opacity='0.4' d='M50 50c0-5.5 4.5-10 10-10s10 4.5 10 10-4.5 10-10 10-10-4.5-10-10z'/%3E%3C/svg%3E");
  background-repeat: repeat;
  min-width: 0;
}

.chat-header {
  height: 60px;
  background: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-text {
  display: flex;
  flex-direction: column;
}

.chat-header-name {
  font-size: 16px;
  font-weight: 500;
}

.chat-header-status {
  font-size: 13px;
  color: var(--text-secondary);
}

.chat-header-actions {
  display: flex;
  gap: 20px;
  color: #54656f;
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 8%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.date-separator {
  align-self: center;
  background: #fff;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 8px 0;
}

.message {
  max-width: 65%;
  padding: 6px 10px 8px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
  box-shadow: var(--shadow);
  margin-top: 2px;
}

.message.out {
  align-self: flex-end;
  background: var(--bg-out);
  border-top-right-radius: 0;
}

.message.in {
  align-self: flex-start;
  background: var(--bg-in);
  border-top-left-radius: 0;
}

.message-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-time);
  float: right;
  position: relative;
  bottom: -2px;
}

.message-meta .check {
  color: var(--blue-check);
}

.message.typing {
  font-style: italic;
  color: var(--text-secondary);
}

.message.error {
  background: #f8d7da;
  color: #721c24;
}

/* Footer */
.chat-footer {
  height: 62px;
  background: var(--bg-header);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
}

.footer-emoji {
  color: #54656f;
  cursor: pointer;
}

.footer-input {
  flex: 1;
  background: #fff;
  border-radius: 8px;
  padding: 10px 16px;
}

.footer-input input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 15px;
  color: var(--text-primary);
}

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--green);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.send-btn:hover {
  background: #008f72;
}

.send-btn:disabled {
  background: #d1d7db;
  cursor: not-allowed;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar,
.chat-list::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-list::-webkit-scrollbar-track {
  background: transparent;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    min-width: 0;
    width: 100%;
    max-width: none;
  }
  .chat-main {
    display: none;
  }
  .main-container.show-chat .sidebar {
    display: none;
  }
  .main-container.show-chat .chat-main {
    display: flex;
  }
  .chat-messages {
    padding: 16px 5%;
  }
  .message {
    max-width: 85%;
  }
}