* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
  background: #ffffff;
  min-height: 100vh;
  padding: 20px;
}

.container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  animation: fadeIn 0.5s ease-in;
  position: relative;
}

.header-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 30px;
}

.header-left {
  flex: 1;
}

.header-right {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1 {
  color: #1f2937;
  text-align: center;
  margin-bottom: 30px;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.status {
  text-align: center;
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 25px;
  font-weight: 500;
  transition: all 0.3s ease;
  border: 1px solid transparent;
}

.status.disconnected {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

.status.connecting {
  background: #fffbeb;
  color: #d97706;
  border-color: #fde68a;
}

.status.connected {
  background: #f0fdf4;
  color: #16a34a;
  border-color: #bbf7d0;
}

.status-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  animation: pulse 2s infinite;
}

.status.disconnected .status-indicator {
  background: #dc2626;
  animation: none;
}

.status.connecting .status-indicator {
  background: #d97706;
}

.status.connected .status-indicator {
  background: #16a34a;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.button-group {
  display: flex;
  flex-direction: row;
  gap: 10px;
  margin-bottom: 0;
}

.button-group.vertical {
  flex-direction: column;
  gap: 15px;
}

button {
  padding: 14px 24px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

button:not(:disabled):active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#connect {
  background: #3b82f6;
  color: white;
  padding: 10px 20px;
  font-size: 14px;
}

#connect:not(:disabled):hover {
  background: #2563eb;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

#disconnect {
  background: #ef4444;
  color: white;
  display: none;
  padding: 10px 20px;
  font-size: 14px;
}

#disconnect:not(:disabled):hover {
  background: #dc2626;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.input-group {
  margin-bottom: 25px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #374151;
  font-weight: 500;
  font-size: 14px;
}

input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  font-size: 16px;
  transition: all 0.2s ease;
  background: #ffffff;
}

input[type="text"]:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input[type="text"]:disabled {
  background: #f9fafb;
  border-color: #e5e7eb;
  cursor: not-allowed;
  color: #9ca3af;
}

#sendData {
  width: 100%;
  background: #10b981;
  color: white;
}

#sendData:not(:disabled):hover {
  background: #059669;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

#refreshDevices {
  width: 100%;
  background: #8b5cf6;
  color: white;
  margin-top: 15px;
}

#refreshDevices:not(:disabled):hover {
  background: #7c3aed;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.devices-container {
  margin-top: 25px;
}

.devices-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.devices-title {
  font-size: 24px;
  font-weight: 600;
  color: #1f2937;
}

.add-device-link {
  font-size: 14px;
  color: #3b82f6;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.2s ease;
}

.add-device-link:hover {
  color: #2563eb;
  text-decoration: underline;
}

#devicesList {
  min-height: 200px;
  max-height: 600px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

#devicesList:empty::before {
  content: "未获取设备列表";
  color: #9ca3af;
  font-style: italic;
  display: block;
  padding: 40px;
  text-align: center;
  grid-column: 1 / -1;
}

.device-item {
  background: #ffffff;
  border-radius: 12px;
  padding: 24px;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  position: relative;
  display: flex;
  flex-direction: column;
}

.device-item:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.device-title {
  font-weight: 600;
  color: #1f2937;
  font-size: 20px;
  margin: 0 0 8px 0;
}

.device-status {
  font-size: 14px;
  color: #6b7280;
  margin: 0;
}

.device-status.on {
  color: #16a34a;
}

.device-status.off {
  color: #6b7280;
}

.device-id-display {
  font-size: 11px;
  color: #9ca3af;
  font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
  margin-top: 4px;
}

.device-icon {
  font-size: 40px;
  opacity: 0.6;
  color: #9ca3af;
}

.device-properties-section {
  margin-top: 16px;
}

.property-control-group {
  margin-bottom: 20px;
  padding: 16px;
  background: #f9fafb;
  border-radius: 8px;
}

.property-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.property-name {
  font-weight: 600;
  color: #374151;
  font-size: 15px;
}

.property-api {
  font-size: 11px;
  color: #6b7280;
  font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
  background: #e5e7eb;
  padding: 4px 8px;
  border-radius: 4px;
}

.property-current-value {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 12px;
}

.property-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.property-input {
  flex: 1;
  min-width: 120px;
  padding: 8px 12px;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
}

.property-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.property-slider {
  flex: 1;
  min-width: 150px;
  height: 6px;
  border-radius: 3px;
  background: #e5e7eb;
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.property-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
}

.property-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
  border: none;
}

.property-btn {
  padding: 8px 16px;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.property-btn:hover {
  background: #2563eb;
}

.property-btn.active {
  background: #16a34a;
}

.property-btn.active:hover {
  background: #15803d;
}

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

.device-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* 开关样式 */
.toggle-switch {
  position: relative;
  width: 48px;
  height: 28px;
  background: #d1d5db;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.3s ease;
}

.toggle-switch.active {
  background: #3b82f6;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  background: #ffffff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch.active::after {
  transform: translateX(20px);
}

.control-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #ffffff;
  color: #6b7280;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s ease;
}

.control-btn:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.device-id {
  display: none;
}

#devicesList::-webkit-scrollbar {
  width: 8px;
}

#devicesList::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 4px;
}

#devicesList::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

#devicesList::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

.output-container {
  margin-top: 25px;
}

.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.output-label {
  color: #374151;
  font-weight: 500;
  font-size: 14px;
}

#clearOutput {
  padding: 6px 12px;
  font-size: 12px;
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

#clearOutput:hover {
  background: #e5e7eb;
  color: #374151;
}

#output {
  background: #f9fafb;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  padding: 16px;
  min-height: 150px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.8;
  color: #1f2937;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
}

#output:empty::before {
  content: "等待接收数据...";
  color: #9ca3af;
  font-style: italic;
}

.output-success {
  color: #16a34a;
  font-weight: 500;
}

.output-error {
  color: #dc2626;
  font-weight: 500;
}

.output-receive {
  color: #3b82f6;
}

.output-send {
  color: #8b5cf6;
}

#output::-webkit-scrollbar {
  width: 8px;
}

#output::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 4px;
}

#output::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

#output::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

.loading {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}

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

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #1f2937;
  color: white;
  padding: 14px 20px;
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.3s ease-out;
  z-index: 1000;
  font-size: 14px;
  font-weight: 500;
}

@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.error {
  background: #ef4444;
}

.toast.success {
  background: #10b981;
}

@media (max-width: 768px) {
  .container {
    padding: 30px 20px;
    max-width: 100%;
  }

  h1 {
    font-size: 24px;
  }

  .header-section {
    flex-direction: column;
    gap: 16px;
  }

  .header-right {
    width: 100%;
  }

  .button-group {
    width: 100%;
  }

  #devicesList {
    grid-template-columns: 1fr;
  }

  .devices-title {
    font-size: 20px;
  }

  .device-item {
    min-height: auto;
  }

  .property-controls {
    flex-direction: column;
  }

  .property-input {
    width: 100%;
  }

  .property-slider {
    width: 100%;
  }
}

