/* ===== RESET & VARIABLES ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --bg-input: #383a40;
  --bg-hover: #35373c;
  --bg-active: #404249;
  --text-primary: #f2f3f5;
  --text-secondary: #b5bac1;
  --text-muted: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --green: #23a559;
  --red: #da373c;
  --yellow: #f0b232;
  --divider: #3f4147;
  --radius: 4px;
  --radius-lg: 8px;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  overflow: hidden;
}

.hidden { display: none !important; }

a { color: var(--text-primary); }

/* ===== AUTH SCREEN ===== */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-tertiary);
}

.auth-card {
  background: var(--bg-secondary);
  padding: 32px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  text-align: center;
}

.auth-logo {
  font-size: 48px;
  margin-bottom: 8px;
}

.auth-card h1 {
  font-size: 24px;
  margin-bottom: 4px;
}

.auth-card p {
  color: var(--text-muted);
  margin-bottom: 20px;
}

.field {
  text-align: left;
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

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

.error-text {
  color: var(--red);
  font-size: 14px;
  margin-bottom: 12px;
}

.auth-card button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.auth-card button:hover {
  background: var(--accent-hover);
}

.auth-switch {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-muted);
}

.auth-switch a {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 600;
}

.auth-switch a:hover {
  text-decoration: underline;
}

/* ===== APP LAYOUT ===== */
.app {
  display: grid;
  grid-template-columns: 72px 240px 1fr 240px;
  height: 100vh;
  overflow: hidden;
}

/* ===== SERVER BAR ===== */
.server-bar {
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
  overflow-y: auto;
}

.server-bar::-webkit-scrollbar { width: 0; }

.server-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: border-radius 0.2s, background 0.2s;
  position: relative;
}

.server-icon:hover,
.server-icon.active {
  border-radius: 16px;
  background: var(--accent);
}

.server-icon.home-icon.active {
  background: var(--accent);
}

.server-divider {
  width: 32px;
  height: 2px;
  background: var(--divider);
  border-radius: 1px;
  margin: 4px 0;
}

.add-server {
  color: var(--green);
  font-size: 24px;
  font-weight: 300;
}

.add-server:hover {
  background: var(--green);
  color: white;
}

.server-icon::before {
  content: '';
  position: absolute;
  left: -16px;
  width: 4px;
  height: 0;
  background: white;
  border-radius: 0 4px 4px 0;
  transition: height 0.2s;
}

.server-icon:hover::before {
  height: 20px;
}

.server-icon.active::before {
  height: 36px;
}

/* ===== CHANNEL BAR ===== */
.channel-bar {
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg) 0 0 0;
}

.channel-header {
  padding: 16px;
  border-bottom: 1px solid var(--divider);
  font-weight: 600;
  cursor: default;
  height: 48px;
  display: flex;
  align-items: center;
}

.channel-header h2 {
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.channel-category {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 16px 8px 4px;
  letter-spacing: 0.5px;
}

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

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

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

.channel-item .hash {
  font-size: 20px;
  opacity: 0.4;
}

/* DM user items */
.dm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
}

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

.dm-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.dm-name {
  font-size: 15px;
  color: var(--text-secondary);
}

.dm-item.active .dm-name,
.dm-item:hover .dm-name {
  color: var(--text-primary);
}

.start-dm-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  margin: 4px 0;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  transition: background 0.1s;
}

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

/* User Panel */
.user-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg-primary);
  border-top: 1px solid var(--divider);
}

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

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

.user-info span:first-child {
  display: block;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-status {
  font-size: 11px;
  color: var(--text-muted);
}

#logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  transition: color 0.2s;
}

#logout-btn:hover {
  color: var(--red);
}

/* ===== CHAT AREA ===== */
.chat-area {
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.chat-header {
  padding: 0 16px;
  height: 48px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.chat-header .hash {
  color: var(--text-muted);
}

.chat-header-desc {
  font-weight: 400;
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--divider);
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-list::-webkit-scrollbar {
  width: 8px;
}

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

.message-list::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.message {
  display: flex;
  gap: 16px;
  padding: 2px 0;
  border-radius: var(--radius);
  transition: background 0.1s;
}

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

.msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-body {
  flex: 1;
  min-width: 0;
}

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

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

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

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

/* Chat Input */
.chat-input-area {
  padding: 0 16px 24px;
  display: flex;
  gap: 8px;
}

#message-input {
  flex: 1;
  padding: 11px 16px;
  background: var(--bg-input);
  border: none;
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
}

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

#send-btn {
  padding: 0 16px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-lg);
  color: white;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s;
}

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

/* ===== MEMBERS BAR ===== */
.members-bar {
  background: var(--bg-secondary);
  padding: 16px;
  border-left: 1px solid var(--divider);
  overflow-y: auto;
}

.members-bar h3 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

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

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

.member-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.member-name {
  font-size: 14px;
  color: var(--text-secondary);
}

.member-item:hover .member-name {
  color: var(--text-primary);
}

.member-role {
  font-size: 11px;
  color: var(--text-muted);
}

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

.modal-card {
  background: var(--bg-primary);
  padding: 24px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
}

.modal-card h2 {
  text-align: center;
  margin-bottom: 20px;
  font-size: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.modal-actions button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.modal-actions button:first-child {
  background: var(--bg-input);
  color: var(--text-primary);
}

.modal-actions button:first-child:hover {
  background: var(--bg-hover);
}

.modal-actions button:last-child {
  background: var(--accent);
  color: white;
}

.modal-actions button:last-child:hover {
  background: var(--accent-hover);
}

.modal-choice {
  display: block;
  width: 100%;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.modal-choice:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.modal-choice.cancel {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  margin-top: 8px;
}

.modal-choice.cancel:hover {
  color: var(--red);
}

/* ===== SCROLLBAR ===== */
.channel-list::-webkit-scrollbar,
.members-bar::-webkit-scrollbar {
  width: 8px;
}

.channel-list::-webkit-scrollbar-track,
.members-bar::-webkit-scrollbar-track {
  background: transparent;
}

.channel-list::-webkit-scrollbar-thumb,
.members-bar::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 72px 200px 1fr;
  }
  .members-bar {
    display: none;
  }
}

@media (max-width: 600px) {
  .app {
    grid-template-columns: 1fr;
  }
  .server-bar,
  .channel-bar {
    display: none;
  }
}

