:root {
  --bg: #0d0d14;
  --bg-soft: #14141f;
  --card: #1a1a28;
  --card-2: #20202f;
  --border: #2a2a3d;
  --text: #f2f2f7;
  --text-dim: #9a9ab0;
  --text-mute: #6b6b82;
  --accent: #8b5cf6;
  --accent-2: #ec4899;
  --grad: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --like: #ec4899;
  --ok: #22c55e;
  --err: #ef4444;
  --radius: 18px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --nav-h: 64px;
  --top-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding-top: var(--top-h);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ---------- Topbar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--top-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; z-index: 50;
  background: rgba(13, 13, 20, 0.8);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.logo {
  font-size: 26px; font-weight: 800; letter-spacing: -0.5px;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.topbar-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-dim); background: transparent; border: none; cursor: pointer;
  transition: background .2s, color .2s, transform .15s;
}
.icon-btn:hover { background: var(--card); color: var(--text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn-sm {
  width: 32px; height: 32px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-mute); background: transparent; border: none; cursor: pointer;
  transition: background .2s, color .2s;
}
.icon-btn-sm:hover { background: var(--card-2); color: var(--err); }

.badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--grad); color: #fff;
  font-size: 11px; font-weight: 700; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}

/* ---------- Avatars ---------- */
.avatar-sm, .avatar-md, .avatar-lg {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--card-2); color: var(--text-dim); font-weight: 700;
}
.avatar-sm { width: 34px; height: 34px; font-size: 15px; }
.avatar-md { width: 42px; height: 42px; font-size: 18px; }
.avatar-lg { width: 96px; height: 96px; font-size: 40px; }
.avatar-sm img, .avatar-md img, .avatar-lg img { width: 100%; height: 100%; object-fit: cover; }
.avatar-fallback {
  background: var(--grad); color: #fff;
}

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

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: cardIn .45s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Feed ---------- */
.feed { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; }

.composer {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  transition: transform .15s, border-color .2s;
}
.composer:hover { border-color: var(--accent); }
.composer:active { transform: scale(.99); }
.composer-ph { color: var(--text-mute); font-size: 15px; }

.post-card { padding: 14px 16px; }
.post-head { display: flex; align-items: center; gap: 10px; }
.post-author { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.post-author-name { font-weight: 700; font-size: 15px; }
.post-time { color: var(--text-mute); font-size: 13px; white-space: nowrap; }
.post-del { margin-left: auto; }

.post-content { margin-top: 12px; font-size: 15px; white-space: pre-wrap; word-wrap: break-word; }
.post-media { display: block; margin-top: 12px; border-radius: 14px; overflow: hidden; }
.post-media img { width: 100%; max-height: 480px; object-fit: cover; }

.post-actions { display: flex; align-items: center; gap: 20px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.action-btn {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--text-dim); background: none; border: none; cursor: pointer;
  font-size: 15px; font-weight: 600; padding: 4px;
  transition: color .2s, transform .15s;
}
.action-btn:hover { color: var(--text); }
.like-btn.liked { color: var(--like); }
.like-btn.liked svg { animation: pop .4s cubic-bezier(.22, 1.6, .36, 1); }
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
.like-btn:active { transform: scale(.9); }

/* ---------- Detail / comments ---------- */
.detail-wrap { display: flex; flex-direction: column; gap: 16px; }
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-dim); font-weight: 600; font-size: 15px;
  transition: color .2s;
}
.back-link:hover { color: var(--text); }

.comments-card { padding: 16px; }
.section-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.comments-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.comment { display: flex; flex-direction: column; gap: 2px; animation: cardIn .35s ease both; }
.comment-author { display: flex; align-items: center; gap: 8px; }
.comment-author-name { font-weight: 700; font-size: 14px; }
.comment-text { font-size: 14px; margin-left: 42px; word-wrap: break-word; }
.comment-time { font-size: 12px; color: var(--text-mute); margin-left: 42px; }

.comment-form { display: flex; gap: 8px; }
.comment-form input {
  flex: 1; background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 22px; padding: 10px 16px; color: var(--text); font-size: 14px;
  outline: none; transition: border-color .2s;
}
.comment-form input:focus { border-color: var(--accent); }

/* ---------- Forms ---------- */
.form { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.field input, .field textarea, .field select {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; color: var(--text);
  font-size: 15px; font-family: inherit; outline: none;
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}
.field input[type="file"] { padding: 10px; }
.field input[type="file"]::file-selector-button {
  background: var(--card-2); color: var(--text); border: none;
  padding: 8px 14px; border-radius: 8px; margin-right: 12px; cursor: pointer;
  font-weight: 600;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: 12px; border: none; cursor: pointer;
  font-size: 15px; font-weight: 700; font-family: inherit;
  transition: transform .15s, opacity .2s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--grad); color: #fff; }
.btn-primary:hover { opacity: .92; }
.btn-ghost { background: var(--card-2); color: var(--text); }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--err); color: #fff; }
.btn-sm { padding: 9px 16px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; justify-content: flex-end; }

