@import url('tokens.css');
@import url('icons.css');
@import url('../../shared/calendar.css');
@import url('motion.css');

/* ─── Reset & Base ─── */

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-6);
}

body {
  margin: 0;
  font-family: var(--space-font-family);
  font-size: var(--space-text-md);
  line-height: var(--space-leading-snug);
  color: var(--space-label-primary);
  background: var(--space-bg-secondary);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: var(--space-color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ─── Typography ─── */

.space-display {
  font-size: var(--space-text-3xl);
  font-weight: var(--space-weight-bold);
  letter-spacing: var(--space-tracking-tight);
  line-height: var(--space-leading-tight);
}

.space-title-1 {
  font-size: var(--space-text-2xl);
  font-weight: var(--space-weight-bold);
  letter-spacing: var(--space-tracking-tight);
  line-height: var(--space-leading-tight);
}

.space-title-2 {
  font-size: var(--space-text-xl);
  font-weight: var(--space-weight-semibold);
  line-height: var(--space-leading-tight);
}

.space-title-3 {
  font-size: var(--space-text-lg);
  font-weight: var(--space-weight-semibold);
  line-height: var(--space-leading-snug);
}

.space-headline {
  font-size: var(--space-text-md);
  font-weight: var(--space-weight-semibold);
}

.space-body {
  font-size: var(--space-text-md);
  font-weight: var(--space-weight-regular);
}

.space-callout {
  font-size: var(--space-text-base);
  font-weight: var(--space-weight-regular);
}

.space-subhead {
  font-size: var(--space-text-base);
  font-weight: var(--space-weight-regular);
  color: var(--space-label-secondary);
}

.space-footnote {
  font-size: var(--space-text-sm);
  color: var(--space-label-secondary);
}

.space-caption {
  font-size: var(--space-text-xs);
  color: var(--space-label-tertiary);
}

.space-text-secondary { color: var(--space-label-secondary); }
.space-text-tertiary { color: var(--space-label-tertiary); }

/* ─── Buttons ─── */

.space-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: none;
  border-radius: var(--space-radius-md);
  font-weight: var(--space-weight-semibold);
  cursor: pointer;
  transition: background var(--space-duration-fast) var(--space-ease-default),
              opacity var(--space-duration-fast) var(--space-ease-default),
              transform var(--space-duration-fast) var(--space-ease-default);
  white-space: nowrap;
  user-select: none;
}

.space-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.space-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.space-btn--sm {
  min-height: 32px;
  padding: 0 var(--space-3);
  font-size: var(--space-text-sm);
  border-radius: var(--space-radius-sm);
}

.space-btn--md {
  min-height: 44px;
  padding: 0 var(--space-5);
  font-size: var(--space-text-md);
  border-radius: 12px;
}

.space-btn--lg {
  min-height: 50px;
  padding: 0 var(--space-6);
  font-size: var(--space-text-md);
  border-radius: var(--space-radius-lg);
}

.space-btn--primary {
  background: var(--space-color-primary);
  color: var(--space-label-on-primary);
}

.space-btn--primary:hover:not(:disabled) {
  background: var(--space-color-primary-pressed);
}

.space-btn--secondary {
  background: var(--space-bg-fill);
  color: var(--space-color-primary);
}

.space-btn--secondary:hover:not(:disabled) {
  background: var(--space-bg-fill-secondary);
}

.space-btn--destructive {
  background: var(--space-color-danger);
  color: var(--space-label-on-primary);
}

.space-btn--destructive:hover:not(:disabled) {
  background: var(--space-color-danger-pressed);
}

.space-btn--ghost {
  background: transparent;
  color: var(--space-color-primary);
}

.space-btn--ghost:hover:not(:disabled) {
  background: var(--space-color-primary-subtle);
}

.space-btn--outline {
  background: transparent;
  color: var(--space-color-primary);
  box-shadow: inset 0 0 0 1px var(--space-color-primary);
}

.space-btn--loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.space-btn__spinner {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: space-spin 0.7s linear infinite;
}

.space-btn--secondary .space-btn__spinner,
.space-btn--ghost .space-btn__spinner {
  border-color: rgba(0, 122, 255, 0.25);
  border-top-color: var(--space-color-primary);
}

/* ─── Inputs ─── */

.space-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.space-label {
  font-size: var(--space-text-sm);
  font-weight: var(--space-weight-medium);
  color: var(--space-label-secondary);
}

.space-input,
.space-textarea,
.space-select {
  width: 100%;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--space-radius-md);
  background: var(--space-bg-fill-tertiary);
  color: var(--space-label-primary);
  outline: none;
  transition: box-shadow var(--space-duration-fast);
}

