/* ═══════════════════════════════════════════════════════════
   Underjoy — Enterprise Design System
   Font: Inter (system-grade, widely trusted)
   Mobile-first, Facebook-style compact layout
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --accent:        #1877f2;
  --accent-dim:    rgba(24,119,242,.10);
  --accent-h:      #1665d8;
  --like:          #e41e3f;
  --online:        #31a24c;
  --offline:       #dc2626;
  --pending:       #f59e0b;

  --font:          'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-display:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --radius-xs:  4px;
  --radius-sm:  6px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-pill:9999px;

  --shadow-sm:    0 1px 2px rgba(0,0,0,.08);
  --shadow-card:  0 1px 3px rgba(0,0,0,.10), 0 1px 8px rgba(0,0,0,.06);
  --shadow-modal: 0 4px 24px rgba(0,0,0,.15);

  --t-fast: 120ms ease;
  --t-med:  220ms ease;
  --header-h: 56px;
  --bottom-nav-h: 56px;
}

/* ── Light theme ─────────────────────────────────────────── */
body {
  --bg:          #f0f2f5;
  --surface:     #ffffff;
  --elevated:    #f7f8fa;
  --hover:       #f0f2f5;
  --border:      #dde1e7;
  --border-hi:   #c8cdd5;
  --text:        #1c1e21;
  --text2:       #65676b;
  --text3:       #8a8d91;
  --header-bg:   #ffffff;
  --modal-overlay: rgba(0,0,0,.55);
}
body.dark {
  --bg:          #18191a;
  --surface:     #242526;
  --elevated:    #3a3b3c;
  --hover:       #3a3b3c;
  --border:      #3e4042;
  --border-hi:   #4e4f50;
  --text:        #e4e6eb;
  --text2:       #b0b3b8;
  --text3:       #8a8d91;
  --header-bg:   #242526;
  --modal-overlay: rgba(0,0,0,.70);
  --accent:      #2d88ff;
  --accent-dim:  rgba(45,136,255,.12);
}

html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text);
       line-height: 1.5; min-height: 100dvh; font-weight: 400; }
img  { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
a  { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
.hidden { display: none !important; }
::selection { background: var(--accent); color: #fff; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 3px; }

/* ── Header ──────────────────────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 200;
  height: var(--header-h);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.header-inner {
  display: flex; align-items: center; gap: 8px;
  max-width: 1100px; margin: 0 auto;
  padding: 0 16px; height: 100%;
}
.wordmark {
  font-size: 1.375rem; font-weight: 700;
  color: var(--accent); letter-spacing: -0.5px;
  white-space: nowrap; flex-shrink: 0;
  font-family: var(--font);
}
.header-nav {
  display: flex; align-items: center; gap: 2px;
  flex: 1; justify-content: center;
}
.nav-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-md);
  font-size: .875rem; font-weight: 500; color: var(--text2);
  transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}
.nav-btn:hover  { background: var(--hover); color: var(--text); }
.nav-btn.active { color: var(--accent); background: var(--accent-dim); }
.header-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* Icon button */
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  color: var(--text2); transition: background var(--t-fast), color var(--t-fast);
  position: relative; flex-shrink: 0;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* User pill */
.user-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 4px;
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}
.user-pill-av {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 600; overflow: hidden; flex-shrink: 0;
}
.user-pill-av img { width: 100%; height: 100%; object-fit: cover; }
.user-pill-name { font-size: .8125rem; font-weight: 500; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill-btn { color: var(--text3); display: flex; padding: 2px; border-radius: 4px; transition: color var(--t-fast); }
.pill-btn:hover { color: var(--like); }

/* Compose button */
.btn-compose {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 16px; background: var(--accent); color: #fff;
  border-radius: var(--radius-md); font-size: .8125rem; font-weight: 600;
  transition: background var(--t-fast), transform var(--t-fast);
}
.btn-compose:hover { background: var(--accent-h); }

/* Offline banner */
.offline-banner {
  display: none; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 16px; background: rgba(220,38,38,.08);
  border-bottom: 1px solid rgba(220,38,38,.2);
  color: var(--offline); font-size: .8125rem;
}
.offline-banner.show { display: flex; }

/* ── Layout ──────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 590px) 240px;
  grid-template-areas: "left feed right";
  gap: 16px;
  max-width: 1100px; margin: 0 auto;
  padding: 16px; align-items: start;
}
.sidebar { position: sticky; top: calc(var(--header-h) + 12px); display: flex; flex-direction: column; gap: 12px; }
.sidebar-left  { grid-area: left; }
.sidebar-right { grid-area: right; }
.feed-col      { grid-area: feed; display: flex; flex-direction: column; gap: 12px; }

/* ── Sidebar cards ───────────────────────────────────────── */
.sidebar-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow-sm);
}
.sidebar-heading {
  font-size: .6875rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 12px;
}
.topic-list { display: flex; flex-direction: column; gap: 2px; }
.topic-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 8px; border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--t-fast); font-size: .875rem;
}
.topic-item:hover { background: var(--hover); }
.topic-tag  { font-weight: 500; color: var(--accent); }
.topic-count{ font-size: .75rem; color: var(--text3); }

