:root{
  --bg:#0b0f16;
  --panel:#0f1623;
  --panel2:#111a2a;
  --stroke:rgba(255,255,255,.08);
  --stroke2:rgba(255,255,255,.12);
  --text:#e9eefb;
  --muted:rgba(233,238,251,.68);
  --muted2:rgba(233,238,251,.50);
  --accent:#7c5cff;
  --accent2:#00d4ff;
  --shadow: 0 20px 60px rgba(0,0,0,.55);
  --radius:18px;

  --ok:#22c55e;
  --warn:#f59e0b;
  --bad:#ef4444;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: Urbanist, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 700px at 70% 10%, rgba(124,92,255,.20), transparent 60%),
              radial-gradient(900px 600px at 15% 20%, rgba(0,212,255,.12), transparent 55%),
              var(--bg);
  color: var(--text);
}

/* Topbar */
.topbar{
  position:sticky;
  top:0;
  z-index:50;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:14px 18px;
  border-bottom:1px solid var(--stroke);
  background: rgba(10,14,22,.72);
  backdrop-filter: blur(14px);
}
.brand{ display:flex; align-items:center; gap:12px; }
.logo{
  width:44px; height:44px;
  border-radius:14px;
  display:grid; place-items:center;
  background: linear-gradient(135deg, rgba(124,92,255,.95), rgba(0,212,255,.65));
  box-shadow: 0 18px 40px rgba(0,0,0,.45);
  font-weight:900;
  letter-spacing:.5px;
}
.brandText .title{ font-weight:900; letter-spacing:.2px; }
.brandText .sub{ font-size:12px; color:var(--muted); margin-top:2px; }

.topActions{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.spark{
  display:inline-grid;
  place-items:center;
  width:18px; height:18px;
  border-radius:999px;
  background: rgba(124,92,255,.22);
  border:1px solid rgba(124,92,255,.35);
  box-shadow: 0 12px 26px rgba(0,0,0,.35);
  font-size:12px;
}

/* Layout */
.app{
  display:grid;
  grid-template-columns: 360px 1fr;
  gap:16px;
  padding:16px;
  max-width: 1600px;
  margin: 0 auto;
}

.sidebar{
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  border:1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}

.panelHead{ padding:16px 16px 10px 16px; border-bottom:1px solid var(--stroke); }
.panelTitle{ font-weight:900; font-size:16px; }
.panelSub{ font-size:12px; color:var(--muted); margin-top:4px; }

.sidebarTools{ padding:12px 16px; border-bottom:1px solid var(--stroke); }
.search{
  width:100%;
  padding:10px 12px;
  border-radius:12px;
  background: rgba(255,255,255,.04);
  border:1px solid var(--stroke);
  color: var(--text);
  outline:none;
}
.search::placeholder{ color: rgba(233,238,251,.45); }
.row{ display:flex; gap:8px; margin-top:10px; }

.listMeta{
  padding:10px 16px;
  border-bottom:1px solid var(--stroke);
  display:flex;
  gap:12px;
  flex-wrap:wrap;
}
.toggle{ display:flex; align-items:center; gap:8px; font-size:12px; color:var(--muted); user-select:none; }
.toggle input{ accent-color: var(--accent); }

.aiLegend{
  padding:12px 16px;
  border-bottom:1px solid var(--stroke);
  background: rgba(255,255,255,.02);
}
.aiLegendTitle{
  font-weight:900;
  font-size:12px;
  letter-spacing:.08em;
  text-transform:uppercase;
  color: rgba(233,238,251,.70);
}
.aiLegendRow{ display:flex; gap:8px; margin-top:10px; flex-wrap:wrap; }
.pill{
  padding:7px 10px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.05);
  font-weight:900;
  font-size:12px;
}
.pill-ai{
  border-color: rgba(0,212,255,.28);
  background: rgba(0,212,255,.10);
}
.pill-manual{
  border-color: rgba(124,92,255,.28);
  background: rgba(124,92,255,.10);
}
.pill-mix{
  border-color: rgba(245,158,11,.30);
  background: rgba(245,158,11,.10);
}
.aiLegendSub{
  margin-top:10px;
  font-size:12px;
  color: var(--muted);
}

