/* BAMF Sites — community template styles.css (plan D22/D28).
 *
 * Skool/Circle-quality: calm, information-dense, airy. Driven entirely by
 * the five brand custom properties on :root; every other colour is derived
 * with color-mix(). No boxes-within-boxes: rows are separated by hairlines
 * and tonal shifts on a continuous surface, not stacked bordered cards.
 * The composer is the one deliberate exception (an interactive utility panel).
 */

:root {
  --brand-primary: #111827;
  --brand-secondary: #4b5563;
  --brand-accent: #2563eb;
  --brand-bg: #ffffff;
  --brand-fg: #0b0f19;
  --font-heading: "Instrument Serif", Georgia, serif;
  --font-body: "Inter", system-ui, sans-serif;

  --tone-1: color-mix(in srgb, var(--brand-bg) 96%, var(--brand-fg) 4%);
  --tone-2: color-mix(in srgb, var(--brand-bg) 90%, var(--brand-primary) 10%);
  --tone-3: color-mix(in srgb, var(--brand-primary) 94%, black 6%);
  --hairline: color-mix(in srgb, var(--brand-fg) 12%, transparent);
  --hairline-strong: color-mix(in srgb, var(--brand-fg) 20%, transparent);
  --muted: color-mix(in srgb, var(--brand-fg) 62%, var(--brand-bg) 38%);
  --on-primary: color-mix(in srgb, var(--brand-bg) 96%, white 4%);
  --accent-soft: color-mix(in srgb, var(--brand-accent) 14%, var(--brand-bg) 86%);
  --accent-soft-strong: color-mix(in srgb, var(--brand-accent) 24%, var(--brand-bg) 76%);
  --focus-ring: color-mix(in srgb, var(--brand-accent) 55%, transparent);
  --error: #b3261e;
  --error-soft: color-mix(in srgb, var(--error) 12%, var(--brand-bg) 88%);
  --shimmer-base: color-mix(in srgb, var(--brand-fg) 6%, var(--brand-bg) 94%);
  --shimmer-sheen: color-mix(in srgb, var(--brand-fg) 11%, var(--brand-bg) 89%);
}

* { box-sizing: border-box; }
html { scroll-behavior: auto; }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  margin: 0;
  background: var(--brand-bg);
  color: var(--brand-fg);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 0;
}

img { max-width: 100%; display: block; }
a { color: inherit; }
button { font: inherit; }

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 400;
  margin: 0;
  letter-spacing: -0.01em;
  color: var(--brand-primary);
}

p { margin: 0; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

/* ---------- buttons / links ---------- */

.text-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--brand-accent);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.35rem 0.2rem;
  cursor: pointer;
  border-radius: 6px;
}
.text-btn:hover { text-decoration: underline; }
.text-btn:disabled { opacity: 0.55; cursor: default; text-decoration: none; }

.submit-btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  background: var(--brand-primary);
  color: var(--on-primary);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.75rem 1.3rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease;
  min-height: 44px;
}
.submit-btn:hover { opacity: 0.9; }
.submit-btn:disabled { opacity: 0.6; cursor: progress; }

a:focus-visible,
button:focus-visible,
.load-more-btn:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--brand-bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.site-header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0.85rem clamp(1rem, 3vw, 2rem);
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.wordmark-link {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--brand-fg);
  flex: none;
}
.brand-logo { height: 26px; width: auto; }
.brand-wordmark {
  font-family: var(--font-heading);
  font-size: 1.1rem;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}
.site-nav a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
}
.site-nav a:hover { color: var(--brand-fg); background: var(--tone-1); }
.site-nav a[aria-current="page"] { color: var(--brand-primary); background: var(--accent-soft); }
.site-nav .nav-icon { display: none; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: none;
}

.account-area { display: flex; align-items: center; }
.account-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.account-name {
  font-size: 0.88rem;
  font-weight: 600;
  max-width: 9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-signin {
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--brand-accent);
}

/* ---------- main region ---------- */

.view-region {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(1.5rem, 4vw, 2.5rem) clamp(1rem, 4vw, 1.5rem) 5rem;
}
.view-members .view-region,
.view-resources .view-region { max-width: 900px; }

.view-heading {
  font-size: clamp(1.6rem, 1vw + 1.3rem, 2.1rem);
  margin-bottom: 1.5rem;
}

/* ---------- avatars / chips ---------- */

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
}
.avatar.monogram {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-primary);
  color: var(--on-primary);
  font-weight: 600;
  font-size: 0.95rem;
}

