:root {
  --spaces-pad-1: 0.75rem;
  --spaces-pad-2: 1rem;
  --spaces-gap-1: 0.5rem;
  --spaces-gap-2: 0.75rem;
  --spaces-font-sm: 0.8125rem;
  --spaces-font-md: 0.875rem;
  --spaces-font-lg: 0.9375rem;
  --spaces-icon-size: 1.25rem;
  --spaces-badge-height: 1.125rem;
  --spaces-badge-min: 1.125rem;
}

/* =========================================
   SPACE FEED LAYOUT
   ========================================= */

.spaces-root {
  max-width: 720px;
  margin: 0 auto;
}

.space-hero-header {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

#space-feed {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 80px;
  width: 100%;
  background: transparent;
  border: 0;
  border-radius: 0;
  overflow: visible;
}

.space-state {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

.space-state-action {
  margin-top: 12px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.space-post-snapshot {
  cursor: default;
}

.space-post-author {
  cursor: pointer;
}

.space-post-snapshot-title {
  margin: 0 0 8px 0;
}

.space-post-snapshot-link {
  color: inherit;
  text-decoration: none;
}

.space-post-snapshot-link:hover {
  text-decoration: underline;
}

.space-post-snapshot-desc {
  margin: 0 0 12px 0;
}

.space-post-snapshot-footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
}

.space-post-snapshot-metrics {
  display: flex;
  align-items: center;
  gap: 6px;
}

.space-post-snapshot-cta {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

.space-post-snapshot-cta:hover {
  background: var(--bg);
}

body.view-space #view-space.spaces-root #space-feed>.post {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  border: 0;
  border-radius: 18px;
  box-shadow: none;
  padding: 14px 26px 0;
  transition: background-color 60ms linear;
}

body.view-space #view-space.spaces-root #space-feed>.post::after {
  left: 26px;
  right: 26px;
}

body.view-space #view-space.spaces-root #space-feed>.post:hover {
  background: #F4F6F8;
  box-shadow: none;
}

body.view-space #view-space.spaces-root #space-feed>.post .p-head {
  margin-bottom: 8px;
}

body.view-space #view-space.spaces-root #space-feed>.post .p-user {
  gap: 7px;
  align-items: center;
}

body.view-space #view-space.spaces-root #space-feed>.post .avatar {
  width: 26px;
  height: 26px;
}

body.view-space #view-space.spaces-root #space-feed>.post .who {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  flex-wrap: wrap;
  line-height: 1.2;
}

body.view-space #view-space.spaces-root #space-feed>.post .who .name {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: #0F1A1C;
}

body.view-space #view-space.spaces-root #space-feed>.post .meta-line {
  font-size: 12px;
  font-weight: 400;
  gap: 5px;
  margin-top: 0;
  color: #576F76;
  line-height: 1.2;
}

body.view-space #view-space.spaces-root #space-feed>.post .title {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.32;
  letter-spacing: 0;
  color: #101214;
  margin: 0 0 8px 0 !important;
}

body.view-space #view-space.spaces-root #space-feed>.post .desc {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.48;
  color: #1f2933;
  margin: 0 0 12px 0 !important;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

body.view-space #view-space.spaces-root #space-feed>.post[data-has-media="true"] .desc {
  display: none;
}

body.view-space #view-space.spaces-root #space-feed>.post .post-foot {
  border-top: 0;
  border-radius: 0;
  justify-content: flex-start !important;
  gap: 12px;
  margin-top: 14px;
  margin-bottom: 0;
  margin-left: -26px;
  margin-right: -26px;
  padding: 4px 26px 14px;
}

body.view-space #view-space.spaces-root #space-feed>.post .posts-card-actions {
  margin-left: 0;
}

body.view-space #view-space.spaces-root #space-feed>.post .posts-card-actions--full {
  gap: 0;
}

body.view-space #view-space.spaces-root #space-feed>.post .like-btn,
body.view-space #view-space.spaces-root #space-feed>.post .view-btn,
body.view-space #view-space.spaces-root #space-feed>.post .posts-share-btn {
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #EEF2F5;
  color: #0F1A1C;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  transition: background-color 0.14s ease, color 0.14s ease;
}

body.view-space #view-space.spaces-root #space-feed>.post .like-btn:hover,
body.view-space #view-space.spaces-root #space-feed>.post .posts-share-btn:hover {
  background: #E2E8F0;
  color: #0F172A;
}

body.view-space #view-space.spaces-root #space-feed>.post .like-btn:hover {
  background: #FEECEF;
  color: #E11D48;
}

body.view-space #view-space.spaces-root #space-feed>.post .like-btn.active {
  background: #EEF2F5;
  color: #E11D48;
}

body.view-space #view-space.spaces-root #space-feed>.post .like-btn.active:hover {
  background: #FEECEF;
  color: #E11D48;
}

body.view-space #view-space.spaces-root #space-feed>.post .posts-meta-chip,
body.view-space #view-space.spaces-root #space-feed>.post .posts-recommendation-chip {
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
}

body.view-space #view-space.spaces-root #space-feed>.post .posts-recommendation-chip {
  background: rgba(37, 99, 235, 0.06);
  border-color: rgba(37, 99, 235, 0.12);
}

.spaces-sidebar-widget {
  background: #FBFCFE;
  border: 1px solid #E8EDF3;
  border-radius: 16px;
  padding: var(--spaces-pad-2);
  margin-bottom: var(--spaces-pad-2);
  box-shadow: none;
}

.spaces-sidebar-title {
  font-size: var(--spaces-font-lg);
  font-weight: 600;
  color: var(--text);
  margin: 0 0 var(--spaces-gap-2) 0;
}

.spaces-list {
  display: flex;
  flex-direction: column;
  gap: var(--spaces-gap-1);
}

.spaces-item {
  display: flex;
  align-items: center;
  gap: var(--spaces-gap-2);
  padding: var(--spaces-gap-1);
  border-radius: calc(var(--radius) - var(--spaces-gap-1));
  cursor: pointer;
  transition: background 0.2s ease;
}

.spaces-item:hover {
  background: #F1F5F9;
}

.spaces-icon {
  font-size: var(--spaces-icon-size);
  line-height: 1;
}

.spaces-info {
  flex: 1;
  min-width: 0;
}

.spaces-title {
  font-size: var(--spaces-font-md);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.spaces-activity {
  font-size: 0.75rem;
  /* 12px */
  color: var(--muted);
  opacity: 0.9;
  white-space: nowrap;
  margin-top: 2px;
}

.spaces-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: #22C55E;
  /* Lighter Green */
  color: #FFFFFF;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 2px 5px rgba(34, 197, 94, 0.25);
  margin-left: 8px;
}

