/* ============ Homelab Simulator ============ */
:root {
  --bg: #0c0e13;
  --panel: #12151d;
  --panel2: #171b25;
  --border: #232938;
  --text: #dde2ec;
  --muted: #8a93a6;
  --accent: #4f7cff;
  --green: #37e07a;
  --amber: #ffb02e;
  --red: #ff5566;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

/* ---- top bar ---- */
#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.brand { font-weight: 800; font-size: 17px; margin-right: 8px; white-space: nowrap; letter-spacing: -0.3px; }
.brand span { color: var(--accent); }
.brand small {
  display: block;
  font-size: 9.5px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-top: -2px;
}
.btn.accent {
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  border: none;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 12px #4f7cff44;
}
.btn.accent:hover { filter: brightness(1.12); }
.spacer { flex: 1; }
select, input[type="number"], input[type="search"] {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
}
select:focus, input:focus { border-color: var(--accent); }
.kwh { display: flex; align-items: center; gap: 2px; color: var(--muted); white-space: nowrap; }
.kwh input { width: 64px; }

.btn {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger:hover { border-color: var(--red); color: var(--red); }
.btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- layout ---- */
main { flex: 1; display: flex; min-height: 0; }

#sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
}
#search { width: 100%; }
#cat-filters { display: flex; flex-wrap: wrap; gap: 5px; }
.cat-btn {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.cat-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#catalog-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }

.part-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  transition: border-color .12s;
}
.part-card:hover { border-color: var(--accent); }
.part-swatch { width: 10px; height: 34px; border-radius: 3px; flex-shrink: 0; }
.part-info { flex: 1; min-width: 0; }
.part-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.part-specs { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.btn-add {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-add:hover { background: var(--accent); color: #fff; }

#viewport { flex: 1; position: relative; min-width: 0; }
#scene { width: 100%; height: 100%; display: block; }

#rack-tabs {
  position: absolute;
  top: 10px; left: 10px;
  display: flex; gap: 6px; flex-wrap: wrap;
  max-width: calc(100% - 20px);
}
.rack-tab {
  display: flex; align-items: center; gap: 6px;
  background: rgba(15,18,26,.85);
  border: 1px solid #2a2f3c;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.rack-tab:hover { border-color: var(--accent); color: #fff; }
.rack-tab.active { border-color: var(--accent); color: #fff; background: rgba(45,70,140,.5); }
.rack-tab .rx { opacity: .55; padding: 0 1px; font-size: 13px; }
.rack-tab .rx:hover { color: var(--red); opacity: 1; }
.rack-tab.add { font-weight: 700; }

#room-panel {
  position: absolute;
  top: 46px; left: 10px;
  display: flex; align-items: center; gap: 5px;
  background: rgba(15,18,26,.85);
  border: 1px solid #2a2f3c;
  color: var(--muted);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  backdrop-filter: blur(4px);
}
#room-panel input {
  width: 52px;
  background: #0e1117;
  border: 1px solid #2a2f3c;
  color: #e8eaef;
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 12px;
}
#room-panel .rp-label { color: #e8eaef; font-weight: 600; }
#room-panel .rp-hint { opacity: .6; margin-left: 4px; }

.elev-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 2px 0 8px;
}
#hint {
  position: absolute;
  bottom: 10px; left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 12px;
  background: rgba(12,14,19,.7);
  padding: 4px 12px;
  border-radius: 12px;
  pointer-events: none;
}

#panel {
  width: 360px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  padding: 11px 4px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-pane { display: none; flex: 1; overflow-y: auto; padding: 14px; }
.tab-pane.active { display: block; }

/* ---- stats ---- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.stat-val { font-size: 19px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.stat-sub { color: var(--accent); font-size: 11px; margin-top: 2px; }

.bars { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.bar-row > span:first-child { width: 76px; flex-shrink: 0; }
.bar { flex: 1; height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #7c9aff); border-radius: 4px; }
.bar-fill.danger { background: var(--red); }
.bar-text { width: 92px; text-align: right; flex-shrink: 0; }

.warnings { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.warning { border-radius: 8px; padding: 8px 11px; font-size: 12.5px; border: 1px solid; }
.warning.err  { background: #ff556614; border-color: #ff556650; color: #ff8a95; }
.warning.warn { background: #ffb02e12; border-color: #ffb02e45; color: #ffc566; }
.warning.info { background: #4f7cff12; border-color: #4f7cff40; color: #9ab4ff; }

.total-price {
  margin-top: 16px;
  padding: 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
  font-size: 14px;
}
.total-price strong { font-size: 20px; color: var(--green); margin-left: 6px; }

/* ---- elevation ---- */
#elevation { display: flex; flex-direction: column; gap: 2px; }
.elev-unit, .elev-empty {
  border-radius: 5px;
  padding: 0 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
}
.elev-unit { border: 1px solid; font-weight: 600; }
.elev-unit.sel { outline: 2px solid var(--accent); }
.elev-empty { height: 24px; border: 1px dashed var(--border); color: var(--muted); opacity: .55; cursor: default; }
.elev-u { color: var(--muted); font-size: 10.5px; min-width: 44px; font-weight: 400; }
.elev-zerou { margin-top: 10px; font-size: 12px; color: var(--muted); }
.chip {
  display: inline-block;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 9px;
  margin: 2px;
  cursor: pointer;
  color: var(--text);
}
.chip:hover { border-color: var(--accent); }

/* ---- detail ---- */
#detail h3 { font-size: 16px; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.spec-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 12.5px; }
.spec-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
.spec-table td:first-child { color: var(--muted); width: 42%; }
.detail-price { font-size: 22px; font-weight: 700; color: var(--green); margin: 14px 0 10px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty { color: var(--muted); font-size: 13px; padding: 18px 6px; text-align: center; }

/* ---- toast ---- */
#toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--panel2);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13px;
  opacity: 0;
  transition: all .25s;
  pointer-events: none;
  z-index: 99;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- build wizard ---- */
#wizard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#wizard-overlay[hidden] { display: none; }
#wizard {
  width: min(620px, 94vw);
  max-height: 88vh;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
.wiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.wiz-head h2 { font-size: 17px; font-weight: 700; }
.wiz-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 8px;
  border-radius: 8px;
}
.wiz-close:hover { color: var(--text); background: var(--panel2); }
.wiz-body { padding: 16px 20px 20px; overflow-y: auto; }
.wiz-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 14px 0 7px;
}
.wiz-label:first-child { margin-top: 0; }
.muted-inline { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.money {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
}
.money input { width: 130px; font-size: 16px; font-weight: 700; }
#wiz-text {
  width: 100%;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  line-height: 1.5;
}
#wiz-text:focus { border-color: var(--accent); }
.wiz-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.wiz-chip input { display: none; }
.wiz-chip span {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.12s;
  user-select: none;
}
.wiz-chip span:hover { border-color: var(--accent); color: var(--text); }
.wiz-chip input:checked + span {
  background: #4f7cff22;
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}
.wiz-prefs { display: flex; gap: 18px; margin-top: 14px; font-size: 13px; color: var(--text); }
.wiz-prefs label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.wiz-prefs input { accent-color: var(--accent); width: 15px; height: 15px; }
.wiz-actions { margin-top: 16px; display: flex; gap: 8px; }
.wiz-actions .btn.primary { padding: 9px 18px; font-size: 14px; }
#wiz-result { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
#wiz-result h3 { font-size: 15px; margin-bottom: 8px; }
.wiz-notes { list-style: none; display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.wiz-notes li {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
}

/* scrollbars */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }
