/* ============ RESET & BASE ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --bg2: #1a1a1a;
  --bg3: #252525;
  --border: #2e2e2e;
  --text: #e8e8e8;
  --text2: #888;
  --text3: #555;
  --accent: #7c5cbf;
  --accent-light: #9b7de3;
  --danger: #e05252;
  --success: #52c87e;
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 56px;
  --max-w: 680px;
}

html { font-size: 16px; scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea { font-family: inherit; }
img { display: block; max-width: 100%; }

.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ============ NAV ============ */
.nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: rgba(15,15,15,0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.nav-inner {
  max-width: 900px;
  margin: 0 auto;
  height: var(--header-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  flex-shrink: 0;
}
.nav-logo { width: 28px; height: auto; }
.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.nav-link {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.9rem;
  color: var(--text2);
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover, .nav-link.active { background: var(--bg3); color: var(--text); }
.nav-link.accent { background: var(--accent); color: #fff; }
.nav-link.accent:hover { background: var(--accent-light); }
.nav-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  margin-left: auto;
}
.nav-mobile {
  display: none;
  flex-direction: column;
  border-top: 1px solid var(--border);
  padding: 8px 16px;
}
.nav-mobile .nav-link { display: block; padding: 10px 0; color: var(--text); border-bottom: 1px solid var(--border); }
.nav-mobile .nav-link:last-child { border-bottom: none; }

@media (max-width: 600px) {
  .nav-links { display: none; }
  .nav-hamburger { display: block; }
  .nav-mobile.open { display: flex; }
}

/* ============ MAIN ============ */
#main {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: calc(var(--header-h) + 24px) 16px 80px;
}

/* ============ SKELETON ============ */
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.sk {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: 6px;
}
.skeleton-post { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.sk-header { display: flex; gap: 10px; margin-bottom: 12px; }
.sk-avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; }
.sk-meta { flex: 1; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.sk-name { height: 13px; width: 120px; }
.sk-time { height: 11px; width: 70px; }
.sk-text-1 { height: 14px; margin-bottom: 6px; }
.sk-text-2 { height: 14px; width: 70%; }

/* ============ CARD ============ */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}

/* ============ POST ============ */
.post {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}
.post:hover { border-color: var(--bg3); }
.post-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; color: #fff;
  flex-shrink: 0; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.post-meta { flex: 1; min-width: 0; }
.post-author { font-weight: 600; font-size: 0.95rem; truncate: ellipsis; white-space: nowrap; overflow: hidden; }
.post-username { color: var(--text2); font-size: 0.8rem; }
.post-time { color: var(--text3); font-size: 0.8rem; }
.post-content { font-size: 0.95rem; line-height: 1.6; white-space: pre-wrap; word-break: break-word; margin-bottom: 12px; }
.post-video { margin: 12px 0; border-radius: var(--radius-sm); overflow: hidden; background: #000; position: relative; }
.post-video video { width: 100%; max-height: 480px; display: block; }
.post-video-thumb { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: var(--radius-sm); cursor: pointer; }
.post-actions { display: flex; gap: 16px; padding-top: 8px; border-top: 1px solid var(--border); }
.action-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; color: var(--text2);
  font-size: 0.85rem; padding: 4px 8px; border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.action-btn:hover { background: var(--bg3); color: var(--text); }
.action-btn.liked { color: #e05252; }
.action-btn svg { width: 18px; height: 18px; }
.processing-badge {
  display: inline-block; padding: 2px 8px;
  background: var(--bg3); border-radius: 10px;
  font-size: 0.75rem; color: var(--text2); margin: 8px 0;
}

/* ============ COMMENTS ============ */
.comments-section { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.comment { display: flex; gap: 10px; margin-bottom: 10px; }
.comment-body { flex: 1; }
.comment-author { font-weight: 600; font-size: 0.85rem; }
.comment-text { font-size: 0.9rem; color: var(--text); margin-top: 2px; word-break: break-word; }
.comment-time { font-size: 0.75rem; color: var(--text3); margin-top: 2px; }
.comment-form { display: flex; gap: 8px; margin-top: 8px; }
.comment-input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: 8px 14px; color: var(--text);
  font-size: 0.9rem; outline: none; transition: border-color 0.15s;
}
.comment-input:focus { border-color: var(--accent); }
.comment-submit {
  background: var(--accent); border: none; border-radius: 20px;
  padding: 8px 16px; color: #fff; font-size: 0.9rem; transition: background 0.15s;
}
.comment-submit:hover { background: var(--accent-light); }

/* ============ FORMS ============ */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.85rem; color: var(--text2); margin-bottom: 6px; font-weight: 500; }
.form-input, .form-textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-error { color: var(--danger); font-size: 0.82rem; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--radius-sm);
  font-size: 0.95rem; font-weight: 600; border: none;
  transition: background 0.15s, opacity 0.15s;
  width: 100%; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; width: auto; }

/* ============ AUTH PAGE ============ */
.auth-page { max-width: 420px; margin: 0 auto; padding: 32px 0; }
.auth-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.auth-subtitle { color: var(--text2); margin-bottom: 28px; font-size: 0.9rem; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 0.9rem; color: var(--text2); }
.auth-footer a { color: var(--accent-light); }

/* ============ CREATE POST ============ */
.create-page { padding: 24px 0; }
.create-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 20px; }
.upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 32px; text-align: center; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}
.upload-area:hover, .upload-area.dragover { border-color: var(--accent); background: rgba(124,92,191,0.05); }
.upload-area input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-icon { font-size: 2rem; margin-bottom: 8px; color: var(--text3); }
.upload-hint { color: var(--text2); font-size: 0.85rem; margin-top: 4px; }
.upload-filename { font-weight: 600; color: var(--text); margin-top: 8px; }
.upload-progress { margin-top: 16px; }
.progress-bar-outer { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.progress-bar-inner { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.2s; }
.progress-label { font-size: 0.8rem; color: var(--text2); margin-top: 4px; }
.char-count { text-align: right; font-size: 0.75rem; color: var(--text3); margin-top: 4px; }

/* ============ PROFILE PAGE ============ */
.profile-header { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 28px; }
.profile-avatar {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 700; color: #fff; flex-shrink: 0; overflow: hidden;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-info { flex: 1; }
.profile-display-name { font-size: 1.3rem; font-weight: 700; }
.profile-username { color: var(--text2); font-size: 0.9rem; margin-bottom: 8px; }
.profile-bio { font-size: 0.9rem; color: var(--text2); margin-bottom: 8px; }
.profile-stats { display: flex; gap: 16px; font-size: 0.85rem; }
.profile-stat span { font-weight: 600; color: var(--text); }
.profile-tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.profile-tab {
  padding: 10px 20px; font-size: 0.9rem; color: var(--text2);
  border-bottom: 2px solid transparent; cursor: pointer; transition: color 0.15s;
}
.profile-tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ============ EMPTY STATE ============ */
.empty-state { text-align: center; padding: 48px 16px; color: var(--text2); }
.empty-state-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.1rem; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 0.9rem; }

/* ============ TOAST ============ */
#toast-container { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 20px;
  font-size: 0.9rem; color: var(--text); min-width: 200px; text-align: center;
  animation: toast-in 0.2s ease, toast-out 0.3s ease 2.7s forwards;
  pointer-events: auto;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px); } }

