/* === TCM Home Sidebar Navigation === */
/* Five-pillar system: 自学-自查-自诊-自疗-自愈 */

/* Reset & container */
.tcm-sidebar,
.tcm-sidebar * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
.tcm-sidebar {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 9990;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 4px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-left: 1px solid var(--tcm-border, #E3DFD6);
  border-radius: 12px 0 0 12px;
  box-shadow: -4px 0 16px rgba(42, 41, 39, 0.06);
  transition: all 0.3s ease;
  font-family: var(--tcm-font-sans, "Inter", Arial, sans-serif);
  max-height: 90vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--tcm-border, #E3DFD6) transparent;
}
.tcm-sidebar::-webkit-scrollbar { width: 3px; }
.tcm-sidebar::-webkit-scrollbar-thumb { background: var(--tcm-border, #E3DFD6); border-radius: 2px; }

/* Dark mode */
[data-theme="dark"] .tcm-sidebar {
  background: rgba(30, 29, 27, 0.92);
  border-left-color: rgba(255,255,255,0.08);
  box-shadow: -4px 0 16px rgba(0,0,0,0.2);
}

/* Each pillar button */
.tcm-sidebar-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 6px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
  text-decoration: none;
  color: var(--tcm-foreground-secondary, #5C5A55);
  min-width: 52px;
}
.tcm-sidebar-item:hover,
.tcm-sidebar-item.active {
  background: var(--tcm-primary-50, #F1F5F1);
}
[data-theme="dark"] .tcm-sidebar-item:hover,
[data-theme="dark"] .tcm-sidebar-item.active {
  background: rgba(95, 125, 98, 0.15);
}

.tcm-sidebar-item.active {
  color: var(--tcm-primary, #5F7D62);
  font-weight: 600;
}

/* Icon circle */
.tcm-sidebar-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tcm-primary-100, #E0E8E1);
  color: var(--tcm-primary, #5F7D62);
  margin-bottom: 3px;
  transition: all 0.2s;
  flex-shrink: 0;
}
.tcm-sidebar-item:hover .tcm-sidebar-icon,
.tcm-sidebar-item.active .tcm-sidebar-icon {
  background: var(--tcm-primary, #5F7D62);
  color: #fff;
}
[data-theme="dark"] .tcm-sidebar-icon {
  background: rgba(95, 125, 98, 0.2);
}
[data-theme="dark"] .tcm-sidebar-item:hover .tcm-sidebar-icon,
[data-theme="dark"] .tcm-sidebar-item.active .tcm-sidebar-icon {
  background: var(--tcm-primary, #5F7D62);
}

.tcm-sidebar-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Label */
.tcm-sidebar-label {
  font-size: 11px;
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
}

/* Main link wrapper (clickable hub navigation) */
.tcm-sidebar-main-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

/* View All link in panel */
.tcm-sidebar-view-all {
  display: flex !important;
  align-items: center;
  justify-content: center;
  padding: 8px 10px !important;
  margin-bottom: 4px;
  font-size: 12px !important;
  font-weight: 600 !important;
  color: var(--tcm-primary, #5F7D62) !important;
  background: var(--tcm-primary-50, #F1F5F1);
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.15s;
}
.tcm-sidebar-view-all:hover {
  background: var(--tcm-primary, #5F7D62) !important;
  color: #fff !important;
}
[data-theme="dark"] .tcm-sidebar-view-all {
  background: rgba(95, 125, 98, 0.15);
}

/* Expand panel */
.tcm-sidebar-panel {
  position: absolute;
  right: 100%;
  top: 0;
  min-width: 200px;
  background: var(--tcm-surface, #FFFFFF);
  border: 1px solid var(--tcm-border, #E3DFD6);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(42, 41, 39, 0.1);
  padding: 8px;
  margin-right: 6px;
  opacity: 0;
  visibility: hidden;
  transform: translateX(8px);
  transition: all 0.25s ease;
  max-height: 400px;
  overflow-y: auto;
  scrollbar-width: thin;
}
[data-theme="dark"] .tcm-sidebar-panel {
  background: var(--tcm-surface, #2A2927);
  border-color: rgba(255,255,255,0.08);
}

.tcm-sidebar-item:hover .tcm-sidebar-panel,
.tcm-sidebar-item.expanded .tcm-sidebar-panel {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

/* Panel header */
.tcm-sidebar-panel-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tcm-foreground-tertiary, #8A8780);
  padding: 6px 10px 4px;
  border-bottom: 1px solid var(--tcm-border, #E3DFD6);
  margin-bottom: 4px;
}

/* Panel links */
.tcm-sidebar-panel a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--tcm-foreground-secondary, #5C5A55);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.15s;
  line-height: 1.4;
}
.tcm-sidebar-panel a:hover {
  background: var(--tcm-primary-50, #F1F5F1);
  color: var(--tcm-primary, #5F7D62);
}
[data-theme="dark"] .tcm-sidebar-panel a:hover {
  background: rgba(95, 125, 98, 0.15);
}
.tcm-sidebar-panel a.current {
  background: var(--tcm-primary-100, #E0E8E1);
  color: var(--tcm-primary, #5F7D62);
  font-weight: 500;
}
[data-theme="dark"] .tcm-sidebar-panel a.current {
  background: rgba(95, 125, 98, 0.2);
}
.tcm-sidebar-panel a svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  flex-shrink: 0;
}

/* Collapse toggle */
.tcm-sidebar-toggle {
  display: none;
}

/* === Mobile === */
@media (max-width: 768px) {
  .tcm-sidebar {
    top: auto;
    bottom: 16px;
    right: 16px;
    transform: none;
    flex-direction: row;
    gap: 4px;
    padding: 4px;
    border-radius: 28px;
    border: 1px solid var(--tcm-border, #E3DFD6);
    max-height: none;
    overflow: visible;
  }
  .tcm-sidebar.collapsed {
    padding: 8px;
  }
  .tcm-sidebar.collapsed .tcm-sidebar-item {
    display: none;
  }
  .tcm-sidebar.collapsed .tcm-sidebar-mobile-btn {
    display: flex;
  }

  .tcm-sidebar-item {
    min-width: 44px;
    padding: 6px 4px;
  }
  .tcm-sidebar-icon {
    width: 28px;
    height: 28px;
  }
  .tcm-sidebar-icon svg {
    width: 16px;
    height: 16px;
  }
  .tcm-sidebar-label {
    font-size: 10px;
  }

  /* Mobile: panels open as overlay */
  .tcm-sidebar-panel {
    position: fixed;
    right: 16px;
    bottom: 70px;
    top: auto;
    transform: none;
    margin-right: 0;
    min-width: 240px;
    max-height: 60vh;
    z-index: 9991;
  }
  .tcm-sidebar-item:hover .tcm-sidebar-panel,
  .tcm-sidebar-item.expanded .tcm-sidebar-panel {
    transform: none;
  }
  /* Close on outside click handled by JS */
}

/* Mobile toggle button */
.tcm-sidebar-mobile-btn {
  display: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--tcm-primary, #5F7D62);
  color: #fff;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  flex-shrink: 0;
}
.tcm-sidebar-mobile-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

/* Backdrop for mobile */
.tcm-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 9989;
}
.tcm-sidebar-backdrop.show {
  display: block;
}

/* Prevent body scroll when sidebar panel open on mobile */
body.tcm-sidebar-open {
  overflow: hidden;
}

/* Adjust page content to not be covered by sidebar */
@media (min-width: 769px) {
  body.tcm-has-sidebar {
    /* No padding needed - sidebar is slim and overlay-style */
  }
}
