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

:root {
  /* Refined, editorial color palette */
  --bg-primary: #fdfcfb;
  --bg-secondary: #f8f6f4;
  --bg-tertiary: #efecea;
  --border-color: #ddd8d3;
  --border-light: #e8e5e1;
  
  --text-primary: #1a1612;
  --text-secondary: #6b6560;
  --text-tertiary: #a39d97;
  
  --accent-primary: #2d5a3f;
  --accent-hover: #234730;
  --accent-light: #e8f0ec;
  
  --shadow-sm: 0 1px 2px rgba(26, 22, 18, 0.04);
  --shadow-md: 0 4px 12px rgba(26, 22, 18, 0.06);
  --shadow-lg: 0 8px 24px rgba(26, 22, 18, 0.08);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  font-family: 'Instrument Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(135deg, #fdfcfb 0%, #f8f6f4 100%);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    radial-gradient(circle at 20% 30%, rgba(45, 90, 63, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(45, 90, 63, 0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.app-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

/* Header */
.header {
  background: rgba(253, 252, 251, 0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-light);
  padding: 20px 32px;
  flex-shrink: 0;
}

.header-content {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.app-title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nickname-input {
  font-family: 'Instrument Sans', sans-serif;
  font-size: 14px;
  padding: 10px 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
  width: 200px;
}

.nickname-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.connection-status:hover {
  background: var(--bg-tertiary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.connection-status.connected .status-dot {
  background: var(--accent-primary);
}

.connection-status.connecting .status-dot {
  background: #d4a574;
}

.connection-status.disconnected .status-dot {
  background: #e74c3c;
}

.connection-status.error .status-dot {
  background: #e74c3c;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 32px 32px;
  gap: 24px;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-light);
  height: 59px;
}

.sidebar-header h2 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  line-height: 1;
}

.user-count {
  background: var(--accent-light);
  color: var(--accent-primary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
}

.users-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px 20px 20px;
}

.users-list::-webkit-scrollbar {
  width: 6px;
}

.users-list::-webkit-scrollbar-track {
  background: transparent;
}

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

.user-item {
  padding: 12px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: var(--transition);
  cursor: pointer;
}

.user-item:hover {
  background: var(--bg-tertiary);
  transform: translateX(2px);
}

.user-item.self {
  background: var(--accent-light);
  border: 1px solid rgba(45, 90, 63, 0.2);
  cursor: default;
}

.user-item.self:hover {
  transform: none;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-hover));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

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

.user-item.self .user-name {
  font-weight: 500;
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.chat-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-secondary);
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.clear-history-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: 'Instrument Sans', sans-serif;
  cursor: pointer;
  transition: var(--transition);
  line-height: 20px;
}

.clear-history-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--text-tertiary);
}

.clear-history-btn svg {
  flex-shrink: 0;
}

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

.messages-container::-webkit-scrollbar {
  width: 8px;
}

.messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.welcome-message {
  text-align: center;
  padding: 60px 20px;
  opacity: 0;
  animation: fadeInUp 0.6s ease forwards;
}

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

.welcome-icon {
  font-size: 48px;
  margin-bottom: 20px;
}

.welcome-message h2 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 32px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.welcome-message p {
  color: var(--text-secondary);
  font-size: 15px;
  max-width: 400px;
  margin: 0 auto;
}

/* Message Bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  opacity: 0;
  animation: messageSlideIn 0.3s ease forwards;
}

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

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

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

.message.highlight .message-bubble {
  animation: highlightPulse 0.5s ease 2;
}

@keyframes highlightPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 0 4px;
}

.message-sender {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.message-time {
  font-size: 12px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.message-status {
  display: inline-flex;
  color: var(--text-tertiary);
  font-size: 11px;
  margin-left: 4px;
  cursor: help;
  transition: var(--transition);
}

.message-status.pending {
  color: #d4a574;
}

.message-status.sending {
  color: #d4a574;
}

.message-status.sent {
  color: var(--text-tertiary);
}

.message-status.read {
  color: var(--accent-primary);
}

.message-status span {
  display: inline-block;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  cursor: pointer;
}

.message.self .message-bubble {
  background: var(--accent-primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.other .message-bubble {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
}

.message-bubble:hover {
  box-shadow: var(--shadow-md);
  opacity: 0.95;
}

/* Reply UI in messages */
.message-reply {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  max-height: 45px;
  overflow: hidden;
}

