/* app.css — Commune app shell and component styles */

/* ── App shell ─────────────────────────────────────────────────────────── */
.app-body {
  background: var(--bg);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 72px 16px 40px;
}

/* ── Nav ────────────────────────────────────────────────────────────────── */
.app-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(10, 10, 12, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
}

.app-nav-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.nav-logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 20px;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: -0.03em;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover { color: var(--fg); background: rgba(255,255,255,0.04); }

.nav-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.nav-avatar-placeholder {
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--accent);
  color: #0a0a0c;
  border: none;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  padding: 10px 20px;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.btn:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-sm {
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 6px;
}

.btn-ghost {
  background: transparent;
  color: var(--fg-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--fg); border-color: rgba(255,255,255,0.2); background: rgba(255,255,255,0.04); }

.btn-full { width: 100%; }

/* ── Auth pages ─────────────────────────────────────────────────────────── */
.auth-body {
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.auth-page {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
}

.auth-logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: -0.03em;
  display: block;
  margin-bottom: 32px;
}

.auth-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.auth-sub {
  color: var(--fg-muted);
  font-size: 15px;
  margin-bottom: 32px;
}

.auth-error {
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--negative);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  margin-bottom: 20px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-hint {
  font-weight: 400;
  color: var(--fg-muted);
  opacity: 0.7;
}

.form-field input,
.form-field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 10px 14px;
  transition: border-color 0.15s;
  outline: none;
  -webkit-appearance: none;
}

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

.form-field textarea {
  resize: vertical;
  min-height: 80px;
}

.form-error {
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  color: var(--negative);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
}

.auth-switch {
  text-align: center;
  color: var(--fg-muted);
  font-size: 14px;
  margin-top: 20px;
}

.auth-switch a {
  color: var(--accent);
  text-decoration: none;
}

/* ── Compose card ───────────────────────────────────────────────────────── */
.compose-card {
  display: flex;
  gap: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.compose-avatar-wrap { flex-shrink: 0; }

.compose-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.compose-avatar-placeholder {
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}

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

.compose-textarea {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  outline: none;
  resize: none;
  padding: 0;
  -webkit-appearance: none;
}

.compose-textarea::placeholder { color: var(--fg-muted); }

.compose-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.compose-img-btn {
  color: var(--fg-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.compose-img-btn:hover { color: var(--accent); }

.compose-char-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--fg-muted);
}

.compose-preview {
  margin-top: 10px;
  position: relative;
  display: flex;
  width: fit-content;
}

.compose-preview img {
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.compose-preview-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Algorithm panel ────────────────────────────────────────────────────── */
.algo-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.algo-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.algo-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg-muted);
}

.algo-panel-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.algo-panel-toggle:hover { background: var(--accent-dim); }

#algo-controls { margin-top: 16px; }

.algo-explanation {
  font-size: 13px;
  color: var(--fg-muted);
  margin-bottom: 16px;
}

.algo-slider-row {
  margin-bottom: 16px;
}

.algo-slider-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.algo-why {
  font-weight: 400;
  color: var(--fg-muted);
  font-size: 12px;
}

.slider-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.algo-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.algo-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

.algo-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.slider-val {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  min-width: 40px;
  text-align: right;
}

.algo-toggle-row { margin-bottom: 16px; }

.toggle-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--fg);
}

.toggle-label input[type="checkbox"] { display: none; }

.toggle-track {
  width: 40px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-track::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--fg-muted);
  top: 3px;
  left: 3px;
  transition: transform 0.2s, background 0.2s;
}

.toggle-label input:checked + .toggle-track {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
}

.toggle-label input:checked + .toggle-track::after {
  transform: translateX(18px);
  background: var(--accent);
}

.algo-saved-msg {
  font-size: 13px;
  color: var(--accent);
  text-align: center;
  margin-top: 8px;
}

/* ── Feed / posts ───────────────────────────────────────────────────────── */
.feed-layout { display: flex; flex-direction: column; }

.feed-container { display: flex; flex-direction: column; gap: 12px; }

.feed-loading,
.feed-empty,
.feed-error {
  padding: 40px 24px;
  text-align: center;
  color: var(--fg-muted);
  font-size: 15px;
  line-height: 1.7;
}

.post-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  transition: border-color 0.15s;
}

.post-card:hover { border-color: rgba(255,255,255,0.12); }

