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

:root {
  --primary: #4F6EF7;
  --primary-dark: #3B54D4;
  --primary-light: #EEF1FE;
  --bg: #F5F6FA;
  --white: #FFFFFF;
  --text: #1A1A2E;
  --text-secondary: #6B7280;
  --border: #E5E7EB;
  --success: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== Navbar ========== */
.navbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.navbar-brand {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.navbar-brand .logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  font-weight: 900;
}

.navbar-search {
  flex: 1;
  max-width: 480px;
  margin: 0 32px;
  position: relative;
}

.navbar-search input {
  width: 100%;
  padding: 10px 16px 10px 42px;
  border: 2px solid var(--border);
  border-radius: 24px;
  font-size: 14px;
  transition: all 0.2s;
  background: var(--bg);
  outline: none;
}

.navbar-search input:focus {
  border-color: var(--primary);
  background: var(--white);
}

.navbar-search .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-size: 16px;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.navbar-actions .btn {
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary) !important;
}
.btn-outline:hover { background: var(--primary-light); }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; text-align: center; justify-content: center; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { opacity: 0.9; }

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  position: relative;
}

.user-menu .avatar-sm {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary-light);
}

.user-menu .avatar-placeholder {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  display: none;
  padding: 8px;
  border: 1px solid var(--border);
}

.dropdown.show { display: block; }

.dropdown-item {
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
}

.dropdown-item:hover { background: var(--bg); }
.dropdown-divider { height: 1px; background: var(--border); margin: 6px 0; }

/* ========== Container ========== */
.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 20px 16px;
}

/* ========== Cards ========== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.card-header .avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--primary-light);
}

.card-header .avatar-placeholder {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
}

.card-header .user-info { flex: 1; }
.card-header .user-name { font-weight: 700; font-size: 15px; }
.card-header .user-hid { font-size: 12px; color: var(--text-secondary); }
.card-header .post-time { font-size: 12px; color: var(--text-secondary); }

.card-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
  cursor: pointer;
}
.card-title:hover { color: var(--primary); }

.card-content {
  font-size: 15px;
  color: var(--text);
  margin-bottom: 14px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Post images */
.post-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.post-images img {
  width: 100%;
  border-radius: 8px;
  cursor: pointer;
  object-fit: cover;
  max-height: 240px;
  transition: transform 0.2s;
}
.post-images img:hover { transform: scale(1.02); }

/* Post files */
.post-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.file-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  color: var(--primary);
  cursor: pointer;
  transition: background 0.15s;
}
.file-badge:hover { background: var(--primary-light); }

/* Topics / Hashtags */
.topic-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.topic-tag {
  padding: 4px 12px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.topic-tag:hover { background: var(--primary); color: white; }

/* Card Actions */
.card-actions {
  display: flex;
  gap: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.card-actions span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.15s;
}
.card-actions span:hover { color: var(--primary); }

/* ========== Post Type Badge ========== */
.post-type-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
}

.type-image { background: #FEF3C7; color: #D97706; }
.type-file { background: #DBEAFE; color: #2563EB; }
.type-text { background: #D1FAE5; color: #059669; }

/* ========== Forms ========== */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  transition: border-color 0.2s;
  outline: none;
  font-family: inherit;
}

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

.form-group textarea {
  resize: vertical;
  min-height: 120px;
}

.form-group .hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ========== Auth Page ========== */
.auth-container {
  max-width: 420px;
  margin: 60px auto;
}

.auth-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px;
}

.auth-card h2 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 4px;
}

.auth-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
}

.auth-card .switch-link {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
}

/* ========== Profile Page ========== */
.profile-header {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  text-align: center;
  margin-bottom: 20px;
  position: relative;
}

.profile-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--primary-light);
  margin-bottom: 12px;
}

.profile-avatar-placeholder {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 12px;
}

.profile-name { font-size: 22px; font-weight: 700; }
.profile-hid { font-size: 14px; color: var(--text-secondary); }
.profile-bio { font-size: 14px; color: var(--text); margin-top: 8px; max-width: 400px; margin-left: auto; margin-right: auto; }

.profile-edit-btn {
  position: absolute;
  top: 20px;
  right: 20px;
}

.profile-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.profile-tab {
  flex: 1;
  padding: 14px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  color: var(--text-secondary);
}
.profile-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.profile-tab:hover { background: var(--bg); }

/* ========== Create Post ========== */
.create-post-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.create-post-card h3 { margin-bottom: 18px; font-size: 18px; }

.post-type-selector {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.post-type-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: 10px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--white);
}

.post-type-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.image-preview .preview-item {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
}

.image-preview .preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview .preview-item .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========== Friends Page ========== */
.friend-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  transition: transform 0.15s;
}
.friend-card:hover { transform: translateY(-1px); }

