* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app { height: 100%; width: 100%; }
body { font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif; background: #1a1d21; color: #e6e8ea; overflow: hidden; }
#app { display: flex; flex-direction: column; height: 100%; }

/* top bar */
#topbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: #23272e; border-bottom: 1px solid #333; flex: 0 0 auto; }
.logo { font-weight: 700; font-size: 17px; color: #5db3ff; letter-spacing: .5px; }
.btn { background: #2f6fed; color: #fff; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; border: none; user-select: none; }
.btn:hover { background: #3d7bf5; }
#filename { font-size: 13px; color: #cbd2d9; }
#modelinfo { font-size: 12px; color: #8b929b; margin-left: auto; }

/* toolbar */
#toolbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 6px 12px; background: #1f2329; border-bottom: 1px solid #2c313a; flex: 0 0 auto; }
.tgroup { display: flex; align-items: center; gap: 4px; padding-right: 10px; border-right: 1px solid #2c313a; }
.tgroup:last-child { border-right: none; }
.tlabel { font-size: 11px; color: #6b7280; margin-right: 4px; }
.tbtn { background: #2b3038; color: #d5dae0; border: 1px solid #3a4049; padding: 5px 9px; border-radius: 5px; font-size: 12px; cursor: pointer; }
.tbtn:hover { background: #353b45; }
.tbtn.active { background: #2f6fed; border-color: #2f6fed; color: #fff; }

/* main */
#main { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

/* tree panel */
#tree-panel { width: 260px; background: #20242b; border-right: 1px solid #2c313a; display: flex; flex-direction: column; flex: 0 0 auto; }
#tree-panel.hidden { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; font-size: 13px; font-weight: 600; border-bottom: 1px solid #2c313a; }
.panel-head .x { background: none; border: none; color: #9aa1a9; font-size: 18px; cursor: pointer; }
.panel-actions { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid #2c313a; }
.mini { background: #2b3038; color: #d5dae0; border: 1px solid #3a4049; padding: 4px 8px; border-radius: 4px; font-size: 11px; cursor: pointer; }
.mini:hover { background: #353b45; }
.mini.active { background: #2f6fed; border-color: #2f6fed; color: #fff; }
#tree-list { list-style: none; overflow-y: auto; flex: 1 1 auto; padding: 4px 0; }
#tree-list li { display: flex; align-items: center; gap: 8px; padding: 4px 12px; font-size: 12px; cursor: pointer; }
#tree-list li:hover { background: #2a2f37; }
#tree-list li.selected { background: #2f4a7a; }
#tree-list li .swatch { width: 11px; height: 11px; border-radius: 2px; flex: 0 0 auto; border: 1px solid #0004; }
#tree-list li .nm { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#tree-list li input { cursor: pointer; }

/* viewport */
#viewport { position: relative; flex: 1 1 auto; min-width: 0; }
#viewport canvas { display: block; }
#drop-hint { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #6b7280; font-size: 15px; pointer-events: none; text-align: center; padding: 20px; }
#drop-hint small { color: #545b64; font-size: 12px; }
#viewport.dragover { outline: 3px dashed #2f6fed; outline-offset: -12px; }
#viewport.has-model #drop-hint { display: none; }

/* progress overlay */
#progress { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(18,20,23,.72); z-index: 20; }
#progress[hidden] { display: none; }   /* ID display:flex would otherwise override the hidden attribute */
.pcard { background: #23272e; border: 1px solid #333; border-radius: 10px; padding: 22px 26px; width: 340px; text-align: center; box-shadow: 0 10px 40px #0007; }
#pstage { font-size: 14px; margin-bottom: 12px; color: #e6e8ea; }
.pbar { height: 8px; background: #333a44; border-radius: 4px; overflow: hidden; margin-bottom: 10px; }
#pfill { height: 100%; width: 0%; background: linear-gradient(90deg, #2f6fed, #5db3ff); transition: width .3s ease; }
#pfill.indeterminate { width: 35% !important; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
#pdetail { font-size: 12px; color: #9aa1a9; margin-bottom: 12px; min-height: 16px; }
#pcancel { margin-top: 2px; }

/* floating controls */
.floatctl { position: absolute; right: 14px; background: rgba(35,39,46,.9); border: 1px solid #3a4049; border-radius: 8px; padding: 10px 12px; z-index: 15; font-size: 12px; }
#section-ctl { top: 14px; width: 210px; }
#explode-ctl { top: 14px; width: 210px; }
#measure-ctl { top: 14px; width: 210px; }
.fc-title { font-weight: 600; margin-bottom: 8px; }
.fc-row { display: flex; gap: 5px; margin-bottom: 8px; }
.floatctl input[type=range] { width: 100%; }
#measure-info { color: #9aa1a9; margin-bottom: 8px; }
#exp-val { color: #9aa1a9; }

/* measurement label */
.measure-label { position: absolute; background: rgba(17,17,17,.85); color: #fff; padding: 2px 6px; border-radius: 4px; font-size: 12px; pointer-events: none; transform: translate(-50%, -130%); white-space: nowrap; z-index: 16; }

.toast { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); background: #c0392b; color: #fff; padding: 10px 16px; border-radius: 6px; font-size: 13px; z-index: 30; max-width: 80%; }