.elementList{
  padding:10px 8px 10px 8px;
  max-height: calc(100vh - 470px);
  overflow:auto;
}
.groupTitle{
  padding:10px 10px 6px 10px;
  font-size:11px;
  color: var(--muted2);
  letter-spacing:.12em;
  text-transform:uppercase;
}
.el{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 10px;
  margin:6px 6px;
  border-radius:14px;
  border:1px solid transparent;
  background: rgba(255,255,255,.03);
  cursor:pointer;
  transition: 160ms ease;
}
.el:hover{
  transform: translateY(-1px);
  border-color: rgba(255,255,255,.08);
  background: rgba(255,255,255,.045);
}
.el.active{
  border-color: rgba(124,92,255,.45);
  background: linear-gradient(90deg, rgba(124,92,255,.18), rgba(0,212,255,.08));
}
.elLeft{ display:flex; align-items:center; gap:10px; min-width:0; }
.dot{
  width:10px; height:10px;
  border-radius:999px;
  background: rgba(255,255,255,.32);
  box-shadow: 0 0 0 3px rgba(255,255,255,.06);
}
.elName{
  font-weight:700;
  font-size:13px;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.elRight{
  display:flex;
  align-items:center;
  gap:8px;
}
.eye{
  width:34px; height:28px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.03);
  color: var(--text);
  display:grid; place-items:center;
  font-size:12px;
  user-select:none;
}
.eye.off{ opacity:.55; }

/* AI confidence mini badge (if you add it in app.js rows) */
.confMini{
  padding:6px 8px;
  border-radius:999px;
  font-size:11px;
  font-weight:900;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  color:#fff;
}
.confMini.ok{
  border-color: rgba(34,197,94,.28);
  background: rgba(34,197,94,.10);
}
.confMini.mid{
  border-color: rgba(245,158,11,.30);
  background: rgba(245,158,11,.10);
}
.confMini.low{
  border-color: rgba(239,68,68,.28);
  background: rgba(239,68,68,.10);
}

.importMask{
  padding:12px 16px 16px 16px;
  border-top:1px solid var(--stroke);
}
.importTitle{ font-weight:900; font-size:13px; }
.importSub{ font-size:12px; color:var(--muted); margin-top:4px; margin-bottom:10px; }
.footerNote{
  padding:0 16px 16px 16px;
  color: var(--muted);
  font-size:12px;
}

/* Work area */
.work{
  position:relative;
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  border:1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
  min-height: 640px;
}

.canvasShell{
  position:relative;
  padding:16px;
}
#view{
  width:100%;
  height:auto;
  display:block;
  border-radius: 16px;
  background: rgba(0,0,0,.20);
  border:1px solid rgba(255,255,255,.08);
}
.hud{
  position:absolute;
  left:26px;
  top:26px;
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  pointer-events:none;
}
.badge{
  pointer-events:none;
  padding:8px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.07);
  border:1px solid rgba(255,255,255,.10);
  color: #fff;
  font-size:12px;
  font-weight:800;
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
}

/* Toolkit */
.toolkit{
  position:absolute;
  right:16px;
  top:16px;
  width: 320px;
  border-radius: 18px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(12,16,24,.70);
  backdrop-filter: blur(16px);
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
  overflow:hidden;
}
.toolkitHead{
  padding:12px 14px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  border-bottom:1px solid rgba(255,255,255,.08);
  cursor: default;
  user-select:none;
}
.toolkitTitle{ font-weight:900; }
.toolkitHint{ font-size:11px; color: var(--muted); }

.toolRow{ display:flex; gap:10px; padding:12px 14px; }
.toolBtn{
  flex:1;
  padding:10px 10px;
  border-radius: 14px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.05);
  color:#fff;
  font-weight:900;
  cursor:pointer;
  transition: 160ms ease;
}
.toolBtn.active{
  border-color: rgba(124,92,255,.55);
  background: linear-gradient(90deg, rgba(124,92,255,.35), rgba(0,212,255,.16));
}
.toolBtn:hover{ transform: translateY(-1px); }

.toolGrid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
  padding:0 14px 14px 14px;
}
.field{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size:12px;
}
.lab{ color: var(--muted); font-weight:800; }
select, input[type="range"], input[type="text"]{ width:100%; }
select{
  padding:9px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.10);
  color:#fff;
  outline:none;
}
input[type="range"]{ accent-color: var(--accent); }

.colorRow{ display:flex; gap:10px; align-items:center; }
#colorPicker{ width:44px; height:36px; border:none; background: transparent; padding:0; }
.hex{
  flex:1;
  padding:9px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.10);
  color:#fff;
  outline:none;
}

