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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-card: #1f2b47;
  --accent: #4caf50;
  --accent-hover: #43a047;
  --accent-dim: #2e7d32;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b8;
  --text-muted: #6a6a80;
  --danger: #e53935;
  --danger-hover: #c62828;
  --border: #2a3050;
  --radius: 8px;
  --transition: 0.15s ease;
}

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

input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border var(--transition);
}
input:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-muted); }

button {
  cursor: pointer;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  transition: background var(--transition), opacity var(--transition);
}
button:hover { opacity: 0.9; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 12px 24px;
  font-size: 15px;
}
.btn-primary:hover { background: var(--accent-hover); opacity: 1; }

.btn-small {
  padding: 6px 12px;
  font-size: 13px;
  background: var(--bg-tertiary);
}
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }

/* ── Landing Page ─────────────────────────────────────────────────────────── */
#landing-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.landing-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 40px;
  width: 420px;
  max-width: 95vw;
  text-align: center;
}

.logo {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 8px;
}
.logo span { color: var(--accent); }

.tagline {
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 15px;
}

.field {
  margin-bottom: 16px;
  text-align: left;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.field label .optional {
  font-weight: 400;
  text-transform: none;
  color: var(--text-muted);
  font-size: 11px;
}
.field input { width: 100%; }

#join-form .btn-primary {
  width: 100%;
  margin-top: 8px;
}

.btn-recent {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 8px 16px;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border var(--transition), color var(--transition);
}
.btn-recent:hover {
  border-color: var(--accent);
  color: var(--accent);
  opacity: 1;
}

.hint {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-muted);
}
.hint code {
  background: var(--bg-primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

/* ── Server Page Layout ───────────────────────────────────────────────────── */
#server-page {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 1fr 56px;
  height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  grid-row: 1 / 3;
}

#server-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
#server-header h2 {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 2px;
}
.channel-item:hover { background: var(--bg-tertiary); }
.channel-item.active { background: var(--bg-tertiary); border-left: 3px solid var(--accent); }

.channel-item .channel-icon { font-size: 18px; }
.channel-item .channel-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-item .channel-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 2px 8px;
  border-radius: 10px;
}
.channel-item.active .channel-count {
  background: var(--accent-dim);
  color: #fff;
}

#add-channel-section {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}
#add-channel-form {
  display: flex;
  gap: 6px;
}
#add-channel-form input {
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
}
#add-channel-form button {
  padding: 8px 12px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}

#sidebar-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-recent-small {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 3px 8px;
  font-size: 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: border var(--transition), color var(--transition);
}
.btn-recent-small:hover {
  border-color: var(--accent);
  color: var(--accent);
  opacity: 1;
}

/* ── Main Area ────────────────────────────────────────────────────────────── */
#main {
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#channel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
#channel-header h2 {
  font-size: 18px;
  font-weight: 600;
}
#channel-user-count {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 4px 12px;
  border-radius: 12px;
}

#user-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}
#user-list .placeholder {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  margin-top: 48px;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 4px;
}
.user-item .user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
}
.user-item .user-avatar.self { background: var(--accent-dim); }
.user-item .user-name {
  font-size: 14px;
  font-weight: 500;
}
.user-item .user-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent-dim);
  color: #fff;
}
.user-item .user-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: auto;
  flex-shrink: 0;
}
.user-item .user-indicator.connected { background: var(--accent); }
.user-item .user-indicator.disconnected { background: var(--text-muted); }

/* ── Control Bar ──────────────────────────────────────────────────────────── */
#control-bar {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  grid-column: 2;
}

.ctrl-btn {
  background: var(--bg-tertiary);
  border: none;
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background var(--transition);
}
.ctrl-btn:hover { background: #1a3a6a; }
.ctrl-btn.active { background: var(--danger); }
.ctrl-btn .icon { font-size: 16px; }

#connection-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot.connected { background: var(--accent); }
.dot.connecting { background: #ffc107; animation: pulse 1s infinite; }
.dot.disconnected { background: var(--danger); }

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

/* ── Modal Overlay ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 400px;
  max-width: 92vw;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-sm { width: 340px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}
.modal-close {
  background: transparent;
  font-size: 18px;
  padding: 4px 8px;
  line-height: 1;
  color: var(--text-secondary);
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-body p {
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--text-secondary);
}
.modal-body .placeholder {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 20px 0;
}

.modal-body input {
  width: 100%;
  margin-bottom: 10px;
}
.modal-body .btn-primary {
  width: 100%;
}

/* ── Recent Server List ───────────────────────────────────────────────────── */
#recent-list {
  min-height: 60px;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 2px;
}
.recent-item:hover { background: var(--bg-tertiary); }

.recent-item .recent-icon {
  font-size: 20px;
  flex-shrink: 0;
}
.recent-item .recent-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recent-item .recent-lock {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.recent-item .recent-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.recent-item .recent-delete {
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.recent-item .recent-delete:hover {
  color: var(--danger);
  background: rgba(229, 57, 53, 0.15);
}

/* ── Error Message ────────────────────────────────────────────────────────── */
.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 8px;
  display: none;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #server-page {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 56px;
  }
  #sidebar {
    grid-row: 1;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #control-bar { grid-column: 1; }
}
