/* ============================================
   微语 (Weiyu) - Social Media Stylesheet
   ============================================ */

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

:root {
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: #EEF2FF;
  --primary-bg: #F8FAFC;
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --text: #0F172A;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;
  --border: #E2E8F0;
  --border-light: #F1F5F9;
  --danger: #EF4444;
  --danger-hover: #DC2626;
  --success: #22C55E;
  --warning: #F59E0B;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-full: 9999px;
  --nav-height: 60px;
  --max-width: 680px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ============================================
   App Container
   ============================================ */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
  max-width: 360px;
  word-break: break-word;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }
.toast-warning { background: var(--warning); }

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

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

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

.confirm-dialog {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.confirm-dialog p {
  font-size: 1.05rem;
  margin-bottom: 24px;
  color: var(--text);
}

.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

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

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  line-height: 1;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

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

.btn-secondary {
  background: #E2E8F0;
  color: var(--text);
}
.btn-secondary:hover { background: #CBD5E1; }

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
}
.btn-ghost:hover { background: var(--primary-light); color: var(--primary); }

.btn-sm {
  padding: 6px 14px;
  font-size: 0.82rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
  font-size: 1.1rem;
}
.btn-icon:hover { background: var(--primary-light); color: var(--primary); }

.btn-block {
  width: 100%;
  padding: 12px;
}

/* ============================================
   Inputs & Forms
   ============================================ */
.input-group {
  margin-bottom: 16px;
}

.input-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-input::placeholder { color: var(--text-muted); }
textarea.form-input { resize: vertical; min-height: 100px; }

/* ============================================
   Auth Pages (Login / Register)
   ============================================ */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #EEF2FF 0%, #E0E7FF 50%, #C7D2FE 100%);
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(79, 70, 229, 0.15);
}

.auth-brand {
  text-align: center;
  margin-bottom: 32px;
}

.auth-brand h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), #818CF8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.auth-brand p {
  color: var(--text-secondary);
  font-size: 0.92rem;
  margin-top: 6px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.25s ease;
  font-family: inherit;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.auth-form .btn-primary {
  margin-top: 8px;
}

.auth-error {
  background: #FEF2F2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: none;
}

.auth-error.show { display: block; }

/* ============================================
   Navbar
   ============================================ */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.navbar-inner {
  width: 100%;
  max-width: var(--max-width);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.navbar-brand {
  font-size: 1.3rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), #818CF8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  cursor: pointer;
}

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

.navbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius-full);
  transition: background 0.2s;
}

.navbar-user:hover { background: var(--primary-light); }

.navbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  overflow: hidden;
}

.navbar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.navbar-username {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

/* ============================================
   Main Layout
   ============================================ */
.main-layout {
  padding-top: calc(var(--nav-height) + 16px);
  padding-bottom: 40px;
  flex: 1;
}

.main-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
}

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

.create-post-textarea {
  width: 100%;
  border: none;
  outline: none;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  min-height: 80px;
  line-height: 1.6;
  color: var(--text);
  background: transparent;
}

.create-post-textarea::placeholder { color: var(--text-muted); }

.create-post-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

.create-post-tools {
  display: flex;
  gap: 8px;
}

.create-post-tool-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.create-post-tool-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.create-post-tool-btn.has-media {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.create-post-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.create-post-preview img,
.create-post-preview video {
  height: 100px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
}

.preview-item {
  position: relative;
  display: inline-block;
}

.preview-item .remove-media {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: 2px solid var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  line-height: 1;
}

/* ============================================
   Post Card
   ============================================ */
.post-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}

.post-card:hover {
  box-shadow: var(--shadow-lg);
}

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

.post-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
  cursor: pointer;
  overflow: hidden;
}

.post-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.post-author-name {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text);
  cursor: pointer;
}

.post-author-name:hover { color: var(--primary); }

.post-time {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
  margin-top: 1px;
}

.post-more-btn {
  position: relative;
}

.post-more-menu {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  min-width: 120px;
  z-index: 10;
  overflow: hidden;
}

.post-more-menu button {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  transition: background 0.15s;
}

.post-more-menu button:hover { background: var(--primary-light); }
.post-more-menu .menu-delete { color: var(--danger); }

.post-content {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 12px;
}

.post-media {
  margin-bottom: 12px;
}