.space-input:focus,
.space-textarea:focus,
.space-select:focus {
  box-shadow: 0 0 0 3px var(--space-color-primary-subtle);
}

.space-input::placeholder,
.space-textarea::placeholder {
  color: var(--space-label-tertiary);
}

.space-textarea {
  min-height: 100px;
  resize: vertical;
  line-height: var(--space-leading-normal);
}

.space-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238e8e93' d='M1.41 0L6 4.58 10.59 0 12 1.41l-6 6-6-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.space-search {
  position: relative;
}

.space-search__icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--space-label-tertiary);
  pointer-events: none;
}

.space-search .space-input {
  padding-left: 36px;
  border-radius: var(--space-radius-full);
  background: var(--space-bg-fill);
}

/* Switch */
.space-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
}

.space-switch__input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.space-switch__track {
  width: 51px;
  height: 31px;
  background: var(--space-bg-fill);
  border-radius: var(--space-radius-full);
  transition: background var(--space-duration-normal);
  flex-shrink: 0;
}

.space-switch__track::after {
  content: '';
  display: block;
  width: 27px;
  height: 27px;
  margin: 2px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  transition: transform var(--space-duration-normal) var(--space-ease-spring);
}

.space-switch__input:checked + .space-switch__track {
  background: var(--space-color-success);
}

.space-switch__input:checked + .space-switch__track::after {
  transform: translateX(20px);
}

/* Checkbox & Radio */
.space-check,
.space-radio {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  min-height: 44px;
}

.space-check__input,
.space-radio__input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.space-check__box {
  width: 22px;
  height: 22px;
  border-radius: var(--space-radius-xs);
  border: 2px solid var(--space-gray-3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--space-duration-fast);
  flex-shrink: 0;
}

.space-check__input:checked + .space-check__box {
  background: var(--space-color-primary);
  border-color: var(--space-color-primary);
}

.space-check__input:checked + .space-check__box::after {
  content: '';
  width: 6px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translateY(-1px);
}

.space-radio__dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--space-gray-3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.space-radio__input:checked + .space-radio__dot {
  border-color: var(--space-color-primary);
}

.space-radio__input:checked + .space-radio__dot::after {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--space-color-primary);
}

/* Stepper */
.space-stepper {
  display: inline-flex;
  align-items: center;
  background: var(--space-bg-fill-tertiary);
  border-radius: var(--space-radius-md);
  overflow: hidden;
}

.space-stepper__btn {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--space-color-primary);
  font-size: 20px;
  font-weight: var(--space-weight-medium);
  cursor: pointer;
}

.space-stepper__btn:disabled {
  color: var(--space-label-tertiary);
  cursor: not-allowed;
}

.space-stepper__value {
  min-width: 44px;
  text-align: center;
  font-weight: var(--space-weight-semibold);
  font-variant-numeric: tabular-nums;
}

/* ─── Tags & Badges ─── */

.space-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 10px;
  border-radius: var(--space-radius-full);
  font-size: var(--space-text-sm);
  font-weight: var(--space-weight-medium);
  background: var(--space-bg-fill);
  color: var(--space-label-primary);
}

.space-tag--primary {
  background: var(--space-color-primary-subtle);
  color: var(--space-color-primary);
}

.space-tag--success {
  background: var(--space-color-success-subtle);
  color: #248a3d;
}

.space-tag--warning {
  background: var(--space-color-warning-subtle);
  color: #c93400;
}

.space-tag--danger {
  background: var(--space-color-danger-subtle);
  color: var(--space-color-danger);
}

.space-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--space-radius-full);
  font-size: var(--space-text-xs);
  font-weight: var(--space-weight-semibold);
  background: var(--space-color-danger);
  color: #fff;
}

