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

:root {
  --bg-primary: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --bg-accent: #404249;
  --bg-hover: #35373c;
  --bg-active: #404249;
  --bg-input: #383a40;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a559;
  --yellow: #f0b232;
  --text-primary: #f2f3f5;
  --text-secondary: #b5bac1;
  --text-muted: #949ba4;
  --text-link: #00a8fc;
  --border: #3f4147;
  --header-height: 48px;
  --sidebar-width: 240px;
  --members-width: 240px;
  --input-height: 44px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ===== Auth ===== */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  min-height: 100vh;
  padding: 20px;
}

.auth-container { width: 100%; max-width: 480px; }

.auth-card {
  background: var(--bg-primary);
  border-radius: 8px;
  padding: 32px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.auth-card h1 { font-size: 24px; text-align: center; margin-bottom: 4px; font-weight: 700; }
.auth-card .subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 24px; font-size: 15px; }

.tabs {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }

.form { display: flex; flex-direction: column; gap: 16px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus { border-color: var(--accent); }

.btn {
  padding: 12px 16px;
  background: var(--accent);
  border: none;
  border-radius: 4px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}

.btn:hover { background: var(--accent-hover); }

.error {
  background: rgba(242,63,67,0.12);
  border: 1px solid #f23f43;
  color: #f23f43;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* ===== Chat Layout ===== */
.chat-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 20;
}

.server-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--bg-tertiary);
  font-weight: 600;
  font-size: 15px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  flex-shrink: 0;
}

.channel-section {
  padding: 16px 0 0;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.channel-section-header {
  padding: 0 8px 4px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.channel-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.channel-item {
  padding: 8px 8px;
  margin: 1px 0;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 15px;
  transition: background 0.1s, color 0.1s;
}

.channel-item:hover { background: var(--bg-hover); color: var(--text-secondary); }
.channel-item.active { background: var(--bg-active); color: var(--text-primary); }

.channel-item .icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.7;
}

.channel-item.active .icon { opacity: 1; }

.channel-item .name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.channel-item .unread-badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  min-width: 18px;
  text-align: center;
}

.channel-item .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.channel-item .status-dot.online { background: var(--green); }
.channel-item .status-dot.offline { background: var(--text-muted); }

/* ===== User Panel ===== */
.user-panel {
  height: 52px;
  padding: 0 8px;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-panel-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-panel-info { flex: 1; min-width: 0; }
.user-panel-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-panel-status { font-size: 11px; color: var(--green); }

/* ===== Main Content ===== */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--bg-tertiary);
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.chat-header-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-header-icon { font-size: 20px; color: var(--text-muted); font-weight: 600; flex-shrink: 0; }
.chat-header-left h3 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-left p { font-size: 12px; color: var(--text-muted); }
.chat-header-right { display: flex; gap: 4px; flex-shrink: 0; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 6px;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: var(--bg-accent); color: var(--text-primary); }
.icon-btn.small { font-size: 14px; padding: 2px 4px; }

/* ===== Chat Body ===== */
.chat-body { flex: 1; display: flex; overflow: hidden; min-height: 0; }

.messages-wrapper { flex: 1; display: flex; flex-direction: column; min-width: 0; }

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

