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

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --bg: #0f172a;
  --bg-light: #1e293b;
  --bg-lighter: #334155;
  --text: #f1f5f9;
  --text-light: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --success: #22c55e;
  --danger: #ef4444;
  --msg-own: #312e81;
  --msg-other: #1e293b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.screen {
  display: none;
  height: 100vh;
}
.screen.active {
  display: flex;
}

/* Login */
#login-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg) 0%, #1a1a2e 100%);
}

.login-card {
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 400px;
  max-width: 90vw;
  text-align: center;
}

.login-card h1 {
  font-size: 2rem;
  margin-bottom: 8px;
}
.subtitle {
  color: var(--text-light);
  margin-bottom: 30px;
}

.form-group {
  text-align: left;
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--text-light);
}

.form-group input,
#message-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
#message-input:focus {
  border-color: var(--primary);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--primary-dark);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm {
  background: transparent;
  color: var(--text-light);
  border: 1px dashed var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  width: 100%;
  margin-top: 8px;
  transition: all 0.2s;
}

.btn-sm:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Chat Layout */
.chat-layout {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-light);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 1.2rem;
}

.channels-section {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

.channels-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.channel-item {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-light);
  font-size: 0.9rem;
  transition: all 0.15s;
  margin-bottom: 2px;
}

.channel-item:hover {
  background: var(--bg-lighter);
  color: var(--text);
}
.channel-item.active {
  background: var(--primary);
  color: white;
}
.channel-item::before {
  content: '#';
  font-weight: bold;
  opacity: 0.5;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.online-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
}

/* Main Chat */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
}

.chat-header h3 {
  font-size: 1rem;
}
.chat-header h3::before {
  content: '# ';
  opacity: 0.5;
}

.menu-btn {
  display: none;
}

.typing-indicator {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  flex: 1;
}

.online-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: rgba(15, 23, 42, 0.95);
  flex-shrink: 0;
  user-select: none;
  background-size: cover;
  background-position: center;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

.avatar--sm {
  width: 24px;
  height: 24px;
  font-size: 0.65rem;
}

.avatar--image {
  color: transparent;
}

.message {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 100%;
}

.message-bubble {
  max-width: 75%;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  position: relative;
}

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

.message.own .message-avatar {
  order: 2;
}

.message.own .message-bubble {
  order: 1;
  background: var(--msg-own);
  border-bottom-right-radius: 4px;
}

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

.message.other .message-bubble {
  background: var(--msg-other);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-author {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 2px;
}

.message.own .message-author {
  color: #a5b4fc;
}

.message-text {
  word-wrap: break-word;
}

.message-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.message-reactions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.reaction-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 6px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.reaction-badge:hover {
  border-color: var(--primary);
}

.system-message {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 8px;
}

/* Chat Input */
.chat-input-area {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

#message-input {
  flex: 1;
}

/* Mobile */
@media (max-width: 768px) {
  .chat-layout {
    position: relative;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
  }

  .sidebar-overlay.open {
    display: block;
  }

  .chat-main {
    width: 100%;
  }

  .chat-header {
    padding: 12px 16px;
  }

  .menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--bg-lighter);
    border: none;
    border-radius: 8px;
    color: var(--text);
    font-size: 1.2rem;
    cursor: pointer;
    flex-shrink: 0;
  }

  .messages {
    padding: 12px 12px;
  }

  .message {
    max-width: 85%;
  }

  .chat-input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 20px));
  }

  #message-input {
    padding: 12px 14px;
    font-size: 16px; /* prevents iOS zoom */
    min-height: 44px;
  }

  .btn-primary {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 16px;
  }

  .channel-item {
    padding: 12px;
    min-height: 44px;
  }

  .btn-sm {
    min-height: 44px;
    font-size: 0.9rem;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--bg-lighter);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
