/* ============================================
   IoT Space - 智物空间 样式表
   ESP32 IoT Platform
   ============================================ */

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2332;
  --bg-card-hover: #1e293b;
  --bg-input: #0f1724;
  --border-color: #1e3a5f;
  --border-light: #2d4a6f;
  --text-primary: #e0e8f0;
  --text-secondary: #8b9cc0;
  --text-muted: #5a6f8f;
  --accent-cyan: #00e5ff;
  --accent-green: #00e676;
  --accent-orange: #ff9100;
  --accent-red: #ff4466;
  --accent-purple: #b388ff;
  --accent-yellow: #ffd740;
  --glow-cyan: 0 0 20px rgba(0, 229, 255, 0.25);
  --glow-green: 0 0 20px rgba(0, 230, 118, 0.25);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 4px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.6);
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, 'Courier New', monospace;
}

/* Reset & Base */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-cyan); text-decoration: none; transition: var(--transition); }
a:hover { color: #fff; text-shadow: var(--glow-cyan); }

::selection { background: rgba(0, 229, 255, 0.3); color: #fff; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-cyan); }

/* ============ NAV ============ */
.nav {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 1000;
  padding: 0 2rem;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(30, 58, 95, 0.5);
  transition: var(--transition);
}

.nav.scrolled {
  background: rgba(10, 14, 23, 0.95);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
}

.nav-brand {
  display: flex; align-items: center; gap: 0.75rem;
  font-size: 1.25rem; font-weight: 700;
  color: var(--accent-cyan);
  letter-spacing: -0.5px;
}

.nav-brand svg { width: 32px; height: 32px; }

.nav-links {
  display: flex; align-items: center; gap: 2rem;
  list-style: none;
}

.nav-links a {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  position: relative;
  padding: 0.25rem 0;
}

.nav-links a::after {
  content: '';
  position: absolute; bottom: -2px; left: 0;
  width: 0; height: 2px;
  background: var(--accent-cyan);
  transition: var(--transition);
}

.nav-links a:hover { color: var(--accent-cyan); }
.nav-links a:hover::after { width: 100%; }

.nav-status {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.8rem; color: var(--text-muted);
}

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-red);
  transition: var(--transition);
}

.status-dot.online {
  background: var(--accent-green);
  box-shadow: 0 0 8px rgba(0, 230, 118, 0.6);
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 8px rgba(0, 230, 118, 0.6); }
  50% { box-shadow: 0 0 16px rgba(0, 230, 118, 0.9); }
}

/* ============ HERO ============ */
.hero {
  position: relative;
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  overflow: hidden;
}

.hero-canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
}

.hero-content {
  position: relative; z-index: 1;
  max-width: 800px;
  padding: 2rem;
}

.hero-badge {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 1rem;
  background: rgba(0, 229, 255, 0.1);
  border: 1px solid rgba(0, 229, 255, 0.3);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--accent-cyan);
  margin-bottom: 1.5rem;
}

.hero-badge .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent-green);
  animation: pulse-green 2s infinite;
}

.hero h1 {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #fff 0%, var(--accent-cyan) 50%, var(--accent-green) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  font-size: clamp(1rem, 2vw, 1.2rem);
  color: var(--text-secondary);
  margin-bottom: 2.5rem;
  max-width: 600px;
  margin-left: auto; margin-right: auto;
}

.hero-actions {
  display: flex; gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.75rem 1.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  font-family: var(--font-sans);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), #0099cc);
  color: #000;
  box-shadow: 0 4px 16px rgba(0, 229, 255, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 229, 255, 0.5);
  color: #000;
}

.btn-outline {
  background: transparent;
  color: var(--accent-cyan);
  border: 1px solid var(--border-light);
}

