:root {
  --bg-primary: #ebebeb;
  --bg-secondary: #f5f5f5;
  --bg-sidebar: #2e2e2e;
  --bg-chat: #f5f5f5;
  --bg-input: #ffffff;
  --bg-bubble-self: #95ec69;
  --bg-bubble-other: #ffffff;
  --text-primary: #191919;
  --text-secondary: #888888;
  --text-sidebar: #b2b2b2;
  --text-bubble: #191919;
  --border-color: #e0e0e0;
  --border-color-dark: #d0d0d0;
  --accent-color: #07c160;
  --hover-bg: #d9d9d9;
  --contact-active: #c9c9c9;
  --shadow-color: rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #191919;
    --bg-secondary: #232323;
    --bg-sidebar: #1c1c1c;
    --bg-chat: #1e1e1e;
    --bg-input: #2d2d2d;
    --bg-bubble-self: #3eb575;
    --bg-bubble-other: #2d2d2d;
    --text-primary: #d9d9d9;
    --text-secondary: #666666;
    --text-sidebar: #707070;
    --text-bubble: #d9d9d9;
    --border-color: #2d2d2d;
    --border-color-dark: #383838;
    --accent-color: #3eb575;
    --hover-bg: #333333;
    --contact-active: #383838;
    --shadow-color: rgba(0, 0, 0, 0.2);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-primary);
}

.sidebar-nav {
  width: 54px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px 0;
  flex-shrink: 0;
}

.nav-top, .nav-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.nav-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-sidebar);
  transition: all 0.2s ease;
}

.nav-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.nav-icon.active {
  color: var(--accent-color);
}

.nav-icon svg {
  width: 22px;
  height: 22px;
}

.nav-icon.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: #444;
  margin-bottom: 20px;
}

.nav-icon.user-avatar svg {
  width: 20px;
  height: 20px;
  color: #888;
}

.contact-list {
  width: 250px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.search-bar {
  padding: 16px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
}

.search-bar svg {
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.search-bar input {
  flex: 1;
  border: none;
  background: var(--bg-input);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
}

.search-bar input::placeholder {
  color: var(--text-secondary);
}

.contacts {
  flex: 1;
  overflow-y: auto;
}

.contact-item {
  display: flex;
  align-items: center;
  padding: 12px 12px;
  cursor: pointer;
  transition: background 0.15s ease;
  gap: 10px;
}

.contact-item:hover {
  background: var(--hover-bg);
}

.contact-item.active {
  background: var(--contact-active);
}

.contact-avatar {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  flex-shrink: 0;
  object-fit: cover;
}

.contact-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.contact-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.contact-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.org-tag {
  color: #f5a623;
}

.pin-icon {
  width: 14px;
  height: 14px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.contact-item.pinned {
  background: rgba(0, 0, 0, 0.02);
}

@media (prefers-color-scheme: dark) {
  .contact-item.pinned {
    background: rgba(255, 255, 255, 0.02);
  }
}

.loading-bar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  color: var(--text-secondary);
  font-size: 12px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-chat);
}

.loading-bar.active {
  display: flex;
}

.loading-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  min-width: 0;
}

.chat-header {
  height: 56px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.back-btn {
  display: none;
  background: none;
  border: none;
  padding: 8px;
  margin-left: -8px;
  cursor: pointer;
  color: var(--text-primary);
}

.back-btn svg {
  width: 24px;
  height: 24px;
}

.chat-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
}

.header-actions svg {
  width: 20px;
  height: 20px;
  color: var(--text-secondary);
  cursor: pointer;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 10px;
  max-width: 70%;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.self {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.other {
  align-self: flex-start;
}

.message-avatar {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  flex-shrink: 0;
  object-fit: cover;
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message.self .message-content {
  align-items: flex-end;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
}

.message.self .message-bubble {
  background: var(--bg-bubble-self);
  color: var(--text-bubble);
}

.message.other .message-bubble {
  background: var(--bg-bubble-other);
  color: var(--text-bubble);
  box-shadow: 0 1px 2px var(--shadow-color);
}

.message-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.system-message {
  align-self: center;
  max-width: 80%;
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 8px 16px;
  animation: fadeIn 0.2s ease;
}

.typing-indicator {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-bubble-other);
  border-radius: 6px;
  gap: 4px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-input-area {
  border-top: 1px solid var(--border-color);
  background: var(--bg-chat);
  padding: 10px 20px 16px;
  flex-shrink: 0;
}

.input-toolbar {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.toolbar-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.toolbar-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.toolbar-btn svg {
  width: 20px;
  height: 20px;
}

.input-wrapper {
  background: var(--bg-input);
  border-radius: 4px;
  border: 1px solid var(--border-color);
  margin-bottom: 10px;
}

.input-wrapper textarea {
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  font-size: 16px;
  color: var(--text-primary);
  resize: none;
  outline: none;
  font-family: inherit;
  line-height: 1.5;
}

.input-wrapper textarea::placeholder {
  color: var(--text-secondary);
}

.input-actions {
  display: flex;
  justify-content: flex-end;
}

.send-btn {
  padding: 6px 20px;
  background: var(--accent-color);
  color: #ffffff;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.send-btn:hover {
  filter: brightness(1.1);
}

.send-btn:active {
  transform: scale(0.98);
}

.service-menu {
  display: none;
  border-top: 1px solid var(--border-color);
  background: var(--bg-chat);
  flex-shrink: 0;
}

.service-menu.active {
  display: flex;
}

.menu-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 8px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  position: relative;
  border-right: 1px solid var(--border-color);
  transition: background 0.15s ease;
}

.menu-item:last-child {
  border-right: none;
}

.menu-item:hover {
  background: var(--hover-bg);
}

.submenu {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  min-width: 140px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 2px 10px var(--shadow-color);
  overflow: hidden;
  z-index: 100;
}

.submenu-right {
  left: auto;
  right: 0;
}

.submenu.open {
  display: block;
}

.submenu a, .submenu-message {
  display: block;
  padding: 10px 16px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  transition: background 0.15s ease;
}

.submenu a:hover, .submenu-message:hover {
  background: var(--hover-bg);
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color-dark);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

@media (max-width: 768px) {
  .sidebar-nav {
    display: none;
  }

  .app-container {
    position: relative;
    overflow: hidden;
  }

  .contact-list {
    width: 100%;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 20;
    background: var(--bg-secondary);
  }

  .contact-list.hidden {
    display: none;
  }

  .chat-area {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: none;
  }

  .chat-area.active {
    display: flex;
  }

  .back-btn {
    display: flex;
  }

  .message {
    max-width: 85%;
  }
}