.space-badge--dot {
  min-width: 8px;
  width: 8px;
  height: 8px;
  padding: 0;
}

/* ─── Avatar ─── */

.space-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  font-weight: var(--space-weight-semibold);
  overflow: hidden;
  flex-shrink: 0;
}

.space-avatar--sm { width: 32px; height: 32px; font-size: var(--space-text-sm); }
.space-avatar--md { width: 44px; height: 44px; font-size: var(--space-text-base); }
.space-avatar--lg { width: 64px; height: 64px; font-size: var(--space-text-lg); }

.space-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.space-avatar-group {
  display: flex;
}

.space-avatar-group .space-avatar {
  margin-left: -8px;
  border: 2px solid var(--space-bg-primary);
}

.space-avatar-group .space-avatar:first-child {
  margin-left: 0;
}

/* ─── Album / Photo Grid ─── */

.space-album-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  border-radius: var(--space-radius-lg);
  overflow: hidden;
}

.space-album-grid__item {
  aspect-ratio: 1;
  background: var(--space-gray-5);
  position: relative;
  overflow: hidden;
}

.space-album-grid__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.space-album-grid__item--upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  background: var(--space-bg-fill-tertiary);
  color: var(--space-label-tertiary);
  font-size: var(--space-text-xs);
  cursor: pointer;
  border: 1.5px dashed var(--space-gray-4);
  transition: background var(--space-duration-fast);
}

.space-album-grid__item--upload:hover {
  background: var(--space-bg-fill);
}

.space-album-grid__upload-icon {
  font-size: 24px;
  line-height: 1;
}

.space-album-grid__more {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--space-text-xl);
  font-weight: var(--space-weight-semibold);
}

/* ─── Banner ─── */

.space-hero-banner {
  position: relative;
  border-radius: var(--space-radius-xl);
  overflow: hidden;
  min-height: 180px;
  background: linear-gradient(135deg, #007aff 0%, #5856d6 100%);
  color: #fff;
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.space-hero-banner__title {
  font-size: var(--space-text-2xl);
  font-weight: var(--space-weight-bold);
  margin: 0 0 var(--space-2);
}

.space-hero-banner__subtitle {
  font-size: var(--space-text-base);
  opacity: 0.85;
  margin: 0;
}

.space-carousel-dots {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3);
}

.space-carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--space-gray-4);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: all var(--space-duration-fast);
}

.space-carousel-dot--active {
  width: 20px;
  border-radius: var(--space-radius-full);
  background: var(--space-color-primary);
}

.space-ad-banner {
  border-radius: var(--space-radius-lg);
  overflow: hidden;
  background: var(--space-bg-grouped-secondary);
  border: 0.5px solid var(--space-separator);
}

.space-ad-banner--320x50 {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--space-text-xs);
  color: var(--space-label-tertiary);
}

.space-ad-banner--300x250 {
  height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--space-text-sm);
  color: var(--space-label-tertiary);
}

.space-ad-banner__label {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 9px;
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: var(--space-radius-xs);
  color: var(--space-label-tertiary);
}

.space-ad-banner {
  position: relative;
}

/* ─── Video ─── */

.space-video-placeholder {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--space-radius-lg);
  overflow: hidden;
  background: linear-gradient(145deg, #1c1c1e, #3a3a3c);
}

.space-video-placeholder__play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
}

.space-video-placeholder__play-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--space-shadow-lg);
  transition: transform var(--space-duration-fast);
}

.space-video-placeholder__play:hover .space-video-placeholder__play-btn {
  transform: scale(1.06);
}

.space-video-placeholder__play-btn::after {
  content: '';
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 10px 0 10px 18px;
  border-color: transparent transparent transparent var(--space-color-primary);
  margin-left: 4px;
}

.space-video-placeholder__duration {
  position: absolute;
  bottom: var(--space-2);
  right: var(--space-2);
  padding: 2px 8px;
  border-radius: var(--space-radius-xs);
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: var(--space-text-xs);
  font-variant-numeric: tabular-nums;
}

/* ─── Ad List ─── */

.space-ad-cell {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--space-bg-grouped-secondary);
  border-radius: var(--space-radius-lg);
}

