:root {
  --bg-primary: #F8FAFC;
  --bg-secondary: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-card-hover: #F1F5F9;
  --border: #E2E8F0;
  --text-primary: #1E293B;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --accent: #0EA5E9;
  --accent-hover: #0284C7;
  --accent-dim: rgba(14, 165, 233, 0.08);
  --green: #16A34A;
  --yellow: #D97706;
  --red: #DC2626;
  --purple: #7C3AED;
  --sidebar-width: 260px;
  --header-height: 60px;
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; transition: color .2s; }
a:hover { color: var(--accent-hover); }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .3s ease;
  box-shadow: 1px 0 8px rgba(0,0,0,.04);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.1rem;
  color: var(--accent);
  letter-spacing: 1px;
}

.sidebar-header .subtitle {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: .9rem;
  transition: all .2s;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}

.sidebar-nav a.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-nav a .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
}

/* ===== MAIN CONTENT ===== */
.main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.header {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background: rgba(248, 250, 252, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 32px;
  z-index: 50;
}

.header .page-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  margin-right: 16px;
}

.content {
  padding: 32px;
  max-width: 1200px;
}

/* ===== HERO SECTION ===== */
.hero {
  text-align: center;
  padding: 60px 20px;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.06), rgba(124, 58, 237, 0.04));
  border-radius: 16px;
  border: 1px solid var(--border);
  margin-bottom: 40px;
}

.hero h2 {
  font-size: 2rem;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

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

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 40px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  transition: transform .2s, border-color .2s, box-shadow .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.1);
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card .stat-label {
  color: var(--text-muted);
  font-size: .85rem;
  margin-top: 4px;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  transition: border-color .2s, box-shadow .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

.card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.08);
}

.card h3 {
  font-size: 1.15rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== PRODUCT GRID ===== */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: transform .2s, border-color .2s, box-shadow .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

.product-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(14, 165, 233, 0.1);
}

.product-card .product-img {
  width: 100%;
  height: 200px;
  object-fit: contain;
  background: #F1F5F9;
  padding: 16px;
}

.product-card .product-placeholder {
  width: 100%;
  height: 200px;
  background: linear-gradient(135deg, #F1F5F9, #E2E8F0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
}

.product-card .product-info {
  padding: 16px;
}

.product-card .product-name {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.product-card .product-model {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.product-card .product-price {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--green);
}

.product-card .product-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ===== TAGS / BADGES ===== */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .5px;
}

.tag-zigbee { background: rgba(22, 163, 74, 0.1); color: var(--green); }
.tag-wifi { background: rgba(14, 165, 233, 0.1); color: var(--accent); }
.tag-ble { background: rgba(124, 58, 237, 0.1); color: var(--purple); }
.tag-ir { background: rgba(217, 119, 6, 0.1); color: var(--yellow); }
.tag-thread { background: rgba(220, 38, 38, 0.1); color: var(--red); }

.difficulty {
  display: inline-flex;
  gap: 2px;
}

.difficulty .star { color: var(--yellow); }
.difficulty .star-empty { color: var(--text-muted); opacity: .3; }

/* ===== TABLES ===== */
.table-wrapper {
  overflow-x: auto;
  margin: 16px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}

thead {
  background: #F1F5F9;
}

th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 16px;
  border-bottom: 1px solid #F1F5F9;
}

tr:hover td {
  background: rgba(14, 165, 233, 0.03);
}

td.table-group {
  background: rgba(14, 165, 233, 0.06);
  font-weight: 600;
  color: var(--accent);
  padding: 8px 16px;
}

/* ===== CODE BLOCKS ===== */
pre {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
  font-size: .85rem;
  line-height: 1.6;
}

code {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  color: #334155;
}

:not(pre) > code {
  background: rgba(14, 165, 233, 0.08);
  color: var(--accent-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .85em;
}

.code-label {
  display: inline-block;
  background: var(--accent);
  color: #FFFFFF;
  padding: 2px 10px;
  border-radius: 4px 4px 0 0;
  font-size: .75rem;
  font-weight: 600;
  margin-bottom: -1px;
  position: relative;
  z-index: 1;
}

/* ===== TIMELINE ===== */
.timeline {
  position: relative;
  padding-left: 32px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  margin-bottom: 32px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -28px;
  top: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-primary);
}

.timeline-item.done::before { background: var(--green); }

.timeline-item h4 {
  font-size: 1.05rem;
  margin-bottom: 4px;
}