.role-chip {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  margin-left: 0.45rem;
  background: var(--accent-soft);
  color: var(--brand-accent);
}
.role-chip.role-owner { background: var(--accent-soft-strong); }

.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.6rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--brand-accent);
  font-size: 0.76rem;
  font-weight: 600;
}

/* ---------- space header (feed) ---------- */

.space-header { padding-bottom: 1.5rem; border-bottom: 1px solid var(--hairline); margin-bottom: 1.5rem; }
.space-name { font-size: clamp(1.8rem, 1.4vw + 1.4rem, 2.4rem); }
.space-promise { margin-top: 0.6rem; color: var(--muted); font-size: 1.02rem; max-width: 52ch; }
.space-stats { margin-top: 0.9rem; display: flex; gap: 0.6rem; align-items: center; color: var(--muted); font-size: 0.88rem; }
.stat { font-weight: 600; color: var(--brand-fg); }
.stat-divider { color: var(--muted); }

/* ---------- composer (allowed bordered surface) ---------- */

.composer {
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  background: var(--tone-1);
  margin-bottom: 1.75rem;
}
.composer-comment { margin: 1.25rem 0; }

.composer .field {
  border: none;
  padding: 0;
  background: transparent;
}
.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 4rem;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 0.98rem;
  color: var(--brand-fg);
  padding: 0.3rem 0;
}
.composer textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.9rem;
  margin-top: 0.5rem;
}
.composer-error { color: var(--error); font-size: 0.85rem; margin-right: auto; }
.composer .submit-btn { padding: 0.6rem 1.2rem; min-height: 40px; }

.signin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 1.25rem;
  color: var(--muted);
  font-size: 0.92rem;
}
.signin-link { color: var(--brand-accent); font-weight: 600; text-decoration: none; }
.signin-link:hover { text-decoration: underline; }

.signin-prompt {
  padding: 3rem 0;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
}

/* ---------- generic field (join forms, search) ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  background: var(--tone-1);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field:focus-within {
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.field label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.field input {
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 1rem;
  color: var(--brand-fg);
  padding: 0.15rem 0;
  width: 100%;
}
.field input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }

/* ---------- post / comment rows ---------- */

.post-list, .comment-list { display: flex; flex-direction: column; }

.post-row, .comment-row {
  padding: 1.4rem 0;
  border-bottom: 1px solid var(--hairline);
}
.comment-row { padding: 1.1rem 0; }
.post-list .post-row:first-child { padding-top: 0; }

.row-head { display: flex; align-items: flex-start; gap: 0.75rem; margin-bottom: 0.7rem; }
.row-meta { display: flex; flex-direction: column; gap: 0.1rem; }
.row-author-line { display: flex; align-items: center; }
.author-name { font-weight: 600; font-size: 0.94rem; }
.row-time { color: var(--muted); font-size: 0.8rem; }

