/**
 * サイドバー固定スタイル（拡張版）
 * SANGOテーマに最適化
 */

/* SANGOのサイドバー構造に対応 */
#sidebar1 .insidesp {
  position: relative;
}

/* normalとfixedの両方に対応 */
#sidebar1 .normal-sidebar,
#sidebar1 #fixed_sidebar {
  position: sticky;
  position: -webkit-sticky;
  top: 20px;
  z-index: 50;
  transition: top 0.3s ease;
}

/* 管理バーがある場合 */
.admin-bar #sidebar1 .normal-sidebar,
.admin-bar #sidebar1 #fixed_sidebar {
  top: 52px; /* 32px + 20px */
}

@media screen and (max-width: 782px) {
  .admin-bar #sidebar1 .normal-sidebar,
  .admin-bar #sidebar1 #fixed_sidebar {
    top: 66px; /* 46px + 20px */
  }
}

/* フローティングヘッダーがある場合 */
#floating-header.visible ~ #container #sidebar1 .normal-sidebar,
#floating-header.visible ~ #container #sidebar1 #fixed_sidebar {
  top: 80px; /* 60px + 20px */
}

.admin-bar #floating-header.visible ~ #container #sidebar1 .normal-sidebar,
.admin-bar #floating-header.visible ~ #container #sidebar1 #fixed_sidebar {
  top: 112px; /* 32px + 60px + 20px */
}

/* サイドバーコンテンツの高さ制限 */
#sidebar1 .normal-sidebar,
#sidebar1 #fixed_sidebar {
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-right: 10px;
}

.admin-bar #sidebar1 .normal-sidebar,
.admin-bar #sidebar1 #fixed_sidebar {
  max-height: calc(100vh - 72px);
}

/* ウィジェット間の余白調整 */
#sidebar1 .widget {
  margin-bottom: 30px;
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

#sidebar1 .widget:last-child {
  margin-bottom: 20px;
}

/* スクロールバーのカスタマイズ */
#sidebar1 .normal-sidebar::-webkit-scrollbar,
#sidebar1 #fixed_sidebar::-webkit-scrollbar {
  width: 6px;
}

#sidebar1 .normal-sidebar::-webkit-scrollbar-track,
#sidebar1 #fixed_sidebar::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 3px;
}

#sidebar1 .normal-sidebar::-webkit-scrollbar-thumb,
#sidebar1 #fixed_sidebar::-webkit-scrollbar-thumb {
  background: #c0c0c0;
  border-radius: 3px;
}

#sidebar1 .normal-sidebar::-webkit-scrollbar-thumb:hover,
#sidebar1 #fixed_sidebar::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* タブレット以下では固定を解除 */
@media screen and (max-width: 1030px) {
  #sidebar1 .normal-sidebar,
  #sidebar1 #fixed_sidebar {
    position: static !important;
    top: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
  }
  
  #sidebar1 .widget {
    margin-bottom: 20px;
  }
}

/* パフォーマンス最適化 */
#sidebar1 .normal-sidebar,
#sidebar1 #fixed_sidebar {
  will-change: position, top;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* 固定時の影（オプション） */
#sidebar1 .normal-sidebar.is-fixed,
#sidebar1 #fixed_sidebar.is-fixed {
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.98);
  border-radius: 8px;
  padding: 15px;
}

/* スムーズな表示 */
#sidebar1 {
  opacity: 0;
  animation: sidebarFadeIn 0.5s ease forwards;
  animation-delay: 0.3s;
}

@keyframes sidebarFadeIn {
  to {
    opacity: 1;
  }
}

/* コンテンツが少ない場合の調整 */
#sidebar1 .normal-sidebar:not(.has-many-widgets),
#sidebar1 #fixed_sidebar:not(.has-many-widgets) {
  position: relative;
  top: 0 !important;
}