/* 라이브러리 상세 뷰 스타일 */

.library-detail-view {
  position: fixed;
  top: 60px; /* 헤더 높이 */
  left: 150px; /* 메인 사이드바 너비 */
  right: 0;
  bottom: 0;
  background: var(--bg-primary, #f5f5f5);
  z-index: 100;
  overflow: hidden;
}

.library-detail-container {
  display: flex;
  height: 100%;
}

/* 3D 뷰어 영역 */
.library-3d-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  position: relative;
}

.viewer-canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.viewer-canvas-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* 로딩 오버레이 */
.viewer-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(26, 26, 46, 0.9);
  color: #fff;
}

.viewer-loading .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--primary-color, #F56342);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.viewer-loading p {
  margin-top: 16px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
}

.viewer-controls {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  background: rgba(0, 0, 0, 0.3);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.viewer-control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

.viewer-control-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.viewer-control-btn.active {
  background: var(--primary-color, #F56342);
}

/* 사이드바 - 왼쪽에 위치 */
.library-detail-sidebar {
  width: 320px;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* 사이드바 헤더 */
.sidebar-header-section {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  background: #fafafa;
}

.sidebar-header-section .back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #f0f0f0;
  border: none;
  border-radius: 6px;
  color: #333;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 12px;
}

.sidebar-header-section .back-btn:hover {
  background: #e0e0e0;
}

.sidebar-header-section .library-title {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin: 0;
  line-height: 1.4;
}

/* 헤더 상단 행: 뒤로가기 + 수정/삭제 버튼 */
.header-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 소유자 전용: 수정/삭제 버튼 */
.library-header-actions {
  display: flex;
  gap: 6px;
}

.library-header-actions button {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  color: #555;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.library-header-actions button:hover {
  background: #e8e8e8;
  color: #333;
}

.library-header-actions .delete-library-btn:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #dc2626;
}

.sidebar-section {
  padding: 20px;
  border-bottom: 1px solid #eee;
}

.sidebar-section:last-child {
  border-bottom: none;
}

.sidebar-section .section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin: 0 0 16px 0;
}

.sidebar-section .section-title svg {
  color: #666;
}

/* 작성자 정보 */
.library-author-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.author-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color, #F56342), #d94a2e);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  background-size: cover;
  background-position: center;
}

.author-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.author-name {
  font-size: 15px;
  font-weight: 600;
  color: #333;
}

.library-date {
  font-size: 12px;
  color: #888;
}

.library-description {
  font-size: 14px;
  color: #555;
  line-height: 1.6;
  margin: 0;
}

/* 제원 정보 */
.dimensions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.dimension-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
}

.dimension-label {
  font-size: 12px;
  color: #888;
}

.dimension-value {
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.dimension-value .unit {
  font-size: 12px;
  font-weight: 400;
  color: #666;
  margin-left: 2px;
}

/* 연결된 상품 목록 */
.linked-count {
  font-weight: 400;
  color: #888;
}

.linked-products-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.linked-product-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.linked-product-card:hover {
  background: #f0f0f0;
}

.product-thumbnail {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  background: #ddd;
}

.product-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.product-name {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

.product-company {
  font-size: 12px;
  color: #888;
}

.product-price {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-color, #F56342);
}

.no-products-message {
  text-align: center;
  padding: 24px;
  color: #888;
  font-size: 14px;
}

/* 연결 요청 중 상태 배지 */
.link-status-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  margin-left: 6px;
  vertical-align: middle;
}

.link-status-badge.pending {
  background: #fff3e0;
  color: #f57c00;
  border: 1px solid #ffe0b2;
}

.link-status-badge.approved {
  background: #e8f5e9;
  color: #388e3c;
  border: 1px solid #c8e6c9;
}

/* pending 상태 카드 스타일 */
.linked-product-card.pending {
  background: #fffbf5;
  border: 1px dashed #ffe0b2;
}

.linked-product-card.pending:hover {
  background: #fff8f0;
}

/* 상품 연결 관리 */
.manage-links-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: var(--primary-color, #F56342);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}

.manage-links-btn:hover {
  opacity: 0.9;
}

.link-management-panel {
  margin-top: 16px;
}

.search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-color, #F56342);
}

.link-management-panel .search-btn {
  position: static;
  transform: none;
  padding: 10px 16px;
  background: #333;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.link-management-panel .search-btn:hover {
  background: #444;
}

.link-management-panel .search-btn.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  min-width: 42px;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
}