.spaces-chevron {
  width: var(--spaces-icon-size);
  height: var(--spaces-icon-size);
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spaces-empty {
  padding: var(--spaces-pad-1);
  font-size: var(--spaces-font-sm);
  color: var(--muted);
  text-align: center;
}

/* =========================
   MOBILE HORIZONTAL SPACES BAR
   ========================= */
.mobile-spaces-bar {
  display: none;
}

@media (max-width: 720px) {
  .spaces-root {
    max-width: 100%;
  }

  #space-feed {
    gap: 12px;
  }

  body.view-space #view-space.spaces-root #space-feed>.post {
    padding: 16px 16px 0;
  }

  body.view-space #view-space.spaces-root #space-feed>.post::after {
    left: 16px;
    right: 16px;
  }

  body.view-space #view-space.spaces-root #space-feed>.post .p-head {
    margin-bottom: 7px;
  }

  body.view-space #view-space.spaces-root #space-feed>.post .p-user {
    gap: 7px;
    align-items: flex-start;
  }

  body.view-space #view-space.spaces-root #space-feed>.post .who {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 2px;
  }

  body.view-space #view-space.spaces-root #space-feed>.post .who .name {
    font-size: 12px;
  }

  body.view-space #view-space.spaces-root #space-feed>.post .meta-line {
    font-size: 12px;
    line-height: 1.4;
  }

  body.view-space #view-space.spaces-root #space-feed>.post .title {
    font-size: 16.5px;
    font-weight: 600;
    line-height: 1.32;
  }

  body.view-space #view-space.spaces-root #space-feed>.post .desc {
    font-size: 14.5px;
    line-height: 1.48;
    -webkit-line-clamp: 2;
  }

  body.view-space #view-space.spaces-root #space-feed>.post .post-foot {
    gap: 8px;
    margin-left: -16px;
    margin-right: -16px;
    padding: 4px 16px 12px;
  }

  .mobile-spaces-bar {
    /* Display controlled by global layout rules in static/css/style.css */
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 8px 0 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-spaces-bar::-webkit-scrollbar {
    display: none;
  }

  .mobile-spaces-list {
    display: flex;
    gap: 10px;
    padding: 0 12px;
    min-width: min-content;
  }

  .mobile-space-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    flex-shrink: 0;
    min-width: 52px;
  }

  .mobile-space-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #F1F5F9 0%, #E2E8F0 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
  }

  .mobile-space-chip:active .mobile-space-icon {
    transform: scale(0.95);
  }

  .mobile-space-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text);
    text-align: center;
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.1;
  }

  .mobile-space-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: #22C55E;
    color: #FFFFFF;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(34, 197, 94, 0.3);
  }

  .mobile-space-icon-wrapper {
    position: relative;
  }

  /* Hide spaces bar on mobile when inside a space (saves vertical space) */
  body.view-space .mobile-spaces-bar {
    display: none !important;
  }
}

/* =========================================
   SPACE HERO & TOOLBAR (Matching Platform UI)
   ========================================= */

.space-hero-header {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

@media (min-width: 768px) {
  .space-hero-header {
    padding: 20px 0;
    margin-bottom: 20px;
  }
}

.space-hero-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

@media (min-width: 768px) {
  .space-hero-top {
    margin-bottom: 20px;
  }
}

.space-hero-icon {
  font-size: 24px;
  width: 48px;
  height: 48px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  overflow: hidden;
}

.space-hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.space-hero-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.01em;
}

.space-hero-desc {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.4;
}


/* Base Toolbar: Always a row now */
.space-toolbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.space-search-wrapper {
  position: relative;
  flex: 1;
  /* Search takes as much as possible */
  min-width: 0;
  /* Prevents overflow */
}

.space-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  z-index: 2;
  pointer-events: none;
  display: inline-flex;
}

.space-search-input {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.space-search-input:focus {
  border-color: var(--brand-dark, #0F172A);
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.05);
}

.space-time-dropdown-wrapper {
  position: relative;
  flex-shrink: 0;
  width: 110px;
  /* Compact on mobile */
}

@media (min-width: 480px) {
  .space-time-dropdown-wrapper {
    width: 140px;
  }
}

@media (min-width: 768px) {
  .space-time-dropdown-wrapper {
    width: 180px;
  }
}

.space-time-dropdown {
  width: 100%;
  height: 40px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  text-overflow: ellipsis;
}

.space-time-dropdown:focus {
  border-color: var(--brand-dark, #0F172A);
}

.space-time-dropdown:hover {
  background-color: #F8FAFC;
  border-color: #CBD5E1;
}

/* Final Spaces view overrides: keep the route aligned with Feed's open stream. */
body.view-space #view-space.spaces-root {
  max-width: 720px;
  margin: 0 auto;
}

body.view-space #view-space.spaces-root .space-hero-header {
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.view-space #view-space.spaces-root .space-search-input {
  min-height: 52px;
  height: 52px;
  border-radius: 16px;
  box-shadow: none;
}

body.view-space #view-space.spaces-root .space-time-dropdown {
  min-height: 52px;
  height: 52px;
  border-radius: 16px;
  box-shadow: none;
}

@media (max-width: 720px) {
  body.view-space #view-space.spaces-root {
    max-width: 100%;
  }

  body.view-space #view-space.spaces-root .space-search-input,
  body.view-space #view-space.spaces-root .space-time-dropdown {
    min-height: 50px;
    height: 50px;
    border-radius: 14px;
  }
}
