/* ============================================================
   Community Forum — Global Styles
   Themes: light (default) | sepia | dark
   ============================================================ */

/* ── Theme variables ─────────────────────────────────────── */
:root {
  --bg:           #f0eeeb;
  --surface:      #ffffff;
  --surface-2:    #f5f4f1;
  --surface-3:    #ece9e4;
  --border:       #dedad4;
  --text:         #1a1714;
  --text-muted:   #6b6560;
  --text-faint:   #9e9892;
  --accent:       #b33a2e;
  --accent-hover: #8f2d23;
  --accent-bg:    #fdf2f1;
  --badge-bg:     #ede9e3;
  --badge-text:   #5a5046;
  --thread-line:  #d4cfc8;
  --amen-active:  #c0392b;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:    0 4px 12px rgba(0,0,0,.10);
  --radius:       10px;
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
}

[data-theme="sepia"] {
  --bg:           #f0e8d8;
  --surface:      #faf5eb;
  --surface-2:    #f2eada;
  --surface-3:    #e8dcc8;
  --border:       #d4c4a0;
  --text:         #2c1f0e;
  --text-muted:   #7a6445;
  --text-faint:   #a08860;
  --accent:       #8b4513;
  --accent-hover: #6b340f;
  --accent-bg:    #fdf7f0;
  --badge-bg:     #ead9c0;
  --badge-text:   #5a3d1a;
  --thread-line:  #c8ae88;
  --amen-active:  #8b4513;
  --shadow:       0 1px 3px rgba(60,30,0,.10);
  --shadow-md:    0 4px 12px rgba(60,30,0,.12);
}