/* ── Feed loading / empty ────────────────────────────────── */
.feed-loading {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; padding: 48px 16px;
  color: var(--text3); font-size: .875rem;
}
.spinner {
  width: 24px; height: 24px; border: 2.5px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.feed-empty {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 10px; padding: 48px 16px; color: var(--text3);
}
.feed-empty svg { opacity: .3; }
.feed-empty h3 { font-size: .9375rem; color: var(--text2); font-weight: 600; }
.feed-empty p  { font-size: .875rem; }

/* ── Post cards ──────────────────────────────────────────── */
.post-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-sm);
  animation: fadeUp 200ms ease both;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.post-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; }
.post-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 600; border: 1px solid var(--border);
  overflow: hidden;
}
.post-avatar img { width: 100%; height: 100%; object-fit: cover; }
.post-meta { flex: 1; min-width: 0; }
.post-author { display: block; font-weight: 600; font-size: .9375rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.post-time   { display: block; font-size: .75rem; color: var(--text3); margin-top: 1px; }
.verified-badge { color: var(--accent); display: inline-flex; vertical-align: -2px; margin-left: 3px; }

.post-body { padding: 0 16px 12px; }
.post-content {
  font-size: .9375rem; line-height: 1.55; color: var(--text);
  word-break: break-word; white-space: pre-wrap;
  margin-bottom: 10px;
}
/* FIX: image shows full — no cropping */
.post-image-wrap {
  margin: 0 -16px;
  background: var(--bg);
  max-height: 520px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.post-image {
  width: 100%;
  max-height: 520px;
  object-fit: contain;   /* show full image, no cropping */
  cursor: zoom-in;
  display: block;
}

.post-footer {
  display: flex; align-items: center; gap: 2px;
  padding: 6px 10px 10px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.action-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: .8125rem; font-weight: 500; color: var(--text2);
  transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
}
.action-btn:hover { background: var(--hover); color: var(--text); }
.like-btn.liked { color: var(--like); }
.view-meta { display: flex; align-items: center; gap: 4px; font-size: .75rem; color: var(--text3); }

/* Ad card */
.ad-card { }
.ad-label { font-size: .6875rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text3); padding: 12px 16px 6px; }
.ad-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 24px 16px; color: var(--text3); font-size: .8125rem; text-align: center;
  border: 1px dashed var(--border-hi); border-radius: var(--radius-sm); margin: 0 16px 16px;
  min-height: 100px;
}
.ad-placeholder small { font-size: .75rem; opacity: .7; }