.friend-card .avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
}

.friend-card .avatar-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.friend-info { flex: 1; }
.friend-name { font-weight: 700; font-size: 15px; }
.friend-hid { font-size: 12px; color: var(--text-secondary); }

.request-badge {
  background: var(--warning);
  color: white;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

/* ========== Search Results ========== */
.search-header {
  padding: 12px 0;
  margin-bottom: 16px;
}

.search-header h3 { font-size: 18px; }
.search-header .query-text { color: var(--primary); }

/* ========== Comments ========== */
.comments-section {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.comment-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.comment-item:last-child { border-bottom: none; }

.comment-item .avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.comment-item .avatar-placeholder-sm {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}

.comment-body { flex: 1; }
.comment-author { font-weight: 600; font-size: 13px; }
.comment-text { font-size: 14px; color: var(--text); }
.comment-time { font-size: 11px; color: var(--text-secondary); }

.comment-form {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.comment-form input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 20px;
  outline: none;
  font-size: 14px;
}
.comment-form input:focus { border-color: var(--primary); }

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

.modal {
  background: var(--white);
  border-radius: 16px;
  padding: 32px;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h3 { margin-bottom: 20px; font-size: 20px; }

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

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

/* ========== Toast ========== */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 28px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  z-index: 300;
  animation: slideDown 0.3s;
  box-shadow: var(--shadow-lg);
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }

@keyframes slideDown {
  from { transform: translateX(-50%) translateY(-20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ========== Loading ========== */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Pagination ========== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 20px 0;
}

.pagination button {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.pagination button:hover { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== Tabs ========== */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tab {
  flex: 1;
  padding: 14px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  color: var(--text-secondary);
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover { background: var(--bg); }

/* ========== Hidden ========== */
.hidden { display: none !important; }

/* ========== Chat ========== */
.chat-container {
  display: flex;
  height: calc(100vh - 140px);
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-sidebar {
  width: 280px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

.chat-sidebar-header {
  padding: 16px;
  font-weight: 700;
  font-size: 16px;
  border-bottom: 1px solid var(--border);
}

.chat-contact {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.chat-contact:hover { background: var(--bg); }
.chat-contact.active { background: var(--primary-light); }

.chat-contact .avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-contact .avatar-placeholder {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
}

.chat-contact-info { flex: 1; min-width: 0; }
.chat-contact-name { font-weight: 600; font-size: 14px; }
.chat-contact-msg { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-contact-time { font-size: 11px; color: var(--text-secondary); }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-main-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
}

.chat-main-header .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-main-header .avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}

.chat-msg {
  display: flex;
  max-width: 70%;
  animation: fadeIn 0.2s;
}

.chat-msg.me { align-self: flex-end; }
.chat-msg.other { align-self: flex-start; }

.chat-msg-bubble {
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.chat-msg.me .chat-msg-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-msg.other .chat-msg-bubble {
  background: var(--white);
  color: var(--text);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-msg-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  padding: 0 4px;
}

.chat-msg.me .chat-msg-time { text-align: right; }

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

.chat-input-area input {
  flex: 1;
  padding: 10px 16px;
  border: 2px solid var(--border);
  border-radius: 24px;
  outline: none;
  font-size: 14px;
}

.chat-input-area input:focus { border-color: var(--primary); }

.chat-input-area button {
  padding: 10px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-input-area button:hover { background: var(--primary-dark); }

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 15px;
}

.chat-back-btn {
  display: none;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  margin-right: 4px;
}

/* ========== Responsive ========== */
@media (max-width: 640px) {
  .navbar { padding: 0 12px; }
  .navbar-search { margin: 0 12px; }
  .navbar-brand { font-size: 18px; }
  .container { padding: 12px 8px; }
  .card { padding: 16px; }
  .post-images { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .auth-card { padding: 24px; }

  /* Chat mobile */
  .chat-container {
    height: calc(100vh - 110px);
    border-radius: 0;
    position: relative;
  }

  .chat-sidebar {
    width: 100%;
    position: absolute;
    inset: 0;
    z-index: 10;
    background: var(--white);
  }

  .chat-sidebar.hidden-mobile {
    display: none;
  }

  .chat-main {
    width: 100%;
    position: absolute;
    inset: 0;
    z-index: 10;
    background: var(--white);
  }

  .chat-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    font-size: 18px;
  }

  .chat-msg {
    max-width: 85%;
  }

  .chat-msg-bubble {
    font-size: 15px;
    padding: 10px 14px;
  }

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

  .chat-input-area input {
    font-size: 15px;
    padding: 10px 14px;
  }

  .chat-input-area button {
    padding: 10px 16px;
    font-size: 14px;
  }

  .chat-messages {
    padding: 12px;
  }

  .chat-main-header {
    padding: 10px 14px;
  }
}