/* CSS Variables for theming */
:root {
  --primary-color: #667eea;
  --primary-dark: #5a67d8;
  --secondary-color: #764ba2;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-color: #f7fafc;
  --surface-color: #ffffff;
  --text-primary: #1a202c;
  --text-secondary: #718096;
  --text-muted: #a0aec0;
  --border-color: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --transition: all 0.2s ease;
}

/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--bg-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.sidebar-content {
  text-align: center;
  color: white;
}

.sidebar-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.sidebar-subtitle {
  font-size: 1rem;
  font-weight: 500;
  opacity: 0.9;
  margin-bottom: 2rem;
}

.sidebar-description {
  font-size: 0.95rem;
  opacity: 0.85;
  line-height: 1.7;
  max-width: 280px;
  margin: 0 auto;
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--bg-color);
  position: relative;
}

/* Header Bar */
.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
}

.room-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.room-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  flex-shrink: 0;
}

.room-id {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary-color);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.user-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
}

.user-name-display {
  padding: 0;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--primary-color);
  background: transparent;
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: var(--transition);
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-name-display:hover {
  color: var(--primary-dark);
}

.user-name-display:active {
  opacity: 0.7;
}

/* Name Edit Container */
.name-edit-container {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex: 1;
}

.name-edit-input {
  flex: 1;
  max-width: 160px;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-color);
  border: 2px solid var(--primary-color);
  border-radius: var(--radius-full);
  outline: none;
  transition: var(--transition);
}

.name-edit-input:focus {
  background: white;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.name-edit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

.name-edit-btn.save {
  background: var(--primary-color);
  color: white;
}

.name-edit-btn.save:hover {
  background: var(--primary-dark);
  transform: scale(1.08);
}

.name-edit-btn.cancel {
  background: var(--bg-color);
  color: var(--text-secondary);
  border: 1.5px solid var(--border-color);
}

.name-edit-btn.cancel:hover {
  background: #fee2e2;
  color: #dc2626;
  border-color: #fca5a5;
}

/* Chat Container */
.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 100%;
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

/* Message Bubble */
.message {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  animation: fadeIn 0.2s ease;
}

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

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

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

.message-user {
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  padding: 0 0.5rem;
}

.my-message .message-user {
  color: var(--primary-color);
  text-align: right;
}

.other-message .message-user {
  color: var(--secondary-color);
  text-align: left;
}

.message-content {
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
}

.my-message .message-content {
  background: var(--surface-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.my-message .message-content a {
  color: var(--primary-color);
}

.other-message .message-content {
  background: var(--surface-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.other-message .message-content a {
  color: var(--primary-color);
}

.message-content a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-content a:hover {
  opacity: 0.8;
}

/* Input Form */
.message-form {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface-color);
  border-top: 1px solid var(--border-color);
  position: sticky;
  bottom: 0;
}

/* Input wrapper for message input */
.input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.message-input {
  width: 100%;
  padding: 0.875rem 1.25rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-full);
  outline: none;
  transition: var(--transition);
  background: var(--bg-color);
}

.message-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.message-input::placeholder {
  color: var(--text-muted);
}

.send-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: white;
  background: var(--bg-gradient);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}

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

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

/* Mobile Responsive */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .app-container {
    flex-direction: column;
  }

  .chat-area {
    width: 100%;
  }

  .chat {
    padding: 0;
  }

  .header-bar {
    padding: 0.625rem 0.75rem;
  }

  .room-id {
    max-width: 80px;
    font-size: 0.8125rem;
  }

  .user-name-display {
    max-width: 100px;
    font-size: 0.8125rem;
  }

  .name-edit-input {
    max-width: 100px;
    font-size: 0.8125rem;
  }

  .messages-container {
    padding: 0.75rem;
    gap: 0.5rem;
  }

  .message {
    max-width: 85%;
  }

  .message-content {
    padding: 0.625rem 0.875rem;
    font-size: 0.9rem;
  }

  .message-form {
    padding: 0.75rem;
    gap: 0.5rem;
  }

  .message-input {
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
  }

  .send-button {
    width: 44px;
    height: 44px;
  }
}

/* Small phones */
@media (max-width: 360px) {
  .message-form {
    flex-direction: column;
    gap: 0.5rem;
  }

  .message-input,
  .send-button {
    width: 100%;
    border-radius: var(--radius-md);
  }
}

/* Scrollbar styling */
.messages-container::-webkit-scrollbar {
  width: 6px;
}

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

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

.messages-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Remove button (hidden by default, shown on hover) */
.message .remove {
  display: none;
}