/* ── Compose modal ───────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 300; background: var(--modal-overlay);
  display: flex; align-items: flex-start; justify-content: center;
  padding: calc(var(--header-h) + 32px) 16px 16px;
  opacity: 0; pointer-events: none; transition: opacity var(--t-med);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); width: 100%; max-width: 540px;
  box-shadow: var(--shadow-modal); transform: translateY(-8px);
  transition: transform var(--t-med); overflow: hidden;
}
.modal-overlay.open .modal-card { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: .9375rem; font-weight: 700; }
.modal-close {
  padding: 6px; border-radius: 50%; color: var(--text3);
  transition: background var(--t-fast), color var(--t-fast);
}
.modal-close:hover { background: var(--hover); color: var(--text); }
.composer-body { display: flex; gap: 12px; padding: 16px 20px; }
.composer-av {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 600; overflow: hidden;
}
.composer-av img { width: 100%; height: 100%; object-fit: cover; }
.composer-fields { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.textarea-field {
  width: 100%; background: var(--elevated); border: 1px solid var(--border);
  border-radius: var(--radius-md); color: var(--text); font-family: var(--font);
  font-size: .9375rem; padding: 10px 12px; outline: none; resize: none;
  transition: border-color var(--t-fast); line-height: 1.5;
}
.textarea-field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.textarea-field::placeholder { color: var(--text3); }
.image-attach-row { display: flex; align-items: center; gap: 8px; }
.btn-attach {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-md); font-size: .8125rem; font-weight: 500;
  color: var(--text2); cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.btn-attach:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.image-preview-wrap { border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); }
.composer-footer { display: flex; align-items: center; justify-content: space-between; }
.char-counter { font-size: .75rem; color: var(--text3); }
.char-counter.warn { color: var(--pending); }
.char-counter.over { color: var(--like); }
.btn-submit {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 20px; background: var(--accent); color: #fff;
  border-radius: var(--radius-md); font-size: .8125rem; font-weight: 600;
  transition: background var(--t-fast);
}
.btn-submit:hover { background: var(--accent-h); }
.btn-submit:disabled { opacity: .45; pointer-events: none; }

/* ── Comments ────────────────────────────────────────────── */
.comments-section { border-top: 1px solid var(--border); padding: 12px 16px 14px; }
.comment-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.comment-item { display: flex; gap: 8px; }
.comment-av {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .65rem; font-weight: 600; overflow: hidden; border: 1px solid var(--border);
}
.comment-av img { width: 100%; height: 100%; object-fit: cover; }
.comment-body { flex: 1; min-width: 0; }
.comment-bubble {
  background: var(--elevated); border-radius: 0 var(--radius-lg) var(--radius-lg) var(--radius-lg);
  padding: 8px 12px; display: inline-block; max-width: 100%;
}
.comment-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.comment-author { font-size: .8125rem; font-weight: 600; }
.comment-time   { font-size: .6875rem; color: var(--text3); }
.comment-content { font-size: .875rem; line-height: 1.5; color: var(--text); word-break: break-word; white-space: pre-wrap; }
.comment-actions { display: flex; gap: 4px; margin-top: 5px; }
.c-vote-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: var(--radius-sm);
  font-size: .75rem; font-weight: 500; color: var(--text3);
  transition: background var(--t-fast), color var(--t-fast);
  cursor: pointer; font-family: inherit; background: none; border: none;
}
.c-vote-btn:hover { background: var(--hover); color: var(--text2); }
.c-vote-btn.active-like    { color: var(--accent); }
.c-vote-btn.active-dislike { color: var(--like); }
.comment-input-wrap { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.comment-ta {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 8px 14px; font-family: var(--font); font-size: .875rem;
  resize: none; outline: none; background: var(--elevated); color: var(--text);
  transition: border-color var(--t-fast); min-height: 36px; line-height: 1.4;
}
.comment-ta:focus { border-color: var(--accent); }
.comment-ta::placeholder { color: var(--text3); }
.comment-submit-row { display: flex; justify-content: flex-end; align-items: center; margin-top: 6px; gap: 8px; }
.comment-char-left { font-size: .7rem; color: var(--text3); }
.comment-submit-btn {
  padding: 5px 14px; background: var(--accent); color: #fff;
  border-radius: var(--radius-md); font-size: .8125rem; font-weight: 600;
  border: none; cursor: pointer; transition: background var(--t-fast);
}
.comment-submit-btn:hover { background: var(--accent-h); }
.comment-submit-btn:disabled { opacity: .45; pointer-events: none; }

/* @mention dropdown */
.mention-dropdown {
  position: absolute; bottom: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border-hi);
  border-radius: var(--radius-md); box-shadow: var(--shadow-modal);
  z-index: 200; overflow: hidden;
}
.mention-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; transition: background var(--t-fast); }
.mention-item:hover { background: var(--hover); }
.mention-av {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .6rem; font-weight: 600; overflow: hidden; flex-shrink: 0;
}
.mention-av img { width: 100%; height: 100%; object-fit: cover; }
.mention-name { display: block; font-size: .8125rem; font-weight: 500; }
.mention-un   { display: block; font-size: .7rem; color: var(--text3); }