.post-images {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.post-images.single {
  grid-template-columns: 1fr;
}

.post-images img {
  width: 100%;
  aspect-ratio: 16/10;
  object-fit: cover;
  cursor: pointer;
  transition: opacity 0.2s;
}

.post-images img:hover { opacity: 0.9; }

.post-video {
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}

.post-video video {
  width: 100%;
  max-height: 400px;
  display: block;
}

.post-video video:focus {
  outline: none;
}

.post-stats {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

.post-stat-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-full);
  transition: all 0.2s;
  font-family: inherit;
}

.post-stat-btn:hover { background: var(--primary-light); }
.post-stat-btn.liked { color: #EF4444; }
.post-stat-btn.liked:hover { background: #FEF2F2; }
.post-stat-btn .icon { font-size: 1.1rem; }

/* ============================================
   Post Detail Page
   ============================================ */
.detail-page {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.detail-back {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  transition: background 0.2s;
}

.detail-back:hover { background: var(--primary-light); color: var(--primary); }

.detail-post {
  padding: 20px;
}

.detail-post .post-content {
  font-size: 1.05rem;
}

.detail-post .post-images img {
  aspect-ratio: auto;
  max-height: 500px;
}

.detail-post .post-video video {
  max-height: 500px;
}

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

.comments-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.comment-input-area {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.comment-input {
  flex: 1;
  padding: 10px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  color: var(--text);
  background: var(--bg);
}

.comment-input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.comment-item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
}

.comment-item:last-child { border-bottom: none; }

.comment-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
  overflow: hidden;
  cursor: pointer;
}

.comment-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.comment-author {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.comment-author:hover { color: var(--primary); }

.comment-text {
  font-size: 0.9rem;
  color: var(--text);
  margin: 4px 0 6px;
  line-height: 1.5;
  word-break: break-word;
}

.comment-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.comment-like-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 3px;
  font-family: inherit;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  transition: all 0.2s;
}

.comment-like-btn:hover { background: var(--primary-light); color: var(--primary); }
.comment-like-btn.liked { color: #EF4444; }

.comment-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  padding: 2px 6px;
  border-radius: var(--radius-full);
}

.comment-delete-btn:hover { color: var(--danger); background: #FEF2F2; }

.comments-empty {
  text-align: center;
  padding: 30px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ============================================
   Profile Page
   ============================================ */
.profile-page {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.profile-header {
  padding: 32px 24px;
  text-align: center;
  background: linear-gradient(135deg, var(--primary-light) 0%, #E0E7FF 100%);
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 2rem;
  margin: 0 auto 12px;
  overflow: hidden;
  border: 3px solid var(--surface);
  box-shadow: var(--shadow);
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-username {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.profile-bio {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 4px;
}

.profile-joined {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 8px;
}

.profile-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.profile-stat {
  text-align: center;
}

.profile-stat-num {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.profile-stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

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

.profile-tab {
  flex: 1;
  padding: 14px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  font-family: inherit;
}

.profile-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.profile-posts {
  padding: 16px;
}

.profile-posts .post-card {
  box-shadow: none;
  border: 1px solid var(--border-light);
  margin-bottom: 12px;
}

.profile-posts .post-card:hover {
  box-shadow: var(--shadow);
}

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

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.95rem;
}

/* ============================================
   Loading Spinner
   ============================================ */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

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

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

/* ============================================
   Image Viewer (Lightbox)
   ============================================ */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  cursor: zoom-out;
}

.lightbox img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  border-radius: 4px;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 600px) {
  .auth-card { padding: 28px 20px; }
  .create-post { padding: 16px; }
  .post-card { padding: 16px; }
  .post-stats { gap: 8px; }
  .post-stat-btn { font-size: 0.8rem; padding: 4px 8px; }
  .navbar-inner { padding: 0 12px; }
  .profile-header { padding: 24px 16px; }
  .profile-stats { gap: 24px; }
  .detail-post { padding: 16px; }
  .comments-section { padding: 16px; }
  .comment-input-area { flex-direction: column; }
  .comment-input { border-radius: var(--radius-sm); }
}

@media (max-width: 480px) {
  .post-images { grid-template-columns: 1fr; }
  .navbar-username { display: none; }
  .create-post-actions { flex-direction: column; gap: 10px; }
  .create-post-tools { width: 100%; justify-content: center; }
  .create-post-tools .btn { flex: 1; }
}