.space-ad-cell__thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--space-radius-md);
  background: var(--space-gray-5);
  flex-shrink: 0;
  overflow: hidden;
}

.space-ad-cell__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.space-ad-cell__body {
  flex: 1;
  min-width: 0;
}

.space-ad-cell__sponsored {
  font-size: var(--space-text-xs);
  color: var(--space-label-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.space-ad-cell__title {
  font-weight: var(--space-weight-semibold);
  margin: 2px 0;
}

.space-ad-cell__desc {
  font-size: var(--space-text-sm);
  color: var(--space-label-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.space-native-ad {
  border-radius: var(--space-radius-lg);
  overflow: hidden;
  background: var(--space-bg-grouped-secondary);
  border: 0.5px solid var(--space-separator);
}

.space-native-ad__media {
  aspect-ratio: 16 / 9;
  background: var(--space-gray-5);
}

.space-native-ad__body {
  padding: var(--space-3) var(--space-4);
}

.space-native-ad__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

/* ─── Modal / Dialog ─── */

.space-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: var(--space-z-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--space-duration-normal), visibility var(--space-duration-normal);
}

.space-overlay--visible {
  opacity: 1;
  visibility: visible;
}

.space-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  width: min(340px, calc(100vw - 32px));
  background: var(--space-bg-elevated);
  border-radius: var(--space-radius-xl);
  z-index: var(--space-z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all var(--space-duration-normal) var(--space-ease-default);
  box-shadow: var(--space-shadow-overlay);
  overflow: hidden;
}

.space-modal--visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.space-modal__header {
  padding: var(--space-5) var(--space-5) var(--space-2);
  text-align: center;
}

.space-modal__title {
  font-size: var(--space-text-lg);
  font-weight: var(--space-weight-semibold);
  margin: 0;
}

.space-modal__body {
  padding: var(--space-2) var(--space-5) var(--space-5);
  text-align: center;
  color: var(--space-label-secondary);
  font-size: var(--space-text-base);
}

.space-modal__footer {
  display: flex;
  border-top: 0.5px solid var(--space-separator);
}

.space-modal__action {
  flex: 1;
  min-height: 44px;
  border: none;
  background: transparent;
  font-size: var(--space-text-md);
  font-weight: var(--space-weight-semibold);
  color: var(--space-color-primary);
  cursor: pointer;
}

.space-modal__action + .space-modal__action {
  border-left: 0.5px solid var(--space-separator);
}

.space-modal__action--destructive {
  color: var(--space-color-danger);
}

/* Bottom Sheet */
.space-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--space-bg-elevated);
  border-radius: var(--space-radius-xl) var(--space-radius-xl) 0 0;
  z-index: var(--space-z-modal);
  transform: translateY(100%);
  transition: transform var(--space-duration-normal) var(--space-ease-default);
  max-height: 85vh;
  overflow: hidden;
}

.space-sheet--visible {
  transform: translateY(0);
}

.space-sheet__handle {
  width: 36px;
  height: 5px;
  background: var(--space-gray-4);
  border-radius: var(--space-radius-full);
  margin: var(--space-2) auto;
}

.space-sheet__header {
  padding: var(--space-2) var(--space-4) var(--space-3);
  text-align: center;
  font-weight: var(--space-weight-semibold);
  border-bottom: 0.5px solid var(--space-separator);
}

.space-sheet__body {
  padding: var(--space-2) 0;
  overflow-y: auto;
}

.space-sheet__item {
  display: block;
  width: 100%;
  padding: var(--space-4);
  border: none;
  background: transparent;
  font-size: var(--space-text-md);
  text-align: center;
  cursor: pointer;
}

.space-sheet__item:hover {
  background: var(--space-bg-fill-tertiary);
}

.space-sheet__item--destructive {
  color: var(--space-color-danger);
}

.space-sheet__cancel {
  margin-top: var(--space-2);
  border-top: 0.5px solid var(--space-separator);
  padding-bottom: var(--space-safe-bottom);
}

/* Alert */
.space-alert {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  width: min(270px, calc(100vw - 48px));
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: saturate(180%) blur(20px);
  border-radius: var(--space-radius-lg);
  z-index: var(--space-z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all var(--space-duration-normal);
  overflow: hidden;
}

.space-alert--visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.space-alert__body {
  padding: var(--space-5);
  text-align: center;
}

.space-alert__title {
  font-weight: var(--space-weight-semibold);
  margin: 0 0 var(--space-2);
}

.space-alert__message {
  font-size: var(--space-text-sm);
  color: var(--space-label-secondary);
  margin: 0;
}

.space-alert__footer {
  display: flex;
  border-top: 0.5px solid var(--space-separator);
}

.space-alert__btn {
  flex: 1;
  min-height: 44px;
  border: none;
  background: transparent;
  font-weight: var(--space-weight-semibold);
  color: var(--space-color-primary);
  cursor: pointer;
}

.space-alert__btn + .space-alert__btn {
  border-left: 0.5px solid var(--space-separator);
}

/* ─── Tabs ─── */

.space-tabs {
  display: flex;
  border-bottom: 0.5px solid var(--space-separator);
  background: var(--space-bg-primary);
}

.space-tabs__item {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  border: none;
  background: transparent;
  font-size: var(--space-text-base);
  font-weight: var(--space-weight-medium);
  color: var(--space-label-secondary);
  cursor: pointer;
  position: relative;
  transition: color var(--space-duration-fast);
}

.space-tabs__item--active {
  color: var(--space-color-primary);
  font-weight: var(--space-weight-semibold);
}

.space-tabs__item--active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--space-color-primary);
  border-radius: 1px;
}

