/* Stitch Community v7
   The Community screens use the exact spatial system from the DLS Community
   Design System exports. This final layer intentionally wins over legacy
   dashboard styling while preserving the live, server-backed markup. */
:root {
  --community-primary: #003639;
  --community-primary-container: #004e53;
  --community-ink: #0f1c2e;
  --community-secondary: #575d78;
  --community-muted: #707979;
  --community-line: rgba(15, 28, 46, .08);
  --community-soft: #f4f6fb;
  --community-mobile-bg: #f9f9ff;
}

body:has(.community-app) {
  margin: 0;
  overflow-x: hidden;
  background: #fff !important;
  color: var(--community-ink);
  font-family: Inter, system-ui, sans-serif;
}

body:has(.community-app) > .dls-community-shell > .dls-sidebar {
  display: none !important;
}

body:has(.community-app) .dls-community-main,
body:has(.community-app) .dls-community-page {
  width: 100%;
  min-width: 0;
  margin: 0 !important;
  padding: 0 !important;
}

.community-app:not(.community-admin-app) {
  width: min(100%, 1440px);
  min-height: 100vh;
  margin-inline: auto;
  background: #fff;
}

.community-app:not(.community-admin-app) .community-topbar {
  position: fixed;
  z-index: 80;
  top: 0;
  right: 0 !important;
  left: 0 !important;
  width: min(100%, 1440px);
  margin-inline: auto !important;
  height: 64px;
  transform: none !important;
  display: grid;
  grid-template-columns: 280px minmax(320px, 576px) 1fr;
  align-items: center;
  gap: 32px;
  padding: 0 24px;
  border-bottom: 1px solid #f0f1f3;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(20px);
}

.community-app:not(.community-admin-app) .community-mobile-brand {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: auto;
  justify-self: start;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--community-primary);
  font: 800 28px/36px "Hanken Grotesk", sans-serif;
}

.community-app:not(.community-admin-app) .community-global-search {
  width: 100%;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: #f3f4f6;
  color: #667085;
  font-size: 14px;
}

.community-app:not(.community-admin-app) .community-top-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 12px;
}

.community-app:not(.community-admin-app) .community-button.primary {
  min-height: 40px;
  padding: 0 24px;
  border-radius: 999px;
  background: var(--community-primary);
  color: #fff;
  font-size: 14px;
}

.community-app:not(.community-admin-app) .community-layout {
  display: grid !important;
  grid-template-columns: 280px minmax(0, 760px) 380px;
  width: 1420px;
  max-width: 100%;
  min-height: 100vh;
  margin: 64px auto 0;
}

.community-app:not(.community-admin-app) .community-section-nav {
  position: sticky;
  top: 64px;
  align-self: start;
  display: flex !important;
  flex-direction: column;
  width: 280px;
  height: calc(100vh - 64px);
  padding: 20px 16px 32px;
  border-right: 1px solid #f0f1f3;
  background: #fff;
  overflow-y: auto;
}

.community-app:not(.community-admin-app) .community-network-brand {
  display: none !important;
}

.community-app:not(.community-admin-app) .community-view-button {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--community-secondary);
  font: 500 18px/24px Inter, sans-serif;
  text-align: left;
}

.community-app:not(.community-admin-app) .community-view-button:hover {
  background: #f6f7f8;
}

.community-app:not(.community-admin-app) .community-view-button.active {
  background: transparent;
  color: var(--community-primary);
  font-weight: 700;
}

.community-app:not(.community-admin-app) .community-view-button .community-icon {
  width: 24px;
  height: 24px;
}

.community-app:not(.community-admin-app) .community-rail-create {
  order: 8;
  width: calc(100% - 32px);
  min-height: 52px;
  margin: 22px 16px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--community-primary);
  color: #fff;
  font: 700 16px/20px Inter, sans-serif;
}

.community-app:not(.community-admin-app) .community-exit-link {
  order: 9;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 16px;
  padding-top: 24px;
  border-top: 1px solid #f0f1f3;
  color: var(--community-secondary);
  font-size: 14px;
  text-decoration: none;
}

.community-app:not(.community-admin-app) .community-content {
  width: 760px;
  max-width: 100%;
  min-width: 0;
  padding: 32px !important;
  border-right: 1px solid #f0f1f3;
  background: #fff;
}

.community-app:not(.community-admin-app) .community-right-rail {
  position: sticky;
  top: 64px;
  align-self: start;
  display: block !important;
  height: calc(100vh - 64px);
  padding: 32px 24px;
  overflow-y: auto;
  background: #fff;
}

.community-app:not(.community-admin-app) .timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 32px;
  padding: 0 8px;
  border: 0;
}