.link-management-panel .search-btn.icon-btn svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
}

/* 연결 요청 중 */
.pending-requests {
  margin-bottom: 16px;
}

.pending-requests h4 {
  font-size: 13px;
  color: #666;
  margin: 0 0 8px 0;
}

.pending-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pending-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #fff8e6;
  border: 1px solid #ffe0b2;
  border-radius: 8px;
}

.pending-item .product-name {
  flex: 1;
  font-size: 13px;
}

.pending-status {
  font-size: 11px;
  color: #f57c00;
  padding: 4px 8px;
  background: rgba(245, 124, 0, 0.1);
  border-radius: 4px;
}

.cancel-pending-btn {
  padding: 4px 8px;
  background: none;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 11px;
  color: #666;
  cursor: pointer;
}

.cancel-pending-btn:hover {
  background: #f5f5f5;
}

/* 검색 결과 */
.search-results {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.search-result-item:hover {
  background: #f0f0f0;
}

.search-result-item.selected {
  background: #e3f2fd;
  border: 1px solid #90caf9;
}

.search-result-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-color, #F56342);
}

.search-result-item .product-thumbnail {
  width: 48px;
  height: 48px;
}

.search-result-item .product-info {
  flex: 1;
}

.search-result-item .product-name {
  font-size: 13px;
}

.search-result-item .product-price {
  font-size: 13px;
}

/* 연결 요청 버튼 */
.link-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #eee;
}

.selected-count {
  font-size: 13px;
  color: #666;
}

.request-link-btn {
  padding: 10px 20px;
  background: var(--primary-color, #F56342);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.request-link-btn:hover {
  opacity: 0.9;
}

.request-link-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 내가 등록한 상품 섹션 */
.my-products-search {
  margin-bottom: 12px;
}

.my-products-search .search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  background-color: #fff;
}

.my-products-search .search-input:focus {
  outline: none;
  border-color: var(--primary-color, #F56342);
}

.my-products-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
}

.my-product-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.my-product-card:hover {
  background: #f0f0f0;
}

.my-product-card.linked {
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
}

.my-product-card .product-checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--primary-color, #F56342);
  cursor: pointer;
  flex-shrink: 0;
}

.my-product-card .product-thumbnail {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  background: #ddd;
  flex-shrink: 0;
}

.my-product-card .product-info {
  flex: 1;
  min-width: 0;
}