.space-tab-panel {
  display: none;
  padding: var(--space-4);
}

.space-tab-panel--active {
  display: block;
}

/* Bottom Tab Bar */
.space-tab-bar {
  display: flex;
  min-height: var(--space-tab-bar-height);
  background: var(--space-bg-blur);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--space-separator);
  padding-bottom: var(--space-safe-bottom);
}

.space-tab-bar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: transparent;
  font-size: 10px;
  color: var(--space-label-secondary);
  cursor: pointer;
  padding: var(--space-1) 0;
}

.space-tab-bar__item--active {
  color: var(--space-color-primary);
}

.space-tab-bar__icon {
  font-size: 22px;
  line-height: 1;
}

/* Segmented Control */
.space-segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--space-bg-fill);
  border-radius: var(--space-radius-md);
}

.space-segmented__item {
  padding: 6px 16px;
  border: none;
  background: transparent;
  border-radius: calc(var(--space-radius-md) - 2px);
  font-size: var(--space-text-sm);
  font-weight: var(--space-weight-medium);
  color: var(--space-label-primary);
  cursor: pointer;
  transition: all var(--space-duration-fast);
  white-space: nowrap;
}

.space-segmented__item--active {
  background: var(--space-bg-primary);
  box-shadow: var(--space-shadow-sm);
  font-weight: var(--space-weight-semibold);
}

/* ─── Layout ─── */

.space-page {
  min-height: 100vh;
  background: var(--space-bg-secondary);
}

.space-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--space-nav-height);
  padding: 0 var(--space-2);
  padding-top: var(--space-safe-top);
  background: var(--space-bg-blur);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--space-separator);
  position: sticky;
  top: 0;
  z-index: var(--space-z-sticky);
}

.space-nav-bar__title {
  font-size: var(--space-text-md);
  font-weight: var(--space-weight-semibold);
  flex: 1;
  text-align: center;
}

.space-nav-bar__back,
.space-nav-bar__action {
  min-width: 44px;
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--space-color-primary);
  font-size: var(--space-text-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.space-nav-bar__back::before {
  content: '‹';
  font-size: 28px;
  margin-right: -4px;
}

.space-card {
  background: var(--space-bg-grouped-secondary);
  border-radius: var(--space-radius-lg);
  overflow: hidden;
}

.space-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-3);
}

.space-card-grid__item {
  background: var(--space-bg-grouped-secondary);
  border-radius: var(--space-radius-lg);
  overflow: hidden;
}

.space-card-grid__media {
  aspect-ratio: 4 / 3;
  background: var(--space-gray-5);
}

.space-card-grid__body {
  padding: var(--space-3);
}

