:root{
  --bg:#f5f5f6; --panel:#ffffff; --line:#dcdee3; --line2:#eff0f3;
  --text:#1c2025; --muted:#6b7280; --accent:#c8202f; --accent-soft:#fbeaec;
  --sel:#f7e2e4; --hover:#f4f4f5; --danger:#b91c1c; --ok:#16a34a; --warn:#d97706;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; font-family:"Segoe UI",-apple-system,Roboto,Helvetica,Arial,sans-serif;
  font-size:13px; color:var(--text); background:var(--bg); display:flex; flex-direction:column;
}

/* ---------- Brand bar ---------- */
.brandbar{
  display:flex; align-items:center; gap:12px; padding:10px 20px; background:var(--panel);
  border-bottom:1px solid var(--line);
}
.brandlogo{height:52px; display:block}
.brandspacer{flex:1}
.brandbar .lab{font-weight:600; color:var(--muted); font-size:12px; text-transform:uppercase; letter-spacing:.5px}
.brandbar .cabtab{
  padding:6px 16px; border:1px solid var(--line); border-radius:8px;
  background:var(--bg); cursor:pointer; font-size:12.5px; margin-left:4px;
}
.brandbar .cabtab.sel{background:#1c2025; color:#fff; border-color:#1c2025; font-weight:600}
.brandbar .status{color:var(--muted); font-size:11.5px; margin-left:12px}

/* ---------- Toolbar ---------- */
.toolbar{
  display:flex; align-items:stretch; gap:2px; padding:6px 10px; background:var(--panel);
  border-bottom:1px solid var(--line); flex-wrap:wrap;
}
.tgroup{display:flex; gap:2px; padding:0 8px; border-right:1px solid var(--line2); align-items:stretch}
.tgroup:last-child{border-right:none}
.tbtn{
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
  min-width:62px; padding:6px 8px; border:1px solid transparent; border-radius:8px;
  background:none; cursor:pointer; color:var(--text); font-size:11.5px;
}
.tbtn .ic{font-size:19px; line-height:1}
.tbtn:hover{background:var(--hover); border-color:var(--line)}
.tbtn:disabled{opacity:.35; cursor:default}
.tbtn:disabled:hover{background:none; border-color:transparent}
.tspacer{flex:1}
.tsearch{display:flex; align-items:center; gap:6px; padding:0 4px}
.tsearch input{
  width:230px; padding:7px 10px; border:1px solid var(--line); border-radius:8px; font-size:12.5px; outline:none;
}
.tsearch input:focus{border-color:var(--accent)}

/* ---------- Cabinet tabs ---------- */
.cabbar{display:flex; align-items:center; gap:4px; padding:5px 12px; background:var(--panel); border-bottom:1px solid var(--line)}
.cabbar .lab{font-weight:600; color:var(--muted); margin-right:6px; font-size:12px}
.cabtab{
  padding:5px 14px; border:1px solid var(--line); border-bottom:none; border-radius:7px 7px 0 0;
  background:var(--bg); cursor:pointer; font-size:12.5px;
}
.cabtab.sel{background:var(--panel); font-weight:600; color:var(--accent); border-color:var(--accent)}
.status{margin-left:auto; color:var(--muted); font-size:11.5px}

/* ---------- Panes ---------- */
.panes{flex:1; display:flex; min-height:0}
.pane{background:var(--panel); border-right:1px solid var(--line); display:flex; flex-direction:column; min-width:0}
.pane-drawers{width:250px; flex-shrink:0}
.pane-folders{width:265px; flex-shrink:0}
.pane-files{flex:1.2}
.pane-preview{flex:1; border-right:none; min-width:280px}
.phead{
  display:flex; align-items:center; gap:8px; padding:8px 12px; border-bottom:1px solid var(--line2);
  font-weight:600; font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:.4px;
}
.phead input{
  flex:1; min-width:0; padding:5px 8px; border:1px solid var(--line); border-radius:6px;
  font-size:12px; outline:none; font-weight:400; text-transform:none; letter-spacing:0;
}
.mini{
  border:1px solid var(--line); background:var(--panel); border-radius:6px; padding:3px 8px;
  cursor:pointer; font-size:12px; font-weight:400; text-transform:none; white-space:nowrap;
}
.mini:hover{border-color:var(--accent); color:var(--accent)}
.plist{flex:1; overflow:auto; padding:4px}

/* Drawer + tree items */
.ditem{
  display:flex; align-items:center; gap:8px; padding:6px 9px; border-radius:6px; cursor:pointer;
  border-bottom:1px solid var(--line2); user-select:none;
}
.ditem:hover{background:var(--hover)}
.ditem.sel{background:var(--sel); font-weight:600}
.ditem .nm{flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
.ditem .fbtns{display:none; flex-shrink:0}
.ditem:hover .fbtns{display:flex}
.ftable th.sortable{cursor:pointer; user-select:none}
.ftable th.sortable:hover{color:var(--accent)}

.titem{display:flex; align-items:center; gap:5px; padding:4px 6px; border-radius:6px; cursor:pointer; user-select:none; white-space:nowrap}
.titem:hover{background:var(--hover)}
.titem.sel{background:var(--sel); font-weight:600}
.titem .tw{width:14px; text-align:center; color:var(--muted); flex-shrink:0; font-size:10px}
.titem .fbtns{display:none; margin-left:auto; flex-shrink:0}
.titem:hover .fbtns{display:flex}
.fcolor{display:inline-flex; align-items:center; cursor:pointer; border-radius:4px; padding:1px; flex-shrink:0}
.fcolor:hover{transform:scale(1.2); background:rgba(0,0,0,.06)}
.titem .nm{overflow:hidden; text-overflow:ellipsis}

/* Files table */
.ftable{width:100%; border-collapse:collapse}
.ftable th{
  text-align:left; font-size:11px; text-transform:uppercase; letter-spacing:.4px; color:var(--muted);
  padding:7px 10px; border-bottom:1px solid var(--line); position:sticky; top:0; background:var(--panel); z-index:1;
}
.ftable td{padding:6px 10px; border-bottom:1px solid var(--line2); white-space:nowrap}
.ftable td.nm{white-space:normal; word-break:break-word; cursor:pointer}
.ftable tr:hover td{background:var(--hover)}
.ftable tr.sel td{background:var(--sel)}
.ftable .sz,.ftable .dt{color:var(--muted); font-size:12px}
.ficon{margin-right:6px}
.fempty{padding:36px 16px; text-align:center; color:var(--muted)}
.droptip{
  margin:8px; padding:10px; border:2px dashed var(--line); border-radius:8px; text-align:center;
  color:var(--muted); font-size:12px;
}
.pane-files.drag .droptip{border-color:var(--accent); color:var(--accent); background:var(--accent-soft)}

/* Preview */
.preview-body{flex:1; display:flex; min-height:0}
.preview-body iframe{flex:1; border:none; width:100%}
.preview-empty{flex:1; display:grid; place-items:center; color:var(--muted); text-align:center; padding:20px}

/* ---------- Modals ---------- */
.overlay{
  position:fixed; inset:0; background:rgba(15,23,42,.45); display:none;
  align-items:center; justify-content:center; z-index:50;
}
.overlay.open{display:flex}
.modal{
  background:var(--panel); border-radius:12px; box-shadow:0 20px 60px rgba(0,0,0,.25);
  width:min(880px, 94vw); max-height:92vh; display:flex; flex-direction:column;
}
.mhead{display:flex; align-items:center; padding:14px 18px; border-bottom:1px solid var(--line); font-weight:600; font-size:15px}
.mhead .x{margin-left:auto; border:none; background:none; font-size:18px; cursor:pointer; color:var(--muted)}
.mbody{padding:16px 18px; overflow:auto}
.mfoot{display:flex; gap:8px; justify-content:flex-end; padding:12px 18px; border-top:1px solid var(--line)}
.btn{
  padding:8px 16px; border-radius:8px; border:1px solid var(--line); background:var(--panel);
  cursor:pointer; font-size:13px;
}
.btn:hover{border-color:var(--accent); color:var(--accent)}
.btn.primary{background:var(--accent); border-color:var(--accent); color:#fff}
.btn.primary:hover{background:#1d4ed8; color:#fff}
.btn.danger{border-color:var(--danger); color:var(--danger)}

/* Organize thumbnails */
.thumbs{display:flex; flex-wrap:wrap; gap:12px}
.thumb{
  width:130px; border:1px solid var(--line); border-radius:8px; padding:6px; text-align:center;
  cursor:grab; background:var(--panel); position:relative;
}
.thumb.dragging{opacity:.4}
.thumb.deleted{opacity:.35; outline:2px solid var(--danger)}
.thumb canvas{width:100%; border:1px solid var(--line2); border-radius:4px; background:#fff}
.thumb .pn{font-size:11px; color:var(--muted); margin-top:4px}
.thumb .tools{display:flex; justify-content:center; gap:4px; margin-top:4px}
.thumb .tools button{border:1px solid var(--line); background:var(--panel); border-radius:5px; cursor:pointer; font-size:12px; padding:2px 7px}
.thumb .tools button:hover{border-color:var(--accent)}

/* Signature */
.sigtabs{display:flex; gap:6px; margin-bottom:12px}
.sigtabs button{padding:6px 14px; border:1px solid var(--line); background:var(--panel); border-radius:7px; cursor:pointer}
.sigtabs button.sel{background:var(--accent-soft); border-color:var(--accent); color:var(--accent); font-weight:600}
#sigPad{border:1px solid var(--line); border-radius:8px; background:#fff; cursor:crosshair; touch-action:none; width:100%}
.sigrow{display:flex; gap:10px; align-items:center; margin-top:10px; flex-wrap:wrap}
.sigrow input[type=text]{flex:1; min-width:180px; padding:8px 10px; border:1px solid var(--line); border-radius:7px; font-size:16px}
#placeWrap{position:relative; display:inline-block; max-width:100%}
#placeCanvas{border:1px solid var(--line); border-radius:6px; max-width:100%; cursor:crosshair; display:block}
#sigGhost{position:absolute; pointer-events:none; opacity:.85; display:none}
.formrow{display:flex; align-items:center; gap:10px; margin:10px 0; flex-wrap:wrap}
.formrow label{color:var(--muted); min-width:90px}
.formrow input[type=text], .formrow input[type=password], .formrow select{
  padding:8px 10px; border:1px solid var(--line); border-radius:7px; flex:1; min-width:160px;
  font-size:13px; height:36px; box-sizing:border-box;
}

/* Move dialog tree reuses .titem */
#moveTree{max-height:50vh; overflow:auto; border:1px solid var(--line2); border-radius:8px; padding:6px}

/* Toasts */
#toasts{position:fixed; bottom:18px; right:18px; display:flex; flex-direction:column; gap:8px; z-index:99}
.toast{
  background:#1c2733; color:#fff; padding:11px 16px; border-radius:9px; font-size:13px;
  box-shadow:0 8px 24px rgba(0,0,0,.25); max-width:380px; animation:tin .2s ease;
}
.toast.err{background:var(--danger)}
.toast.ok{background:var(--ok)}
@keyframes tin{from{transform:translateY(8px); opacity:0}}

/* Search results dropdown */
#searchResults{
  position:absolute; top:100%; right:0; width:420px; max-height:420px; overflow:auto; background:var(--panel);
  border:1px solid var(--line); border-radius:0 0 10px 10px; box-shadow:0 14px 40px rgba(0,0,0,.18); z-index:40; display:none;
}
#searchResults .hit{padding:8px 12px; cursor:pointer; border-bottom:1px solid var(--line2); font-size:12.5px}
#searchResults .hit:hover{background:var(--hover)}
#searchResults .hit .pth{color:var(--muted); font-size:11px}