.timeline-item .meta {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ===== ARCHITECTURE DIAGRAM ===== */
.arch-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin: 8px 0;
  font-family: monospace;
  white-space: pre;
  overflow-x: auto;
  font-size: .82rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

/* ===== SECTION HEADERS ===== */
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 40px 0 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.section-header h2 {
  font-size: 1.4rem;
}

.section-header .section-icon {
  font-size: 1.6rem;
}

/* ===== PHASE CARDS ===== */
.phase-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 20px;
  border-left: 4px solid var(--accent);
  transition: border-color .2s, box-shadow .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

.phase-card:nth-child(2) { border-left-color: var(--green); }
.phase-card:nth-child(3) { border-left-color: var(--yellow); }
.phase-card:nth-child(4) { border-left-color: var(--purple); }
.phase-card:nth-child(5) { border-left-color: var(--red); }
.phase-card:nth-child(6) { border-left-color: #EC4899; }

.phase-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.phase-header h3 { font-size: 1.1rem; }

.phase-meta {
  display: flex;
  gap: 16px;
  font-size: .82rem;
  color: var(--text-muted);
}

.phase-meta span { display: flex; align-items: center; gap: 4px; }

.checklist {
  list-style: none;
  padding: 0;
}

.checklist li {
  padding: 6px 0;
  padding-left: 24px;
  position: relative;
  color: var(--text-secondary);
  font-size: .9rem;
}

.checklist li::before {
  content: '○';
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

/* ===== WIRING DIAGRAM ASCII ===== */
.wiring-box {
  background: #F8FAFC;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  font-family: 'JetBrains Mono', monospace;
  font-size: .82rem;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
  color: var(--accent-hover);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
  }

  .hamburger {
    display: block;
  }

  .content {
    padding: 20px 16px;
  }

  .hero h2 {
    font-size: 1.4rem;
  }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 90;
}

.overlay.open { display: block; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== ROOM TABS ===== */
.room-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.room-tab {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: .85rem;
  transition: all .2s;
}

.room-tab:hover, .room-tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== SCENE TABLE ENHANCEMENTS ===== */
.scene-row td:first-child {
  font-weight: 600;
  color: var(--accent);
}

/* ===== BUDGET BAR ===== */
.budget-bar {
  height: 8px;
  border-radius: 4px;
  background: #F1F5F9;
  overflow: hidden;
  margin: 8px 0;
}

.budget-bar .fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  transition: width .6s ease;
}

/* ===== COPY BUTTON ===== */
.code-wrapper {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: .75rem;
  cursor: pointer;
  transition: all .2s;
}

.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ===== PRODUCT DRAWER ===== */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 200;
}

.drawer-overlay.open { display: block; }

.product-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 210;
  transform: translateX(100%);
  transition: transform .3s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,.08);
}

.product-drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  z-index: 1;
}

.drawer-header h3 { font-size: 1rem; color: var(--text-primary); }

.drawer-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}

.drawer-close:hover {
  border-color: var(--red);
  color: var(--red);
  background: rgba(220, 38, 38, 0.05);
}

.drawer-body { padding: 24px; flex: 1; }

.drawer-img-wrap {
  width: 100%;
  height: 220px;
  background: #F1F5F9;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.drawer-product-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  padding: 16px;
}

.drawer-placeholder {
  font-size: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.drawer-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.drawer-product-name { font-size: 1.2rem; font-weight: 700; }
.drawer-product-price { font-size: 1.3rem; font-weight: 700; color: var(--green); }
.drawer-product-model { font-size: .82rem; color: var(--text-muted); }
.drawer-product-protocol { font-size: .82rem; color: var(--accent); }

.drawer-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.drawer-section h4 {
  font-size: .9rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.drawer-features {
  list-style: none;
  padding: 0;
}

.drawer-features li {
  padding: 4px 0 4px 20px;
  position: relative;
  font-size: .88rem;
  color: var(--text-secondary);
}

.drawer-features li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--green);
  font-weight: bold;
}

.drawer-specs-table {
  width: 100%;
  border-collapse: collapse;
}

.drawer-specs-table td {
  padding: 6px 0;
  font-size: .85rem;
  border-bottom: 1px solid #F1F5F9;
}

.drawer-specs-table td:first-child {
  color: var(--text-muted);
  width: 35%;
}

.drawer-install-text {
  font-size: .88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.drawer-buy-btn {
  display: block;
  text-align: center;
  padding: 12px;
  margin-top: 24px;
  background: var(--accent);
  color: #FFFFFF;
  border-radius: 8px;
  font-weight: 600;
  font-size: .95rem;
  transition: background .2s;
}

.drawer-buy-btn:hover {
  background: var(--accent-hover);
  color: #FFFFFF;
}

/* ===== CLICKABLE PRODUCT IN TABLE ===== */
.product-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px dashed rgba(14, 165, 233, 0.3);
  transition: border-color .2s;
}

.product-link:hover {
  border-bottom-color: var(--accent);
}

/* ===== SVG DIAGRAMS ===== */
.svg-diagram {
  width: 100%;
  overflow-x: auto;
  margin: 16px 0;
}

.svg-diagram svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}

.svg-diagram text {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', sans-serif;
}

.product-card[data-product-id] {
  cursor: pointer;
}