.message.self .message-reply {
  background: rgba(255, 255, 255, 0.15);
}

.reply-indicator {
  width: 3px;
  background: var(--accent-primary);
  border-radius: 2px;
  flex-shrink: 0;
}

.message.self .reply-indicator {
  background: rgba(255, 255, 255, 0.6);
}

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

.reply-to-sender {
  font-weight: 600;
  color: var(--accent-primary);
  font-size: 12px;
}

.message.self .reply-to-sender {
  color: rgba(255, 255, 255, 0.9);
}

.reply-to-text {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.message.self .reply-to-text {
  color: rgba(255, 255, 255, 0.7);
}

/* Image Messages */
.image-bubble {
  padding: 4px;
  background: transparent;
  border: none;
  box-shadow: none;
}

.message.self .image-bubble {
  background: transparent;
}

.message.other .image-bubble {
  background: transparent;
  border: none;
}

.message-image {
  max-width: 400px;
  max-height: 300px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  display: block;
}

.message-image:hover {
  opacity: 0.9;
  transform: scale(1.02);
}

/* Image Preview */
.image-preview-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.image-preview-container {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

.image-preview-container img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.close-preview {
  position: absolute;
  top: -40px;
  right: 0;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.close-preview:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* File Messages */
.file-bubble {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
}

.file-icon {
  font-size: 32px;
  flex-shrink: 0;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-weight: 500;
  font-size: 14px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message.self .file-name {
  color: white;
}

.file-size {
  font-size: 12px;
  opacity: 0.7;
}

.file-download-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  color: inherit;
  text-decoration: none;
  font-size: 13px;
  transition: var(--transition);
  white-space: nowrap;
}

.message.other .file-download-btn {
  background: var(--accent-light);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.file-download-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.message.other .file-download-btn:hover {
  background: var(--accent-primary);
  color: white;
}

.file-status {
  font-size: 12px;
  opacity: 0.7;
}

.file-receiving {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.file-progress {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.file-progress-bar {
  height: 100%;
  background: var(--accent-primary);
  transition: width 0.3s ease;
}

/* Drag and Drop */
.messages-container.drag-over {
  background: var(--accent-light);
  border: 2px dashed var(--accent-primary);
}

.system-message {
  align-self: center;
  padding: 8px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  max-width: 80%;
  opacity: 0;
  animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Input Container */
.input-container {
  padding: 20px 24px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reply-preview {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent-primary);
  border-radius: var(--radius-sm);
}

.reply-content {
  flex: 1;
  min-width: 0;
}

.reply-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-primary);
  margin-bottom: 2px;
}

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

.reply-close {
  padding: 4px;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.reply-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.attach-btn {
  padding: 0;
  width: 47px;
  height: 47px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.attach-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

.message-input {
  flex: 1;
  font-family: 'Instrument Sans', sans-serif;
  font-size: 15px;
  padding: 12px 18px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  resize: none;
  outline: none;
  transition: var(--transition);
  height: 47px;
  line-height: 1.5;
  overflow-y: hidden;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.message-input::-webkit-scrollbar {
  display: none;
}

.message-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.send-btn {
  padding: 0;
  width: 47px;
  height: 47px;
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.send-btn:active {
  transform: translateY(0);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Responsive */
@media (max-width: 1024px) {
  .main-content {
    padding: 0 20px 20px;
  }
  
  .sidebar {
    width: 240px;
  }
}

@media (max-width: 768px) {
  .header {
    padding: 16px 20px;
  }
  
  .app-title {
    font-size: 24px;
  }
  
  .nickname-input {
    width: 150px;
    font-size: 13px;
  }
  
  .main-content {
    flex-direction: column;
    gap: 16px;
    padding: 0 16px 16px;
  }
  
  .sidebar {
    width: 100%;
    height: 200px;
    flex-shrink: 0;
  }
  
  .message {
    max-width: 85%;
  }
}