.post-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.post-author-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.post-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.post-avatar-placeholder {
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.post-author-info { display: flex; flex-direction: column; }

.post-display-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.post-username {
  font-size: 13px;
  color: var(--fg-muted);
}

.post-time {
  font-size: 12px;
  color: var(--fg-muted);
  flex-shrink: 0;
}

.post-content {
  font-size: 15px;
  line-height: 1.65;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 12px;
}

.post-image-wrap { margin-bottom: 12px; }

.post-image {
  width: 100%;
  max-height: 400px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

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

.post-like-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.post-like-btn:hover { color: #ff6b8a; background: rgba(255, 107, 138, 0.08); }
.post-like-btn.liked { color: #ff6b8a; }

.post-delete-btn,
.post-why-btn {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.post-delete-btn:hover { color: var(--negative); }
.post-why-btn:hover { color: var(--accent); }

.post-why-tooltip {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.post-why {
  font-size: 12px;
  color: var(--fg-muted);
}

.post-why-label {
  font-weight: 600;
  color: var(--fg);
  margin-right: 4px;
}

/* ── Profile ────────────────────────────────────────────────────────────── */
.profile-layout { display: flex; flex-direction: column; gap: 16px; }

.profile-header-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.profile-avatar-wrap { flex-shrink: 0; }

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
}

.profile-avatar-placeholder {
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 28px;
}

.profile-meta { flex: 1; min-width: 0; }

.profile-names { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }

.profile-display-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.profile-username { color: var(--fg-muted); font-size: 15px; }

.profile-bio { color: var(--fg-muted); font-size: 14px; line-height: 1.6; margin-bottom: 12px; }

.profile-stats { display: flex; gap: 20px; font-size: 14px; color: var(--fg-muted); }

.profile-stats strong { color: var(--fg); }

.profile-actions { margin-left: auto; }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  padding: 32px;
  position: relative;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.modal-close:hover { color: var(--fg); }

/* ── Verified badge ─────────────────────────────────────────────────────── */
.verified-badge {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-left: 4px;
  flex-shrink: 0;
}

.verified-badge svg { display: block; }

.post-verified-badge {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Mobile tweaks ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .app-main { padding: 64px 12px 32px; }
  .auth-card { padding: 28px 20px; }
  .compose-card { padding: 12px; }
  .post-card { padding: 12px; }
  .profile-header-card { padding: 16px; }
}

/* ── Comment system ─────────────────────────────────────────────────────── */

/* Comment button on post card */
.post-comment-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  color: var(--fg-muted);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  transition: color 0.15s, background 0.15s;
}
.post-comment-btn:hover { color: var(--accent); background: var(--accent-dim); }

/* Comment panel — inline below post */
.comment-panel {
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 12px;
}

.comment-panel-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Comment list */
.comment-list { display: flex; flex-direction: column; gap: 0; }
.comment-loading, .comment-empty, .comment-error-inline {
  color: var(--fg-muted);
  font-size: 13px;
  padding: 8px 0;
}

/* Individual comment */
.comment-item {
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.comment-item:last-child { border-bottom: none; }

.comment-body-wrap {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.comment-avatar-link { flex-shrink: 0; }

.comment-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.comment-avatar-placeholder {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

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

.comment-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
  flex-wrap: wrap;
}
.comment-display-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.comment-time {
  font-size: 12px;
  color: var(--fg-muted);
}
.comment-text {
  font-size: 14px;
  color: var(--fg);
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.comment-actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.comment-like-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  min-height: 28px;
  transition: color 0.15s;
  font-family: var(--font-body);
}
.comment-like-btn:hover { color: var(--accent); }
.comment-like-btn.liked { color: var(--accent); }
.comment-like-count { min-width: 12px; }

.comment-reply-btn, .comment-delete-btn {
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  min-height: 28px;
  min-width: 44px;
  font-family: var(--font-body);
  transition: color 0.15s;
}
.comment-reply-btn:hover { color: var(--accent); }
.comment-delete-btn:hover { color: var(--negative); }

.comment-deleted {
  font-size: 13px;
  color: var(--fg-subtle, rgba(255,255,255,0.25));
  padding: 8px 0;
  font-style: italic;
}

/* Threaded replies — indented */
.comment-replies {
  margin-left: 38px;
  border-left: 2px solid var(--border);
  padding-left: 12px;
  margin-top: 4px;
}
.comment-reply { border-bottom: none; padding: 8px 0; }
.comment-reply:last-child { padding-bottom: 0; }

/* Reply indicator (above composer when replying to someone) */
.reply-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-muted);
  padding: 6px 8px;
  background: var(--accent-dim);
  border-radius: 6px;
  margin-bottom: 8px;
}
.reply-indicator strong { color: var(--accent); }
.reply-cancel {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  min-height: 28px;
}
.reply-cancel:hover { color: var(--fg); }

/* Comment composer */
.comment-composer {
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
.comment-input {
  width: 100%;
  background: var(--bg-elevated, rgba(255,255,255,0.04));
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 12px;
  resize: vertical;
  min-height: 60px;
  box-sizing: border-box;
  transition: border-color 0.15s;
}
.comment-input:focus {
  outline: none;
  border-color: var(--accent);
}
.comment-input::placeholder { color: var(--fg-muted); }

.comment-composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.comment-char-count {
  font-size: 12px;
  color: var(--fg-muted);
}

.comment-verified {
  display: inline-block;
  vertical-align: middle;
  margin-left: 2px;
}

/* Mobile: ensure tap targets ≥ 44px everywhere in comment panel */
@media (max-width: 480px) {
  .comment-panel { padding-top: 10px; }
  .comment-reply-btn, .comment-delete-btn { min-height: 44px; min-width: 44px; }
  .comment-like-btn { min-height: 44px; }
  .comment-input { font-size: 16px; } /* prevents iOS zoom on focus */
}

/* Touch-friendly tap targets */
button, a, input, [role="button"] {
  -webkit-tap-highlight-color: transparent;
}

html {
  touch-action: manipulation; /* disable double-tap zoom */
}
