/* Devices 页面样式：极简风格，响应式设计 */

/* 主容器 */
.Devices-container {
  width: 100%;
  height: 100%;

  display: flex;
  box-sizing: border-box;
  flex-direction: column;
  align-items: flex-start;
  background: #f8f9fa;
  /* padding: clamp(0.75rem, 2vw, 1.5rem); */
}

/* 头部区域 */
.devices-header {
  width: 100%;
  display: grid;
  grid-template-columns: 65% 35%;
  align-items: center;
  gap: clamp(0.5rem, 1.5vw, 1rem);
  box-sizing: border-box;
  border: 1px solid #e5e7eb;
  border-radius: clamp(6px, 1vw, 8px);
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  container-type: inline-size; /* enable cqw-based scaling */
  padding: clamp(0.5rem, 1.5vw, 1rem);
}

/* 标题 */
.devices-title {
  width: 100%; /* takes its 60% grid column */
  display: flex;
  box-sizing: border-box;
  align-items: center;

  font-size: clamp(1rem, 6cqw, 1.9rem);
  font-weight: 600;
  color: #1a1a1a;
  letter-spacing: -0.5px;
  line-height: 1.2;
  white-space: nowrap;
}

/* 刷新按钮 */
.refresh-btn {
  justify-self: start;
  width: 80%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.15rem, 0.8cqw, 0.4rem);
  padding: clamp(0.36rem, 1.1cqw, 0.6rem) clamp(0.6rem, 1.5cqw, 1rem);
  background: #1a1a1a;
  color: white;
  border: none;
  border-radius: clamp(6px, 1vw, 8px);
  cursor: pointer;
  /* about 80% of original size */
  font-size: clamp(0.6rem, 2.1cqw, 0.84rem); /* scale text/icon with button */
  font-weight: 500;
  transition: all 0.2s ease;
  line-height: 1.2;
  user-select: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.refresh-btn:hover:not(.disabled) {
  background: #333;
  transform: translateY(-1px);
}

.refresh-btn:active:not(.disabled) {
  transform: translateY(0);
}

.refresh-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #ccc;
}

.refresh-btn.disabled:hover {
  transform: none;
}

/* 刷新图标 */
.refresh-icon {
  font-size: 1em; /* inherit current button size */
  transition: transform 0.3s ease;
  display: inline-block;
}

/* 悬停时图标旋转 */
.refresh-btn:hover .refresh-icon:not(.spinning) {
  transform: rotate(180deg);
}

/* 扫描中图标持续旋转 */
.refresh-icon.spinning {
  animation: spin 1s linear infinite;
}

/* 旋转动画 */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 滚动区域 */
.devices-scroll-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  width: 100%;
  box-sizing: border-box;
}

/* 自定义滚动条 */
.devices-scroll-area::-webkit-scrollbar {
  width: 6px;
}

.devices-scroll-area::-webkit-scrollbar-track {
  background: transparent;
}

.devices-scroll-area::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.devices-scroll-area::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* 设备项 */
.device-item {
  display: grid;
  grid-template-columns: 1fr auto; /* text flexes, button keeps size */
  align-items: center;
  width: 100%; /* align with header width */
  box-sizing: border-box;
  column-gap: clamp(0.25rem, 0.8vw, 0.6rem);
  padding: clamp(0.6rem, 1.2vw, 0.85rem) clamp(0.75rem, 1.6vw, 1rem);
  margin-bottom: clamp(0.5rem, 1.5vw, 0.75rem);
  background: white;
  border-radius: clamp(6px, 1vw, 8px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
  border: 1px solid #e5e7eb;
  container-type: inline-size; /* allow cqw-based scaling inside */

}

.device-item:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-color: #d1d5db;
  transform: translateY(-1px);
}

.device-actions {
  display: flex;
  flex-direction: column;
  gap: clamp(0.4rem, 1vw, 0.75rem);
  align-items: flex-start;
}

.action-row {
  display: flex;
  flex-direction: column;
  gap: clamp(0.4rem, 1vw, 0.75rem);
  align-items: flex-end;
}

/* 设备信息容器 */
.device-info {
  width: 100%;
  min-width: 0;
}

/* 设备 ID（IP:端口） */
.device-id {
  /* scale with device-item width */
  width: 100%;
  font-size: clamp(0.45rem, 2.4cqw, 0.85rem);
  font-weight: 500;
  color: #1a1a1a;
  font-family: 'Courier New', 'Consolas', monospace;
  overflow-wrap: anywhere;
  word-break: break-all;
  white-space: normal;
  letter-spacing: 0;
  line-height: 1.35;
}

/* 连接按钮 */
.connect-btn {
  /* scale with device-item width */
  width: auto;
  padding: clamp(0.32rem, 0.9cqw, 0.5rem) clamp(0.5rem, 1.3cqw, 0.85rem);
  background: #1a1a1a;
  color: white;
  border: none;
  border-radius: clamp(6px, 1vw, 8px);
  cursor: pointer;
  font-size: clamp(0.65rem, 1.6cqw, 0.85rem);
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
  margin-left: clamp(0.25rem, 1vw, 0.75rem);
  user-select: none;
  flex-shrink: 0;
}

.connect-btn:hover:not(.disabled) {
  background: #333;
  transform: translateY(-1px);
}

.connect-btn:active:not(.disabled) {
  transform: translateY(0);
}

.connect-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #ccc;
}

.connect-btn.disabled:hover {
  transform: none;
}

/* 断开按钮 */
.disconnect-btn {
  /* match connect button sizing */
  padding: clamp(0.32rem, 0.9cqw, 0.5rem) clamp(0.5rem, 1.3cqw, 0.85rem);
  background: #dc2626;
  color: white;
  border: none;
  border-radius: clamp(6px, 1vw, 8px);
  cursor: pointer;
  font-size: clamp(0.65rem, 1.6cqw, 0.85rem);
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
  user-select: none;
  flex-shrink: 0;
}

.disconnect-btn:hover:not(.disabled) {
  background: #b91c1c;
  transform: translateY(-1px);
}

.disconnect-btn:active:not(.disabled) {
  transform: translateY(0);
}

.disconnect-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #ccc;
}

.disconnect-btn.disabled:hover {
  transform: none;
}

/* 预览按钮 */
.preview-btn {
  padding: clamp(0.32rem, 0.9cqw, 0.5rem) clamp(0.5rem, 1.3cqw, 0.85rem);
  background: #2abf6e;
  color: white;
  border: none;
  border-radius: clamp(6px, 1vw, 8px);
  cursor: pointer;
  font-size: clamp(0.65rem, 1.6cqw, 0.85rem);
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
  user-select: none;
  flex-shrink: 0;
}

.preview-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: #ccc;
}

.preview-btn--active {
  background: #4a90e2;
  color: #fff;
}

/* 平板适配 */
@media (min-width: 768px) and (max-width: 1023px) {
  .devices-header {
    padding: clamp(0.75rem, 1.5vw, 1rem);
  }
}

/* 移动端适配 */
@media (max-width: 767px) {
  .Devices-container {
    padding: clamp(0.5rem, 2vw, 1rem);
  }
  
  .devices-header {
    flex-direction: column;
    align-items: flex-start;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    padding: clamp(0.75rem, 2vw, 1rem);
  }
  
  .refresh-btn {
    width: 100%;
    justify-content: center;
  }
  
  .device-item {
    flex-direction: column;
    align-items: flex-start;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
  }
  
  .connect-btn {
    width: 100%;
    margin-left: 0;
  }
}