.my-product-card .product-name {
  font-size: 13px;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.my-product-card .product-price {
  font-size: 12px;
  color: var(--primary-color, #F56342);
  font-weight: 500;
}

/* 연결 요청 버튼 (소형) */
.request-link-btn-small {
  padding: 6px 12px;
  background: var(--primary-color, #F56342);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.request-link-btn-small:hover {
  opacity: 0.85;
}

/* 연결된 상품 체크박스 (소유자용) */
.linked-product-card .product-checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--primary-color, #F56342);
  cursor: pointer;
  flex-shrink: 0;
}

/* 저장 버튼 섹션 */
.save-section {
  padding: 16px 20px;
  background: #fafafa;
  border-top: 1px solid #eee;
  position: sticky;
  bottom: 0;
}

.save-links-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  background: var(--primary-color, #F56342);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.save-links-btn:hover {
  opacity: 0.9;
}

.save-links-btn:active {
  transform: scale(0.98);
}

.save-links-btn svg {
  width: 18px;
  height: 18px;
}

/* 반응형 - 태블릿 (메인 사이드바 축소형 옆에 배치) */
@media (min-width: 769px) and (max-width: 1024px) {
  .library-detail-view {
    left: var(--sidebar-collapsed-width, 80px); /* 축소된 메인 사이드바 너비 */
    top: 60px;
  }
}

/* 반응형 - 모바일 */
@media (max-width: 768px) {
  .library-detail-view {
    left: 0;
    top: 60px;
  }

  .library-detail-container {
    flex-direction: column;
    position: relative;
  }

  /* 모바일: 사이드바 전체 화면 */
  .library-detail-sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    width: 100% !important;
    height: calc(100vh - 60px) !important;
    max-height: none;
    border-right: none;
    border-bottom: none;
    z-index: 1000;
    transform: translateX(0);
    transition: transform 0.3s ease-in-out;
  }

  /* 모바일: 사이드바 접힘 */
  .library-detail-sidebar.collapsed {
    transform: translateX(-100%) !important;
  }

  /* 모바일: 3D 뷰어 숨김 (기본) */
  .library-3d-viewer {
    display: none !important;
  }

  /* 모바일: 사이드바 접히면 3D 뷰어 보임 */
  .library-detail-container.sidebar-collapsed .library-3d-viewer {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    top: 60px;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 60px) !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 999;
  }

  .library-detail-container.sidebar-collapsed .viewer-canvas-container,
  .library-detail-container.sidebar-collapsed #library-viewer-container {
    flex: 1;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .library-detail-container.sidebar-collapsed .viewer-canvas-container canvas,
  .library-detail-container.sidebar-collapsed #library-viewer-container canvas {
    display: block !important;
    width: 100vw !important;
    height: 100% !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
  }

  /* 모바일: 정보 툴바 숨김 */
  .library-detail-container.sidebar-collapsed #library-info-toolbar,
  .library-detail-container.sidebar-collapsed .canvas-info-toolbar {
    display: none !important;
  }

  /* 모바일: 뷰어 컨트롤 숨김 */
  .library-detail-container.sidebar-collapsed .viewer-controls {
    display: none !important;
  }

  /* 모바일: 토글 버튼 위치 */
  .library-sidebar-toggle {
    position: fixed;
    left: auto !important;
    right: 10px;
    top: 80px;
    transform: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid #ddd;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 1100;
  }

  .library-detail-container.sidebar-collapsed .library-sidebar-toggle {
    left: auto !important;
    right: 10px;
  }

  .sidebar-header-section {
    padding: 12px 16px;
  }

  .sidebar-header-section .library-title {
    font-size: 16px;
  }
}

/* ============================================
   라이브러리 정보 툴바 (3D 뷰어 상단)
   ============================================ */

.canvas-info-toolbar {
  height: 56px;
  background: #fff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

.canvas-toolbar-section {
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  border-right: 1px solid #eee;
}

.canvas-toolbar-section:last-child {
  border-right: none;
}

.canvas-toolbar-section.title-section {
  flex: 1;
  min-width: 100px;
}

.canvas-toolbar-section.keywords-section {
  flex: 2;
  min-width: 150px;
}

.canvas-toolbar-section.visibility-section {
  min-width: 80px;
}

.canvas-toolbar-section.thumbnail-section {
  padding: 4px 16px;
  justify-content: center;
}

.canvas-toolbar-label {
  font-size: 10px;
  color: #888;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.canvas-toolbar-title,
.canvas-toolbar-keywords,
.canvas-toolbar-visibility {
  font-size: 13px;
  color: #333;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.canvas-toolbar-category {
  font-size: 13px;
  color: #4A90E2;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.canvas-toolbar-keywords {
  font-weight: 400;
  color: #555;
}

.canvas-toolbar-thumbnail {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid #eee;
}

.canvas-toolbar-no-image {
  font-size: 11px;
  color: #999;
  white-space: nowrap;
}

/* ========== 사이드바 토글 버튼 ========== */
.library-sidebar-toggle {
  position: absolute;
  left: 308px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 48px;
  background: #fff;
  border: 1px solid #ddd;
  border-left: none;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #666;
  box-shadow: 2px 0 4px rgba(0,0,0,0.1);
  transition: left 0.3s ease-in-out;
}

.library-sidebar-toggle:hover {
  background: #f5f5f5;
  color: #333;
}

/* 사이드바 접힘 상태 */
.library-detail-sidebar {
  transition: transform 0.3s ease-in-out;
}

.library-detail-sidebar.collapsed {
  transform: translateX(-320px);
}

.library-detail-container.sidebar-collapsed .library-sidebar-toggle {
  left: 0;
  border-left: 1px solid #ddd;
}

.library-detail-container.sidebar-collapsed .library-3d-viewer {
  margin-left: -320px;
  transition: margin-left 0.3s ease-in-out;
}

.library-3d-viewer {
  transition: margin-left 0.3s ease-in-out;
}

.header-top-row .back-btn {
  margin-bottom: 0px;
}