.space-list-group {
  background: var(--space-bg-grouped-secondary);
  border-radius: var(--space-radius-lg);
  overflow: hidden;
}

.space-list-group__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
  border-bottom: 0.5px solid var(--space-separator);
}

.space-list-group__item:last-child {
  border-bottom: none;
}

.space-list-group__chevron {
  margin-left: auto;
  color: var(--space-gray-3);
}

.space-form-layout {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.space-form-section {
  background: var(--space-bg-grouped-secondary);
  border-radius: var(--space-radius-lg);
  padding: var(--space-4);
}

.space-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
}

.space-empty__icon {
  font-size: 48px;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.space-empty__title {
  font-weight: var(--space-weight-semibold);
  margin: 0 0 var(--space-2);
}

.space-empty__desc {
  font-size: var(--space-text-base);
  color: var(--space-label-secondary);
  margin: 0 0 var(--space-4);
  max-width: 280px;
}

/* ─── Toast & Spinner ─── */

.space-toast-container {
  position: fixed;
  top: calc(var(--space-safe-top) + var(--space-4));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--space-z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.space-toast {
  padding: var(--space-3) var(--space-5);
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  border-radius: var(--space-radius-full);
  font-size: var(--space-text-sm);
  font-weight: var(--space-weight-medium);
  opacity: 0;
  transform: translateY(-12px);
  transition: all var(--space-duration-normal);
  white-space: nowrap;
}

.space-toast--visible {
  opacity: 1;
  transform: translateY(0);
}

.space-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--space-gray-5);
  border-top-color: var(--space-color-primary);
  border-radius: 50%;
  animation: space-spin 0.8s linear infinite;
}

.space-spinner--sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

.space-spinner--lg {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

@keyframes space-spin {
  to { transform: rotate(360deg); }
}

/* ─── DS Documentation Shell ─── */

.ds-shell {
  display: flex;
  min-height: 100vh;
}

.ds-sidebar {
  display: none;
  width: var(--space-sidebar-width);
  flex-shrink: 0;
  background: var(--space-bg-secondary);
  border-right: 0.5px solid var(--space-separator);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: var(--space-6) var(--space-3);
}

.ds-sidebar__brand {
  margin-bottom: var(--space-6);
}

.ds-sidebar__logo {
  font-size: var(--space-text-lg);
  font-weight: var(--space-weight-bold);
  color: var(--space-label-primary);
  letter-spacing: var(--space-tracking-tight);
}

.ds-sidebar__tagline {
  font-size: var(--space-text-xs);
  color: var(--space-label-tertiary);
  margin-top: var(--space-1);
}

.ds-sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ds-sidebar__section {
  font-size: var(--space-text-xs);
  font-weight: var(--space-weight-semibold);
  color: var(--space-label-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: var(--space-4) 0 var(--space-2);
  padding-left: var(--space-2);
}

.ds-sidebar__link {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--space-radius-md);
  font-size: var(--space-text-sm);
  color: var(--space-label-primary);
  text-decoration: none;
  transition: background var(--space-duration-fast);
}

.ds-sidebar__link:hover {
  background: var(--space-bg-fill-tertiary);
  text-decoration: none;
}

.ds-sidebar__link--active {
  background: var(--space-color-primary-subtle);
  color: var(--space-color-primary);
  font-weight: var(--space-weight-semibold);
}

.ds-main {
  flex: 1;
  min-width: 0;
}

.ds-header {
  padding: var(--space-6) var(--space-4);
  background: var(--space-bg-primary);
  border-bottom: 0.5px solid var(--space-separator);
}

.ds-header__title {
  font-size: var(--space-text-3xl);
  font-weight: var(--space-weight-bold);
  margin: 0;
  letter-spacing: var(--space-tracking-tight);
}

.ds-header__desc {
  margin: var(--space-2) 0 0;
  color: var(--space-label-secondary);
  font-size: var(--space-text-base);
  max-width: 560px;
}

.ds-content {
  padding: var(--space-4);
  max-width: var(--space-content-max);
}

.ds-section {
  margin-bottom: var(--space-8);
  scroll-margin-top: var(--space-6);
}

.ds-section__title {
  font-size: var(--space-text-xl);
  font-weight: var(--space-weight-semibold);
  margin: 0 0 var(--space-1);
}

.ds-section__desc {
  font-size: var(--space-text-sm);
  color: var(--space-label-secondary);
  margin: 0 0 var(--space-4);
}

.ds-panel {
  background: var(--space-bg-primary);
  border-radius: var(--space-radius-xl);
  padding: var(--space-5);
  margin-bottom: var(--space-3);
  border: 0.5px solid var(--space-separator);
}

.ds-panel--grouped {
  background: var(--space-bg-secondary);
  border: none;
}

.ds-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.ds-row--stack {
  flex-direction: column;
  align-items: stretch;
}

.ds-row + .ds-row {
  margin-top: var(--space-4);
}

.ds-label {
  font-size: var(--space-text-xs);
  color: var(--space-label-tertiary);
  margin-bottom: var(--space-2);
  font-weight: var(--space-weight-medium);
}

.ds-swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-3);
}