.btn-outline:hover {
  background: rgba(0, 229, 255, 0.1);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* ============ SECTIONS ============ */
.section {
  padding: 6rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

.section-header {
  text-align: center;
  margin-bottom: 4rem;
}

.section-header h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.section-header p {
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 600px;
  margin: 0 auto;
}

.gradient-text {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ============ PRODUCT CARDS ============ */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.75rem;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.product-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-green));
  opacity: 0;
  transition: var(--transition);
}

.product-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.product-card:hover::before { opacity: 1; }

.product-icon {
  width: 56px; height: 56px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem;
  margin-bottom: 1.25rem;
  position: relative;
}

.product-icon.led { background: rgba(255, 145, 0, 0.15); }
.product-icon.env { background: rgba(0, 229, 255, 0.15); }
.product-icon.switch { background: rgba(0, 230, 118, 0.15); }
.product-icon.motor { background: rgba(179, 136, 255, 0.15); }

.product-status {
  position: absolute; top: 1rem; right: 1rem;
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
}

.product-status.online {
  background: rgba(0, 230, 118, 0.15);
  color: var(--accent-green);
}

.product-status.offline {
  background: rgba(255, 68, 102, 0.15);
  color: var(--accent-red);
}

.product-card h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.product-card .desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

.product-tags {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.tag {
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-xs);
  font-size: 0.75rem;
  background: rgba(0, 229, 255, 0.08);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 229, 255, 0.15);
}

.product-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.product-mqtt {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.product-link {
  font-size: 0.85rem;
  font-weight: 600;
  display: flex; align-items: center; gap: 0.25rem;
}

.product-link:hover { transform: translateX(2px); }

/* ============ FEATURES ============ */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
}

.feature-item {
  padding: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  transition: var(--transition);
}

.feature-item:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
}

.feature-icon {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.feature-item h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.feature-item p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* ============ TECH STACK ============ */
.tech-stack {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  padding: 3rem;
}

.tech-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2rem;
  margin-top: 2rem;
}

.tech-item {
  text-align: center;
  padding: 1.5rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.tech-item:hover {
  border-color: var(--accent-cyan);
  box-shadow: var(--glow-cyan);
}

.tech-item .icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.tech-item h4 { font-size: 1rem; margin-bottom: 0.25rem; }
.tech-item p { font-size: 0.8rem; color: var(--text-muted); }

/* ============ MINIPROGRAM ============ */
.miniprogram-section {
  text-align: center;
  padding: 6rem 2rem;
  background: linear-gradient(180deg, transparent, rgba(0, 229, 255, 0.03), transparent);
}

.qr-placeholder {
  width: 200px; height: 200px;
  margin: 2rem auto;
  background: var(--bg-card);
  border: 2px dashed var(--border-light);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  transition: var(--transition);
}

.qr-placeholder:hover {
  border-color: var(--accent-cyan);
  background: rgba(0, 229, 255, 0.05);
}

.qr-placeholder .icon { font-size: 3rem; opacity: 0.5; }

/* ============ FOOTER ============ */
.footer {
  padding: 3rem 2rem;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.footer-links {
  display: flex; justify-content: center; gap: 2rem;
  margin-bottom: 1rem;
}

.footer a { color: var(--text-secondary); font-size: 0.85rem; }
.footer a:hover { color: var(--accent-cyan); }

/* ============ CONTROL PANEL ============ */
.control-layout {
  display: flex;
  min-height: calc(100vh - 64px);
  margin-top: 64px;
}

.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 1.5rem;
  overflow-y: auto;
}

.sidebar h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.device-list { list-style: none; }

.device-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 0.25rem;
}

.device-item:hover { background: rgba(0, 229, 255, 0.05); }
.device-item.active { background: rgba(0, 229, 255, 0.1); border: 1px solid rgba(0, 229, 255, 0.2); }

.device-item .icon { font-size: 1.25rem; }
.device-item .name { flex: 1; font-size: 0.9rem; font-weight: 500; }

.device-item .status-indicator {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-red);
}