.community-app:not(.community-admin-app) .timeline-header strong {
  color: var(--community-primary);
  font: 800 36px/44px "Hanken Grotesk", sans-serif;
  letter-spacing: -.02em;
}

.community-app:not(.community-admin-app) .timeline-header small,
.community-app:not(.community-admin-app) .timeline-header > span {
  display: none;
}

.community-app:not(.community-admin-app) .mobile-feed-tabs,
.community-app:not(.community-admin-app) .quick-composer,
.community-app:not(.community-admin-app) .mobile-shorts-preview {
  display: none;
}

.community-app:not(.community-admin-app) .discoveries-strip {
  display: block;
  margin-bottom: 32px;
}

.community-app:not(.community-admin-app) .discoveries-heading {
  display: none;
}

.community-app:not(.community-admin-app) .community-mobile-stories {
  display: flex !important;
  gap: 16px;
  overflow-x: auto;
  padding: 0 0 8px;
}

.community-app:not(.community-admin-app) .mobile-story-item {
  flex: 0 0 136px;
  height: 224px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  padding: 12px;
  border: 0;
  border-radius: 16px;
  overflow: hidden;
  color: #fff;
  background:
    linear-gradient(to top, rgba(0, 0, 0, .72), rgba(0, 0, 0, .05)),
    linear-gradient(145deg, #114e52, #91d6d8);
  box-shadow: 0 2px 8px rgba(15, 28, 46, .08);
}

.community-app:not(.community-admin-app) .mobile-story-item span {
  position: absolute;
  align-self: flex-start;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 2px solid #b0edf3;
  border-radius: 50%;
  background: #fff;
  color: var(--community-primary);
  font-weight: 700;
}

.community-app:not(.community-admin-app) .mobile-story-item small {
  color: inherit;
  font-size: 12px;
  font-weight: 700;
}

.community-app:not(.community-admin-app) .mobile-story-item.add-story {
  background: linear-gradient(145deg, #eaf1f5, #cadfe3);
  color: var(--community-primary);
}

.community-app:not(.community-admin-app) .feed-list {
  display: grid;
  gap: 24px;
}

.community-app:not(.community-admin-app) .community-post {
  width: 100%;
  margin: 0;
  padding: 20px;
  border: 1px solid rgba(15, 28, 46, .06);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .05), 0 4px 12px rgba(0, 0, 0, .03);
}

.community-app:not(.community-admin-app) .post-media {
  width: 100%;
  max-height: 560px;
  margin: 16px 0;
  border-radius: 12px;
  object-fit: cover;
}

.community-app:not(.community-admin-app) .post-actions {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid #edf0f2;
}

.community-app:not(.community-admin-app) .post-actions button {
  min-width: 0;
  padding: 8px;
  font-size: 12px;
}

.community-right-rail .rail-card {
  margin: 0 0 16px;
  padding: 20px;
  border: 0;
  border-radius: 16px;
  background: #f7f8fa;
  box-shadow: none;
}

.community-right-rail .rail-heading {
  margin-bottom: 10px;
}

.community-right-rail .rail-heading h2 {
  margin: 0;
  color: var(--community-ink);
  font: 700 18px/26px "Hanken Grotesk", sans-serif;
}

.community-trending-card .trend-item {
  width: 100%;
  display: grid;
  gap: 2px;
  padding: 12px 0;
  border: 0;
  border-bottom: 1px solid #e7eaee;
  background: transparent;
  color: var(--community-ink);
  text-align: left;
}

.community-trending-card .trend-item small,
.community-trending-card .trend-item span {
  color: var(--community-muted);
  font-size: 11px;
}

.community-trending-card .trend-item strong {
  font-size: 14px;
}

.community-nova-cta {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--community-primary);
  color: #fff;
  font-weight: 700;
}

.community-suggested-card .rail-destination {
  width: 100%;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border: 0;
  background: transparent;
  color: var(--community-ink);
  text-align: left;
}

.community-suggested-card .rail-destination > .community-icon {
  width: 36px;
  height: 36px;
  padding: 8px;
  border-radius: 50%;
  background: #e8eef0;
  color: var(--community-primary);
}

.community-suggested-card .rail-destination span {
  display: grid;
}

.community-suggested-card .rail-destination small {
  color: var(--community-muted);
  font-size: 11px;
}

.community-suggested-card .rail-destination b {
  color: var(--community-primary);
  font-size: 12px;
}

.community-rail-footer {
  padding: 8px 12px;
  color: #98a0aa;
  font-size: 11px;
  line-height: 1.8;
}

/* Stitch route surfaces */
body[data-community-view]:not([data-community-view="home"]) .community-content > .community-page-header,
body[data-community-view]:not([data-community-view="home"]) .community-content > header:not(.timeline-header) {
  margin-bottom: 28px;
  padding: 0;
  border: 0;
  background: transparent;
}

