:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --blue: #0284c7;
  --blue-soft: #38bdf8;
  --emerald: #059669;
  --brick: #b91c1c;
  --line: #e2e8f0;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.10);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
#appbar {
  height: 58px;
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--blue), var(--emerald));
  color: #fff; font-weight: 800; font-size: 15px;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(2, 132, 199, .35);
}
.brand-name { font-weight: 800; letter-spacing: .5px; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); }

.plan-switch { display: flex; align-items: center; gap: 6px; }
.switch-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.plan-btn {
  border: 1px solid var(--line); background: #f8fafc; color: var(--text);
  padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: 12.5px; font-weight: 600;
  transition: all .15s;
}
.plan-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.status-cluster { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f8fafc; border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-pill.ok .dot { background: var(--emerald); box-shadow: 0 0 0 3px rgba(5,150,105,.18); }
.hdr-btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: 12.5px; font-weight: 600;
  transition: all .15s;
}
.hdr-btn:hover { border-color: var(--blue); color: var(--blue); }

/* ===== Viewport ===== */
#viewport { position: relative; flex: 1 1 auto; overflow: hidden; }
#scene { display: block; width: 100%; height: 100%; }

.loading-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: var(--bg); color: var(--muted); font-size: 14px; font-weight: 600;
  z-index: 15; transition: opacity .4s;
}
.hidden { display: none !important; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 16;
  background: rgba(15,23,42,.92); color: #fff;
  padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 600;
  transform: translate(-50%, -130%); white-space: nowrap;
}

.overlay-card {
  position: absolute; z-index: 12;
  background: rgba(255,255,255,.86); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; width: 268px;
}
#viewControls { top: 14px; right: 14px; }
#telemetry { top: 230px; right: 14px; bottom: 92px; overflow-y: auto; }

.overlay-card h3 { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--blue); margin-bottom: 10px; }
.overlay-card h4 { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 14px 0 6px; }

.ctl-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 8px; font-size: 12px; }
.ctl-row input[type=range] { grid-column: 1 / -1; width: 100%; accent-color: var(--blue); }
.toggle-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-top: 8px; cursor: pointer; }

.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 12px; }
.preset {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 7px 6px; border-radius: 8px; cursor: pointer; font-size: 11.5px; font-weight: 600;
  transition: all .15s;
}
.preset:hover { border-color: var(--blue); color: var(--blue); }
.preset[data-preset="reset"] { grid-column: 1 / -1; background: #f8fafc; }

.spec-cards { display: flex; flex-direction: column; gap: 7px; }
.spec-card {
  background: #f8fafc; border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px;
}
.spec-card .sc-k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.spec-card .sc-v { font-size: 13px; font-weight: 700; }

.layer-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.layer-list li {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
  padding: 4px 6px; border-radius: 6px;
}
.layer-list li .sw { width: 10px; height: 10px; border-radius: 3px; }
.layer-list li.on { background: #eff6ff; }
.layer-list li .nm { font-weight: 600; }
.layer-list li .st { margin-left: auto; font-size: 10.5px; color: var(--emerald); font-weight: 700; }

.inspector { font-size: 12px; line-height: 1.5; }
.inspector .insp-name { font-weight: 800; color: var(--blue); margin-bottom: 4px; }
.inspector .kv { display: flex; justify-content: space-between; gap: 8px; }
.inspector .kv span:first-child { color: var(--muted); }
.muted { color: var(--muted); }
.export-btn {
  margin-top: 14px; width: 100%; border: none; cursor: pointer;
  background: var(--blue); color: #fff; font-weight: 700; font-size: 12.5px;
  padding: 9px; border-radius: 9px; transition: all .15s;
}
.export-btn:hover { background: #0369a1; }

/* ===== Model switcher ===== */
#modelBar {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  z-index: 13; display: flex; gap: 6px; padding: 8px;
  background: rgba(255,255,255,.88); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.model-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 84px; padding: 8px 10px; border-radius: 11px; cursor: pointer;
  border: 1px solid transparent; background: #f8fafc; color: var(--text);
  transition: all .15s;
}
.model-btn b {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: #e2e8f0; font-size: 12px; color: var(--text);
}
.model-btn span { font-size: 10.5px; font-weight: 600; }
.model-btn:hover { border-color: var(--blue-soft); }
.model-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.model-btn.active b { background: #fff; color: var(--blue); }

/* ===== Blueprint panel ===== */
#blueprintPanel {
  position: absolute; inset: 58px 0 0 0; z-index: 30;
  background: #0f172a; display: flex; flex-direction: column;
}
.bp-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; color: #fff; background: #0b1220; }
.bp-head h2 { font-size: 15px; font-weight: 700; }
.bp-thumbs { display: flex; gap: 10px; padding: 12px 18px; overflow-x: auto; background: #0b1220; }
.bp-thumb {
  flex: 0 0 auto; width: 120px; height: 84px; border: 2px solid #1e293b; border-radius: 8px;
  background: #fff; cursor: pointer; display: grid; place-items: center; padding: 4px;
}
.bp-thumb.active { border-color: var(--blue); }
.bp-thumb img { max-width: 100%; max-height: 100%; }
.bp-thumb .tlabel { font-size: 9px; color: #94a3b8; text-align: center; }
.bp-stage { flex: 1 1 auto; background: #111827; padding: 14px; }
#bpObject { width: 100%; height: 100%; border: none; background: #fff; border-radius: 8px; }

/* ===== Footer ===== */
#statusbar {
  height: 28px; flex: 0 0 28px; display: flex; align-items: center; gap: 22px;
  padding: 0 16px; background: var(--panel); border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted); font-weight: 600; z-index: 20;
}

@media (max-width: 760px) {
  #telemetry { display: none; }
  .model-btn { min-width: 64px; }
  .plan-switch .switch-label { display: none; }
}