/* ===== Messages ===== */
.message-group {
  padding: 2px 16px 2px 72px;
  position: relative;
  min-height: 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.message-group:hover { background: rgba(0,0,0,0.06); }

.message-group.has-header {
  margin-top: 16px;
  padding-top: 4px;
  min-height: 44px;
}

.msg-avatar {
  position: absolute;
  left: 16px;
  top: 4px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  line-height: 1.375;
}

.msg-username {
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.msg-username:hover { text-decoration: underline; }

.msg-timestamp { font-size: 12px; color: var(--text-muted); font-weight: 400; }

.msg-content {
  font-size: 15px;
  line-height: 1.375;
  color: var(--text-secondary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg-content a { color: var(--text-link); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }

.msg-content img.msg-image {
  max-width: 400px;
  max-height: 300px;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
  display: block;
}

.msg-file {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-primary);
  font-size: 14px;
  margin-top: 4px;
}

.msg-file:hover { background: var(--bg-accent); }

/* ===== Typing ===== */
.typing-indicator {
  padding: 4px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.typing-dots { display: inline-flex; gap: 3px; align-items: center; }
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== Members Panel ===== */
.members-panel {
  width: var(--members-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--bg-tertiary);
  overflow-y: auto;
  flex-shrink: 0;
  transition: width 0.2s ease;
}

.members-panel.hidden { width: 0; overflow: hidden; border: none; }

.members-header {
  padding: 16px 16px 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.members-list { padding: 0 8px; }

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s;
}

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

.member-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  position: relative;
  flex-shrink: 0;
}

.member-avatar .status-indicator {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

.member-avatar .status-indicator.online { background: var(--green); }
.member-avatar .status-indicator.offline { background: var(--text-muted); }

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

.member-name.offline { opacity: 0.4; }

/* ===== Chat Input ===== */
.chat-input-area {
  padding: 0 16px 24px;
  flex-shrink: 0;
}

.chat-input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border-radius: 8px;
  padding: 2px 4px;
}

.chat-input-wrapper input[type="text"] {
  flex: 1;
  padding: 10px 12px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  min-width: 0;
}

.chat-input-wrapper input[type="text"]::placeholder { color: var(--text-muted); }

.input-icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  padding: 8px;
  border-radius: 4px;
  transition: color 0.15s;
  flex-shrink: 0;
}

.input-icon-btn:hover { color: var(--text-primary); }

/* ===== Empty State ===== */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 8px;
  padding: 40px 20px;
}

.empty-icon { font-size: 48px; margin-bottom: 8px; opacity: 0.5; }
.empty-state h3 { font-size: 18px; color: var(--text-secondary); }
.empty-state p { font-size: 14px; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s;
}

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

.modal {
  background: var(--bg-primary);
  border-radius: 8px;
  padding: 24px;
  width: 90%;
  max-width: 440px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  animation: slideUp 0.15s;
}

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

.modal h3 { font-size: 20px; font-weight: 700; margin-bottom: 16px; }
.modal .form-group { margin-bottom: 16px; }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.modal-actions button {
  padding: 8px 24px;
  border-radius: 4px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.modal-cancel { background: transparent; color: var(--text-primary); border: 1px solid var(--border) !important; }
.modal-cancel:hover { text-decoration: underline; }
.modal-confirm { background: var(--accent); color: white; }
.modal-confirm:hover { background: var(--accent-hover); }

.member-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.1s;
}

.member-checkbox:hover { background: var(--bg-hover); }
.member-checkbox input { accent-color: var(--accent); width: 16px; height: 16px; }
.member-checkbox-label { font-size: 14px; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-accent); }

/* ===== Date Divider ===== */
.date-divider {
  display: flex;
  align-items: center;
  padding: 2px 16px;
  margin: 8px 0;
}

.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.date-divider span {
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

/* ===== Welcome ===== */
.welcome-msg {
  padding: 16px 16px 8px 16px;
}

.welcome-msg h2 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.welcome-msg p { color: var(--text-muted); font-size: 14px; }

/* ===== Notification toast ===== */
.toast-container {
  position: fixed;
  bottom: 80px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 12px 16px;
  min-width: 280px;
  max-width: 360px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  cursor: pointer;
  animation: slideInRight 0.25s ease;
}

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

.toast-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.toast-body { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===== Mobile ===== */
.mobile-sidebar-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 30;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 15;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 20;
    transition: left 0.25s ease;
    width: 260px;
  }

  .sidebar.open { left: 0; }

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

  .mobile-sidebar-toggle { display: flex; }

  .chat-header { padding-left: 52px; }

  .members-panel {
    position: fixed;
    right: -260px;
    top: 0;
    bottom: 0;
    z-index: 20;
    transition: right 0.25s ease;
    width: 260px;
    border-left: 1px solid var(--border);
  }

  .members-panel.open { right: 0; }
  .members-panel.hidden { right: -260px; width: 260px; }

  .message-group { padding-left: 56px; padding-right: 12px; }
  .msg-avatar { left: 12px; width: 36px; height: 36px; font-size: 14px; }

  .chat-input-area { padding: 0 8px 12px; }
}

@media (max-width: 480px) {
  .chat-header-left p { display: none; }
  .msg-content { font-size: 14px; }
  .msg-username { font-size: 14px; }
}