.device-item .status-indicator.online {
  background: var(--accent-green);
  box-shadow: 0 0 6px rgba(0, 230, 118, 0.5);
}

/* Control Main */
.control-main {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

.control-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.control-header h2 { font-size: 1.5rem; font-weight: 700; }

.device-info {
  display: flex; align-items: center; gap: 1rem;
  font-size: 0.85rem; color: var(--text-secondary);
}

/* Control Widgets */
.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.control-widget {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.control-widget h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 1rem;
}

/* Switch Control */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(30, 58, 95, 0.3);
}

.switch-row:last-child { border-bottom: none; }
.switch-row .label { font-size: 0.9rem; }

.toggle {
  position: relative;
  width: 48px; height: 26px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.toggle.active {
  background: rgba(0, 230, 118, 0.3);
  border-color: var(--accent-green);
}

.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: var(--transition);
}

.toggle.active::after {
  left: 25px;
  background: var(--accent-green);
  box-shadow: 0 0 8px rgba(0, 230, 118, 0.5);
}

/* Slider Control */
.slider-control {
  margin: 0.75rem 0;
}

.slider-label {
  display: flex; justify-content: space-between;
  font-size: 0.85rem; color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.slider-label .value {
  font-family: var(--font-mono);
  color: var(--accent-cyan);
}

input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--bg-input);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  background: var(--accent-cyan);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
}

/* Color Picker */
.color-picker-row {
  display: flex; align-items: center; gap: 1rem;
  margin: 0.75rem 0;
}

.color-picker-row label {
  font-size: 0.9rem; flex: 1;
}

input[type="color"] {
  width: 48px; height: 32px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  background: var(--bg-input);
  cursor: pointer;
  padding: 2px;
}

/* Data Display */
.data-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

.data-cell {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
}

.data-cell .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.data-cell .value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.data-cell .unit {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Chart Container */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.chart-container h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 1rem;
}

.chart-container canvas {
  width: 100% !important;
  height: 200px !important;
}

/* MQTT Console */
.mqtt-console {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.mqtt-console h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 1rem;
  display: flex; align-items: center; justify-content: space-between;
}

.mqtt-log {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  max-height: 250px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.8;
}

.mqtt-log .msg-in { color: var(--accent-green); }
.mqtt-log .msg-out { color: var(--accent-orange); }
.mqtt-log .msg-sys { color: var(--text-muted); }
.mqtt-log .msg-err { color: var(--accent-red); }

.mqtt-log .timestamp { color: var(--text-muted); margin-right: 0.5rem; }

.clear-log {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-xs);
  font-size: 0.75rem;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: var(--transition);
}

.clear-log:hover { border-color: var(--accent-red); color: var(--accent-red); }

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .nav { padding: 0 1rem; }
  .nav-links { display: none; }
  .section { padding: 4rem 1rem; }
  .products-grid { grid-template-columns: 1fr; }
  .control-layout { flex-direction: column; }
  .sidebar {
    width: 100%; min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    max-height: 200px;
  }
  .control-grid { grid-template-columns: 1fr; }
  .tech-grid { grid-template-columns: repeat(2, 1fr); }
  .hero h1 { font-size: 2rem; }
}

/* ============ ANIMATIONS ============ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in-up {
  animation: fadeInUp 0.6s ease forwards;
  opacity: 0;
}

.fade-in-up:nth-child(1) { animation-delay: 0.1s; }
.fade-in-up:nth-child(2) { animation-delay: 0.2s; }
.fade-in-up:nth-child(3) { animation-delay: 0.3s; }
.fade-in-up:nth-child(4) { animation-delay: 0.4s; }

/* No data placeholder */
.no-device-selected {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--text-muted);
  text-align: center;
}

.no-device-selected .icon { font-size: 4rem; margin-bottom: 1rem; opacity: 0.3; }
.no-device-selected h3 { font-size: 1.2rem; margin-bottom: 0.5rem; }
.no-device-selected p { font-size: 0.9rem; }
