: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 (Industry Standard)
   ========================================= */

#space-feed {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Standardize gap to match Home Feed */
  padding-bottom: 80px;
  width: 100%;
}

.spaces-sidebar-widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--spaces-pad-2);
  margin-bottom: var(--spaces-pad-2);
  box-shadow: var(--shadow-sm);
}

.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: var(--bg);
}

.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) {
  .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;
}

.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;
}

.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;
}