/* ── Notifications ───────────────────────────────────────── */
.notif-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background var(--t-fast); font-size: .875rem;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--hover); }
.notif-item.unread { background: var(--accent-dim); }
.notif-av {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent-dim); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 600; overflow: hidden; flex-shrink: 0;
}
.notif-av img { width: 100%; height: 100%; object-fit: cover; }
.notif-body { flex: 1; min-width: 0; line-height: 1.4; }
.notif-actor { font-weight: 600; }
.notif-time  { font-size: .6875rem; color: var(--text3); margin-top: 2px; }

/* ── Toasts ──────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 500;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); font-size: .875rem; font-weight: 500;
  box-shadow: var(--shadow-card); pointer-events: all; max-width: 300px;
  animation: toastIn 220ms ease both;
}
.toast::before { content: ''; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.toast.success::before { background: var(--online); }
.toast.error::before   { background: var(--like); }
.toast.info::before    { background: var(--accent); }
@keyframes toastIn  { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(12px); } }
.toast.removing { animation: toastOut 180ms ease forwards; }

/* ── Lightbox ────────────────────────────────────────────── */
.lightbox {
  position: fixed; inset: 0; z-index: 600;
  background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox img { max-width: 96vw; max-height: 96vh; object-fit: contain; border-radius: var(--radius-md); }
.lightbox-close { position: absolute; top: 14px; right: 18px; color: #fff; font-size: 2rem; opacity: .75; }
.lightbox-close:hover { opacity: 1; }

/* ── Bottom mobile nav ───────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  height: var(--bottom-nav-h);
  background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -1px 4px rgba(0,0,0,.08);
}
.bottom-nav-inner {
  display: flex; height: 100%;
}
.bottom-nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; color: var(--text3);
  font-size: .65rem; font-weight: 500; transition: color var(--t-fast);
  position: relative;
}
.bottom-nav-btn.active { color: var(--accent); }
.bottom-nav-btn svg { width: 22px; height: 22px; }

/* ═══ RESPONSIVE ═════════════════════════════════════════ */

/* Tablet — hide right sidebar */
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 200px minmax(0, 1fr);
    grid-template-areas: "left feed";
    padding: 12px;
    gap: 12px;
  }
  .sidebar-right { display: none; }
}

/* Mobile — single column, bottom nav */
@media (max-width: 680px) {
  :root { --header-h: 50px; }
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas: "feed";
    padding: 8px 0;
    gap: 8px;
    padding-bottom: calc(var(--bottom-nav-h) + 8px);
  }
  .sidebar-left  { display: none; }
  .sidebar-right { display: none; }

  /* Full-width cards on mobile */
  .post-card { border-radius: 0; border-left: none; border-right: none; }
  .post-image-wrap { margin: 0; }

  /* Hide desktop nav, show bottom nav */
  .header-nav { display: none; }
  .bottom-nav { display: block; }

  /* Compact header */
  .header-inner { padding: 0 12px; }
  .user-pill-name { display: none; }
  .btn-compose span { display: none; }
  .btn-compose { padding: 7px; border-radius: 50%; }

  /* Toast full-width */
  .toast-container { bottom: calc(var(--bottom-nav-h) + 12px); right: 12px; left: 12px; }
  .toast { max-width: 100%; }

  /* Modal adjustments */
  .modal-overlay { padding: calc(var(--header-h) + 8px) 0 0; align-items: flex-end; }
  .modal-card { border-radius: var(--radius-xl) var(--radius-xl) 0 0; max-width: 100%; }
}

/* Very small phones */
@media (max-width: 390px) {
  .wordmark { font-size: 1.125rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