/* ============ SPINNER ============ */
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ LOAD MORE ============ */
.load-more-btn {
  display: block; width: 100%; padding: 12px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text2);
  font-size: 0.9rem; margin-top: 4px; transition: background 0.15s, color 0.15s;
}
.load-more-btn:hover { background: var(--bg3); color: var(--text); }

/* ============ EDIT PROFILE ============ */
.edit-profile-form { margin-top: 16px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 520px) {
  #main { padding-left: 12px; padding-right: 12px; }
  .profile-header { flex-direction: column; align-items: center; text-align: center; }
  .profile-stats { justify-content: center; }
}

/* ============ ADMIN PAGE ============ */
.admin-page {
  padding: 24px 0;
}
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}
.admin-title {
  font-size: 1.4rem;
  font-weight: 700;
}
.admin-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.admin-tab {
  background: none;
  border: none;
  padding: 8px 18px;
  border-radius: calc(var(--radius-sm) - 2px);
  color: var(--text2);
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { background: var(--bg3); color: var(--text); }

/* Stats grid */
.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  transition: border-color 0.15s;
}
.stat-card:hover { border-color: var(--accent); }
.stat-icon { font-size: 1.6rem; margin-bottom: 6px; }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: 0.85rem; color: var(--text2); margin-bottom: 4px; }
.stat-sub { font-size: 0.75rem; color: var(--success); }

/* Toolbar */
.admin-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.admin-search {
  flex: 1;
  min-width: 200px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.admin-search:focus { border-color: var(--accent); }
.admin-check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
}
.admin-check-label input { cursor: pointer; }

/* Table */
.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.admin-table thead {
  background: var(--bg3);
}
.admin-table th {
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text2);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.admin-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: rgba(255,255,255,0.02); }

/* Action group (multiple buttons in one cell) */
.action-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Extra-small buttons */
.btn-xs {
  padding: 5px 10px;
  font-size: 0.78rem;
  border-radius: 6px;
  font-weight: 600;
  width: auto;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
}
.btn-danger:hover { background: #c94040; }
.btn-accent {
  background: var(--accent);
  color: #fff;
  border: none;
}
.btn-accent:hover { background: var(--accent-light); }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
  vertical-align: middle;
  margin-left: 4px;
}
.badge-admin { background: rgba(124,92,191,0.25); color: var(--accent-light); }
.badge-banned { background: rgba(224,82,82,0.2); color: var(--danger); }
.badge-deleted { background: rgba(100,100,100,0.2); color: var(--text3); }

/* Pagination */
.admin-pagination {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 8px 0;
}
.page-btn {
  min-width: 34px;
  height: 34px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-size: 0.85rem;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}
.page-btn:hover { background: var(--border); color: var(--text); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Responsive admin */
@media (max-width: 600px) {
  .admin-header { flex-direction: column; align-items: flex-start; }
  .admin-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .admin-tabs { width: 100%; }
  .admin-tab { flex: 1; text-align: center; padding: 8px 8px; font-size: 0.82rem; }
}

/* Admin page needs wider layout */
.admin-page ~ * { max-width: 100%; }
#main:has(.admin-page) { max-width: 1000px; }