body[data-community-view]:not([data-community-view="home"]) .community-content h1 {
  color: var(--community-primary);
  font-family: "Hanken Grotesk", sans-serif;
}

body[data-community-view="saved"] .collection-grid,
body[data-community-view="groups"] .card-grid,
body[data-community-view="challenges"] .card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

body[data-community-view="saved"] .collection-card,
body[data-community-view="groups"] .feature-card,
body[data-community-view="challenges"] .feature-card {
  border: 1px solid var(--community-line);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .04);
}

@media (max-width: 1023px) {
  body:has(.community-app) {
    background: var(--community-mobile-bg) !important;
  }

  .community-app:not(.community-admin-app) {
    width: 100%;
    max-width: 480px;
    min-height: 100vh;
    background: var(--community-mobile-bg);
  }

  .community-app:not(.community-admin-app) .community-topbar {
    right: 0 !important;
    left: 0 !important;
    width: min(100%, 480px);
    margin-inline: auto !important;
    height: 60px !important;
    min-height: 60px !important;
    grid-template-columns: minmax(0, 1fr) 92px !important;
    align-content: center;
    gap: 0 !important;
    padding: 0 14px !important;
    transform: none !important;
    border-bottom-color: rgba(191, 200, 201, .3);
    background: rgba(249, 249, 255, .92);
  }

  .community-app:not(.community-admin-app) .community-mobile-brand {
    position: relative !important;
    z-index: 3 !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    min-height: 40px;
    width: auto !important;
    min-width: 0 !important;
    max-width: calc(100vw - 112px) !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 24px;
    line-height: 32px;
  }

  .community-app:not(.community-admin-app) .community-mobile-brand span {
    display: inline !important;
    color: var(--community-primary) !important;
    font-size: 24px !important;
  }

  .community-app:not(.community-admin-app) .community-mobile-brand span::after {
    content: none;
  }

  .community-app:not(.community-admin-app) .community-global-search {
    position: absolute;
    top: 10px;
    right: 58px;
    width: 40px;
    height: 40px;
    justify-content: center;
    padding: 0;
    background: transparent;
  }

  .community-app:not(.community-admin-app) .community-global-search span {
    display: none;
  }

  .community-app:not(.community-admin-app) .community-top-actions {
    position: absolute;
    top: 10px;
    right: 10px;
  }

  .community-app:not(.community-admin-app) .community-top-actions .community-button {
    display: none;
  }

  .community-app:not(.community-admin-app) .community-topbar::after {
    content: none;
  }

  .community-app:not(.community-admin-app) .community-topbar::before {
    content: none;
  }

  .community-app:not(.community-admin-app) .community-layout {
    display: block !important;
    width: 100%;
    min-height: 100vh;
    margin-top: 0 !important;
    padding-top: 60px !important;
  }

  .community-app:not(.community-admin-app) .community-section-nav,
  .community-app:not(.community-admin-app) .community-right-rail {
    display: none !important;
  }

  .community-app:not(.community-admin-app) .community-content {
    width: 100%;
    padding: 0 0 84px !important;
    border: 0;
    background: var(--community-mobile-bg);
  }

  .community-app:not(.community-admin-app) .timeline-header {
    display: none;
  }

  .community-app:not(.community-admin-app) .mobile-feed-tabs {
    position: sticky;
    z-index: 35;
    top: 60px;
    display: block;
    width: 100%;
    overflow: hidden;
    border-bottom: 1px solid rgba(191, 200, 201, .35);
    background: rgba(249, 249, 255, .96);
    backdrop-filter: blur(14px);
  }

  .community-app:not(.community-admin-app) .mobile-feed-tabs .feed-tabs {
    display: flex;
    gap: 22px;
    width: 100%;
    top: auto !important;
    margin: 0 !important;
    padding: 0 16px;
    overflow-x: auto;
    border: 0;
    scrollbar-width: none;
  }

  .community-app:not(.community-admin-app) .mobile-feed-tabs .feed-tabs::-webkit-scrollbar {
    display: none;
  }

  .community-app:not(.community-admin-app) .mobile-feed-tabs .feed-tabs button {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--community-secondary);
    font: 700 12px/16px Inter, sans-serif;
    white-space: nowrap;
  }

  .community-app:not(.community-admin-app) .mobile-feed-tabs .feed-tabs button.active {
    border-bottom-color: var(--community-primary);
    color: var(--community-primary);
  }

  .community-app:not(.community-admin-app) .discoveries-strip {
    margin: 0 !important;
    padding: 18px 16px 10px;
    background: var(--community-mobile-bg);
  }

  .community-app:not(.community-admin-app) .discoveries-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }

  .community-app:not(.community-admin-app) .discoveries-heading strong {
    color: var(--community-primary);
    font: 700 20px/28px "Hanken Grotesk", sans-serif;
  }

  .community-app:not(.community-admin-app) .community-mobile-stories {
    gap: 14px;
    padding: 0;
  }

  .community-app:not(.community-admin-app) .mobile-story-item {
    flex-basis: 72px;
    height: auto;
    display: grid;
    justify-items: center;
    gap: 6px;
    padding: 0;
    overflow: visible;
    color: var(--community-secondary);
    background: transparent;
    box-shadow: none;
  }

  .community-app:not(.community-admin-app) .mobile-story-item span {
    position: static;
    width: 72px;
    height: 72px;
    border: 2px solid #94d1d6;
    background: #fff;
  }

  .community-app:not(.community-admin-app) .mobile-story-item.add-story {
    color: var(--community-secondary);
    background: transparent;
  }

  .community-app:not(.community-admin-app) .mobile-story-item small {
    max-width: 72px;
    overflow: hidden;
    color: var(--community-secondary);
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .community-app:not(.community-admin-app) .mobile-shorts-preview {
    display: block;
    padding: 6px 16px 18px;
  }

  .community-app:not(.community-admin-app) .mobile-shorts-preview > div:last-child {
    display: flex;
    gap: 8px;
    overflow-x: auto;
  }

  .community-app:not(.community-admin-app) .mobile-short-card {
    flex: 0 0 128px;
    height: 224px;
    position: relative;
    display: flex;
    align-items: flex-end;
    padding: 10px;
    overflow: hidden;
    border: 0;
    border-radius: 12px;
    background: #dce6ef;
    color: #fff;
    text-align: left;
  }

  .community-app:not(.community-admin-app) .mobile-short-card img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .community-app:not(.community-admin-app) .mobile-short-card::after {
    content: "";
    position: absolute;
    inset: 45% 0 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, .68));
  }

  .community-app:not(.community-admin-app) .mobile-short-card strong {
    position: relative;
    z-index: 1;
    font-size: 11px;
  }

  .community-app:not(.community-admin-app) .quick-composer {
    display: none;
  }

  .community-app:not(.community-admin-app) .feed-list {
    gap: 4px;
  }

  .community-app:not(.community-admin-app) .community-post {
    padding: 16px;
    border-width: 1px 0;
    border-radius: 0;
    box-shadow: none;
  }

  .community-app:not(.community-admin-app) .post-media {
    width: calc(100% + 32px);
    max-height: none;
    margin: 14px -16px;
    border-radius: 0;
  }

  .community-app:not(.community-admin-app) .post-actions button span {
    display: none;
  }

  .community-app:not(.community-admin-app) .post-actions .community-icon {
    width: 20px;
    height: 20px;
  }

  .community-app:not(.community-admin-app) .community-mobile-nav {
    position: fixed;
    z-index: 100;
    left: 50%;
    right: auto;
    bottom: 0;
    width: min(100%, 480px);
    height: 64px;
    display: grid !important;
    grid-template-columns: repeat(5, 1fr);
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    border-top: 1px solid rgba(191, 200, 201, .45);
    background: rgba(249, 249, 255, .96);
    backdrop-filter: blur(20px);
  }

  .community-app:not(.community-admin-app) .community-mobile-nav .community-view-button {
    min-height: 52px;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2px;
    padding: 0;
    border-radius: 0;
    font-size: 10px;
  }

  .community-app:not(.community-admin-app) .community-mobile-nav .community-view-button .community-icon {
    width: 20px;
    height: 20px;
  }

  .community-app:not(.community-admin-app) .community-mobile-nav .mobile-create .community-icon {
    width: 42px;
    height: 42px;
    padding: 10px;
    border-radius: 50%;
    background: var(--community-primary);
    color: #fff;
  }

  body[data-community-view="saved"] .collection-grid,
  body[data-community-view="groups"] .card-grid,
  body[data-community-view="challenges"] .card-grid {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  body[data-community-view]:not([data-community-view="home"]) .community-content > .community-page-header,
  body[data-community-view]:not([data-community-view="home"]) .community-content > header:not(.timeline-header) {
    padding: 20px 16px 0;
  }
}

.dls-community-shell {
  background: #fff;
}

.community-app,
.community-app button,
.community-app input,
.community-app select,
.community-app textarea {
  font-family: Inter, system-ui, sans-serif;
  color: var(--sc-text);
  letter-spacing: 0;
}

.community-app h1,
.community-app h2,
.community-app h3,
.community-app strong {
  font-family: "Hanken Grotesk", Inter, sans-serif;
}