.ds-swatch {
  border-radius: var(--space-radius-lg);
  overflow: hidden;
  border: 0.5px solid var(--space-separator);
}

.ds-swatch__color {
  height: 64px;
}

.ds-swatch__info {
  padding: var(--space-2) var(--space-3);
  background: var(--space-bg-primary);
}

.ds-swatch__name {
  font-size: var(--space-text-sm);
  font-weight: var(--space-weight-medium);
}

.ds-swatch__value {
  font-size: var(--space-text-xs);
  color: var(--space-label-tertiary);
  font-family: var(--space-font-mono);
}

.ds-type-sample {
  padding: var(--space-3) 0;
  border-bottom: 0.5px solid var(--space-separator);
}

.ds-type-sample:last-child {
  border-bottom: none;
}

.ds-type-meta {
  font-size: var(--space-text-xs);
  color: var(--space-label-tertiary);
  font-family: var(--space-font-mono);
  margin-top: var(--space-1);
}

.ds-mobile-nav {
  display: flex;
  overflow-x: auto;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--space-bg-primary);
  border-bottom: 0.5px solid var(--space-separator);
  -webkit-overflow-scrolling: touch;
}

.ds-mobile-nav__link {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--space-radius-full);
  font-size: var(--space-text-sm);
  background: var(--space-bg-fill-tertiary);
  color: var(--space-label-primary);
  text-decoration: none;
}

.ds-mobile-nav__link:hover {
  text-decoration: none;
  background: var(--space-bg-fill);
}

.ds-device-frame {
  max-width: 390px;
  border-radius: var(--space-radius-2xl);
  overflow: hidden;
  border: 6px solid #1c1c1e;
  box-shadow: var(--space-shadow-lg);
  background: var(--space-bg-secondary);
}

@media (min-width: 900px) {
  .ds-sidebar {
    display: block;
  }

  .ds-mobile-nav {
    display: none;
  }

  .ds-header {
    padding: var(--space-8) var(--space-6);
  }

  .ds-content {
    padding: var(--space-6);
  }
}

@media (max-width: 899px) {
  .ds-header__title {
    font-size: var(--space-text-2xl);
  }
}

/* ─── Links ─── */

.space-link {
  color: var(--space-color-link);
  text-decoration: none;
  cursor: pointer;
}

.space-link:hover {
  color: var(--space-color-link-hover);
  text-decoration: underline;
}

.space-link:visited {
  color: var(--space-color-link-visited);
}

.space-link--inline {
  font-weight: var(--space-weight-medium);
}

.space-link--muted {
  color: var(--space-label-secondary);
}

.space-link--muted:hover {
  color: var(--space-color-link);
}

.space-link-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) 0;
  color: var(--space-color-link);
  font-size: var(--space-text-md);
  text-decoration: none;
}

.space-link-row:hover {
  text-decoration: none;
  opacity: 0.8;
}

.space-link-row .space-icon {
  color: var(--space-color-primary);
}

/* ─── Map ─── */