/* Buttons */
.btn{
  appearance:none;
  border:none;
  border-radius: 14px;
  padding:10px 12px;
  font-weight:900;
  color:#fff;
  cursor:pointer;
  transition: 160ms ease;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  user-select:none;
}
.btn:disabled{
  opacity:.45;
  cursor:not-allowed;
  transform:none !important;
}
.btn:hover{ transform: translateY(-1px); }
.btn.primary{
  background: linear-gradient(90deg, rgba(124,92,255,1), rgba(0,212,255,.85));
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
}
.btn.soft{
  background: rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.10);
}
.btn.tiny{ padding:8px 10px; border-radius: 12px; font-size:12px; }
.btn.small{ padding:9px 10px; border-radius: 12px; font-size:12px; }
.btn.wide{ width:100%; }

/* Fullscreen overlay */
.fsOverlay{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.86);
  z-index:10000;
  display:flex;
  flex-direction:column;
}
.fsOverlay.hidden{ display:none; }

.fsTopbar{
  height:68px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:12px 14px;
  border-bottom:1px solid rgba(255,255,255,.10);
  background: rgba(10,14,22,.45);
  backdrop-filter: blur(14px);
}
.fsLeft{ display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
.fsPill{
  padding:8px 10px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.06);
  font-weight:900;
  font-size:12px;
}
.fsPill.subtle{ font-weight:800; opacity:.85; }
#fsView{
  width:100%;
  height: calc(100vh - 68px);
  display:block;
  cursor: default;
}
.fsExitX{
  position:absolute;
  top:16px;
  right:16px;
  width:42px;
  height:42px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.06);
  color:#fff;
  font-size:18px;
  font-weight:900;
  cursor:pointer;
}
body.isFullscreen .toolkit{
  position:fixed;
  top: 88px;
  right: 18px;
  z-index:10002;
}
body.isFullscreen #toolkitDragHandle{ cursor: grab; }

/* Modal (AI scan) */
.modal{
  position:fixed;
  inset:0;
  z-index:11000;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
}
.modal.hidden{ display:none; }
.modalCard{
  width:min(720px, 100%);
  border-radius: 22px;
  border:1px solid rgba(255,255,255,.12);
  background: rgba(12,16,24,.92);
  box-shadow: 0 40px 120px rgba(0,0,0,.65);
  overflow:hidden;
}
.modalHead{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 16px;
  border-bottom:1px solid rgba(255,255,255,.08);
}
.modalTitle{
  display:flex;
  align-items:center;
  gap:10px;
  font-weight:900;
  letter-spacing:.2px;
}
.iconBtn{
  width:38px; height:38px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color:#fff;
  cursor:pointer;
  font-weight:900;
}
.modalBody{ padding:16px; }
.progressBar{
  height:12px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.06);
  overflow:hidden;
}
.progressFill{
  height:100%;
  width:0%;
  border-radius:999px;
  background: linear-gradient(90deg, rgba(124,92,255,1), rgba(0,212,255,.95));
  box-shadow: 0 18px 40px rgba(0,0,0,.25);
  transition: width 180ms ease;
}
.progressMeta{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-top:10px;
  gap:10px;
}
.progressStep{ font-weight:900; font-size:13px; }
.progressPct{ font-weight:900; font-size:13px; color: rgba(233,238,251,.82); }

.aiLog{
  margin-top:12px;
  padding:12px;
  border-radius:16px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  max-height: 200px;
  overflow:auto;
}
.logRow{
  display:flex;
  gap:10px;
  align-items:flex-start;
  padding:8px 6px;
  border-bottom:1px solid rgba(255,255,255,.06);
  color: rgba(233,238,251,.82);
  font-weight:700;
  font-size:12px;
}
.logRow:last-child{ border-bottom:none; }
.dotMini{
  width:8px; height:8px;
  border-radius:999px;
  background: rgba(0,212,255,.65);
  box-shadow: 0 0 0 3px rgba(0,212,255,.10);
  margin-top:4px;
  flex:0 0 auto;
}

.modalHint{
  margin-top:12px;
  font-size:12px;
  color: var(--muted);
  line-height:1.45;
}
.modalFoot{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  padding:14px 16px;
  border-top:1px solid rgba(255,255,255,.08);
}

/* Responsive */
@media (max-width: 980px){
  .app{ grid-template-columns: 1fr; }
  .toolkit{ position:relative; right:auto; top:auto; width:auto; margin: 0 16px 16px 16px; }
  body.isFullscreen .toolkit{ position:fixed; width:320px; }
}