.alert { padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 500; }
.alert-err { background: rgba(239, 68, 68, 0.12); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }

/* ---------- Auth ---------- */
.auth-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 40px 0; }
.auth-logo {
  font-size: 52px; font-weight: 800; letter-spacing: -1px;
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.auth-sub { color: var(--text-dim); margin-bottom: 10px; }
.auth-alt { color: var(--text-dim); font-size: 14px; }
.auth-alt a { color: var(--accent); font-weight: 700; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center; padding: 50px 20px; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty-state h2 { color: var(--text); font-size: 20px; }
.empty-icon { color: var(--text-mute); margin-bottom: 6px; }
.empty-actions { display: flex; gap: 10px; margin-top: 10px; }

/* ---------- Profile ---------- */
.profile-wrap { display: flex; flex-direction: column; gap: 16px; }
.profile-head { padding: 24px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.profile-avatar { margin-bottom: 6px; }
.profile-name { font-size: 24px; font-weight: 800; }
.profile-bio { color: var(--text-dim); font-size: 15px; max-width: 400px; }
.profile-stats { display: flex; gap: 18px; font-size: 14px; color: var(--text-dim); margin: 6px 0; }
.profile-stats strong { color: var(--text); }
.avatar-preview { display: flex; justify-content: center; }

/* ---------- Ads ---------- */
.ads-wrap { display: flex; flex-direction: column; gap: 14px; }
.ads-head { display: flex; align-items: center; justify-content: space-between; }
.page-title { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }

.ads-search { display: flex; gap: 8px; }
.ads-search input {
  flex: 1; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 11px 14px; color: var(--text); font-size: 15px; outline: none;
  transition: border-color .2s;
}
.ads-search input:focus { border-color: var(--accent); }
.ads-search .icon-btn { background: var(--card); border: 1px solid var(--border); }

.cat-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.cat-chips::-webkit-scrollbar { display: none; }
.chip {
  white-space: nowrap; padding: 8px 16px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 14px; font-weight: 600;
  transition: all .2s;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active { background: var(--grad); color: #fff; border-color: transparent; }

.ads-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 480px) { .ads-grid { grid-template-columns: 1fr 1fr; } }

.ad-card { overflow: hidden; display: flex; flex-direction: column; transition: transform .18s, border-color .2s; }
.ad-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.ad-card.sold { opacity: .6; }
.ad-img { position: relative; aspect-ratio: 16/10; background: var(--card-2); overflow: hidden; }
.ad-img img { width: 100%; height: 100%; object-fit: cover; }
.ad-noimg {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--text-mute); font-size: 14px; font-weight: 600;
  background: var(--grad); opacity: .15;
}
.ad-sold-badge {
  position: absolute; top: 10px; left: 10px;
  background: var(--err); color: #fff; font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 8px;
}
.ad-body { padding: 12px 14px; }
.ad-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ad-price { font-size: 16px; font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
.ad-cat { font-size: 12px; color: var(--text-mute); }
.ad-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); }

.ad-detail { overflow: hidden; }
.ad-detail-img { position: relative; aspect-ratio: 16/10; background: var(--card-2); }
.ad-detail-img img { width: 100%; height: 100%; object-fit: cover; }
.ad-detail-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.ad-detail-title { font-size: 22px; font-weight: 800; }
.ad-detail-price { font-size: 24px; font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent; }
.ad-detail-desc { color: var(--text-dim); font-size: 15px; white-space: pre-wrap; }
.ad-contact {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-soft); border-radius: 12px; padding: 12px 14px;
}
.ad-seller { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; }
.card-inner { }

/* ---------- Notifications ---------- */
.notif-wrap { display: flex; flex-direction: column; gap: 14px; }
.notif-list { display: flex; flex-direction: column; gap: 10px; }
.notif-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; transition: border-color .2s, transform .15s; }
.notif-item:hover { border-color: var(--accent); transform: translateX(3px); }
.notif-text { flex: 1; font-size: 14px; color: var(--text-dim); }
.notif-text strong { color: var(--text); }
.notif-time { font-size: 12px; color: var(--text-mute); white-space: nowrap; }

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(13, 13, 20, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  z-index: 50;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--text-mute); font-size: 11px; font-weight: 600;
  padding: 6px 14px; border-radius: 12px;
  transition: color .2s, transform .15s;
}
.nav-item:hover { color: var(--text-dim); }
.nav-item.active { color: var(--accent); }
.nav-item:active { transform: scale(.92); }
.nav-create {
  width: 52px; height: 40px; border-radius: 14px;
  background: var(--grad); color: #fff !important;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
}
.nav-create:active { transform: scale(.92); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%) translateY(20px);
  padding: 12px 22px; border-radius: 24px;
  font-size: 14px; font-weight: 600; z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .3s;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.toast-ok { border-color: var(--ok); color: var(--ok); }
.toast-err { border-color: var(--err); color: var(--err); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.muted { color: var(--text-mute); font-size: 14px; }

/* ---------- Create wrap ---------- */
.create-wrap { display: flex; flex-direction: column; gap: 16px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