.post-title { font-size: 1.2rem; margin-bottom: 0.4rem; }
.post-body, .comment-body {
  font-family: var(--font-body);
  font-size: 0.98rem;
  color: var(--brand-fg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-top: 0.9rem;
}

.like-btn, .comment-link, .comment-count-static {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  background: transparent;
  border: none;
  padding: 0.4rem 0.5rem;
  margin: -0.4rem -0.5rem;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}
.like-btn:hover, .comment-link:hover { background: var(--tone-1); color: var(--brand-fg); }
.like-btn.is-liked { color: #d6336c; }
.like-btn:disabled { cursor: progress; opacity: 0.75; }

.back-link {
  display: inline-block;
  margin-bottom: 1.5rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.back-link:hover { color: var(--brand-fg); }

.comments-heading { margin: 2rem 0 0.5rem; font-size: 1.15rem; font-family: var(--font-body); font-weight: 600; }

/* ---------- members grid ---------- */

.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0;
}
.member-tile {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 0.25rem;
  border-bottom: 1px solid var(--hairline);
}
.member-info { min-width: 0; }
.member-name-line { display: flex; align-items: center; flex-wrap: wrap; }
.member-name { font-weight: 600; font-size: 0.95rem; }
.member-headline, .member-joined { color: var(--muted); font-size: 0.82rem; margin-top: 0.15rem; }

/* ---------- resources ---------- */

.search-field { max-width: 26rem; margin-bottom: 0.9rem; }
.search-field input[type="search"] { -webkit-appearance: none; appearance: none; }
.result-count { color: var(--muted); font-size: 0.85rem; margin-bottom: 1rem; }
.clear-search-btn { font-size: 0.85rem; padding: 0; }

.resource-list { display: flex; flex-direction: column; }
.resource-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 1rem 0.25rem;
  border-bottom: 1px solid var(--hairline);
  text-decoration: none;
  color: var(--brand-fg);
  border-radius: 8px;
}
.resource-row:hover { background: var(--tone-1); }
.resource-glyph {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--brand-accent);
}
.resource-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.resource-name { font-weight: 600; font-size: 0.96rem; }
.resource-desc { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resource-open { flex: none; color: var(--muted); font-size: 0.82rem; font-weight: 600; }

/* ---------- join view ---------- */

.view-join .view-region { max-width: 26rem; }
.join-invite {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
}
.join-invite .avatar { width: 32px; height: 32px; }
.join-sub { color: var(--muted); margin-top: 0.5rem; margin-bottom: 1.5rem; }
.join-form { display: flex; flex-direction: column; gap: 1rem; }
.join-form .submit-btn { width: 100%; }
.join-secondary-actions { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.form-error { color: var(--error); font-size: 0.85rem; }

/* ---------- guidelines dialog ---------- */

.guidelines-dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  max-width: min(30rem, 92vw);
  width: 100%;
  background: var(--brand-bg);
  color: var(--brand-fg);
  box-shadow: 0 20px 60px color-mix(in srgb, var(--brand-fg) 25%, transparent);
}
.guidelines-dialog::backdrop {
  background: color-mix(in srgb, var(--brand-fg) 45%, transparent);
}
.dialog-inner { padding: 1.5rem; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.9rem; }
.dialog-close {
  appearance: none;
  border: none;
  background: var(--tone-1);
  color: var(--brand-fg);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.dialog-close:hover { background: var(--tone-2); }
.dialog-body { color: var(--muted); white-space: pre-wrap; line-height: 1.6; }

@media (prefers-reduced-motion: no-preference) {
  .guidelines-dialog {
    transition: opacity 0.18s ease, transform 0.18s ease, overlay 0.18s ease allow-discrete, display 0.18s ease allow-discrete;
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  .guidelines-dialog[open] { opacity: 1; transform: none; }
  @starting-style {
    .guidelines-dialog[open] { opacity: 0; transform: translateY(8px) scale(0.98); }
  }
}

/* ---------- empty / error / loading states ---------- */

.empty-state, .error-state {
  padding: 3rem 0.5rem;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.empty-title, .error-title { font-weight: 600; color: var(--brand-fg); font-size: 1rem; }
.inline-error {
  color: var(--error);
  background: var(--error-soft);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.load-more-wrap { display: flex; justify-content: center; padding-top: 1rem; }
.load-more-btn {
  appearance: none;
  border: 1px solid var(--hairline-strong);
  background: transparent;
  color: var(--brand-fg);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.6rem 1.3rem;
  border-radius: 999px;
  cursor: pointer;
  min-height: 44px;
}
.load-more-btn:hover { background: var(--tone-1); }
.load-more-btn:disabled { opacity: 0.6; cursor: progress; }

/* ---------- skeleton shimmer ---------- */

.skeleton { display: flex; flex-direction: column; gap: 1rem; padding-top: 0.25rem; }
.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.skeleton-row {
  height: 4.5rem;
  border-radius: 12px;
  background: linear-gradient(100deg, var(--shimmer-base) 30%, var(--shimmer-sheen) 50%, var(--shimmer-base) 70%);
  background-size: 220% 100%;
}
@media (prefers-reduced-motion: no-preference) {
  .skeleton-row { animation: shimmer 1.5s ease-in-out infinite; }
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -20% 0; }
}

/* ---------- footer ---------- */

.site-footer {
  padding: 2rem clamp(1rem, 4vw, 2rem) 6.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ---------- mobile ---------- */

@media (max-width: 720px) {
  .site-header-inner { padding: 0.75rem 1rem; gap: 0.75rem; }
  .header-actions { gap: 0.6rem; }
  .guidelines-open { display: none; }
  .account-name { max-width: 5.5rem; }

  .site-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: color-mix(in srgb, var(--brand-bg) 96%, transparent);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--hairline);
    justify-content: space-around;
    padding: 0.4rem env(safe-area-inset-right) calc(0.4rem + env(safe-area-inset-bottom)) env(safe-area-inset-left);
  }
  .site-nav a {
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.68rem;
    min-width: 60px;
    min-height: 48px;
    justify-content: center;
  }
  .site-nav .nav-icon { display: block; width: 20px; height: 20px; }

  body { padding-bottom: 4.75rem; }
  .site-footer { padding-bottom: 5.5rem; }
}

@media (min-width: 721px) {
  .site-footer { padding-bottom: 2rem; }
}