.space-map {
  position: relative;
  border-radius: var(--space-radius-lg);
  overflow: hidden;
  background: linear-gradient(160deg, #d4e8d0 0%, #b8d4f0 45%, #e8e0d0 100%);
  min-height: 200px;
}

.space-map--tall {
  min-height: 280px;
}

.space-map__grid {
  position: absolute;
  inset: 0;
  opacity: 0.15;
  background-image:
    linear-gradient(var(--space-gray-3) 1px, transparent 1px),
    linear-gradient(90deg, var(--space-gray-3) 1px, transparent 1px);
  background-size: 24px 24px;
}

.space-map__pin {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -100%);
  width: 32px;
  height: 40px;
  background: var(--space-color-danger);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z'/%3E%3C/svg%3E") center/contain no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z'/%3E%3C/svg%3E") center/contain no-repeat;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.space-map__card {
  position: absolute;
  bottom: var(--space-3);
  left: var(--space-3);
  right: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--space-bg-primary);
  border-radius: var(--space-radius-md);
  box-shadow: var(--space-shadow-md);
}

.space-map__card-body {
  flex: 1;
  min-width: 0;
}

.space-map__card-title {
  font-size: var(--space-text-base);
  font-weight: var(--space-weight-semibold);
}

.space-map__card-desc {
  font-size: var(--space-text-sm);
  color: var(--space-label-secondary);
  margin-top: 2px;
}

.space-map__nav-btn {
  flex-shrink: 0;
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--space-radius-full);
  background: var(--space-color-primary);
  color: #fff;
  font-size: var(--space-text-sm);
  font-weight: var(--space-weight-semibold);
  cursor: pointer;
}

/* ─── Filter chips (selected state) ─── */

.space-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 8px 14px;
  border-radius: var(--space-radius-full);
  border: 1.5px solid var(--space-gray-4);
  background: var(--space-bg-primary);
  font-size: var(--space-text-base);
  color: var(--space-label-primary);
  cursor: pointer;
  transition: all var(--space-duration-fast);
}

.space-chip:hover {
  border-color: var(--space-gray-3);
}

.space-chip--selected {
  border-color: var(--space-color-selected);
  background: var(--space-color-selected-bg);
  color: var(--space-color-selected);
  font-weight: var(--space-weight-semibold);
}

.space-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ─── Social action bar ─── */

.space-social-bar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: var(--space-2) 0;
  border-top: 0.5px solid var(--space-separator);
}

/* ─── Color state samples ─── */

.ds-state-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.ds-state-card {
  flex: 1;
  min-width: 140px;
  padding: var(--space-4);
  border-radius: var(--space-radius-lg);
  text-align: center;
  font-size: var(--space-text-sm);
  font-weight: var(--space-weight-medium);
}

.ds-state-card--primary {
  background: var(--space-color-primary);
  color: #fff;
}

.ds-state-card--secondary {
  background: var(--space-color-secondary);
  color: #fff;
}

.ds-state-card--selected {
  background: var(--space-color-selected-bg);
  color: var(--space-color-selected);
  border: 1.5px solid var(--space-color-selected);
}

.ds-state-card--accent {
  background: var(--space-color-accent-subtle);
  color: var(--space-color-accent);
}

.ds-state-card--disabled {
  background: var(--space-bg-fill-tertiary);
  color: var(--space-color-disabled);
}

/* ─── Search variants ─── */

.space-search--nav {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  margin: 0;
  border-radius: 10px;
  background: var(--space-bg-fill);
}

.space-search--nav .space-input {
  padding-left: 0;
  border-radius: 0;
  background: transparent;
}

/* ─── Link card ─── */

.space-link-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--space-bg-primary);
  border-radius: var(--space-radius-lg);
  text-decoration: none;
  color: inherit;
  border: 0.5px solid var(--space-separator);
  transition: background var(--space-duration-fast);
}

.space-link-card:hover {
  background: var(--space-bg-fill-tertiary);
  text-decoration: none;
}

.space-link-card__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--space-radius-md);
  background: var(--space-color-primary-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.space-link-card__body {
  flex: 1;
  min-width: 0;
}

.space-link-card__title {
  font-size: var(--space-text-base);
  font-weight: var(--space-weight-semibold);
}

.space-link-card__url {
  font-size: var(--space-text-sm);
  color: var(--space-label-secondary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