[data-theme="dark"] {
  --bg:           #141414;
  --surface:      #1e1e1e;
  --surface-2:    #252525;
  --surface-3:    #2e2e2e;
  --border:       #333333;
  --text:         #e2e2e2;
  --text-muted:   #999999;
  --text-faint:   #666666;
  --accent:       #e05252;
  --accent-hover: #c84040;
  --accent-bg:    #2a1818;
  --badge-bg:     #2a2a2a;
  --badge-text:   #aaaaaa;
  --thread-line:  #3a3a3a;
  --amen-active:  #e05252;
  --shadow:       0 1px 3px rgba(0,0,0,.30);
  --shadow-md:    0 4px 12px rgba(0,0,0,.40);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background .25s, color .25s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button { cursor: pointer; font-family: inherit; }

/* ── Header ──────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.site-logo {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.site-logo:hover { text-decoration: none; opacity: .85; }

.header-spacer { flex: 1; }

.theme-toggle {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: 20px;
  padding: 3px;
}
.theme-btn {
  background: none;
  border: none;
  border-radius: 16px;
  padding: 4px 10px;
  font-size: .75rem;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.theme-btn.active, .theme-btn:hover {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-link {
  font-size: .875rem;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--accent); font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
  line-height: 1;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-3); }
.btn-ghost {
  background: none;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Layout ──────────────────────────────────────────────── */
.page-wrapper {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px;
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  align-items: start;
}
@media (max-width: 768px) {
  .page-wrapper { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

.main-content { min-width: 0; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar { position: sticky; top: 72px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.card-stat {
  display: flex;
  gap: 16px;
}
.stat-item {
  text-align: center;
}
.stat-value {
  display: block;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}
.stat-label {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
}

/* ── Page header ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}
.page-count {
  color: var(--text-muted);
  font-size: .9rem;
}
.header-spacer-flex { flex: 1; }

/* ── Sort bar ────────────────────────────────────────────── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.sort-label { font-size: .8rem; color: var(--text-muted); margin-right: 4px; }
.sort-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: .8rem;
  color: var(--text-muted);
  transition: all .15s;
}
.sort-btn.active, .sort-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Post card (flat view) ───────────────────────────────── */
.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.post-card:hover { border-color: var(--thread-line); }

.post-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}
.avatar-sm { width: 28px; height: 28px; font-size: .75rem; }

.post-meta {
  flex: 1;
  min-width: 0;
}
.post-author {
  font-weight: 600;
  font-size: .9rem;
  color: var(--text);
}
.post-time {
  font-size: .78rem;
  color: var(--text-faint);
  margin-left: 8px;
}
.badge {
  display: inline-block;
  font-size: .68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-left: 6px;
  background: var(--badge-bg);
  color: var(--badge-text);
}
.badge-topic-starter { background: var(--accent-bg); color: var(--accent); }
.badge-pending { background: #fef3cd; color: #856404; }

.reply-context {
  font-size: .78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.post-content {
  font-size: .925rem;
  color: var(--text);
  line-height: 1.65;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.post-content.truncated { /* JS applies overflow clamp */ }

.read-more {
  font-size: .8rem;
  color: var(--accent);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.post-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.action-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all .15s;
  cursor: pointer;
}
.action-btn:hover { background: var(--surface-2); color: var(--text); }
.action-btn.amen-btn.amened {
  background: var(--accent-bg);
  border-color: var(--amen-active);
  color: var(--amen-active);
  font-weight: 600;
}
.action-btn .count { font-weight: 600; }
.action-btn.report-btn:hover { border-color: #c0392b; color: #c0392b; }

.view-thread-link {
  margin-left: auto;
  font-size: .8rem;
  color: var(--accent);
  white-space: nowrap;
}

/* ── Thread view ─────────────────────────────────────────── */
.thread-root {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 22px 16px;
  margin-bottom: 4px;
  box-shadow: var(--shadow);
}

/* Thread connecting lines via CSS */
.replies-container {
  padding-left: 0;
}
.reply-group {
  display: flex;
  gap: 0;
  position: relative;
}
.thread-line-col {
  width: 36px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  position: relative;
  cursor: pointer;
}
.thread-line-col::before {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--thread-line);
  border-radius: 1px;
  transition: background .15s;
}
.thread-line-col:hover::before { background: var(--accent); }
.reply-group.collapsed > .thread-line-col::before { background: var(--border); }

.reply-children {
  flex: 1;
  min-width: 0;
}
.reply-children.collapsed { display: none; }

.thread-comment {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 10px;
  margin-bottom: 4px;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.thread-comment:hover { border-color: var(--thread-line); }
.thread-comment.pending-post {
  border-style: dashed;
  opacity: .75;
}

/* ── Reply form ──────────────────────────────────────────── */
.reply-form {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 6px 0 10px;
}
.reply-form textarea {
  width: 100%;
  min-height: 80px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: inherit;
  font-size: .9rem;
  color: var(--text);
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
.reply-form textarea:focus { border-color: var(--accent); }
.reply-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: flex-end;
}

/* ── New post form ───────────────────────────────────────── */
.new-post-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.new-post-box textarea {
  width: 100%;
  min-height: 72px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: .9rem;
  color: var(--text);
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
.new-post-box textarea:focus { border-color: var(--accent); }
.new-post-box textarea::placeholder { color: var(--text-faint); }
.new-post-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

/* ── Load more ───────────────────────────────────────────── */
.load-more-btn {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  cursor: pointer;
  margin-top: 12px;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.load-more-btn:hover { background: var(--surface-2); color: var(--text); }
.load-more-btn:disabled { opacity: .5; cursor: not-allowed; }
.chevron { display: inline-block; transition: transform .2s; }
.chevron.open { transform: rotate(180deg); }

/* ── Collapse toggle ─────────────────────────────────────── */
.collapse-btn {
  background: none;
  border: none;
  font-size: .75rem;
  color: var(--text-faint);
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  margin-left: auto;
}
.collapse-btn:hover { background: var(--surface-2); color: var(--text-muted); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
  animation: fadeIn .15s;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
  animation: slideUp .2s;
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}
.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}
.radio-group { display: flex; flex-direction: column; gap: 10px; }
.radio-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s;
}
.radio-option:hover { background: var(--surface-2); }
.radio-option input[type="radio"] { accent-color: var(--accent); }
.radio-option label { cursor: pointer; font-size: .9rem; color: var(--text); }

/* ── Auth page ───────────────────────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: var(--bg);
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}
.auth-logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
}
.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: .875rem;
  margin-bottom: 28px;
}

.auth-steps { position: relative; overflow: hidden; }
.auth-step {
  animation: slideIn .25s ease;
}
.auth-step.hidden { display: none; }

.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .95rem;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--accent); background: var(--surface); }
.form-input::placeholder { color: var(--text-faint); }

.code-input {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: .5rem;
  padding: 14px;
}

.form-hint { font-size: .78rem; color: var(--text-muted); margin-top: 4px; }

.form-error {
  font-size: .82rem;
  color: #c0392b;
  margin-top: 8px;
  padding: 8px 12px;
  background: #fdf2f1;
  border-radius: 6px;
  display: none;
}
.form-error.visible { display: block; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
}
.checkbox-row input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.checkbox-row label { font-size: .875rem; color: var(--text); cursor: pointer; }

.step-indicator {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}
.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background .2s;
}
.step-dot.active { background: var(--accent); }
.step-dot.done { background: var(--text-muted); }

/* ── Notification toast ──────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  box-shadow: var(--shadow-md);
  font-size: .875rem;
  color: var(--text);
  animation: slideUpFade .3s ease;
  pointer-events: all;
  max-width: 320px;
}
.toast.success { border-left: 3px solid #27ae60; }
.toast.error   { border-left: 3px solid #c0392b; }
.toast.info    { border-left: 3px solid var(--accent); }

/* ── Loading ─────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
.loading-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes slideUpFade {
  from { transform: translateY(10px); opacity: 0 }
  to   { transform: none; opacity: 1 }
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ── Misc ────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-small { font-size: .8rem; }
.mt-8  { margin-top:  8px; }
.mt-16 { margin-top: 16px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state p { margin-top: 8px; font-size: .9rem; }
